· 6 years ago · Nov 23, 2019, 10:40 PM
1/*
2 Current Version: 6.2.0
3 Last updated: 06.17.2016
4 Character Sheet and Script Maintained by: Samuel T.
5 Older Verions: https://github.com/dayst/StarWarsEdgeOfTheEmpire_Dice
6
7 Credits:
8 Original creator: Konrad J.
9 Helped with Dice specs: Alicia G. and Blake the Lake
10 Dice graphics hosted by Alicia G. at galacticcampaigns.com
11 Dice graphics borrowed from the awesome google+ hangouts EotE Dice App
12 Basic Character Sheet and Advanced Dice Roller: Steve Day
13 GM Sheet Campaign Details design inspiration: www.reddit.com/user/JohnSquiggleton
14 Sheet Autocreator: www.reddit.com/user/lowdownfool
15 New Tab Labels: Steve D., GM Knowledge Rhino, and Loki
16 Skill Description by: Gribble - https://dl.dropboxusercontent.com/u/9077657/SW-EotE-Reference-Sheets.pdf
17 Critical Descriptions by: Gribble - https://dl.dropboxusercontent.com/u/9077657/SW-EotE-Reference-Sheets.pdf
18 Debugger: Arron
19 Basic Roll Templates for basic rolls: Josh A.
20 Initiative Roller: Andrew H.
21 Opposed Roller: Tom F.
22 Method to hide depreciated Vehicle Tabs: Phil B.
23 Work done by GM Knowledge Rhino:
24 Group Tab
25 Companion Tab
26 GM Resources
27 Redesign of Vehicle Tab
28 Riding Beast Display
29 Roll Template Code Fixes
30 Roll Templates integrated with all Rolls
31 Overencumbrance roll notification
32 Work done by Samuel T.
33 Versions 4.0.10.0 - Current
34
35 API Chat Commands
36 Settings:
37 Log
38 * default: 'on' and 'single'
39 * Description: Sets the visual output in the chat window for the dice rolls
40 * Command: !eed log on|off|multi|single
41
42 Graphics
43 * default: 'on' and 'm'
44 * Description: Sets chat window dice output as graphic, small, medium, or large if "on" or as text if "off"
45 * Command: !eed graphics on|off|s|m|l
46
47 Test
48 * Description: Output every side of every die to the chat window
49 * !eed test
50
51 Debug
52 * default: 'off'
53 * DescriptionL Sets the logging level of the script in the API console. If you are having issues with the
54 * script rolling incorrectt dice, turn on debug logging and post the result in the forums. No need to restart the
55 * script with this command.
56 * Command: !eed debug on|off
57
58 Roll:
59 Label
60 * default: null
61 * Description: set the skill name of the roll
62 * Command: !eed label(Name of Skill)
63
64 Initiative
65 * default: false
66 * Description: Set NPC/PC initiative true
67 * Command: !eed npcinit or pcinit and #b #g #y #blk #p #r #w
68
69 Skill
70 * default:
71 * Description: create the ability and proficiency dice for a skill check
72 * Command: !eed skill(char_value|skill_value)
73
74 Opposed
75 * default:
76 * Description: create the difficulty and challenge dice for an opposed skill check
77 * Command: !eed opposed(char_value|skill_value|[NPC minion group size]|[Is skill a minion skill])
78
79 Dice
80 * default:
81 * Description: Loop thru the dice and adds or subtracts them from the dice object
82 * Command: !eed #g #y #b #blk #r #p #w #s #a
83
84 Upgrade
85 * default:
86 * Description: upgrades ability and difficulty dice
87 * Command: !eed upgrade(ability|#) or upgrade(difficulty|#)
88
89 Downgrade
90 * default:
91 * Description: downgrades proficiency and challenge dice
92 * Command: !eed downgrade(proficiency|#) or downgrade(challenge|#)
93
94 Destiny
95 * default:
96 * Description: Rolls 1w die and adds the result to the destiny pool
97 * Command: !eed #w destiny doRoll
98
99 Other:
100 Charsheet
101 * default:
102 * Description: Generates a blank character sheet and automatically makes it viewable and editable by the person calling the script.
103 * Command: !charsheet
104 */
105
106/* Begin Sheet Character Sheet Auto Creator */
107var Charsheet = Charsheet || {};
108
109on('chat:message', function (msg) {
110 // Exit if not an api command
111 if (msg.type != "api") {
112 return;
113 }
114 if (msg.content.indexOf('!charsheet') != -1) {
115 Charsheet.Generate(msg);
116 }
117});
118
119Charsheet.Generate = function (msg) {
120 var player = msg.who;
121 var character_name = msg.who + Date.now();
122
123 var character = createObj('character', {
124 name: character_name,
125 inplayerjournals: msg.playerid,
126 controlledby: msg.playerid
127 });
128 /* Create attributes */
129 createObj('attribute', {
130 name: 'player_name',
131 current: player,
132 _characterid: character.id
133 });
134 createObj('attribute', {
135 name: 'name',
136 current: character_name,
137 _characterid: character.id
138 });
139 sendChat("Dice System", "/w " + msg.who + " a blank character sheet was created for you named \"" + character_name);
140 sendChat("GM", "/w " + "gm " + "A blank character sheet was created for " + msg.who)
141};
142
143if (!Date.now) {
144 Date.now = function now() {
145 return new Date().getTime();
146 };
147}
148/* End Sheet Character Sheet Auto Creator */
149
150var eote = {};
151
152eote.init = function () {
153 eote.setCharacterDefaults();
154 eote.createGMDicePool();
155 eote.events();
156 convertTokensToTags();
157 log("Finished converting tokens to tags");
158};
159
160eote.skillSuggestions = {
161 general: {
162 Astrogation: {
163 success: [
164 {
165 text: "Better target for the destination, e.g.: place vessel directly into orbit around target planet.",
166 required: 1
167 },
168 {text: "Reduce time spent calculating.", required: 1}
169 ],
170 advantage: [
171 {text: "Reduce travel time.", required: 1},
172 {text: "Identify convenient stopovers to resupply or conduct additional business.", required: 1}
173 ],
174 triumph: [
175 {text: "Complete calculations in minimum time.", required: 1},
176 {text: "Greatly reduce travel time.", required: 1},
177 {text: "Reveal highly valuable but previously unknown information.", required: 1}
178 ],
179 threat: [
180 {text: "Decrease accuracy of hyperspace jump.", required: 1},
181 {text: "Increase travel time.", required: 1},
182 {text: "Miss relevant details when analyzing hyperspace routes or galactic maps.", required: 1}
183 ],
184 despair: [
185 {text: "Greatly decrease accuracy of hyperspace jump.", required: 1},
186 {text: "Greatly increase travel time.", required: 1},
187 {
188 text: "Miss large amounts of relevant details when analyzing hyperspace routes or galactic maps.",
189 required: 1
190 },
191 {
192 text: "Trigger something truly awful happening, such as jumping out of hyperspace in the path of an asteroid.",
193 required: 1
194 }
195 ]
196 },
197 Athletics: {
198 success: [
199 {text: "Reduce time required.", required: 1},
200 {text: "Increase distance travelled.", required: 1}
201 ],
202 advantage: [
203 {text: "Generate bonus on other physical checks performed later or by allies that turn.", required: 1},
204 {
205 text: "Spend $ADVANTAGE$$ADVANTAGE$ to grant additional maneuver during turn to move or perform physical activity.",
206 required: 2
207 }
208 ],
209 triumph: [
210 {text: "Perform the check with truly impressive results.", required: 1}
211 ],
212 threat: [
213 {text: "Small amounts cause strain.", required: 1},
214 {
215 text: "Larger amounts may cause character to fall prone, or even suffer a wound from sprains and bruises.",
216 required: 1
217 }
218 ],
219 despair: [
220 {
221 text: "Inflict a Critical Injury, which the GM can choose to be thematic or roll randomly.",
222 required: 1
223 }
224 ]
225 },
226 Charm: {
227 success: [
228 {
229 text: "Gain an extra scene in which target is willing to support you for each additional success.",
230 required: 1
231 }
232 ],
233 advantage: [
234 {text: "Affect unexpected subjects beyond the original target.", required: 1}
235 ],
236 triumph: [
237 {text: "Have target NPC become recurring character who remains predisposed to assist.", required: 1}
238 ],
239 threat: [
240 {text: "Reduce the number of people able to influence", required: 1},
241 {text: "Turn those affected negatively against character.", required: 1}
242 ],
243 despair: [
244 {text: "Turn NPC against character and make into a minor recurring adversary.", required: 1}
245 ]
246 },
247 Coercion: {
248 success: [
249 {text: "Spend 2 extra successes to inflict one strain on target. ", required: 2}
250 ],
251 advantage: [
252 {text: "Affect unexpected subjects beyond the original target.", required: 1}
253 ],
254 triumph: [
255 {text: "Shift allegiance of target.", required: 1}
256 ],
257 threat: [
258 {text: "Target has building resentment towards character.", required: 1}
259 ],
260 despair: [
261 {text: "Reveal something about goals and motivations to target.", required: 1}
262 ]
263 },
264 Computers: {
265 success: [
266 {text: "Reduce time required.", required: 1}
267 ],
268 advantage: [
269 {text: "Uncover additional information about the system.", required: 1}
270 ],
271 triumph: [
272 {
273 text: "Obfuscate actions taken add a challenge die to any check to detect or identify the characters actions.",
274 required: 1
275 }
276 ],
277 threat: [
278 {
279 text: "The character does a poor job of concealing his presence in the system. Security systems are alerted, and add a boost die to the check of any NPC attempting to discover evidence of his actions.",
280 required: 1
281 }
282 ],
283 despair: [
284 {
285 text: "Leave behind trace information of your own system in the system being sliced. Add a boost die to the check of any NPC using the target system to slice the character's system.",
286 required: 1
287 }
288 ]
289 },
290 Cool: {
291 success: [
292 {
293 text: "If fear check: The character avoids any fear effects, except those triggered by threats",
294 required: 1
295 }],
296 advantage: [
297 {text: "Gain an additional insight into the situation at hand.", required: 1},
298 {text: "If fear check: Gain a boost die on the character's first check.", required: 1},
299 {
300 text: "If fear check: If spending multiple advantage, grant a boost die to an additional player's first check.",
301 required: 2
302 }
303 ],
304 triumph: [
305 {text: "Heal 3 strain.", required: 1},
306 {
307 text: "If fear check: Can be spent to cancel all previous penalties from fear checks, or",
308 required: 1
309 },
310 {
311 text: "If fear check: Spent to ensure the character need not make any additional fear checks during the encounter, no matter the source.",
312 required: 1
313 }
314 ],
315 failure: [
316 {
317 text: "If fear check: The character adds a setback die to each action he takes during the encounter.",
318 required: 1
319 }
320 ],
321 threat: [
322 {text: "Miss a vital detail or event.", required: 1},
323 {
324 text: "If fear check: The character suffers a number of strain equal to the number of Failures.",
325 required: 1
326 },
327 {
328 text: "If fear check: If the check generates three threat or more, the character can be staggered for his first turn, instead.",
329 required: 3
330 }
331 ],
332 despair: [
333 {text: "The character is overwhelmed by the chaos and is stunned for one round.", required: 1},
334 {
335 text: "If fear check: The character is incredibly frightened and increases the difficulty of all checks until the end of the encounter by one.",
336 required: 1
337 }
338 ]
339 },
340 Coordination: {
341 success: [
342 {text: "Reduce time required.", required: 1},
343 {text: "Increase distance travelled by 25%, (maximum 100% increase).", required: 1}
344 ],
345 advantage: [
346 {text: "Spend 2 advantage to grant additional maneuver during turn.", required: 2}
347 ],
348 triumph: [
349 {text: "Perform the check with truly impressive results.", required: 1}
350 ],
351 threat: [
352 {text: "Lose free maneuver for one round.", required: 1}
353 ],
354 despair: [
355 {text: "Suffer a wound", required: 1},
356 {text: "Lose a vital piece of equipment.", required: 1}
357 ]
358 },
359 Deception: {
360 success: [
361 {text: "Extend duration of Deceit action.", required: 1}
362 ],
363 advantage: [
364 {text: "Increase the value of any goods or services gained through the action.", required: 1}
365 ],
366 triumph: [
367 {
368 text: "Fool the target into believing the character is trustworthy - future Deceit checks against target do not require an opposed check.",
369 required: 1
370 }
371 ],
372 threat: [
373 {text: "Give away a portion of the lie, making target suspicious.", required: 1}
374 ],
375 despair: [
376 {
377 text: "Target realises he has been lied to and spreads word of his deceit to harm his reputation or uses the situation to his advantage.",
378 required: 1
379 }
380 ]
381 },
382 Discipline: {
383 success: [
384 {text: "Downgrade difficulty of the dice pool for next action (max. 1).", required: 1},
385 {
386 text: "If fear check: The character avoids any fear effects, except those triggered by threats",
387 required: 1
388 }
389 ],
390 advantage: [
391 {text: "Gain an additional insight into the situation at hand.", required: 1},
392 {text: "If fear check: Gain a boost die on the character's first check.", required: 1},
393 {
394 text: "If fear check: If spending multiple advantage, grant a boost die to an additional player's first check.",
395 required: 2
396 }
397 ],
398 triumph: [
399 {
400 text: "Add a boost die to any Discipline checks made by allies during the following round.",
401 required: 1
402 },
403 {
404 text: "If fear check: Can be spent to cancel all previous penalties from fear checks, or",
405 required: 1
406 },
407 {
408 text: "If fear check: Spent to ensure the character need not make any additional fear checks during the encounter, no matter the source.",
409 required: 1
410 }
411 ],
412 failure: [
413 {
414 text: "If fear check: The character adds a setback die to each action he takes during the encounter.",
415 required: 1
416 }
417 ],
418 threat: [
419 {
420 text: "Undermine the characters resolve, perhaps inflicting a penalty on further actions in distressing circumstances.",
421 required: 1
422 },
423 {
424 text: "If fear check: The character suffers a number of strain equal to the number of Failures.",
425 required: 1
426 },
427 {
428 text: "If fear check: If the check generates three threat or more, the character can be staggered for his first turn, instead.",
429 required: 3
430 }
431 ],
432 despair: [
433 {
434 text: "The character is overwhelmed entirely and is unable to perform more than one maneuver next round.",
435 required: 1
436 },
437 {
438 text: "If fear check: The character is incredibly frightened and increases the difficulty of all checks until the end of the encounter by one.",
439 required: 1
440 }
441 ]
442 },
443 Leadership: {
444 success: [
445 {text: "Extend target's support for additional scenes.", required: 1},
446 {text: "Increase efficiency or effectiveness of target during ordered actions.", required: 1}
447 ],
448 advantage: [
449 {text: "Affect bystanders in addition to target.", required: 1}
450 ],
451 triumph: [
452 {
453 text: "Have target NPC become recurring character who decides to faithfully follow the acting character.",
454 required: 1
455 }
456 ],
457 threat: [
458 {
459 text: "Decrease the efficiency of ordered actions, causing them to take longer or be done poorly.",
460 required: 1
461 }
462 ],
463 despair: [
464 {
465 text: "Undermine the character's authority, damaging the characters ability to command target or those who witnessed the attempt.",
466 required: 1
467 },
468 {
469 text: "With multiple despair the target may become a recurring thorn in the character's side,refusing future orders or turning others against the character.",
470 required: 2
471 }
472 ]
473 },
474 Mechanics: {
475 success: [
476 {text: "Reduce time required by 10-20%", required: 1}
477 ],
478 advantage: [
479 {
480 text: "Grant a boost die on checks when using repaired item, or even the Superior quality, for a session.",
481 required: 1
482 }
483 ],
484 triumph: [
485 {text: "Give device additional single use function.", required: 1}
486 ],
487 threat: [
488 {
489 text: "Particularly shoddy repairs or temporary measures, the GM may spend threat to cause the target object or system to malfunction shortly after check completed.",
490 required: 1
491 }
492 ],
493 despair: [
494 {text: "Cause further harm to target object or system.", required: 1},
495 {text: "Cause other components of target to malfunction.", required: 1}
496 ]
497 },
498 Medicine: {
499 success: [
500 {text: "Target recovers one additional wound.", required: 1},
501 {text: "Reduce healing time by one hour.", required: 1}
502 ],
503 advantage: [
504 {text: "Eliminate one strain from target.", required: 1}
505 ],
506 triumph: [
507 {text: "Heal additional wounds while attempting to heal Critical Injury, or vice versa.", required: 1}
508 ],
509 threat: [
510 {text: "Inflict strain on the target due to shock of procedure.", required: 1},
511 {text: "Increase time procedure takes.", required: 1}
512 ],
513 despair: [
514 {text: "A truly terrible accident, perhaps inflicting further wounds on target.", required: 1}
515 ]
516 },
517 Negotiation: {
518 success: [
519 {text: "Increase acting character's profit by 5%.", required: 1},
520 {text: "Modify scope of agreement.", required: 1}
521 ],
522 advantage: [
523 {text: "Earn unrelated boons from target, concessions if failed or extra perks if passed.", required: 1}
524 ],
525 triumph: [
526 {text: "Have target NPC become regular client or specialist vendor.", required: 1}
527 ],
528
529 threat: [
530 {text: "Increase cost of goods purchased.", required: 1},
531 {text: "Decrease value of goods sold.", required: 1},
532 {text: "Shorten contracts negotiated.", required: 1}
533 ],
534 despair: [
535 {
536 text: "Seriously sabotage goals during the interaction, perhaps receive counterfeit goods or payment, or agree to terms entirely beyond scope of negotiation.",
537 required: 1
538 }
539 ]
540 },
541 Perception: {
542 success: [
543 {text: "Reveal additional details.", required: 1}
544 ],
545 advantage: [
546 {text: "Recall additional information associated with object noticed.", required: 1}
547 ],
548 triumph: [
549 {
550 text: "Notice details that can be useful later to gain a boost die on future interactions with noticed object.",
551 required: 1
552 }
553 ],
554 threat: [
555 {text: "Conceal a vital detail about situation or environment.", required: 1}
556 ],
557 despair: [
558 {text: "Obtain false information about surroundings or target.", required: 1}
559 ]
560 },
561 PilotingPlanetary: {
562 success: [
563 {text: "Gain insights into situation.", required: 1},
564 {text: "Deduce way to modify vehicle to make it more effective in future.", required: 1}
565 ],
566 advantage: [
567 {
568 text: "Reveal vulnerability in opponent's piloting style or vehicle, giving benefit in later rounds.",
569 required: 1
570 }
571 ],
572 triumph: [
573 {text: "Grant additional maneuver while continuing to pilot vehicle.", required: 1}
574 ],
575 threat: [
576 {
577 text: "Spend $THREAT$$THREAT$ to give opponents a boost die on checks against character and vehicle due to momentary malfunction in system.",
578 required: 2
579 }
580 ],
581 despair: [
582 {
583 text: "Deal damage to vehicle as character strains systems throughout vehicle during check.",
584 required: 1
585 }
586 ]
587 },
588 PilotingSpace: {
589 success: [
590 {text: "Gain insights into situation.", required: 1},
591 {text: "Deduce way to modify vehicle to make it more effective in future.", required: 1}
592 ],
593 advantage: [
594 {
595 text: "Reveal vulnerability in opponent's piloting style or vehicle, giving benefit in later rounds.",
596 required: 1
597 }
598 ],
599 triumph: [
600 {text: "Grant additional maneuver while continuing to pilot vehicle.", required: 1}
601 ],
602 threat: [
603 {
604 text: "Spend $THREAT$$THREAT$ to give opponents a boost die on checks against character and vehicle due to momentary malfunction in system.",
605 required: 2
606 }
607 ],
608 despair: [
609 {
610 text: "Deal damage to vehicle as character strains systems throughout vehicle during check.",
611 required: 1
612 }
613 ]
614 },
615 Resilience: {
616 success: [
617 {text: "Extend effects of the success to increase time between checks.", required: 1}
618 ],
619 advantage: [
620 {text: "Identify way to reduce difficulty of future checks against same threat.", required: 1}
621 ],
622 triumph: [
623 {text: "Recover 3 strain.", required: 1}
624 ],
625 threat: [
626 {text: "Overburden the character, inflicting penalties on subsequent checks.", required: 1}
627 ],
628 despair: [
629 {
630 text: "Inflict a wound or minor Critical Injury on character, as they succumb to harsh conditions.",
631 required: 1
632 }
633 ]
634 },
635 Skulduggery: {
636 success: [
637 {text: "Gain additional insights about nature of opposition.", required: 1}
638 ],
639 advantage: [
640 {text: "Identify additional potential target.", required: 1}
641 ],
642 triumph: [
643 {text: "Earn an unexpected boon.", required: 1}
644 ],
645 threat: [
646 {
647 text: "Opportunity to catch character immediately after act, number of threats determine immediacy of discovery and ensuing danger.",
648 required: 1
649 }
650 ],
651 despair: [
652 {text: "Leave behind evidence of larceny.", required: 1}
653 ]
654 },
655 Stealth: {
656 success: [
657 {text: "Assist allied character infiltrating at same time.", required: 1}
658 ],
659 advantage: [
660 {text: "Decrease time taken to perform action while hidden.", required: 1}
661 ],
662 triumph: [
663 {text: "Identify way to completely distract opponent for duration of scene.", required: 1}
664 ],
665 threat: [
666 {text: "Increase time taken to perform action while hidden by 20%.", required: 1}
667 ],
668 despair: [
669 {text: "Leave behind evidence of passing, concerning identity and possibly motive.", required: 1}
670 ]
671 },
672 Streetwise: {
673 success: [
674 {text: "Reduce time or funds required to obtain item, information or service.", required: 1}
675 ],
676 advantage: [
677 {text: "Reveal additional rumours or alternative sources.", required: 1}
678 ],
679 triumph: [
680 {text: "Gain semi-permanent contact on street.", required: 1}
681 ],
682 threat: [
683 {text: "Seed gathered information with minor falsehoods.", required: 1}
684 ],
685 despair: [
686 {text: "Character lets slip details about self or information sought.", required: 1}
687 ]
688 },
689 Survival: {
690 success: [
691 {text: "Assist other character in surviving.", required: 1},
692 {text: "Stockpile goods to increase time between checks.", required: 1}
693 ],
694 advantage: [
695 {text: "Gain insight into environment to make future checks simpler.", required: 1},
696 {
697 text: "When tracking, learn significant detail about target, such as number, species or how recently tracks were made.",
698 required: 1
699 }
700 ],
701 triumph: [
702 {
703 text: "When handling domesticated animal, predispose animal towards character earning loyal companion.",
704 required: 1
705 },
706 {text: "When tracking, learn vital clue about target.", required: 1}
707 ],
708 threat: [
709 {text: "Spend vital resources (food, fuel, etc.) during check.", required: 1}
710 ],
711 despair: [
712 {text: "Inflict wounds, Critical Injuries or large amounts of strain on character.", required: 1}
713 ]
714 },
715 Vigilance: {
716 success: [
717 {text: "Character is particularly well prepared.", required: 1}
718 ],
719 advantage: [
720 {text: "Notice key environmental factor.", required: 1}
721 ],
722 triumph: [
723 {text: "Gain extra maneuver during first round of combat.", required: 1}
724 ],
725 threat: [
726 {text: "Miss key piece of information about situation or environment.", required: 1}
727 ],
728 despair: [
729 {
730 text: "The character is unable to perform more than one maneuver during first round of combat.",
731 required: 1
732 }
733 ]
734 }
735 }
736};
737
738eote.defaults = {
739 globalVars: {
740 diceLogChat: true,
741 diceGraphicsChat: true,
742 diceGraphicsChatSize: 30,//medium size
743 diceTextResult: "",
744 diceTextResultLog: "",
745 diceGraphicResult: "",
746 diceGraphicResultLog: "",
747 diceTestEnabled: false,
748 diceLogRolledOnOneLine: true,
749 scriptDebug: false
750 },
751 '-DicePoolID': '',
752 character: {
753 attributes: [
754 /* Don't need to update characterID
755 *
756 *{
757 name : "characterID",
758 current : "UPDATES TO CURRENT ID",
759 max : "",
760 update : false
761 }*/
762 ],
763 abilities: []
764 },
765 graphics: {
766 SIZE: {
767 SMALL: 20,
768 MEDIUM: 30,
769 LARGE: 40
770 },
771 ABILITY: {
772 BLANK: "http://i.imgur.com/X79LrVi.png",
773 A: "http://i.imgur.com/NsRABfB.png",
774 AA: "http://i.imgur.com/1JC2CKz.png",
775 S: "http://i.imgur.com/e7x6XMK.png",
776 SA: "http://i.imgur.com/zZHRNLg.png",
777 SS: "http://i.imgur.com/uYUCq6H.png"
778 },
779 BOOST: {
780 BLANK: "http://i.imgur.com/TXPJeM0.png",
781 A: "http://i.imgur.com/RPcuZOW.png",
782 AA: "http://i.imgur.com/ginyiWi.png",
783 S: "http://i.imgur.com/oCjW2ht.png",
784 SA: "http://i.imgur.com/CplkDUT.png"
785 },
786 CHALLENGE: {
787 BLANK: "http://i.imgur.com/Gmr2Fpv.png",
788 F: "http://i.imgur.com/dxi40gd.png",
789 FF: "http://i.imgur.com/NroPqEm.png",
790 FT: "http://i.imgur.com/yOkULBB.png",
791 T: "http://i.imgur.com/j8l5MbS.png",
792 TT: "http://i.imgur.com/Fhs4eRF.png",
793 DESPAIR: "http://i.imgur.com/Fjht2ak.png"
794 },
795 DIFFICULTY: {
796 BLANK: "http://i.imgur.com/G23emVy.png",
797 F: "http://i.imgur.com/GddUHRX.png",
798 FF: "http://i.imgur.com/uqdcqdA.png",
799 FT: "http://i.imgur.com/qe9ukJp.png",
800 T: "http://i.imgur.com/ANvLBk6.png",
801 TT: "http://i.imgur.com/17WkR3h.png"
802 },
803 FORCE: {
804 D: "http://i.imgur.com/INzXWN0.png",
805 DD: "http://i.imgur.com/V1vUv1h.png",
806 L: "http://i.imgur.com/K1eq002.png",
807 LL: "http://i.imgur.com/GwfRxWL.png"
808 },
809 PROFICIENCY: {
810 BLANK: "http://i.imgur.com/ZxQtqOM.png",
811 A: "http://i.imgur.com/FoTa8mn.png",
812 S: "http://i.imgur.com/n67KZrH.png",
813 SA: "http://i.imgur.com/p0K4d8B.png",
814 SS: "http://i.imgur.com/SVgzm7a.png",
815 AA: "http://i.imgur.com/HQGapl1.png",
816 TRIUMPH: "http://i.imgur.com/zPtkgeh.png"
817 },
818 SETBACK: {
819 BLANK: "http://i.imgur.com/WzvXpUr.png",
820 F: "http://i.imgur.com/cXwXuFb.png",
821 T: "http://i.imgur.com/QC0c5ym.png"
822 },
823 SYMBOLS: {
824 A: "http://i.imgur.com/BVYw9aM.png",
825 S: "http://i.imgur.com/uGLwBcq.png",
826 T: "http://i.imgur.com/ejwfSM4.png",
827 F: "http://i.imgur.com/DTuRGR4.png",
828 TRIUMPH: "http://i.imgur.com/G1ZNK8G.png",
829 DESPAIR: "http://i.imgur.com/YX5DEix.jpg",
830 L: "http://i.imgur.com/TsDwb2K.png",
831 D: "http://i.imgur.com/sxswtG0.png"
832 },
833 SymbolicReplacement: {}
834 },
835 regex: {
836 cmd: /!eed/,
837 log: /log (on|multi|single|off)/,
838 debug: /debug (on|off)/,
839 graphics: /graphics (on|off|s|m|l)/,
840 test: /test/,
841 resetdice: /(resetgmdice|resetdice)/,
842 initiative: /\bnpcinit|\bpcinit/,
843 characterID: /characterID\((.*?)\)/,
844 rollPlayer: /rollPlayer(\(.*?\))/,
845 label: /label\((.*?)\)/,
846 skill: /skill\((.*?)\)/g,
847 opposed: /opposed\((.*?)\)/g,
848 upgrade: /upgrade\((.*?)\)/g,
849 downgrade: /downgrade\((.*?)\)/g,
850 gmdice: /\(gmdice\)/,
851 encum: /encum\((.*?)\)/g,
852 dice: /(-?\d{1,2}blk)\b|(-?\d{1,2}b)\b|(-?\d{1,2}g)\b|(-?\d{1,2}y)\b|(-?\d{1,2}p)\b|(-?\d{1,2}r)\b|(-?\d{1,2}w)\b|(-?\d{1,2}a)\b|(-?\d{1,2}s)|(-?\d{1,2}t)\b|(-?\d{1,2}f)/g,
853 crit: /crit\((.*?)\)/,
854 critShip: /critship\((.*?)\)/,
855 unusable: /unusableWeapon/,
856 destiny: /destiny (useDark|useLight|registerPlayer|sendUpdate|doRoll|clearPool)/
857 },
858 destinyListeners: []
859};
860
861eote.defaults.graphics.SymbolicReplacement.success = {matcher:/\$SUCCESS\$/g, replacer:"<img src=\"" + eote.defaults.graphics.SYMBOLS.S + "\" title=\"success\" height=\"" + eote.defaults.graphics.SIZE.SMALL + "\" width=\"" + eote.defaults.graphics.SIZE.SMALL + "\"/>"};
862eote.defaults.graphics.SymbolicReplacement.advantage = {matcher:/\$ADVANTAGE\$/g, replacer:"<img src=\"" + eote.defaults.graphics.SYMBOLS.A + "\" title=\"advantage\" height=\"" + eote.defaults.graphics.SIZE.SMALL + "\" width=\"" + eote.defaults.graphics.SIZE.SMALL + "\"/>"};
863eote.defaults.graphics.SymbolicReplacement.triumph = {matcher:/\$TRIUMPH\$/g, replacer:"<img src=\"" + eote.defaults.graphics.SYMBOLS.TRIUMPH + "\" title=\"triumph\" height=\"" + eote.defaults.graphics.SIZE.SMALL + "\" width=\"" + eote.defaults.graphics.SIZE.SMALL + "\"/>"};
864eote.defaults.graphics.SymbolicReplacement.failure = {matcher:/\$FAILURE\$/g, replacer:"<img src=\"" + eote.defaults.graphics.SYMBOLS.F + "\" title=\"failure\" height=\"" + eote.defaults.graphics.SIZE.SMALL + "\" width=\"" + eote.defaults.graphics.SIZE.SMALL + "\"/>"};
865eote.defaults.graphics.SymbolicReplacement.threat = {matcher:/\$THREAT\$/g, replacer:"<img src=\"" + eote.defaults.graphics.SYMBOLS.T + "\" title=\"threat\" height=\"" + eote.defaults.graphics.SIZE.SMALL + "\" width=\"" + eote.defaults.graphics.SIZE.SMALL + "\"/>"};
866eote.defaults.graphics.SymbolicReplacement.despair = {matcher:/\$DESPAIR\$/g, replacer:"<img src=\"" + eote.defaults.graphics.SYMBOLS.DESPAIR + "\" title=\"despair\" height=\"" + eote.defaults.graphics.SIZE.SMALL + "\" width=\"" + eote.defaults.graphics.SIZE.SMALL + "\"/>"};
867
868eote.createGMDicePool = function () {
869
870 var charObj_DicePool = findObjs({ _type: "character", name: "-DicePool" })[0];
871 var attrObj_DicePool = [
872 {
873 name: 'pcgm',
874 current: 3,
875 max: '',
876 update: true
877 },
878 {
879 name: 'gmdicepool',
880 current: 2,
881 max: '',
882 update: true
883 }
884 ];
885 //create character -DicePool
886 if (!charObj_DicePool) {
887 charObj_DicePool = createObj("character", {
888 name: "-DicePool",
889 bio: "GM Dice Pool"
890 });
891 }
892 eote.defaults['-DicePoolID'] = charObj_DicePool.id;
893 eote.updateAddAttribute(charObj_DicePool, attrObj_DicePool);
894};
895
896eote.createObj = function () {//Create Object Fix - Firebase.set failed
897 var obj = createObj.apply(this, arguments);
898 var id = obj.id;
899 var characterID = obj.get('characterid');
900 var type = obj.get('type');
901 if (obj && !obj.fbpath && obj.changed) {
902 obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/");
903 } else if (obj && !obj.changed && type == 'attribute') { //fix for dynamic attribute after in character created in game
904 obj.fbpath = '/char-attribs/char/' + characterID + '/' + id;
905 // /char-attribs/char/characterID/attributeID
906 }
907 return obj;
908};
909
910eote.setCharacterDefaults = function (characterObj) {
911
912 var charObj = [characterObj];
913
914 if (!characterObj) {
915 charObj = findObjs({ _type: "character" });
916 }
917 //add/update characterID field
918 _.each(charObj, function (charObj) {
919 //updates default attr:CharacterID to current character id
920 //_.findWhere(eote.defaults.character.attributes, {'name':'characterID'}).current = charObj.id;
921
922 //Attributes
923 eote.updateAddAttribute(charObj, eote.defaults.character.attributes);//Update Add Attribute defaults
924 //Abilities
925 });
926};
927
928eote.updateListeners = function (attributes) {
929
930 _.each(eote.defaults.destinyListeners, function (charID) {
931
932 var charObj = findObjs({
933 _type: "character",
934 _id: charID
935 });
936 //add/update characterID feild
937 _.each(charObj, function (charObj) {
938 //Attributes
939 eote.updateAddAttribute(charObj, attributes); //Update Add Attribute defaults
940 });
941 });
942 //Update GM
943 var GMObj = findObjs({
944 _type: "character",
945 _id: eote.defaults['-DicePoolID']
946 });
947 eote.updateAddAttribute(GMObj, attributes);
948};
949
950eote.updateAddAttribute = function (charactersObj, updateAddAttributesObj) { // charactersObj = object or array objects, updateAddAttributesObj = object or array objects
951
952 //check if object or array
953 if (!_.isArray(charactersObj)) {
954 charactersObj = [charactersObj];
955 }
956 if (!_.isArray(updateAddAttributesObj)) {
957 updateAddAttributesObj = [updateAddAttributesObj];
958 }
959 _.each(charactersObj, function (characterObj) {//loop characters
960
961 var characterName = '';
962
963 if (characterObj.name) {
964 characterName = characterObj.name;
965 } else {
966 characterName = characterObj.get('name');
967 }
968 //find attribute via character ID
969 var characterAttributesObj = findObjs({ _type: "attribute", characterid: characterObj.id });
970
971 if (updateAddAttributesObj.length != 0) {
972
973 log('UPDATE/ADD ATTRIBUTES FOR:----------------------->' + characterName);
974
975 _.each(updateAddAttributesObj, function (updateAddAttrObj) { //loop attributes to update / add
976
977 attr = _.find(characterAttributesObj, function (a) {
978 return (a.get('name') === updateAddAttrObj.name);
979 });
980 if (attr) {
981 if (updateAddAttrObj.update) {
982 log('Update Attr: ' + updateAddAttrObj.name);
983 attr.set({ current: updateAddAttrObj.current });
984 attr.set({ max: updateAddAttrObj.max ? updateAddAttrObj.max : '' });
985 }
986 } else {
987 // log('Add Attr: '+ updateAddAttrObj.name);
988 eote.createObj('attribute', {
989 characterid: characterObj.id,
990 name: updateAddAttrObj.name,
991 current: updateAddAttrObj.current,
992 max: updateAddAttrObj.max ? updateAddAttrObj.max : ''
993 });
994 }
995 });
996 }
997 });
998};
999
1000/* DICE PROCESS
1001 *
1002 * Matches the different regex commands and runs that dice processing step
1003 * The order of step should not be change or dice could be incorrectly rolled.
1004 * example: All dice needs to be 'upgraded" before it can be 'downgraded'
1005 * ---------------------------------------------------------------- */
1006
1007eote.defaults.dice = function () {
1008 this.vars = {
1009 characterName: '',
1010 characterID: '',
1011 playerName: '',
1012 playerID: '',
1013 label: '',
1014 spendingSuggestions: {},
1015 skillName: ''
1016 };
1017 this.totals = {
1018 success: 0,
1019 failure: 0,
1020 advantage: 0,
1021 threat: 0,
1022 triumph: 0,
1023 despair: 0,
1024 light: 0,
1025 dark: 0
1026 };
1027 this.graphicsLog = {
1028 Boost: '',
1029 Ability: '',
1030 Proficiency: '',
1031 SetBack: '',
1032 Difficulty: '',
1033 Challenge: '',
1034 Force: '',
1035 Success: '',
1036 Advantage: '',
1037 Threat: '',
1038 Failure: ''
1039 };
1040 this.textLog = {
1041 Boost: '',
1042 Ability: '',
1043 Proficiency: '',
1044 SetBack: '',
1045 Difficulty: '',
1046 Challenge: '',
1047 Force: '',
1048 Success: '',
1049 Advantage: '',
1050 Threat: '',
1051 Failure: ''
1052 };
1053 this.count = {
1054 boost: 0,
1055 ability: 0,
1056 proficiency: 0,
1057 setback: 0,
1058 difficulty: 0,
1059 challenge: 0,
1060 force: 0,
1061 success: 0,
1062 advantage: 0,
1063 threat: 0,
1064 failure: 0
1065 }
1066};
1067
1068eote.process = {};
1069eote.process.skillSpending = {};
1070
1071eote.process.logger = function (functionName, cmd) {
1072 if (eote.defaults.globalVars.debugScript) {
1073 log(functionName + ' : ' + cmd);
1074 }
1075};
1076
1077eote.process.setup = function (cmd, playerName, playerID) {
1078
1079 if (!cmd.match(eote.defaults.regex.cmd)) { //check for api cmd !eed
1080 return false;
1081 }
1082 var debugMatch = cmd.match(eote.defaults.regex.debug);
1083 if (debugMatch) {
1084 eote.process.debug(debugMatch);
1085 return false;
1086 }
1087 eote.process.logger("eote.process.setup", "NEW ROLL");
1088 eote.process.logger("eote.process.setup", "Original Command: " + cmd);
1089
1090 /* reset dice - test, might not need this */
1091 var diceObj = new eote.defaults.dice();
1092 diceObj.vars.playerName = playerName;
1093 diceObj.vars.playerID = playerID;
1094
1095 /* Dice config
1096 * Description: Change dice roller default config
1097 * --------------------------------------------------------------*/
1098 var logMatch = cmd.match(eote.defaults.regex.log);
1099
1100 if (logMatch) {
1101 eote.process.log(logMatch);
1102 return false; //Stop current roll and run test
1103 }
1104 var graphicsMatch = cmd.match(eote.defaults.regex.graphics);
1105
1106 if (graphicsMatch) {
1107 eote.process.graphics(graphicsMatch);
1108 return false; //Stop current roll and run test
1109 }
1110 var testMatch = cmd.match(eote.defaults.regex.test);
1111
1112 if (testMatch) {
1113 eote.process.test(testMatch);
1114 return false; //Stop current roll and run test
1115 }
1116 /* Roll information
1117 * Description: Set default dice roll information Character Name and Skill Label
1118 * --------------------------------------------------------------*/
1119
1120 var rollPlayerMatch = cmd.match(eote.defaults.regex.rollPlayer);
1121
1122 if (rollPlayerMatch) {
1123 diceObj = eote.process.rollPlayer(rollPlayerMatch, diceObj);
1124
1125 if (!diceObj) {
1126 return false;
1127 }
1128 }
1129 var characterIDMatch = cmd.match(eote.defaults.regex.characterID);
1130
1131 if (characterIDMatch) {
1132 diceObj = eote.process.characterID(characterIDMatch, diceObj);
1133 //Once Character ID is parsed, remove it from the cmd.
1134 //it is possible that the character ID could contain dice values
1135 //for ex. characterID(-JMBFmYX1i0L259bjb-X) will add 59 blue dice to the pool
1136 cmd = cmd.replace(characterIDMatch[0], '');
1137 eote.process.logger("eote.process.setup.characterIDMatch", "New command: " + cmd);
1138 }
1139 var unusableMatch = cmd.match(eote.defaults.regex.unusable);
1140
1141 if (unusableMatch) {
1142 eote.process.logger("eote.process.setup.unusableMatch", "Roll ended because of unusable weapon");
1143 sendChat(diceObj.vars.characterName, "&{template:base} {{title=" + diceObj.vars.characterName + "}} {{wide=Weapon is too damaged to be used. Try repairing it.}}");
1144 return false;
1145 }
1146 var labelMatch = cmd.match(eote.defaults.regex.label);
1147
1148 if (labelMatch) {
1149 diceObj = eote.process.label(labelMatch, diceObj);
1150 }
1151 /* Dice rolls
1152 * Description: Create dice pool before running any custom roll
1153 * script commands that may need dice evaluated.
1154 * --------------------------------------------------------------*/
1155 var gmdiceMatch = cmd.match(eote.defaults.regex.gmdice);
1156
1157 if (gmdiceMatch) {
1158 cmd = eote.process.gmdice(cmd); // update the cmd string to contain the gmdice
1159 eote.process.logger("eote.process.setup.gmDice", "New command: " + cmd);
1160 }
1161 var encumMatch = cmd.match(eote.defaults.regex.encum);
1162
1163 if (encumMatch) {
1164 diceObj = eote.process.encum(encumMatch, diceObj);
1165 //eote.process.logger("eote.process.setup.encumMatch","New dice:" + diceObj);
1166 }
1167 var skillMatch = cmd.match(eote.defaults.regex.skill);
1168
1169 if (skillMatch) {
1170 diceObj = eote.process.skill(skillMatch, diceObj);
1171 }
1172 var opposedMatch = cmd.match(eote.defaults.regex.opposed);
1173
1174 if (opposedMatch) {
1175 diceObj = eote.process.opposed(opposedMatch, diceObj);
1176 }
1177 var diceMatch = cmd.match(eote.defaults.regex.dice);
1178
1179 if (diceMatch) {
1180 diceObj = eote.process.setDice(diceMatch, diceObj);
1181 }
1182 var upgradeMatch = cmd.match(eote.defaults.regex.upgrade);
1183
1184 if (upgradeMatch) {
1185 diceObj = eote.process.upgrade(upgradeMatch, diceObj);
1186 }
1187 var downgradeMatch = cmd.match(eote.defaults.regex.downgrade);
1188
1189 if (downgradeMatch) {
1190 diceObj = eote.process.downgrade(downgradeMatch, diceObj);
1191 }
1192 /* Roll dice and update success / fail
1193 * ------------------------------------------------------------- */
1194 diceObj = eote.process.rollDice(diceObj);
1195
1196 // process and display skill suggestions
1197 if (diceObj.vars.skillName != null) {
1198 diceObj = eote.process.skillSpending.processSuggestions(diceObj);
1199 }
1200
1201 /* Custom rolls
1202 * Description: Custom dice components have their own message, results and
1203 * often will return false to not allow proceeding scripts to fire
1204 * --------------------------------------------------------------*/
1205 var resetdiceMatch = cmd.match(eote.defaults.regex.resetdice);
1206
1207 if (resetdiceMatch) {
1208 eote.process.resetdice(resetdiceMatch, diceObj);
1209 return false;
1210 }
1211 var initiativeMatch = cmd.match(eote.defaults.regex.initiative);
1212
1213 if (initiativeMatch) {
1214 eote.process.initiative(initiativeMatch, diceObj);
1215 //return false;
1216 }
1217 var destinyMatch = cmd.match(eote.defaults.regex.destiny);
1218
1219 if (destinyMatch) {
1220 eote.process.logger("etoe.process.setup.destiny", "Destiny Point Command");
1221 var doRoll = eote.process.destiny(destinyMatch, diceObj);
1222 if (!doRoll) {
1223 return false;
1224 }
1225 }
1226 var critMatch = cmd.match(eote.defaults.regex.crit);
1227
1228 if (critMatch) {
1229 eote.process.crit(critMatch, diceObj);
1230 return false;
1231 }
1232 var critShipMatch = cmd.match(eote.defaults.regex.critShip);
1233
1234 if (critShipMatch) {
1235 eote.process.critShip(critShipMatch, diceObj);
1236 return false;
1237 }
1238 /* Display dice output in chat window
1239 * ------------------------------------------------------------- */
1240 eote.process.diceOutput(diceObj, playerName, playerID);
1241};
1242
1243/* DICE PROCESS FUNCTION
1244 *
1245 * ---------------------------------------------------------------- */
1246
1247
1248eote.process.skillSpending.processSuggestions = function(diceObj) {
1249 diceObj.vars.spendingSuggestions = {
1250 success: "",
1251 advantage: "",
1252 triumph: "",
1253 failure: "",
1254 threat: "",
1255 despair: "",
1256 isSuggestions: false
1257 };
1258
1259 var skillSpending = eote.process.skillSpending.getSkillSuggestion;
1260 var spendingSuggestions = diceObj.vars.spendingSuggestions;
1261 Object.keys(diceObj.totals).forEach(function(key) {
1262 var value = diceObj.totals[key];
1263 if (value > 0) {
1264 diceObj = skillSpending(diceObj, key, value, 0);
1265 }
1266 });
1267
1268 return diceObj;
1269};
1270
1271eote.process.skillSpending.getSkillSuggestion = function(diceObj, key, value, skillType) {
1272 var skillName = diceObj.vars.skillName;
1273 switch (skillType) {
1274 case 0:
1275 var generalSkills = eote.skillSuggestions.general;
1276 if (generalSkills.hasOwnProperty(skillName)) {
1277 var skill = generalSkills[skillName];
1278 if (skill.hasOwnProperty(key)) {
1279 var skillJSON = skill[key];
1280 for (var i = 0; i < skillJSON.length; i++) {
1281 if (skillJSON[i].required <= value) {
1282 diceObj.vars.spendingSuggestions[key] += "<li>" + skillJSON[i].text + "</li>";
1283 diceObj.vars.spendingSuggestions.isSuggestions = true;
1284 }
1285 }
1286 }
1287 }
1288 break;
1289 default:
1290 // this should never be entered
1291 sendChat("System", "No skill group associated with skill: " + skillName);
1292 }
1293 return diceObj;
1294};
1295
1296/*TODO buildSuggestions*/
1297eote.process.skillSpending.buildSuggestions = function (diceObj) {
1298 var suggestions = diceObj.vars.spendingSuggestions;
1299 var msg = "";
1300
1301 // display results shown to character owners and GM
1302 Object.keys(suggestions).forEach(function (key) {
1303 property = suggestions[key];
1304 if (property != "" && key != "isSuggestions") {
1305 msg += "{{" + key + "=<ul>" + property + "</ul>}}";
1306 }
1307 });
1308 msg = "{{is_suggestions=true}} " + msg;
1309 return msg;
1310};
1311
1312eote.process.log = function (cmd) {
1313
1314 /* Log
1315 * default: 'on' and 'single'
1316 * Description: Sets the visual output in the chat window for the dice rolls
1317 * Command: !eed log on|off|multi|single
1318 * ---------------------------------------------------------------- */
1319
1320 //log(cmd[1]);
1321 switch (cmd[1]) {
1322 case "on": //if 'on' outputs dice to chat window
1323 eote.defaults.globalVars.diceLogChat = true;
1324 sendChat("Dice System", 'Output rolled dice to chat window "On"');
1325 break;
1326 case "off": //if 'off' outputs only results to chat window
1327 eote.defaults.globalVars.diceLogChat = false;
1328 sendChat("Dice System", 'Output rolled dice to chat window "Off"');
1329 break;
1330 case "multi": //if 'multi' multiple sets dice per line
1331 eote.defaults.globalVars.diceLogRolledOnOneLine = false;
1332 sendChat("Dice System", 'Multiple line output "Off". NOTE: This setting can cause issues with the Roll Templates. Recommended setting is !eed log single');
1333 break;
1334 case "single": //if 'single' single set of dice per line
1335 eote.defaults.globalVars.diceLogRolledOnOneLine = true;
1336 sendChat("Dice System", 'Multiple line output "On"');
1337 break;
1338 }
1339};
1340
1341eote.process.debug = function (cmd) {
1342 switch (cmd[1]) {
1343 case "on":
1344 eote.defaults.globalVars.debugScript = true;
1345 sendChat("Dice System", 'Debug Script "On"');
1346 break;
1347 case "off":
1348 eote.defaults.globalVars.debugScript = false;
1349 sendChat("Dice System", 'Debug Script "Off"');
1350 break;
1351 }
1352};
1353
1354eote.process.graphics = function (cmd) {
1355
1356 /* Graphics
1357 * default: 'on' and 'm'
1358 * Description: Sets chat window dice output as graphic, small, medium, or large if "on" or as text if "off"
1359 * Command: !eed graphics on|off|s|m|l
1360 * ---------------------------------------------------------------- */
1361
1362 //log(cmd[1]);
1363 switch (cmd[1]) {
1364 case "on":
1365 eote.defaults.globalVars.diceGraphicsChat = true;
1366 sendChat("Dice System", 'Chat graphics "On"');
1367 break;
1368 case "off":
1369 eote.defaults.globalVars.diceGraphicsChat = false;
1370 sendChat("Dice System", 'Chat graphics "Off"');
1371 break;
1372 case "s":
1373 eote.defaults.globalVars.diceGraphicsChatSize = eote.defaults.graphics.SIZE.SMALL;
1374 sendChat("Dice System", 'Chat graphics size "Small"');
1375 break;
1376 case "m":
1377 eote.defaults.globalVars.diceGraphicsChatSize = eote.defaults.graphics.SIZE.MEDIUM;
1378 sendChat("Dice System", 'Chat graphics size "Medium"');
1379 break;
1380 case "l":
1381 eote.defaults.globalVars.diceGraphicsChatSize = eote.defaults.graphics.SIZE.LARGE;
1382 sendChat("Dice System", 'Chat graphics size "Large"');
1383 break;
1384 }
1385};
1386
1387eote.process.test = function (cmd) {
1388
1389 eote.process.logger("eote.process.test", cmd);
1390
1391 //Set test vars to true
1392 eote.defaults.globalVars.diceTestEnabled = true;
1393 tmpLogChat = eote.defaults.globalVars.diceLogChat;
1394 tmpGraphicsChat = eote.defaults.globalVars.diceGraphicsChat;
1395 eote.defaults.globalVars.diceLogChat = true;
1396 eote.defaults.globalVars.diceGraphicsChat = true;
1397
1398 //Roll dice
1399 eote.process.setup('!eed 1b 1g 1y 1blk 1p 1r 1w', 'GM', 'Dice Test');
1400
1401 //After test reset vars back
1402 eote.defaults.globalVars.diceTestEnabled = false;
1403 eote.defaults.globalVars.diceLogChat = tmpLogChat;
1404 eote.defaults.globalVars.diceGraphicsChat = tmpGraphicsChat;
1405};
1406
1407eote.process.rollPlayer = function (cmd, diceObj) {
1408 //Build cmd string
1409 //get characterID
1410 //get skills
1411 //get encum
1412 //remove rollPlayer(xxxx) from string
1413 var match = {
1414 skill: /skill:(.*?)[\|\)]/,
1415 encum: /encum/,
1416 character: /character:(.*?)[\|\)]/
1417 };
1418 var characterMatch = cmd[1].match(match.character);
1419
1420 var companion = null;
1421 var character = null;
1422 if (characterMatch) {
1423 var charObj = findObjs({ _type: "character", name: characterMatch[1] });
1424
1425 if (charObj.length > 0) {
1426 diceObj.vars.characterName = charObj[0].get('name');
1427 diceObj.vars.characterID = charObj[0].id;
1428 }
1429 else {
1430 sendChat("Alert", "Can't find character. Please update character, or npc, name field to match sheet character name and try again.");
1431 return false;
1432 }
1433 }
1434 else {
1435 sendChat("Alert", "Please update character, or npc, name field.");
1436 return false;
1437 }
1438 var encumMatch = cmd[1].match(match.encum);
1439 var attr_1 = null;
1440 var attr_2 = null;
1441 if (encumMatch) {
1442 //encumbrance
1443 attr_1 = getAttrByName(diceObj.vars.characterID, 'encumbrance', 'max');
1444 attr_2 = getAttrByName(diceObj.vars.characterID, 'encumbrance');
1445 var cmdEncum = ['encum(' + attr_1 + '|' + attr_2 + ')']; //["encum(3|5)"]
1446
1447 diceObj = eote.process.encum(cmdEncum, diceObj);
1448 }
1449 var skillMatch = cmd[1].match(match.skill);
1450 if (eote.defaults.globalVars.debugScript) sendChat("Alert", "skillmatch=" + skillMatch.toString());
1451
1452 if (skillMatch) {
1453
1454 var attrArray = skillMatch[1].split(',');
1455 attr_1 = getAttrByName(diceObj.vars.characterID, attrArray[0]);
1456 attr_2 = getAttrByName(diceObj.vars.characterID, attrArray[1]);
1457
1458 if (eote.defaults.globalVars.debugScript) {
1459 sendChat("Alert", "attr_1 = " + attr_1);
1460 sendChat("Alert", "attr_2 = " + attr_2);
1461 }
1462
1463 var cmdSkill;
1464 if(!isNaN((parseFloat(attr_1)) && isFinite(attr_1))) { // is numeric
1465 cmdSkill = ['skill(' + attr_1 + '|' + attr_2 + ')']; //['skill(0|2)']
1466 } else {
1467 var attr_3 = getAttrByName(diceObj.vars.characterID, attr_1.substr(2,attr_1.length-3));
1468 cmdSkill = ['skill(' + attr_3 + '|' + attr_2 + ')']; //['skill(0|2)']
1469 }
1470
1471 diceObj = eote.process.skill(cmdSkill, diceObj);
1472 }
1473 return diceObj;
1474};
1475
1476eote.process.destiny = function (cmd, diceObj) {
1477
1478 var charObj_DicePool = findObjs({ _type: "character", name: "-DicePool" })[0];
1479 var doRoll = false;
1480
1481 if (!charObj_DicePool) {
1482 sendChat("GM", "/w " + "gm The DicePool character sheet could not be found! Re-save this script and it should be recreated. In the future do not rename the -DicePool Character Sheet.");
1483 return doRoll;
1484 }
1485 //GM's Destiny Point Pool
1486 var currentLightSidePoints = findObjs({
1487 _characterid: charObj_DicePool.get("_id"),
1488 _type: "attribute",
1489 _name: "lightSidePoints"
1490 });
1491 var currentDarkSidePoints = findObjs({
1492 _characterid: charObj_DicePool.get("_id"),
1493 _type: "attribute",
1494 _name: "darkSidePoints"
1495 });
1496 if (!currentDarkSidePoints[0] || !currentLightSidePoints[0]) {
1497 sendChat("Dice System", "No Destiny Points Defined. The GM has been whispered with instructions to reset the Destiny Pool.");
1498 sendChat("GM", "/w " + "gm The Destiny Pool system needs to be (or has been) reset. To fix this functionality, go to the -DicePool Character Sheet and add 1 dark side and 1 light side destiny point, then click the Force Player Update button. This should clear up the issue.");
1499 return doRoll;
1500 }
1501 var darkSide = parseInt(currentDarkSidePoints[0].get("current"));
1502 var lightSide = parseInt(currentLightSidePoints[0].get("current"));
1503
1504 var displayPool = '';
1505 //noinspection FallThroughInSwitchStatementJS
1506 switch (cmd[1]) {
1507 case "useDark":
1508 if (darkSide > 0) {
1509 darkSide = darkSide - 1;
1510 lightSide = lightSide + 1;
1511
1512 displayPool = '/direct &{template:base} {{title=' + 'The GM flips a Dark Side Destiny Point' + '}}';
1513 displayPool = displayPool + '{{Dark Side points remaining=' + darkSide + '}}';
1514 displayPool = displayPool + '{{New Light Side total=' + lightSide + '}}';
1515
1516 sendChat('Dice System', displayPool);
1517 }
1518 else {
1519 sendChat("GM", "/w " + "gm There are no Dark Side points left in the Destiny Pool. Encourage your Players to use a Light Side Point." );
1520 return doRoll;
1521 }
1522 break;
1523 case "useLight":
1524 if (lightSide > 0) {
1525 lightSide = lightSide - 1;
1526 darkSide = darkSide + 1;
1527
1528 displayPool = '/direct &{template:base} {{title=' + diceObj.vars.characterName + ' flips a Light Side Destiny Point' + '}}';
1529 displayPool = displayPool + '{{New Dark Side total=' + darkSide + '}}';
1530 displayPool = displayPool + '{{Light Side points remaining=' + lightSide + '}}';
1531
1532 sendChat('Dice System', displayPool);
1533 }
1534 else {
1535 sendChat("Dice System", "/w " + diceObj.vars.characterName + " There are no Light Side points left in the Destiny Pool. Suggest to your GM to use a Dark Side point to make one available.");
1536 return doRoll;
1537 }
1538 break;
1539 case "doRoll":
1540 sendChat(diceObj.vars.characterName, '/direct Rolling a Destiny Point.');
1541 doRoll = true;
1542 // falls through on purpose (I think) to sync automatically when destiny point is rolled
1543 case "registerPlayer":
1544 if (!doRoll) {
1545 sendChat("Dice System", "/w " + diceObj.vars.characterName + '&{template:base} {{title=Syncing your Destiny Pool to the GM\'s}}')
1546 }
1547 darkSide = darkSide + diceObj.totals.dark;
1548 lightSide = lightSide + diceObj.totals.light;
1549
1550 //Register
1551 if (eote.defaults.destinyListeners.indexOf(diceObj.vars.characterID) == -1) {
1552 eote.defaults.destinyListeners.push(diceObj.vars.characterID);
1553 }
1554 break;
1555 case "sendUpdate":
1556 sendChat("Dice System", "Updating Players Destiny Pools");
1557 break;
1558 case "clearPool":
1559 sendChat("Dice System", '&{template:base} {{title=The GM cleared the Destiny Pool}}');
1560 lightSide = 0;
1561 darkSide = 0;
1562 break;
1563 }
1564 var newDestPool = [
1565 {
1566 name: 'lightSidePoints',
1567 current: lightSide,
1568 max: '',
1569 update: true
1570 },
1571 {
1572 name: 'darkSidePoints',
1573 current: darkSide,
1574 max: '',
1575 update: true
1576 }
1577 ];
1578 eote.updateListeners(newDestPool);
1579 return doRoll;
1580};
1581
1582eote.process.characterID = function (cmd, diceObj) {
1583
1584 /* CharacterId
1585 * default: null
1586 * Description: looks up the characters name based on character ID
1587 * Command: !eed characterID(##########)
1588 * ---------------------------------------------------------------- */
1589
1590 eote.process.logger("eote.process.characterID", cmd);
1591
1592 var characterID = cmd[1];
1593
1594 if (characterID) {
1595
1596 diceObj.vars.characterName = getObj("character", characterID).get('name');
1597 diceObj.vars.characterID = characterID;
1598 }
1599 return diceObj;
1600};
1601
1602eote.process.label = function (cmd, diceObj) {
1603
1604 /* Label
1605 * default: null
1606 * Description: set the skill name of the roll
1607 * Command: !eed label(Name of Skill)
1608 * ---------------------------------------------------------------- */
1609 //log(cmd);
1610
1611 var label = cmd[1];
1612
1613 if (label) {
1614
1615 var labelStr = '';
1616 var labelArray = label.split('|');
1617
1618 _.each(labelArray, function (labelVal) {
1619 var labelArray = labelVal.split(':');
1620 var label = labelArray[0];
1621 var message = labelArray[1];
1622
1623 if (label == "Weapon") {
1624 labelStr = labelStr + message + '}}';
1625 }
1626 else if (label == "skill") {
1627 labelStr = labelStr + message + '}}';
1628 }
1629 else if (label == "Dice") {
1630 labelStr = labelStr + message + '}}';
1631 }
1632 else {
1633 labelStr = labelStr + '{{' + label + '=' + message + '}}';
1634 }
1635 });
1636 diceObj.vars.label = labelStr;
1637 }
1638 return diceObj;
1639};
1640
1641eote.process.resetdice = function (cmd, diceObj) {
1642
1643 var characterObj = [{ name: diceObj.vars.characterName, id: diceObj.vars.characterID }];
1644 eote.process.logger("eote.process.resetdice", cmd);
1645
1646 if (cmd[1] == 'resetdice') {
1647 var resetdice = [
1648 {
1649 name: "b",
1650 current: 0,
1651 update: true
1652 },
1653 {
1654 name: "g",
1655 current: 0,
1656 update: true
1657 },
1658 {
1659 name: "y",
1660 current: 0,
1661 update: true
1662 },
1663 {
1664 name: "blk",
1665 current: 0,
1666 update: true
1667 },
1668 {
1669 name: "r",
1670 current: 0,
1671 update: true
1672 },
1673 {
1674 name: "p",
1675 current: 0,
1676 update: true
1677 },
1678 {
1679 name: "w",
1680 current: 0,
1681 update: true
1682 },
1683 {
1684 name: "upgradeAbility",
1685 current: 0,
1686 update: true
1687 },
1688 {
1689 name: "downgradeProficiency",
1690 current: 0,
1691 update: true
1692 },
1693 {
1694 name: "upgradeDifficulty",
1695 current: 0,
1696 update: true
1697 },
1698 {
1699 name: "downgradeChallenge",
1700 current: 0,
1701 update: true
1702 }
1703 ]
1704 }
1705
1706 if (cmd[1] == 'resetgmdice') {
1707 var resetdice = [
1708 {
1709 name: "bgm",
1710 current: 0,
1711 update: true
1712 },
1713 {
1714 name: "ggm",
1715 current: 0,
1716 update: true
1717 },
1718 {
1719 name: "ygm",
1720 current: 0,
1721 update: true
1722 },
1723 {
1724 name: "blkgm",
1725 current: 0,
1726 update: true
1727 },
1728 {
1729 name: "rgm",
1730 current: 0,
1731 update: true
1732 },
1733 {
1734 name: "pgm",
1735 current: 0,
1736 update: true
1737 },
1738 {
1739 name: "wgm",
1740 current: 0,
1741 update: true
1742 },
1743 {
1744 name: "upgradeAbilitygm",
1745 current: 0,
1746 update: true
1747 },
1748 {
1749 name: "downgradeProficiencygm",
1750 current: 0,
1751 update: true
1752 },
1753 {
1754 name: "upgradeDifficultygm",
1755 current: 0,
1756 update: true
1757 },
1758 {
1759 name: "downgradeChallengegm",
1760 current: 0,
1761 update: true
1762 }
1763 ]
1764 }
1765 eote.updateAddAttribute(characterObj, resetdice);
1766};
1767
1768eote.process.initiative = function (cmd, diceObj) {
1769
1770 /* initiative
1771 * default: false
1772 * Description: Set NPC/PC initiative true
1773 * Command: !eed npcinit or pcinit
1774 * ---------------------------------------------------------------- */
1775
1776 var type = '';
1777 var NumSuccess = diceObj.totals.success;
1778 var NumAdvantage = diceObj.totals.advantage;
1779 var turnorder;
1780
1781 eote.process.logger("eote.process.initiative.diceObj", diceObj);
1782 eote.process.logger("eote.process.initiative.NumSuccess", NumSuccess);
1783 eote.process.logger("eote.process.initiativeNumAdvantage", NumAdvantage);
1784
1785 if (Campaign().get("turnorder") == "") turnorder = []; //NOTE: We check to make sure that the turnorder isn't just an empty string first. If it is treat it like an empty array.
1786 else turnorder = JSON.parse(Campaign().get("turnorder"));
1787
1788 if (cmd[0] == 'pcinit') {
1789 type = 'PC';
1790 }
1791
1792 if (cmd[0] == 'npcinit') {
1793 type = 'NPC';
1794 }
1795 //Add a new custom entry to the end of the turn order.
1796 turnorder.push({
1797 id: "-1",
1798 pr: NumSuccess + ":" + NumAdvantage,
1799 custom: type
1800 });
1801 turnorder.sort(function (x, y) {
1802 // verify that x or y contains a colon, if it doesn't put it below
1803 if (x.toString().indexOf(":") < 1 || y.toString().indexOf(":") < 1) {
1804 return 1;
1805 } else {
1806 var a = x.pr.split(":");
1807 var b = y.pr.split(":");
1808
1809 if (b[0] - a[0] != 0) {//First rank on successes
1810 return b[0] - a[0];
1811 } else if (b[1] - a[1] != 0) {//Then rank on Advantage
1812 return b[1] - a[1];
1813 } else { //If they are still tied, PC goes first
1814
1815 if (x.custom == y.custom) {
1816 return 0;
1817 } else if (x.custom == "NPC") {
1818 return 1;
1819 } else {
1820 return -1;
1821 }
1822 }
1823 }
1824 });
1825 Campaign().set("turnorder", JSON.stringify(turnorder));
1826};
1827
1828eote.process.crit = function (cmd, diceObj) {
1829
1830 /* Crit
1831 * default:
1832 * Description: Rolls critical injury table
1833 * Command: !eed crit(roll) crit(roll|#) crit(heal|#)
1834 * ---------------------------------------------------------------- */
1835
1836 eote.process.logger("eote.process.crit", "");
1837
1838 var characterObj = [{ name: diceObj.vars.characterName, id: diceObj.vars.characterID }];
1839 var critTable = [
1840 {
1841 percent: '1 to 5',
1842 severity: 1,
1843 name: 'Minor Nick',
1844 Result: 'Suffer 1 strain.'
1845 },
1846 {
1847 percent: '6 to 10',
1848 severity: 1,
1849 name: 'Slowed Down',
1850 Result: 'May only act during last allied Initiative slot on next turn.'
1851 },
1852 {
1853 percent: '11 to 15',
1854 severity: 1,
1855 name: 'Sudden Jolt',
1856 Result: 'May only act during last hero Initiative slot on next turn.'
1857 },
1858 {
1859 percent: '16 to 20',
1860 severity: 1,
1861 name: 'Distracted',
1862 Result: 'Cannot perform free maneuver on next turn.'
1863 },
1864 {
1865 percent: '21 to 25',
1866 severity: 1,
1867 name: 'Off-Balance',
1868 Result: 'Add 1 Setback die to next skill check.'
1869 },
1870 {
1871 percent: '26 to 30',
1872 severity: 1,
1873 name: 'Discouraging Wound',
1874 Result: 'Flip one light destiny to dark.'
1875 },
1876 {
1877 percent: '31 to 35',
1878 severity: 1,
1879 name: 'Stunned',
1880 Result: 'Staggered, cannot perform action on next turn.'
1881 },
1882 {
1883 percent: '36 to 40',
1884 severity: 1,
1885 name: 'Stinger',
1886 Result: 'Increase difficulty of next check by 1 Difficulty die.'
1887 },
1888 //----------------------------- Severity 2
1889 {
1890 percent: '41 to 45',
1891 severity: 2,
1892 name: 'Bowled Over',
1893 Result: 'Knocked prone and suffer 1 strain.'
1894 },
1895 {
1896 percent: '46 to 50',
1897 severity: 2,
1898 name: 'Head Ringer',
1899 Result: 'Increase difficulty of all Intellect and Cunning checks by 1 Difficulty die until end of encounter.'
1900 },
1901 {
1902 percent: '51 to 55',
1903 severity: 2,
1904 name: 'Fearsome Wound',
1905 Result: 'Increase difficulty of all Presence and Willpower checks by 1 Difficulty die until end of encounter.'
1906 },
1907 {
1908 percent: '56 to 60',
1909 severity: 2,
1910 name: 'Agonizing Wound',
1911 Result: 'Increase difficulty of all Brawn and Agility checks by 1 Difficulty die until end of encounter.'
1912 },
1913 {
1914 percent: '61 to 65',
1915 severity: 2,
1916 name: 'Slightly Dazed',
1917 Result: 'Add 1 Setback die to all skill checks until end of encounter.'
1918 },
1919 {
1920 percent: '66 to 70',
1921 severity: 2,
1922 name: 'Scattered Senses',
1923 Result: 'Remove all Boost dice from all skill checks until end of encounter.'
1924 },
1925 {
1926 percent: '71 to 75',
1927 severity: 2,
1928 name: 'Hamstrung',
1929 Result: 'Lose free maneuver until end of encounter.'
1930 },
1931 {
1932 percent: '76 to 80',
1933 severity: 2,
1934 name: 'Staggered',
1935 Result: 'Attacker may immediately attempt another free attack against you using same dice pool as original attack.'
1936 },
1937 {
1938 percent: '81 to 85',
1939 severity: 2,
1940 name: 'Winded',
1941 Result: 'Cannot voluntarily suffer strain to activate abilities or gain additional maneuvers until end of encounter.'
1942 },
1943 {
1944 percent: '86 to 90',
1945 severity: 2,
1946 name: 'Compromised',
1947 Result: 'Increase difficulty of all skill checks by 1 Difficulty die until end of encounter.'
1948 },
1949 //---------------------------------------- Severity 3
1950 {
1951 percent: '91 to 95',
1952 severity: 3,
1953 name: 'At the Brink',
1954 Result: 'Suffer 1 strain each time you perform an action.'
1955 },
1956 {
1957 percent: '96 to 100',
1958 severity: 3,
1959 name: 'Crippled',
1960 Result: 'Limb crippled until healed or replaced. Increase difficulty of all checks that use that limb by 1 Difficulty die.'
1961 },
1962 {
1963 percent: '101 to 105',
1964 severity: 3,
1965 name: 'Maimed',
1966 Result: 'Limb permanently lost. Unless you have a cybernetic replacement, cannot perform actions that use that limb. Add 1 Setback to all other actions.'
1967 },
1968 {
1969 percent: '106 to 110',
1970 severity: 3,
1971 name: 'Horrific Injury',
1972 Result: 'Roll 1d10 to determine one wounded characteristic -- roll results(1-3 = Brawn, 4-6 = Agility, 7 = Intellect, 8 = Cunning, 9 = Presence, 10 = Willpower. Until Healed, treat characteristic as one point lower.'
1973 },
1974 {
1975 percent: '111 to 115',
1976 severity: 3,
1977 name: 'Temporarily Lame',
1978 Result: 'Until healed, may not perform more than one maneuver each turn.'
1979 },
1980 {
1981 percent: '116 to 120',
1982 severity: 3,
1983 name: 'Blinded',
1984 Result: 'Can no longer see. Upgrade the difficulty of Perception and Vigilance checks three times, and all other checks twice.'
1985 },
1986 {
1987 percent: '121 to 125',
1988 severity: 3,
1989 name: 'Knocked Senseless',
1990 Result: 'You can no longer upgrade dice for checks.'
1991 },
1992 //---------------------------------------- Severity 4
1993 {
1994 percent: '126 to 130',
1995 severity: 4,
1996 name: 'Gruesome Injury',
1997 Result: 'Roll 1d10 to determine one wounded characteristic -- roll results(1-3 = Brawn, 4-6 = Agility, 7 = Intellect, 8 = Cunning, 9 = Presence, 10 = Willpower. Characteristic is permanently one point lower.'
1998 },
1999 {
2000 percent: '131 to 140',
2001 severity: 4,
2002 name: 'Bleeding Out',
2003 Result: 'Suffer 1 wound and 1 strain every round at the beginning of turn. For every 5 wounds suffered beyond wound threshold, suffer one additional Critical Injury (ignore the details for any result below this result).'
2004 },
2005 {
2006 percent: '141 to 150',
2007 severity: 4,
2008 name: 'The End is Nigh',
2009 Result: 'Die after the last Initiative slot during the next round.'
2010 },
2011 {
2012 percent: '151',
2013 severity: 4,
2014 name: 'Dead',
2015 Result: 'Complete, absolute death.'
2016 }
2017 ];
2018 var critRoll = function (addCritNum, type) {
2019
2020 var openSlot = false;
2021 var diceRoll = '';
2022 var critMod = '';
2023 var rollTotal = '';
2024 var rollOffset = parseInt(getAttrByName(diceObj.vars.characterID, type + '-critAddOffset'));
2025 rollOffset = rollOffset ? rollOffset : 0;
2026 eote.process.logger("critRoll", "rollOffset: " + rollOffset);
2027 var totalcrits = 0;
2028
2029 //check open critical spot
2030 for (i = 15; i >= 1; i--) {
2031
2032 var slot = getAttrByName(diceObj.vars.characterID, type + '-critOn' + i);
2033
2034 if (slot == '0' || slot == '') {
2035 openSlot = i;
2036 } else {
2037 totalcrits = totalcrits + 1;
2038 }
2039 }
2040 if (!openSlot) {
2041 sendChat("Alert", "&{template:critical} {{title=Alert}} {{wide=Why are you not dead!?}}");
2042 return false;
2043 }
2044 //roll random
2045 if (!addCritNum) {
2046 diceRoll = randomInteger(100);
2047 critMod = (totalcrits * 10);
2048 rollTotal = diceRoll + critMod + rollOffset;
2049 rollTotal = rollTotal < 1 ? 1 : rollTotal;
2050 eote.process.logger("critRoll", "diceRoll: " + diceRoll);
2051 eote.process.logger("critRoll", "critMod: " + critMod);
2052 eote.process.logger("critRoll", "rollTotal " + rollTotal);
2053 } else {
2054 rollTotal = parseInt(addCritNum);
2055 }
2056 //find crit in critical table
2057 for (var key in critTable) {
2058
2059 var percent = critTable[key].percent.split(' to ');
2060 var low = parseInt(percent[0]);
2061 var high = percent[1] ? parseInt(percent[1]) : 1000;
2062
2063 if ((rollTotal >= low) && (rollTotal <= high)) {
2064
2065 critAttrs = [
2066 {
2067 name: type + '-critName' + openSlot,
2068 current: critTable[key].name,
2069 max: '',
2070 update: true
2071 },
2072 {
2073 name: type + '-critSeverity' + openSlot,
2074 current: critTable[key].severity,
2075 max: '',
2076 update: true
2077 },
2078 {
2079 name: type + '-critRange' + openSlot,
2080 current: critTable[key].percent,
2081 max: '',
2082 update: true
2083 },
2084 {
2085 name: type + '-critSummary' + openSlot,
2086 current: critTable[key].Result,
2087 max: '',
2088 update: true
2089 },
2090 {
2091 name: type + '-critOn' + openSlot,
2092 current: openSlot,
2093 max: '',
2094 update: true
2095 }
2096 ];
2097 eote.updateAddAttribute(characterObj, critAttrs);
2098 var chat = '/direct &{template:base} {{title=' + diceObj.vars.characterName + '}}';
2099 chat = chat + '{{subtitle=Critical Injury}}';
2100 chat = chat + '{{Previous Criticals=' + totalcrits + ' x 10}}';
2101 if (rollOffset) {
2102 chat = chat + '{{Dice Roll Offset=' + rollOffset + '}}';
2103 }
2104 chat = chat + '{{Dice Roll=' + diceRoll + '}}';
2105 chat = chat + '{{Total=' + rollTotal + '}}';
2106 chat = chat + '{{wide=<b>' + critTable[key].name + '</b><br>';
2107 chat = chat + critTable[key].Result + '<br>}}';
2108
2109 sendChat(diceObj.vars.characterName, chat);
2110 }
2111 }
2112 };
2113
2114 var critHeal = function (critID, type) {
2115
2116 critAttrs = [
2117 {
2118 name: type + '-critName' + critID,
2119 current: '',
2120 max: '',
2121 update: true
2122 },
2123 {
2124 name: type + '-critSeverity' + critID,
2125 current: '',
2126 max: '',
2127 update: true
2128 },
2129 {
2130 name: type + '-critRange' + critID,
2131 current: '',
2132 max: '',
2133 update: true
2134 },
2135 {
2136 name: type + '-critSummary' + critID,
2137 current: '',
2138 max: '',
2139 update: true
2140 },
2141 {
2142 name: type + '-critOn' + critID,
2143 current: 0,
2144 max: '',
2145 update: true
2146 }
2147 ];
2148 eote.updateAddAttribute(characterObj, critAttrs);
2149 };
2150 var critArray = cmd[1].split('|');
2151 var command = critArray[0];
2152 var type = critArray[1] ? critArray[1] : null;
2153 var input = critArray[2] ? critArray[2] : null;
2154
2155 if (type == null) {
2156 sendChat("Alert", "Type not supplied. Needs character, companion or beast");
2157 return;
2158 }
2159
2160 if (command == 'heal') {
2161 critHeal(input, type);
2162 } else if (command == 'add') {
2163 critRoll(input, type);
2164 } else { // crit(roll)
2165 critRoll(null, type);
2166 }
2167};
2168
2169eote.process.critShip = function (cmd, diceObj) {
2170
2171 /* CritShip
2172 * default:
2173 * Description: Rolls vehicle critical table, Both crit() and critShip() function the same
2174 * Command: !eed critShip(roll) critShip(roll|#) critShip(heal|#)
2175 * ---------------------------------------------------------------- */
2176
2177 var characterObj = [{ name: diceObj.vars.characterName, id: diceObj.vars.characterID }];
2178
2179 var critTable = [
2180 {
2181 percent: '1 to 9',
2182 severity: 1,
2183 name: 'Mechanical Stress',
2184 Result: 'Ship or vehicle suffers 1 system strain.'
2185 },
2186 {
2187 percent: '10 to 18',
2188 severity: 1,
2189 name: 'Jostled',
2190 Result: 'All crew members suffer 1 strain.'
2191 },
2192 {
2193 percent: '19 to 27',
2194 severity: 1,
2195 name: 'Losing Power to Shields',
2196 Result: 'Decrease defense in affected defense zone by 1 until repaired. If ship or vehicle has no defense, suffer 1 system strain.'
2197 },
2198 {
2199 percent: '28 to 36',
2200 severity: 1,
2201 name: 'Knocked Off Course',
2202 Result: 'On next turn, pilot cannot execute any maneuvers. Instead, must make a Piloting check to regain bearings and resume course. Difficulty depends on current speed.'
2203 },
2204 {
2205 percent: '37 to 45',
2206 severity: 1,
2207 name: 'Tailspin',
2208 Result: 'All firing from ship or vehicle suffers 2 setback dice until end of pilot\'s next turn.'
2209 },
2210 {
2211 percent: '46 to 54',
2212 severity: 1,
2213 name: 'Component Hit',
2214 Result: 'One component of the attacker\'s choice is knocked offline, and is rendered inoperable until the end of the following round. See page 245 CRB for Small/Large Vehicle and Ship Component tables. '
2215 },
2216 // --------------- severity : 2
2217 {
2218 percent: '55 to 63',
2219 severity: 2,
2220 name: 'Shields Failing',
2221 Result: 'Decrease defense in all defense zones by 1 until repaired. If ship or vehicle has no defense, suffer 2 system strain.'
2222 },
2223 {
2224 percent: '64 to 72',
2225 severity: 2,
2226 name: 'Hyperdrive or Navicomputer Failure',
2227 Result: 'Cannot make any jump to hyperspace until repaired. If ship or vehicle has no hyperdrive, navigation systems fail leaving it unable to tell where it is or is going.'
2228 },
2229 {
2230 percent: '73 to 81',
2231 severity: 2,
2232 name: 'Power Fluctuations',
2233 Result: 'Pilot cannot voluntarily inflict system strain on the ship until repaired.'
2234 },
2235 // --------------- severity : 3
2236 {
2237 percent: '82 to 90',
2238 severity: 3,
2239 name: 'Shields Down',
2240 Result: 'Decrease defense in affected defense zone to 0 and all other defense zones by 1 point until repaired. If ship or vehicle has no defense, suffer 4 system strain.'
2241 },
2242 {
2243 percent: '91 to 99',
2244 severity: 3,
2245 name: 'Engine Damaged',
2246 Result: 'Ship or vehicle\'s maximum speed reduced by 1, to a minimum of 1, until repaired.'
2247 },
2248 {
2249 percent: '100 to 108',
2250 severity: 3,
2251 name: 'Shield Overload',
2252 Result: 'Decrease defense in all defense zones to 0 until repaired. In addition, suffer 2 system strain. Cannot be repaired until end of encounter. If ship or vehicle has no defense, reduce armor by 1 until repaired.'
2253 },
2254 {
2255 percent: '109 to 117',
2256 severity: 3,
2257 name: 'Engines Down',
2258 Result: 'Ship or vehicle\'s maximum speed reduced to 0. In addition, ship or vehicle cannot execute maneuvers until repaired. Ship continues on course at current speed and cannot be stopped or course changed until repaired.'
2259 },
2260 {
2261 percent: '118 to 126',
2262 severity: 3,
2263 name: 'Major System Failure',
2264 Result: 'One component of the attacker\'s choice is heavily damages, and is inoperable until the critical hit is repaired. See page 245 CRB for Small/Large Vehicle and Ship Component tables. '
2265 },
2266 // --------------- severity : 4
2267 {
2268 percent: '127 to 133',
2269 severity: 4,
2270 name: 'Major Hull Breach',
2271 Result: 'Ships and vehicles of silhouette 4 and smaller depressurize in a number of rounds equal to silhouette. Ships of silhouette 5 and larger don\'t completely depressurize, but parts do (specifics at GM discretion). Ships and vehicles operating in atmosphere instead suffer a Destabilized Critical.'
2272 },
2273 {
2274 percent: '134 to 138',
2275 severity: 4,
2276 name: 'Destabilised',
2277 Result: 'Reduce ship or vehicle\'s hull integrity threshold and system strain threshold to half original values until repaired.'
2278 },
2279 {
2280 percent: '139 to 144',
2281 severity: 4,
2282 name: 'Fire!',
2283 Result: 'Fire rages through ship or vehicle and it immediately takes 2 system strain. Fire can be extinguished with appropriate skill, Vigilance or Cool checks at GM\'s discretion. Takes one round per two silhouette to put out.'
2284 },
2285 {
2286 percent: '145 to 153',
2287 severity: 4,
2288 name: 'Breaking Up',
2289 Result: 'At the end of next round, ship is completely destroyed. Anyone aboard has one round to reach escape pod or bail out before they are lost.'
2290 },
2291 {
2292 percent: '154+',
2293 severity: 4,
2294 name: 'Vaporized',
2295 Result: 'The ship or Vehicle is completely destroyed.'
2296 }
2297 ];
2298 var critRoll = function (addCritNum, type) {
2299
2300 var openSlot = false;
2301 var diceRoll = '';
2302 var critMod = '';
2303 var rollTotal = '';
2304 var rollOffset = parseInt(getAttrByName(diceObj.vars.characterID, type + '-critShipAddOffset'));
2305 rollOffset = rollOffset ? rollOffset : 0;
2306 var totalcrits = 0;
2307
2308 //check open critical spot
2309 for (i = 15; i >= 1; i--) {
2310
2311 var slot = getAttrByName(diceObj.vars.characterID, type + '-critShipOn' + i);
2312
2313 if (slot == '0' || slot == '') {
2314 openSlot = i;
2315 } else {
2316 totalcrits = totalcrits + 1;
2317 }
2318 }
2319 if (!openSlot) {
2320 sendChat("Alert", "&{template:critical} {{title=Alert}} {{wide=Why are you not dead!?}}");
2321 return false;
2322 }
2323 //roll random
2324 if (!addCritNum) {
2325 diceRoll = randomInteger(100);
2326 critMod = (totalcrits * 10);
2327 rollTotal = diceRoll + critMod + rollOffset;
2328 rollTotal = rollTotal < 1 ? 1 : rollTotal;
2329 } else {
2330 rollTotal = parseInt(addCritNum);
2331 }
2332 //find crit in critical table
2333 for (var key in critTable) {
2334
2335 var percent = critTable[key].percent.split(' to ');
2336 var low = parseInt(percent[0]);
2337 var high = percent[1] ? parseInt(percent[1]) : 1000;
2338
2339 if ((rollTotal >= low) && (rollTotal <= high)) {
2340
2341 critAttrs = [
2342 {
2343 name: type + '-critShipName' + openSlot,
2344 current: critTable[key].name,
2345 max: '',
2346 update: true
2347 },
2348 {
2349 name: type + '-critShipSeverity' + openSlot,
2350 current: critTable[key].severity,
2351 max: '',
2352 update: true
2353 },
2354 {
2355 name: type + '-critShipRange' + openSlot,
2356 current: critTable[key].percent,
2357 max: '',
2358 update: true
2359 },
2360 {
2361 name: type + '-critShipSummary' + openSlot,
2362 current: critTable[key].Result,
2363 max: '',
2364 update: true
2365 },
2366 {
2367 name: type + '-critShipOn' + openSlot,
2368 current: openSlot,
2369 max: '',
2370 update: true
2371 }
2372 ];
2373 eote.updateAddAttribute(characterObj, critAttrs);
2374
2375 var chat = '/direct &{template:base} {{title=Vehicle Critical}} ';
2376 chat = chat + '{{subtitle=' + diceObj.vars.characterName + '}}';
2377 chat = chat + '{{Previous Criticals=' + totalcrits + ' x 10}}';
2378 if (rollOffset) {
2379 chat = chat + '{{Dice Roll Offset=' + rollOffset + '}}';
2380 }
2381 chat = chat + '{{Dice Roll=' + diceRoll + '}}';
2382 chat = chat + '{{Total=' + rollTotal + '}}';
2383 chat = chat + '{{wide=<b>' + critTable[key].name + '</b><br>';
2384 chat = chat + critTable[key].Result + '}}';
2385
2386 sendChat(diceObj.vars.characterName, chat);
2387 }
2388 }
2389 };
2390
2391 var critHeal = function (critID, type) {
2392
2393 critAttrs = [
2394 {
2395 name: type + '-critShipName' + critID,
2396 current: '',
2397 max: '',
2398 update: true
2399 },
2400 {
2401 name: type + '-critShipSeverity' + critID,
2402 current: '',
2403 max: '',
2404 update: true
2405 },
2406 {
2407 name: type + '-critShipRange' + critID,
2408 current: '',
2409 max: '',
2410 update: true
2411 },
2412 {
2413 name: type + '-critShipSummary' + critID,
2414 current: '',
2415 max: '',
2416 update: true
2417 },
2418 {
2419 name: type + '-critShipOn' + critID,
2420 current: 0,
2421 max: '',
2422 update: true
2423 }
2424 ];
2425
2426 eote.updateAddAttribute(characterObj, critAttrs);
2427 };
2428 var critArray = cmd[1].split('|');
2429 var command = critArray[0];
2430 var type = critArray[1] ? critArray[1] : null;
2431 var input = critArray[2] ? critArray[2] : null;
2432
2433 if (type == null) {
2434 sendChat("Alert", "Type not supplied. Needs starship or vehicle");
2435 return;
2436 }
2437
2438 if (command == 'heal') {
2439 critHeal(input, type);
2440 } else if (command == 'add') {
2441 critRoll(input, type);
2442 } else { // crit(roll)
2443 critRoll(null, type);
2444 }
2445};
2446
2447eote.process.gmdice = function (cmd) {
2448
2449 /* gmdice
2450 * default:
2451 * Description: Update CMD string to include -DicePool dice
2452 * Command: (gmdice)
2453 * ---------------------------------------------------------------- */
2454
2455 //var charObj = findObjs({ _type: "character", name: "-DicePool" });
2456 var charID = eote.defaults['-DicePoolID'];//charObj[0].id;
2457
2458 var g = getAttrByName(charID, 'ggm');
2459 var y = getAttrByName(charID, 'ygm');
2460 var p = getAttrByName(charID, 'pgm');
2461 var r = getAttrByName(charID, 'rgm');
2462 var b = getAttrByName(charID, 'bgm');
2463 var blk = getAttrByName(charID, 'blkgm');
2464 var w = getAttrByName(charID, 'wgm');
2465 var upAbility = getAttrByName(charID, 'upgradeAbilitygm');
2466 var upDifficulty = getAttrByName(charID, 'upgradeDifficultygm');
2467 var downProficiency = getAttrByName(charID, 'downgradeProficiencygm');
2468 var downChallenge = getAttrByName(charID, 'downgradeChallengegm');
2469
2470 var gmdiceCMD = g + 'g ' + y + 'y ' + p + 'p ' + r + 'r ' + b + 'b ' + blk + 'blk ' + w + 'w upgrade(ability|' + upAbility + ') downgrade(proficiency|' + downProficiency + ') upgrade(difficulty|' + upDifficulty + ') downgrade(challenge|' + downChallenge + ')';
2471
2472 eote.process.logger("eote.process.gmDice.charID", charID);
2473 cmd = cmd.replace('(gmdice)', gmdiceCMD);
2474 //log(cmd);
2475 return cmd;
2476};
2477
2478eote.process.encum = function (cmd, diceObj) {
2479
2480 /* Encumberment
2481 * default:
2482 * Description: If the current encum is great than threshold add 1 setback per unit over current encum
2483 * Command: !eed encum(encum_current|encum_threshold)
2484 * ---------------------------------------------------------------- */
2485
2486 eote.process.logger("eote.process.encum", cmd);
2487
2488 _.each(cmd, function (encum) {
2489
2490 var diceArray = encum.match(/\((.*?)\|(.*?)\)/);
2491
2492 if (diceArray && diceArray[1] && diceArray[2]) {
2493
2494 var num1 = eote.process.math(diceArray[1]);
2495 var num2 = eote.process.math(diceArray[2]);
2496 var setbackDice = diceObj.count.setback;
2497
2498 if (num2 > num1) {
2499 diceObj.count.setback = setbackDice + (num2 - num1);
2500 eote.process.logger("eote.process.encum.NewSetbackTotal", diceObj.count.setback + "blk");
2501 //sendChat("Dice System", "/w " + diceObj.vars.characterName + " **Overencumbered** " + diceObj.count.setback + " Setbacks added");
2502 }
2503 else {
2504 eote.process.logger("eote.process.encum", "No New Setback");
2505 }
2506 }
2507 });
2508 return diceObj;
2509};
2510
2511eote.process.skill = function (cmd, diceObj) {
2512
2513 /* Skill
2514 * default:
2515 * Description: create the ability and proficiency dice for a skill check
2516 * Command: !eed skill(char_value|skill_value|[NPC minion group size]|[Is minion skill])
2517 * ---------------------------------------------------------------- */
2518
2519 eote.process.logger("eote.process.skill", cmd);
2520
2521 _.each(cmd, function (skill) {
2522 var matchers = {
2523 matchNPCGroupWSkillName: /\((.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\)/,
2524 matchNPCGroupWOSkillName: /\((.*?)\|(.*?)\|(.*?)\|(.*?)\)/,
2525 matchRegSkillWSkillName: /\((.*?)\|(.*?)\|(.*?)\)/,
2526 matchRegSkillWOSkillName: /\((.*?)\|(.*?)\)/
2527 };
2528 var diceArray = null;
2529 Object.keys(matchers).some(function(key) {
2530 if ((diceArray = skill.match(matchers[key])) != null) {
2531 return true;
2532 }
2533 });
2534
2535 if (diceArray && diceArray[1] && diceArray[2]) {
2536 var num1 = eote.process.math(diceArray[1]);
2537 if (diceArray[3] && diceArray[4] && diceArray[4] === "1") {
2538 num1 += (eote.process.math(diceArray[3]) - 1);
2539 }
2540 var num2 = eote.process.math(diceArray[2]);
2541 var totalAbil = Math.abs(num1 - num2);
2542 var totalProf = (num1 < num2 ? num1 : num2);
2543 var abilityDice = diceObj.count.ability;
2544 var proficiencyDice = diceObj.count.proficiency;
2545
2546 diceObj.count.ability = abilityDice + totalAbil;
2547 diceObj.count.proficiency = proficiencyDice + totalProf;
2548
2549 // check for skill name
2550 if (diceArray[5] || diceArray[3] && !diceArray[4]) {
2551 var name = (diceArray[5] ? diceArray[5] : diceArray[3]);
2552
2553 /* remove all non-letter characters to bring the name in line with the JSON properties
2554 * in order to have the closest chance in getting a match.
2555 * still does not guarantee a match.
2556 */
2557 name = name.replace(/[^A-Za-z]/g, "");
2558
2559 diceObj.vars.skillName = name;
2560 } else {
2561 diceObj.vars.skillName = null;
2562 }
2563
2564 eote.process.logger("eote.process.skill.abilityTotal", diceObj.count.ability + "g");
2565 eote.process.logger("eote.process.skill.proficiencyTotal", diceObj.count.proficiency + "y");
2566 }
2567
2568 });
2569 return diceObj;
2570};
2571
2572eote.process.opposed = function (cmd, diceObj) {
2573 /*Opposed
2574 * default:
2575 * Description: create the difficulty and challenge dice for an opposed skill check
2576 * Command: !eed opposed(char_value|skill_value)
2577 * ---------------------------------------------------------------- */
2578
2579 eote.process.logger("eote.process.opposed", cmd);
2580
2581 _.each(cmd, function (opposed) {
2582
2583 var diceArray = opposed.match(/\((.*?)\|(.*?)\)/);
2584
2585 if (diceArray && diceArray[1] && diceArray[2]) {
2586 var num1 = eote.process.math(diceArray[1]);
2587 var num2 = eote.process.math(diceArray[2]);
2588 var totalOppDiff = Math.abs(num1 - num2);
2589 var totalOppChal = (num1 < num2 ? num1 : num2);
2590 var opposeddifficultyDice = diceObj.count.difficulty;
2591 var opposedchallengeDice = diceObj.count.challenge;
2592 diceObj.count.difficulty = opposeddifficultyDice + totalOppDiff;
2593 diceObj.count.challenge = opposedchallengeDice + totalOppChal;
2594 }
2595 });
2596 return diceObj;
2597};
2598
2599eote.process.setDice = function (cmd, diceObj) {
2600
2601 /* setDice
2602 * default:
2603 * Description: Loop thru the dice and adds or subtracts them from the dice object
2604 * Command: !eed g# y# b# blk# r# p# w# or g#+# or g#-#
2605 * ---------------------------------------------------------------- */
2606
2607 eote.process.logger("eote.process.setDice", cmd);
2608
2609 _.each(cmd, function (dice) {
2610
2611 var diceArray = dice.match(/(-?\d{1,2})(\w{1,3})/);
2612
2613 if (diceArray && diceArray[1] && diceArray[2]) {
2614
2615 var diceQty = eote.process.math(diceArray[1]);
2616 diceQty = (isNaN(diceQty) ? 0 : diceQty);
2617
2618 var abilityDice = diceObj.count.ability;
2619 var proficiencyDice = diceObj.count.proficiency;
2620 var difficultyDice = diceObj.count.difficulty;
2621 var challengeDice = diceObj.count.challenge;
2622 var boostDice = diceObj.count.boost;
2623 var setbackDice = diceObj.count.setback;
2624 var forceDice = diceObj.count.force;
2625 var success = diceObj.count.success;
2626 var advantage = diceObj.count.advantage;
2627 var threat = diceObj.count.threat;
2628 var failure = diceObj.count.failure;
2629
2630 switch (diceArray[2]) {
2631 case 'b':
2632 diceObj.count.boost = boostDice + diceQty;
2633 break;
2634 case 'g':
2635 diceObj.count.ability = abilityDice + diceQty;
2636 break;
2637 case 'y':
2638 diceObj.count.proficiency = proficiencyDice + diceQty;
2639 break;
2640 case 'blk':
2641 diceObj.count.setback = setbackDice + diceQty;
2642 break;
2643 case 'p':
2644 diceObj.count.difficulty = difficultyDice + diceQty;
2645 break;
2646 case 'r':
2647 diceObj.count.challenge = challengeDice + diceQty;
2648 break;
2649 case 'w':
2650 diceObj.count.force = forceDice + diceQty;
2651 break;
2652 case 's':
2653 diceObj.count.success = success + diceQty;
2654 break;
2655 case 'a':
2656 diceObj.count.advantage = advantage + diceQty;
2657 break;
2658 case 't':
2659 diceObj.count.threat = threat + diceQty;
2660 break;
2661 case 'f':
2662 diceObj.count.failure = failure + diceQty;
2663 break;
2664 }
2665 }
2666 });
2667 diceObj = eote.process.checkNegative(diceObj);
2668
2669 eote.process.logger("eote.process.setDice.DiceToRoll", diceObj.count.boost + "b," + diceObj.count.ability + "g," + diceObj.count.proficiency + "y," + diceObj.count.setback + "blk," + diceObj.count.difficulty + "p," + diceObj.count.challenge + "r," + diceObj.count.force + "w," + diceObj.count.advantage + "a," + diceObj.count.threat + "t," + diceObj.count.failure + "f");
2670
2671 return diceObj;
2672};
2673
2674eote.process.checkNegative = function (diceObj) {
2675 if (diceObj.count.boost < 0) {
2676 eote.process.logger("eote.process.checkNegative.boost", "Setting count to 0 for being negative.");
2677 diceObj.count.boost = 0;
2678 }
2679 if (diceObj.count.ability < 0) {
2680 eote.process.logger("eote.process.checkNegative.ability", "Setting count to 0 for being negative.");
2681 diceObj.count.ability = 0;
2682 }
2683 if (diceObj.count.proficiency < 0) {
2684 eote.process.logger("eote.process.checkNegative.proficiency", "Setting count to 0 for being negative.");
2685 diceObj.count.proficiency = 0;
2686 }
2687 if (diceObj.count.setback < 0) {
2688 eote.process.logger("eote.process.checkNegative.setback", "Setting count to 0 for being negative.");
2689 diceObj.count.setback = 0;
2690 }
2691 if (diceObj.count.difficulty < 0) {
2692 eote.process.logger("eote.process.checkNegative.difficulty", "Setting count to 0 for being negative.");
2693 diceObj.count.difficulty = 0;
2694 }
2695 if (diceObj.count.challenge < 0) {
2696 eote.process.logger("eote.process.checkNegative.challenge", "Setting count to 0 for being negative.");
2697 diceObj.count.challenge = 0;
2698 }
2699 if (diceObj.count.force < 0) {
2700 eote.process.logger("eote.process.checkNegative.force", "Setting count to 0 for being negative.");
2701 diceObj.count.force = 0;
2702 }
2703 if (diceObj.count.success < 0) {
2704 eote.process.logger("eote.process.checkNegative.success", "Setting count to 0 for being negative.");
2705 diceObj.count.success = 0;
2706 }
2707 if (diceObj.count.advantage < 0) {
2708 eote.process.logger("eote.process.checkNegative.advantage", "Setting count to 0 for being negative.");
2709 diceObj.count.advantage = 0;
2710 }
2711 if (diceObj.count.threat < 0) {
2712 eote.process.logger("eote.process.checkNegative.threat", "Setting count to 0 for being negative.");
2713 diceObj.count.threat = 0;
2714 }
2715 if (diceObj.count.failure < 0) {
2716 eote.process.logger("eote.process.checkNegative.failure", "Setting count to 0 for being negative.");
2717 diceObj.count.failure = 0;
2718 }
2719 return diceObj;
2720};
2721
2722eote.process.upgrade = function (cmd, diceObj) {
2723
2724 /* Upgrade
2725 * default:
2726 * Description: upgrades ability and difficulty dice
2727 * Command: !eed upgrade(ability|#) or upgrade(difficulty|#)
2728 * ---------------------------------------------------------------- */
2729
2730 eote.process.logger("eote.process.upgrade", cmd);
2731
2732 _.each(cmd, function (dice) {
2733
2734 var diceArray = dice.match(/\((.*?)\|(.*?)\)/);
2735
2736 if (diceArray && diceArray[1] && diceArray[2]) {
2737
2738 var type = diceArray[1];
2739 var upgradeVal = eote.process.math(diceArray[2]);
2740 var abilityDice = diceObj.count.ability;
2741 var proficiencyDice = diceObj.count.proficiency;
2742 var difficultyDice = diceObj.count.difficulty;
2743 var challengeDice = diceObj.count.challenge;
2744
2745 switch (type) {
2746 case 'ability':
2747
2748 var totalProf = (upgradeVal < abilityDice ? upgradeVal : abilityDice);
2749 var totalAbil = Math.abs(upgradeVal - abilityDice);
2750
2751 if (upgradeVal > abilityDice) {
2752 totalProf = totalProf + Math.floor(totalAbil / 2);
2753 totalAbil = totalAbil % 2;
2754 }
2755 diceObj.count.ability = totalAbil;
2756 diceObj.count.proficiency = proficiencyDice + totalProf;
2757
2758 eote.process.logger("eote.process.upgrade.abilityTotal", diceObj.count.ability + "g");
2759 eote.process.logger("eote.process.upgrade.proficiencyTotal", diceObj.count.proficiency + "y");
2760
2761 break;
2762 case 'difficulty':
2763
2764 var totalChall = (upgradeVal < difficultyDice ? upgradeVal : difficultyDice);
2765 var totalDiff = Math.abs(upgradeVal - difficultyDice);
2766
2767 if (upgradeVal > difficultyDice) {
2768 totalChall = totalChall + Math.floor(totalDiff / 2);
2769 totalDiff = totalDiff % 2;
2770 }
2771 diceObj.count.difficulty = totalDiff;
2772 diceObj.count.challenge = challengeDice + totalChall;
2773
2774 eote.process.logger("eote.process.upgrade.difficultyTotal", diceObj.count.difficulty + "p");
2775 eote.process.logger("eote.process.upgrade.challengeTotal", diceObj.count.challenge + "r");
2776
2777 break;
2778 }
2779 }
2780 });
2781 return diceObj;
2782};
2783
2784eote.process.downgrade = function (cmd, diceObj) {
2785
2786 /* Downgrade
2787 * default:
2788 * Description: downgrades proficiency and challenge dice
2789 * Command: !eed downgrade(proficiency|#) or downgrade(challenge|#)
2790 * ---------------------------------------------------------------- */
2791
2792 eote.process.logger("eote.process.downgrade", cmd);
2793
2794 _.each(cmd, function (dice) {
2795
2796 var diceArray = dice.match(/\((.*?)\|(.*?)\)/);
2797
2798 if (diceArray && diceArray[1] && diceArray[2]) {
2799
2800 var type = diceArray[1];
2801 var downgradeVal = eote.process.math(diceArray[2]);
2802 var abilityDice = diceObj.count.ability;
2803 var proficiencyDice = diceObj.count.proficiency;
2804 var difficultyDice = diceObj.count.difficulty;
2805 var challengeDice = diceObj.count.challenge;
2806
2807 switch (type) {
2808 case 'proficiency':
2809
2810 var profConvertedToAbil = proficiencyDice * 2;
2811
2812 if (downgradeVal > (abilityDice + profConvertedToAbil)) {
2813 diceObj.count.ability = 0;
2814 diceObj.count.proficiency = 0;
2815 } else if (downgradeVal > profConvertedToAbil) {
2816 downgradeVal = Math.abs(downgradeVal - profConvertedToAbil);
2817 diceObj.count.ability = Math.abs(downgradeVal - abilityDice);
2818 diceObj.count.proficiency = 0;
2819 } else {
2820 diceObj.count.ability = abilityDice + (profConvertedToAbil - downgradeVal) % 2;
2821 diceObj.count.proficiency = Math.floor((profConvertedToAbil - downgradeVal) / 2);
2822 }
2823 break;
2824 case 'challenge':
2825
2826 var challConvertedToDiff = challengeDice * 2;
2827
2828 if (downgradeVal > (difficultyDice + challConvertedToDiff)) {
2829 diceObj.count.difficulty = 0;
2830 diceObj.count.challenge = 0;
2831 } else if (downgradeVal > challConvertedToDiff) {
2832 downgradeVal = Math.abs(downgradeVal - challConvertedToDiff);
2833 diceObj.count.difficulty = Math.abs(downgradeVal - difficultyDice);
2834 diceObj.count.challenge = 0;
2835 } else {
2836 diceObj.count.difficulty = difficultyDice + (challConvertedToDiff - downgradeVal) % 2;
2837 diceObj.count.challenge = Math.floor((challConvertedToDiff - downgradeVal) / 2);
2838 }
2839 break;
2840 }
2841 }
2842 });
2843 return diceObj;
2844};
2845
2846eote.process.math = function (expr) {
2847
2848 /* Math
2849 * Returns: Number
2850 * Description: Evaluates a mathematical expression (as a string) and return the result
2851 * ---------------------------------------------------------------- */
2852
2853 var chars = expr.split("");
2854 var n = [], op = [], index = 0, oplast = true;
2855
2856 n[index] = "";
2857
2858 // Parse the expression
2859 for (var c = 0; c < chars.length; c++) {
2860
2861 if (isNaN(parseInt(chars[c])) && chars[c] !== "." && !oplast) {
2862 op[index] = chars[c];
2863 index++;
2864 n[index] = "";
2865 oplast = true;
2866 } else {
2867 n[index] += chars[c];
2868 oplast = false;
2869 }
2870 }
2871 // Calculate the expression
2872 expr = parseFloat(n[0]);
2873 for (var o = 0; o < op.length; o++) {
2874 var num = parseFloat(n[o + 1]);
2875 switch (op[o]) {
2876 case "+":
2877 expr = expr + num;
2878 break;
2879 case "-":
2880 expr = expr - num;
2881 break;
2882 case "*":
2883 expr = expr * num;
2884 break;
2885 case "/":
2886 expr = expr / num;
2887 break;
2888 }
2889 }
2890 return expr;
2891};
2892
2893eote.process.addDiceValues = function (diceTotalObj, diceResult) {
2894
2895 diceTotalObj.success = diceTotalObj.success + diceResult.success;
2896 diceTotalObj.failure = diceTotalObj.failure + diceResult.failure;
2897 diceTotalObj.advantage = diceTotalObj.advantage + diceResult.advantage;
2898 diceTotalObj.threat = diceTotalObj.threat + diceResult.threat;
2899 diceTotalObj.triumph = diceTotalObj.triumph + diceResult.triumph;
2900 diceTotalObj.despair = diceTotalObj.despair + diceResult.despair;
2901 diceTotalObj.light = diceTotalObj.light + diceResult.light;
2902 diceTotalObj.dark = diceTotalObj.dark + diceResult.dark;
2903
2904 return diceTotalObj;
2905};
2906
2907eote.process.totalDiceValues = function (diceTotalObj) {
2908
2909 var diceTS = {
2910 success: 0,
2911 failure: 0,
2912 advantage: 0,
2913 threat: 0,
2914 triumph: 0,
2915 despair: 0,
2916 light: 0,
2917 dark: 0,
2918 diceGraphicsLog: "",
2919 diceTextLog: ""
2920 };
2921 var i = 0;
2922
2923 i = diceTotalObj.success - diceTotalObj.failure;
2924
2925 if (i >= 0) {
2926 diceTS.success = i;
2927 } else {
2928 diceTS.failure = Math.abs(i);
2929 }
2930 i = diceTotalObj.advantage - diceTotalObj.threat;
2931
2932 if (i >= 0) {
2933 diceTS.advantage = i;
2934 } else {
2935 diceTS.threat = Math.abs(i);
2936 }
2937 diceTS.triumph = diceTotalObj.triumph;
2938 diceTS.despair = diceTotalObj.despair;
2939 diceTS.light = diceTotalObj.light;
2940 diceTS.dark = diceTotalObj.dark;
2941
2942 return diceTS;
2943};
2944
2945eote.process.rollDice = function (diceObj) {
2946
2947 results = {
2948 success: 0,
2949 failure: 0,
2950 advantage: 0,
2951 threat: 0,
2952 triumph: 0,
2953 despair: 0,
2954 light: 0,
2955 dark: 0,
2956 diceGraphicsLog: '',
2957 diceTextLog: ''
2958 };
2959 eote.process.logger("eote.process.rollDice.FinalDiceToRoll", diceObj.count.boost + "b," + diceObj.count.ability + "g," + diceObj.count.proficiency + "y," + diceObj.count.setback + "blk," + diceObj.count.difficulty + "p," + diceObj.count.challenge + "r," + diceObj.count.force + "w," + diceObj.count.advantage + "a," + diceObj.count.threat + "t," + diceObj.count.failure + "f");
2960
2961 //Blue "Boost" die (d6)
2962 if (diceObj.count.boost > 0) {
2963 results = eote.roll.boost(diceObj.count.boost);
2964 diceObj.graphicsLog.Boost = results.diceGraphicsLog;
2965 diceObj.textLog.Boost = results.diceTextLog;
2966 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
2967 }
2968 //Green "Ability" die (d8)
2969 if (diceObj.count.ability > 0) {
2970 results = eote.roll.ability(diceObj.count.ability);
2971 diceObj.graphicsLog.Ability = results.diceGraphicsLog;
2972 diceObj.textLog.Ability = results.diceTextLog;
2973 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
2974 }
2975 //Yellow "Proficiency" die (d12)
2976 if (diceObj.count.proficiency > 0) {
2977 results = eote.roll.proficiency(diceObj.count.proficiency);
2978 diceObj.graphicsLog.Proficiency = results.diceGraphicsLog;
2979 diceObj.textLog.Proficiency = results.diceTextLog;
2980 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
2981 }
2982 //Black "SetBack" die (d6)
2983 if (diceObj.count.setback > 0) {
2984 results = eote.roll.setback(diceObj.count.setback);
2985 diceObj.graphicsLog.SetBack = results.diceGraphicsLog;
2986 diceObj.textLog.SetBack = results.diceTextLog;
2987 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
2988 }
2989 //Purple "Difficulty" die (d8)
2990 if (diceObj.count.difficulty > 0) {
2991 results = eote.roll.difficulty(diceObj.count.difficulty);
2992 diceObj.graphicsLog.Difficulty = results.diceGraphicsLog;
2993 diceObj.textLog.Difficulty = results.diceTextLog;
2994 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
2995 }
2996 //Red "Challenge" die (d12)
2997 if (diceObj.count.challenge > 0) {
2998 results = eote.roll.challenge(diceObj.count.challenge);
2999 diceObj.graphicsLog.Challenge = results.diceGraphicsLog;
3000 diceObj.textLog.Challenge = results.diceTextLog;
3001 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
3002 }
3003 //White "Force" die (d12)
3004 if (diceObj.count.force > 0) {
3005 results = eote.roll.force(diceObj.count.force);
3006 diceObj.graphicsLog.Force = results.diceGraphicsLog;
3007 diceObj.textLog.Force = results.diceTextLog;
3008 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
3009 }
3010 // Free Successes (from skills)
3011 if (diceObj.count.success > 0) {
3012 results = eote.roll.success(diceObj.count.success);
3013 diceObj.graphicsLog.Success = results.diceGraphicsLog;
3014 diceObj.textLog.Success = results.diceTextLog;
3015 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
3016 }
3017 // Free Advantage (from skills)
3018 if (diceObj.count.advantage > 0) {
3019 results = eote.roll.advantage(diceObj.count.advantage);
3020 diceObj.graphicsLog.Advantage = results.diceGraphicsLog;
3021 diceObj.textLog.Advantage = results.diceTextLog;
3022 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
3023 }
3024 //Free Threat (from skills)
3025 if (diceObj.count.threat > 0) {
3026 results = eote.roll.threat(diceObj.count.threat);
3027 diceObj.graphicsLog.Threat = results.diceGraphicsLog;
3028 diceObj.textLog.Threat = results.diceTextLog;
3029 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
3030 }
3031 // Free Failure (from skills)
3032 if (diceObj.count.failure > 0) {
3033 results = eote.roll.failure(diceObj.count.failure);
3034 diceObj.graphicsLog.Failure = results.diceGraphicsLog;
3035 diceObj.textLog.Failure = results.diceTextLog;
3036 diceObj.totals = eote.process.addDiceValues(diceObj.totals, results);
3037 }
3038 //finds the sum of each dice attribute
3039 diceObj.totals = eote.process.totalDiceValues(diceObj.totals);
3040 return diceObj;
3041};
3042
3043eote.process.diceOutput = function (diceObj, playerName, playerID) {
3044
3045 //log(diceObj);
3046 var s1 = '<img src="';
3047 var s2 = '" title="';
3048 var s3 = '" height="';
3049 var s4 = '" width="';
3050 var s5 = '"/>';
3051 var chatGlobal = '';
3052 var diceGraphicsResults = "";
3053 var diceGraphicsRolled = "";
3054 var diceTextRolled = "";
3055 var diceTextResults = "";
3056
3057 diceTextResults = "[";
3058 if (diceObj.totals.success > 0) {
3059 diceTextResults = diceTextResults + " Success:" + diceObj.totals.success;
3060 for (i = 1; i <= diceObj.totals.success; i++) {
3061 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.S + s2 + "Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3062 }
3063 }
3064 if (diceObj.totals.failure > 0) {
3065 diceTextResults = diceTextResults + " Fail:" + diceObj.totals.failure;
3066 for (i = 1; i <= diceObj.totals.failure; i++) {
3067 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.F + s2 + "Failure" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3068 }
3069 }
3070 if (diceObj.totals.advantage > 0) {
3071 diceTextResults = diceTextResults + " Advant:" + diceObj.totals.advantage;
3072 for (i = 1; i <= diceObj.totals.advantage; i++) {
3073 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.A + s2 + "Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3074 }
3075 }
3076 if (diceObj.totals.threat > 0) {
3077 diceTextResults = diceTextResults + " Threat:" + diceObj.totals.threat;
3078 for (i = 1; i <= diceObj.totals.threat; i++) {
3079 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.T + s2 + "Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3080 }
3081 }
3082 if (diceObj.totals.triumph > 0) {
3083 diceTextResults = diceTextResults + " Triumph:" + diceObj.totals.triumph;
3084 for (i = 1; i <= diceObj.totals.triumph; i++) {
3085 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.TRIUMPH + s2 + "Triumph" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3086 }
3087 }
3088 if (diceObj.totals.despair > 0) {
3089 diceTextResults = diceTextResults + " Despair:" + diceObj.totals.despair;
3090 for (i = 1; i <= diceObj.totals.despair; i++) {
3091 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.DESPAIR + s2 + "Despair" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3092 }
3093 }
3094 if (diceObj.totals.light > 0) {
3095 diceTextResults = diceTextResults + " Light:" + diceObj.totals.light;
3096
3097 for (i = 1; i <= diceObj.totals.light; i++) {
3098 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.L + s2 + "Light" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3099 }
3100 }
3101 if (diceObj.totals.dark > 0) {
3102 diceTextResults = diceTextResults + " Dark:" + diceObj.totals.dark;
3103 for (i = 1; i <= diceObj.totals.dark; i++) {
3104 diceGraphicsResults = diceGraphicsResults + s1 + eote.defaults.graphics.SYMBOLS.D + s2 + "Dark" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3105 }
3106 }
3107 diceTextResults = diceTextResults + "]";
3108 //------------------------------------>
3109 if (eote.defaults.globalVars.diceTestEnabled === true) {
3110 characterPlayer = 'TEST';
3111 } else if (diceObj.vars.characterName) {
3112 characterPlayer = diceObj.vars.characterName;
3113 } else {
3114 characterPlayer = playerName;
3115 }
3116
3117 var templateName = (diceObj.vars.spendingSuggestions.isSuggestions ? "suggestion" : "base");
3118
3119 /*Dice roll images work just fine when whispered*/
3120 if (eote.defaults.globalVars.diceTestEnabled === true) {
3121 chatGlobal = "/direct <br>6b 8g 12y 6blk 8p 12r 12w <br>";
3122 } else if (diceObj.vars.label) {
3123 chatGlobal = "/direct &{template:" + templateName +"} {{title=" + diceObj.vars.label + "}} {{subtitle=" + characterPlayer + "}}";
3124 } else {
3125 chatGlobal = "/direct &{template:" + templateName +"} {{title=" + characterPlayer + "}}";
3126 }
3127 //------------------------------------>
3128 if (eote.defaults.globalVars.diceLogChat === true) {
3129 if (eote.defaults.globalVars.diceLogRolledOnOneLine === true) {
3130
3131 diceGraphicsRolled = diceObj.graphicsLog.Boost + diceObj.graphicsLog.Ability + diceObj.graphicsLog.Proficiency + diceObj.graphicsLog.SetBack + diceObj.graphicsLog.Difficulty + diceObj.graphicsLog.Challenge + diceObj.graphicsLog.Force + diceObj.graphicsLog.Success + diceObj.graphicsLog.Advantage + diceObj.graphicsLog.Failure + diceObj.graphicsLog.Threat;
3132
3133 if (diceObj.textLog.Boost != "") diceTextRolled = diceTextRolled + "Boost:" + diceObj.textLog.Boost;
3134 if (diceObj.textLog.Ability != "") diceTextRolled = diceTextRolled + "Ability:" + diceObj.textLog.Ability;
3135 if (diceObj.textLog.Proficiency != "") diceTextRolled = diceTextRolled + "Proficiency:" + diceObj.textLog.Proficiency;
3136 if (diceObj.textLog.SetBack != "") diceTextRolled = diceTextRolled + "SetBack:" + diceObj.textLog.SetBack;
3137 if (diceObj.textLog.Difficulty != "") diceTextRolled = diceTextRolled + "Difficulty:" + diceObj.textLog.Difficulty;
3138 if (diceObj.textLog.Challenge != "") diceTextRolled = diceTextRolled + "Challenge:" + diceObj.textLog.Challenge;
3139 if (diceObj.textLog.Force != "") diceTextRolled = diceTextRolled + "Force:" + diceObj.textLog.Force;
3140 if (diceObj.textLog.Success != "") diceTextRolled = diceTextRolled + "Success:" + diceObj.textLog.Success;
3141 if (diceObj.textLog.Advantage != "") diceTextRolled = diceTextRolled + "Advantage:" + diceObj.textLog.Advantage;
3142 if (diceObj.textLog.Failure != "") diceTextRolled = diceGraphicsRolled + "Failure:" + diceObj.textLog.Failure;
3143 if (diceObj.textLog.Threat != "") diceTextRolled = diceGraphicsRolled + "Threat:" + diceObj.textLog.Threat;
3144
3145 if (eote.defaults.globalVars.diceGraphicsChat === true) {
3146 chatGlobal = chatGlobal + '{{roll=' + diceGraphicsRolled + '}}';
3147 } else {
3148 sendChat("", diceTextRolled);
3149 }
3150 } else {
3151
3152 if (eote.defaults.globalVars.diceGraphicsChat === true) {
3153
3154 if (diceObj.vars.label) {
3155 sendChat(characterPlayer, "/direct " + diceObj.vars.label + '<br>');
3156 }
3157 if (diceObj.graphicsLog.Boost != "") sendChat("", "/direct " + diceObj.graphicsLog.Boost);
3158 if (diceObj.graphicsLog.Ability != "") sendChat("", "/direct " + diceObj.graphicsLog.Ability);
3159 if (diceObj.graphicsLog.Proficiency != "") sendChat("", "/direct " + diceObj.graphicsLog.Proficiency);
3160 if (diceObj.graphicsLog.SetBack != "") sendChat("", "/direct " + diceObj.graphicsLog.SetBack);
3161 if (diceObj.graphicsLog.Difficulty != "") sendChat("", "/direct " + diceObj.graphicsLog.Difficulty);
3162 if (diceObj.graphicsLog.Challenge != "") sendChat("", "/direct " + diceObj.graphicsLog.Challenge);
3163 if (diceObj.graphicsLog.Force != "") sendChat("", "/direct " + diceObj.graphicsLog.Force);
3164 if (diceObj.graphicsLog.Success != "") sendChat("", "/direct " + diceObj.graphicsLog.Success);
3165 if (diceObj.graphicsLog.Advantage != "") sendChat("", "/direct " + diceObj.graphicsLog.Advantage);
3166 if (diceObj.graphicsLog.Failure != "") sendChat("", "/direct " + diceObj.graphicsLog.Failure);
3167 if (diceObj.graphicsLog.Threat != "") sendChat("", "/direct " + diceObj.graphicsLog.Threat);
3168 } else {
3169 if (diceObj.vars.label) {
3170 sendChat(characterPlayer, "/direct " + diceObj.vars.label + '<br>');
3171 }
3172 if (diceObj.textLog.Boost != "") sendChat("", "Boost:" + diceObj.textLog.Boost);
3173 if (diceObj.textLog.Ability != "") sendChat("", "Ability:" + diceObj.textLog.Ability);
3174 if (diceObj.textLog.Proficiency != "") sendChat("", "Proficiency:" + diceObj.textLog.Proficiency);
3175 if (diceObj.textLog.SetBack != "") sendChat("", "SetBack:" + diceObj.textLog.SetBack);
3176 if (diceObj.textLog.Difficulty != "") sendChat("", "Difficulty:" + diceObj.textLog.Difficulty);
3177 if (diceObj.textLog.Challenge != "") sendChat("", "Challenge:" + diceObj.textLog.Challenge);
3178 if (diceObj.textLog.Force != "") sendChat("", "Force:" + diceObj.textLog.Force);
3179 if (diceObj.textLog.Success != "") sendChat("", "Success:" + diceObj.textLog.Success);
3180 if (diceObj.textLog.Advantage != "") sendChat("", "Advantage:" + diceObj.textLog.Advantage);
3181 if (diceObj.textLog.Failure != "") sendChat("", "Failure:" + diceObj.textLog.Failure);
3182 if (diceObj.textLog.Threat != "") sendChat("", "Threat:" + diceObj.textLog.Threat);
3183 }
3184 }
3185 }
3186 /*TODO where things are sent to the game*/
3187 if (eote.defaults.globalVars.diceGraphicsChat === true) {
3188 chatGlobal = chatGlobal + '{{results=' + diceGraphicsResults + '}}';
3189 if (diceObj.vars.spendingSuggestions.isSuggestions)
3190 chatGlobal += " " + eote.process.skillSpending.buildSuggestions(diceObj);
3191 sendChat(characterPlayer, chatGlobal);
3192 } else {
3193 sendChat("Roll", diceTextResults);
3194 }
3195 eote.process.logger("eote.process.rollResult", diceTextResults);
3196};
3197
3198eote.roll = {
3199
3200 boost: function (diceQty) {
3201 //Blue "Boost" die (d6)
3202 //1 Blank
3203 //2 Blank
3204 //3 Success
3205 //4 Advantage
3206 //5 Advantage + Advantage
3207 //6 Success + Advantage
3208 var roll = 0;
3209 var diceResult = {
3210 success: 0,
3211 failure: 0,
3212 advantage: 0,
3213 threat: 0,
3214 triumph: 0,
3215 despair: 0,
3216 light: 0,
3217 dark: 0,
3218 diceGraphicsLog: "",
3219 diceTextLog: ""
3220 };
3221 var i = 0;
3222 var s1 = '<img src="';
3223 var s2 = '" title="';
3224 var s3 = '" height="';
3225 var s4 = '" width="';
3226 var s5 = '"/>';
3227
3228 if (eote.defaults.globalVars.diceTestEnabled === true) {
3229 diceQty = 6;
3230 }
3231 for (i = 1; i <= diceQty; i++) {
3232 if (eote.defaults.globalVars.diceTestEnabled === true) {
3233 roll = roll + 1;
3234 } else {
3235 roll = randomInteger(6);
3236 }
3237 switch (roll) {
3238 case 1:
3239 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3240 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.BOOST.BLANK + s2 + "Boost Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3241 break;
3242 case 2:
3243 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3244 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.BOOST.BLANK + s2 + "Boost Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3245 break;
3246 case 3:
3247 diceResult.diceTextLog = diceResult.diceTextLog + "(Success)";
3248 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.BOOST.S + s2 + "Boost Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3249 diceResult.success = diceResult.success + 1;
3250 break;
3251 case 4:
3252 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage)";
3253 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.BOOST.A + s2 + "Boost Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3254 diceResult.advantage = diceResult.advantage + 1;
3255 break;
3256 case 5:
3257 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage x2)";
3258 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.BOOST.AA + s2 + "Boost Advantage x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3259 diceResult.advantage = diceResult.advantage + 2;
3260 break;
3261 case 6:
3262 diceResult.diceTextLog = diceResult.diceTextLog + "(Success + Advantage)";
3263 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.BOOST.SA + s2 + "Boost Success + Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3264 diceResult.success = diceResult.success + 1;
3265 diceResult.advantage = diceResult.advantage + 1;
3266 break;
3267 }
3268 }
3269 return diceResult;
3270 },
3271 ability: function (diceQty) {
3272 //Green "Ability" die (d8)
3273 //1 Blank
3274 //2 Success
3275 //3 Success
3276 //4 Advantage
3277 //5 Advantage
3278 //6 Success + Advantage
3279 //7 Advantage + Advantage
3280 //8 Success + Success
3281 var roll = 0;
3282 var diceTextLog = "";
3283 var diceGraphicsLog = "";
3284 var diceResult = {
3285 success: 0,
3286 failure: 0,
3287 advantage: 0,
3288 threat: 0,
3289 triumph: 0,
3290 despair: 0,
3291 light: 0,
3292 dark: 0,
3293 diceGraphicsLog: "",
3294 diceTextLog: ""
3295 };
3296 var i = 0;
3297 var s1 = '<img src="';
3298 var s2 = '" title="';
3299 var s3 = '" height="';
3300 var s4 = '" width="';
3301 var s5 = '"/>';
3302
3303 if (eote.defaults.globalVars.diceTestEnabled === true) {
3304 diceQty = 8;
3305 }
3306 for (i = 1; i <= diceQty; i++) {
3307 if (eote.defaults.globalVars.diceTestEnabled === true) {
3308 roll = roll + 1;
3309 }
3310 else {
3311 roll = randomInteger(8);
3312 }
3313 switch (roll) {
3314 case 1:
3315 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3316 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.BLANK + s2 + "Ability Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3317 break;
3318 case 2:
3319 diceResult.diceTextLog = diceResult.diceTextLog + "(Success)";
3320 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.S + s2 + "Ability Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3321 diceResult.success = diceResult.success + 1;
3322 break;
3323 case 3:
3324 diceResult.diceTextLog = diceResult.diceTextLog + "(Success)";
3325 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.S + s2 + "Ability Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3326 diceResult.success = diceResult.success + 1;
3327 break;
3328 case 4:
3329 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage)";
3330 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.A + s2 + "Ability Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3331 diceResult.advantage = diceResult.advantage + 1;
3332 break;
3333 case 5:
3334 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage)";
3335 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.A + s2 + "Ability Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3336 diceResult.advantage = diceResult.advantage + 1;
3337 break;
3338 case 6:
3339 diceResult.diceTextLog = diceResult.diceTextLog + "(Success + Advantage)";
3340 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.SA + s2 + "Ability Success + Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3341 diceResult.success = diceResult.success + 1;
3342 diceResult.advantage = diceResult.advantage + 1;
3343 break;
3344 case 7:
3345 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage x2)";
3346 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.AA + s2 + "Ability Advantage x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3347 diceResult.advantage = diceResult.advantage + 2;
3348 break;
3349 case 8:
3350 diceResult.diceTextLog = diceResult.diceTextLog + "(Success x2)";
3351 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.ABILITY.SS + s2 + "Ability Success x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3352 diceResult.success = diceResult.success + 2;
3353 break;
3354 }
3355 }
3356 return diceResult;
3357 },
3358 proficiency: function (diceQty) {
3359 //Yellow "Proficiency" die (d12)
3360 //1 Blank
3361 //2 Triumph
3362 //3 Success
3363 //4 Success
3364 //5 Advantage
3365 //6 Success + Advantage
3366 //7 Success + Advantage
3367 //8 Success + Advantage
3368 //9 Success + Success
3369 //10 Success + Success
3370 //11 Advantage + Advantage
3371 //12 Advantage + Advantage
3372 var roll = 0;
3373 var diceTextLog = "";
3374 var diceGraphicsLog = "";
3375 var diceResult = {
3376 success: 0,
3377 failure: 0,
3378 advantage: 0,
3379 threat: 0,
3380 triumph: 0,
3381 despair: 0,
3382 light: 0,
3383 dark: 0,
3384 diceGraphicsLog: "",
3385 diceTextLog: ""
3386 };
3387 var i = 0;
3388 var s1 = '<img src="';
3389 var s2 = '" title="';
3390 var s3 = '" height="';
3391 var s4 = '" width="';
3392 var s5 = '"/>';
3393
3394 if (eote.defaults.globalVars.diceTestEnabled === true) {
3395 diceQty = 12;
3396 }
3397 for (i = 1; i <= diceQty; i++) {
3398 if (eote.defaults.globalVars.diceTestEnabled === true) {
3399 roll = roll + 1;
3400 }
3401 else {
3402 roll = randomInteger(12);
3403 }
3404 switch (roll) {
3405 case 1:
3406 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3407 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.BLANK + s2 + "Proficiency Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3408 break;
3409 case 2:
3410 diceResult.diceTextLog = diceResult.diceTextLog + "(Triumph(+Success))";
3411 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.TRIUMPH + s2 + "Proficiency Triumph(+Success)" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3412 diceResult.triumph = diceResult.triumph + 1;
3413 diceResult.success = diceResult.success + 1;
3414 break;
3415 case 3:
3416 diceResult.diceTextLog = diceResult.diceTextLog + "(Success)";
3417 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.S + s2 + "Proficiency Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3418 diceResult.success = diceResult.success + 1;
3419 break;
3420 case 4:
3421 diceResult.diceTextLog = diceResult.diceTextLog + "(Success)";
3422 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.S + s2 + "Proficiency Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3423 diceResult.success = diceResult.success + 1;
3424 break;
3425 case 5:
3426 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage)";
3427 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.A + s2 + "Proficiency Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3428 diceResult.advantage = diceResult.advantage + 1;
3429 break;
3430 case 6:
3431 diceResult.diceTextLog = diceResult.diceTextLog + "(Success + Advantage)";
3432 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.SA + s2 + "Proficiency Success + Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3433 diceResult.success = diceResult.success + 1;
3434 diceResult.advantage = diceResult.advantage + 1;
3435 break;
3436 case 7:
3437 diceResult.diceTextLog = diceResult.diceTextLog + "(Success + Advantage)";
3438 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.SA + s2 + "Proficiency Success + Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3439 diceResult.success = diceResult.success + 1;
3440 diceResult.advantage = diceResult.advantage + 1;
3441 break;
3442 case 8:
3443 diceResult.diceTextLog = diceResult.diceTextLog + "(Success + Advantage)";
3444 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.SA + s2 + "Proficiency Success + Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3445 diceResult.success = diceResult.success + 1;
3446 diceResult.advantage = diceResult.advantage + 1;
3447 break;
3448 case 9:
3449 diceResult.diceTextLog = diceResult.diceTextLog + "(Success x2)";
3450 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.SS + s2 + "Proficiency Success x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3451 diceResult.success = diceResult.success + 2;
3452 break;
3453 case 10:
3454 diceResult.diceTextLog = diceResult.diceTextLog + "(Success x2)";
3455 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.SS + s2 + "Proficiency Success x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3456 diceResult.success = diceResult.success + 2;
3457 break;
3458 case 11:
3459 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage x2)";
3460 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.AA + s2 + "Proficiency Advantage x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3461 diceResult.advantage = diceResult.advantage + 2;
3462 break;
3463 case 12:
3464 diceResult.diceTextLog = diceResult.diceTextLog + "(Advantage x2)";
3465 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.PROFICIENCY.AA + s2 + "Proficiency Advantage x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3466 diceResult.advantage = diceResult.advantage + 2;
3467 break;
3468 }
3469 }
3470 return diceResult;
3471 },
3472 setback: function (diceQty) {
3473 //Black "Setback" die (d6)
3474 //1 Blank
3475 //2 Blank
3476 //3 Failure
3477 //4 Failure
3478 //5 Threat
3479 //6 Threat
3480 var roll = 0;
3481 var diceTextLog = "";
3482 var diceGraphicsLog = "";
3483 var diceResult = {
3484 success: 0,
3485 failure: 0,
3486 advantage: 0,
3487 threat: 0,
3488 triumph: 0,
3489 despair: 0,
3490 light: 0,
3491 dark: 0,
3492 diceGraphicsLog: "",
3493 diceTextLog: ""
3494 };
3495 var i = 0;
3496 var s1 = '<img src="';
3497 var s2 = '" title="';
3498 var s3 = '" height="';
3499 var s4 = '" width="';
3500 var s5 = '"/>';
3501
3502 if (eote.defaults.globalVars.diceTestEnabled === true) {
3503 diceQty = 6;
3504 }
3505 for (i = 1; i <= diceQty; i++) {
3506 if (eote.defaults.globalVars.diceTestEnabled === true) {
3507 roll = roll + 1;
3508 }
3509 else {
3510 roll = randomInteger(6);
3511 }
3512 switch (roll) {
3513 case 1:
3514 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3515 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SETBACK.BLANK + s2 + "Setback Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3516 break;
3517 case 2:
3518 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3519 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SETBACK.BLANK + s2 + "Setback Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3520 break;
3521 case 3:
3522 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure)";
3523 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SETBACK.F + s2 + "Setback Failure" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3524 diceResult.failure = diceResult.failure + 1;
3525 break;
3526 case 4:
3527 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure)";
3528 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SETBACK.F + s2 + "Setback Failure" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3529 diceResult.failure = diceResult.failure + 1;
3530 break;
3531 case 5:
3532 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat)";
3533 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SETBACK.T + s2 + "Setback Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3534 diceResult.threat = diceResult.threat + 1;
3535 break;
3536 case 6:
3537 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat)";
3538 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SETBACK.T + s2 + "Setback Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3539 diceResult.threat = diceResult.threat + 1;
3540 break;
3541 }
3542 }
3543 return diceResult;
3544 },
3545 difficulty: function (diceQty) {
3546 //Purple "Difficulty" die (d8)
3547 //1 Blank
3548 //2 Failure
3549 //3 Threat
3550 //4 Threat
3551 //5 Threat
3552 //6 Failure + Failure
3553 //7 Failure + Threat
3554 //8 Threat + Threat
3555 var roll = 0;
3556 var diceTextLog = "";
3557 var diceGraphicsLog = "";
3558 var diceResult = {
3559 success: 0,
3560 failure: 0,
3561 advantage: 0,
3562 threat: 0,
3563 triumph: 0,
3564 despair: 0,
3565 light: 0,
3566 dark: 0,
3567 diceGraphicsLog: "",
3568 diceTextLog: ""
3569 };
3570 var i = 0;
3571 var s1 = '<img src="';
3572 var s2 = '" title="';
3573 var s3 = '" height="';
3574 var s4 = '" width="';
3575 var s5 = '"/>';
3576
3577 if (eote.defaults.globalVars.diceTestEnabled === true) {
3578 diceQty = 8;
3579 }
3580 for (i = 1; i <= diceQty; i++) {
3581 if (eote.defaults.globalVars.diceTestEnabled === true) {
3582 roll = roll + 1;
3583 }
3584 else {
3585 roll = randomInteger(8);
3586 }
3587 switch (roll) {
3588 case 1:
3589 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3590 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.BLANK + s2 + "Difficulty Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3591 break;
3592 case 2:
3593 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure)";
3594 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.F + s2 + "Difficulty Failure" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3595 diceResult.failure = diceResult.failure + 1;
3596 break;
3597 case 3:
3598 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat)";
3599 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.T + s2 + "Difficulty Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3600 diceResult.threat = diceResult.threat + 1;
3601 break;
3602 case 4:
3603 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat)";
3604 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.T + s2 + "Difficulty Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3605 diceResult.threat = diceResult.threat + 1;
3606 break;
3607 case 5:
3608 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat)";
3609 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.T + s2 + "Difficulty Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3610 diceResult.threat = diceResult.threat + 1;
3611 break;
3612 case 6:
3613 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure x2)";
3614 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.FF + s2 + "Difficulty Failure x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3615 diceResult.failure = diceResult.failure + 2;
3616 break;
3617 case 7:
3618 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure + Threat)";
3619 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.FT + s2 + "Difficulty Failure + Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3620 diceResult.failure = diceResult.failure + 1;
3621 diceResult.threat = diceResult.threat + 1;
3622 break;
3623 case 8:
3624 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat x2)";
3625 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.DIFFICULTY.TT + s2 + "Difficulty Threat x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3626 diceResult.threat = diceResult.threat + 2;
3627 break;
3628 }
3629 }
3630 return diceResult;
3631 },
3632 challenge: function (diceQty) {
3633 //Red "Challenge" die (d12)
3634 //1 Blank
3635 //2 Despair
3636 //3 Failure
3637 //4 Failure
3638 //5 Threat
3639 //6 Threat
3640 //7 Failure + Failure
3641 //8 Failure + Failure
3642 //9 Threat + Threat
3643 //10 Threat + Threat
3644 //11 Failure + Threat
3645 //12 Failure + Threat
3646 var roll = 0;
3647 var diceTextLog = "";
3648 var diceGraphicsLog = "";
3649 var diceResult = {
3650 success: 0,
3651 failure: 0,
3652 advantage: 0,
3653 threat: 0,
3654 triumph: 0,
3655 despair: 0,
3656 light: 0,
3657 dark: 0,
3658 diceGraphicsLog: "",
3659 diceTextLog: ""
3660 };
3661 var i = 0;
3662 var s1 = '<img src="';
3663 var s2 = '" title="';
3664 var s3 = '" height="';
3665 var s4 = '" width="';
3666 var s5 = '"/>';
3667
3668 if (eote.defaults.globalVars.diceTestEnabled === true) {
3669 diceQty = 12;
3670 }
3671 for (i = 1; i <= diceQty; i++) {
3672 if (eote.defaults.globalVars.diceTestEnabled === true) {
3673 roll = roll + 1;
3674 }
3675 else {
3676 roll = randomInteger(12);
3677 }
3678 switch (roll) {
3679 case 1:
3680 diceResult.diceTextLog = diceResult.diceTextLog + "(Blank)";
3681 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.BLANK + s2 + "Challenge Blank" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3682 break;
3683 case 2:
3684 diceResult.diceTextLog = diceResult.diceTextLog + "(Despair)";
3685 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.DESPAIR + s2 + "Challenge Despair" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3686 diceResult.despair = diceResult.despair + 1;
3687 diceResult.failure = diceResult.failure + 1;
3688 break;
3689 case 3:
3690 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure)";
3691 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.F + s2 + "Challenge Failure" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3692 diceResult.failure = diceResult.failure + 1;
3693 break;
3694 case 4:
3695 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure)";
3696 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.F + s2 + "Challenge Failure" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3697 diceResult.failure = diceResult.failure + 1;
3698 break;
3699 case 5:
3700 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat)";
3701 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.T + s2 + "Challenge Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3702 diceResult.threat = diceResult.threat + 1;
3703 break;
3704 case 6:
3705 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat)";
3706 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.T + s2 + "Challenge Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3707 diceResult.threat = diceResult.threat + 1;
3708 break;
3709 case 7:
3710 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure x2)";
3711 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.FF + s2 + "Challenge Failure x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3712 diceResult.failure = diceResult.failure + 2;
3713 break;
3714 case 8:
3715 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure x2)";
3716 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.FF + s2 + "Challenge Failure x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3717 diceResult.failure = diceResult.failure + 2;
3718 break;
3719 case 9:
3720 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat x2)";
3721 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.TT + s2 + "Challenge Threat x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3722 diceResult.threat = diceResult.threat + 2;
3723 break;
3724 case 10:
3725 diceResult.diceTextLog = diceResult.diceTextLog + "(Threat x2)";
3726 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.TT + s2 + "Challenge Threat x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3727 diceResult.threat = diceResult.threat + 2;
3728 break;
3729 case 11:
3730 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure + Threat)";
3731 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.FT + s2 + "Challenge Failure + Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3732 diceResult.failure = diceResult.failure + 1;
3733 diceResult.threat = diceResult.threat + 1;
3734 break;
3735 case 12:
3736 diceResult.diceTextLog = diceResult.diceTextLog + "(Failure + Threat)";
3737 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.CHALLENGE.FT + s2 + "Challenge Failure + Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3738 diceResult.failure = diceResult.failure + 1;
3739 diceResult.threat = diceResult.threat + 1;
3740 break;
3741 }
3742 }
3743 return diceResult;
3744 },
3745 force: function (diceQty) {
3746 //White "Force" die (d12)
3747 //1 Light
3748 //2 Light
3749 //3 Light + Light
3750 //4 Light + Light
3751 //5 Light + Light
3752 //6 Dark
3753 //7 Dark
3754 //8 Dark
3755 //9 Dark
3756 //10 Dark
3757 //11 Dark
3758 //12 Dark + Dark
3759 var roll = 0;
3760 var diceTextLog = "";
3761 var diceGraphicsLog = "";
3762 var diceResult = {
3763 success: 0,
3764 failure: 0,
3765 advantage: 0,
3766 threat: 0,
3767 triumph: 0,
3768 despair: 0,
3769 light: 0,
3770 dark: 0,
3771 diceGraphicsLog: "",
3772 diceTextLog: ""
3773 };
3774 var i = 0;
3775 var s1 = '<img src="';
3776 var s2 = '" title="';
3777 var s3 = '" height="';
3778 var s4 = '" width="';
3779 var s5 = '"/>';
3780
3781 if (eote.defaults.globalVars.diceTestEnabled === true) {
3782 diceQty = 12;
3783 }
3784 for (i = 1; i <= diceQty; i++) {
3785 if (eote.defaults.globalVars.diceTestEnabled === true) {
3786 roll = roll + 1;
3787 }
3788 else {
3789 roll = randomInteger(12);
3790 }
3791 switch (roll) {
3792 case 1:
3793 diceResult.diceTextLog = diceResult.diceTextLog + "(Light)";
3794 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.L + s2 + "Force Light" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3795 diceResult.light = diceResult.light + 1;
3796 break;
3797 case 2:
3798 diceResult.diceTextLog = diceResult.diceTextLog + "(Light)";
3799 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.L + s2 + "Force Light" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3800 diceResult.light = diceResult.light + 1;
3801 break;
3802 case 3:
3803 diceResult.diceTextLog = diceResult.diceTextLog + "(Light x2)";
3804 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.LL + s2 + "Force Light x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3805 diceResult.light = diceResult.light + 2;
3806 break;
3807 case 4:
3808 diceResult.diceTextLog = diceResult.diceTextLog + "(Light x2)";
3809 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.LL + s2 + "Force Light x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3810 diceResult.light = diceResult.light + 2;
3811 break;
3812 case 5:
3813 diceResult.diceTextLog = diceResult.diceTextLog + "(Light x2)";
3814 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.LL + s2 + "Force Light x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3815 diceResult.light = diceResult.light + 2;
3816 break;
3817 case 6:
3818 diceResult.diceTextLog = diceResult.diceTextLog + "(Dark)";
3819 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.D + s2 + "Force Dark" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3820 diceResult.dark = diceResult.dark + 1;
3821 break;
3822 case 7:
3823 diceResult.diceTextLog = diceResult.diceTextLog + "(Dark)";
3824 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.D + s2 + "Force Dark" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3825 diceResult.dark = diceResult.dark + 1;
3826 break;
3827 case 8:
3828 diceResult.diceTextLog = diceResult.diceTextLog + "(Dark)";
3829 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.D + s2 + "Force Dark" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3830 diceResult.dark = diceResult.dark + 1;
3831 break;
3832 case 9:
3833 diceResult.diceTextLog = diceResult.diceTextLog + "(Dark)";
3834 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.D + s2 + "Force Dark" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3835 diceResult.dark = diceResult.dark + 1;
3836 break;
3837 case 10:
3838 diceResult.diceTextLog = diceResult.diceTextLog + "(Dark)";
3839 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.D + s2 + "Force Dark" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3840 diceResult.dark = diceResult.dark + 1;
3841 break;
3842 case 11:
3843 diceResult.diceTextLog = diceResult.diceTextLog + "(Dark)";
3844 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.D + s2 + "Force Dark" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3845 diceResult.dark = diceResult.dark + 1;
3846 break;
3847 case 12:
3848 diceResult.diceTextLog = diceResult.diceTextLog + "(Dark x2)";
3849 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.FORCE.DD + s2 + "Force Dark x2" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3850 diceResult.dark = diceResult.dark + 2;
3851 break;
3852 }
3853 }
3854 return diceResult;
3855 },
3856 success: function (diceQty) {
3857 //Free Success
3858 var i = 0;
3859 var s1 = '<img src="';
3860 var s2 = '" title="';
3861 var s3 = '" height="';
3862 var s4 = '" width="';
3863 var s5 = '"/>';
3864
3865 var roll = 0;
3866 var diceTextLog = "";
3867 var diceGraphicsLog = "";
3868
3869 var diceResult = {
3870 success: 0,
3871 failure: 0,
3872 advantage: 0,
3873 threat: 0,
3874 triumph: 0,
3875 despair: 0,
3876 light: 0,
3877 dark: 0,
3878 diceGraphicsLog: "",
3879 diceTextLog: ""
3880 };
3881 diceResult.diceTextLog = diceTextLog + "(Success x" + diceQty + ")";
3882 diceResult.success = diceResult.success + diceQty;
3883 for (i = 0; i < diceQty; i++) {
3884 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SYMBOLS.S + s2 + "Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3885 }
3886 return diceResult;
3887 },
3888 advantage: function (diceQty) {
3889 //Free Advantage
3890 var i = 0;
3891 var s1 = '<img src="';
3892 var s2 = '" title="';
3893 var s3 = '" height="';
3894 var s4 = '" width="';
3895 var s5 = '"/>';
3896
3897 var roll = 0;
3898 var diceTextLog = "";
3899 var diceGraphicsLog = "";
3900
3901 var diceResult = {
3902 success: 0,
3903 failure: 0,
3904 advantage: 0,
3905 threat: 0,
3906 triumph: 0,
3907 despair: 0,
3908 light: 0,
3909 dark: 0,
3910 diceGraphicsLog: "",
3911 diceTextLog: ""
3912 };
3913 diceResult.diceTextLog = diceTextLog + "(Advantage x" + diceQty + ")";
3914 diceResult.advantage = diceResult.advantage + diceQty;
3915 for (i = 0; i < diceQty; i++) {
3916 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SYMBOLS.A + s2 + "Advantage" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3917 }
3918 return diceResult;
3919 },
3920 threat: function (diceQty) {
3921 //Free threat
3922 var i = 0;
3923 var s1 = '<img src="';
3924 var s2 = '" title="';
3925 var s3 = '" height="';
3926 var s4 = '" width="';
3927 var s5 = '"/>';
3928
3929 var roll = 0;
3930 var diceTextLog = "";
3931 var diceGraphicsLog = "";
3932
3933 var diceResult = {
3934 success: 0,
3935 failure: 0,
3936 advantage: 0,
3937 threat: 0,
3938 triumph: 0,
3939 despair: 0,
3940 light: 0,
3941 dark: 0,
3942 diceGraphicsLog: "",
3943 diceTextLog: ""
3944 };
3945 diceResult.diceTextLog = diceTextLog + "(Threat x" + diceQty + ")";
3946 diceResult.threat = diceResult.threat + diceQty;
3947 for (i = 0; i < diceQty; i++) {
3948 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SYMBOLS.T + s2 + "Threat" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3949 }
3950 return diceResult;
3951 },
3952 failure: function (diceQty) {
3953 //Free Failure
3954 var i = 0;
3955 var s1 = '<img src="';
3956 var s2 = '" title="';
3957 var s3 = '" height="';
3958 var s4 = '" width="';
3959 var s5 = '"/>';
3960
3961 var roll = 0;
3962 var diceTextLog = "";
3963 var diceGraphicsLog = "";
3964
3965 var diceResult = {
3966 success: 0,
3967 failure: 0,
3968 advantage: 0,
3969 threat: 0,
3970 triumph: 0,
3971 despair: 0,
3972 light: 0,
3973 dark: 0,
3974 diceGraphicsLog: "",
3975 diceTextLog: ""
3976 };
3977 diceResult.diceTextLog = diceTextLog + "(Failure x" + diceQty + ")";
3978 diceResult.failure = diceResult.failure + diceQty;
3979 for (i = 0; i < diceQty; i++) {
3980 diceResult.diceGraphicsLog = diceResult.diceGraphicsLog + s1 + eote.defaults.graphics.SYMBOLS.F + s2 + "Success" + s3 + eote.defaults.globalVars.diceGraphicsChatSize + s4 + eote.defaults.globalVars.diceGraphicsChatSize + s5;
3981 }
3982 return diceResult;
3983 }
3984};
3985
3986eote.events = function () {
3987
3988 //event listener Add character defaults to new characters
3989 on("add:character", function (characterObj) {
3990 eote.setCharacterDefaults(characterObj);
3991 });
3992 on("chat:message", function (msg) {
3993
3994 if (msg.type != 'api') {
3995 return;
3996 }
3997 eote.process.setup(msg.content, msg.who, msg.playerid);
3998 });
3999};
4000
4001// this only runs once per initialization of the script in order to prevent this process from running too frequently
4002function convertTokensToTags() {
4003 var generalSkills = eote.skillSuggestions.general;
4004 // iterate over the general skill names in the skill suggestion json
4005 Object.keys(generalSkills).forEach(function(generalSkillsKey) {
4006 var skill = generalSkills[generalSkillsKey];
4007
4008 // iterate over each skill's symbols keys: success, advantage, etc...
4009 Object.keys(skill).forEach(function(symbolKey) {
4010 // for each item in the json array, replace it's tokens with image urls
4011 var skillSymbolJArray = skill[symbolKey];
4012 var symReplace = eote.defaults.graphics.SymbolicReplacement[symbolKey];
4013 var item = {};
4014 for (var i = 0; i < skillSymbolJArray.length; i++) {
4015 item = skillSymbolJArray[i];
4016 item.text = item.text.replace(symReplace.matcher, symReplace.replacer);
4017 }
4018 });
4019 });
4020}
4021
4022on('ready', function() {
4023 eote.init();
4024});