-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautocombat.js
1786 lines (1634 loc) · 75.3 KB
/
autocombat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Github: Roll20-HERO
The macro sends the ID or name of the attacker, the ID or name of the defender, and optionally some other modifiers to the script:
attmod - Default = 0, optional OCV modifier (because of status like SET, BRACE or various types of bonus/malus);
distance - Default = 0, optional distance (in meters) - In case you have to manually specify a distance in metres;
shots - optional modifiers - can be: shots[n] - Number of shots firing for that phase for weapons with selective autofire [1 (max = autofire value)];
abort - optional modifier needed for "abort" type maneuvers like block and dodge.
manualroll - optional in case players want to roll manually to hit
macro example:
!heroHit mainhand;@{selected|token_id};@{target|token_id};manualroll?{dice roll total?|0}
The weapon string in token's gmnotes has to be:
{weaponname}[a]|[optionals]{/weaponname}
Note: use ":" to separate the name of the parameter from its value ONLY when the value is NOT numeric. For example, efftype MUST have a column before its value, while maxammo doesn't require it (i.e. efftype:e, maxammo10).
Other parameters are true/false, so it is only required their presence to activate their effect (i.e. ind - the weapon is indestructible).
a NUMBER Number of dice of damage. This is the only compulsory parameter. If it is 0 all the others can be omitted, since it means it is a spell (but probably you will use some optionals - see below); use "." for half die and "+" for 1 pip,
"-" for -1. If the damage is other than 0, other 2 parameters are required: "efftype:" and "damtype:" - see below.
Set it to 0 for spells, -1 for maneuvers.
OPTIONAL PARAMETERS - they can be in any order
efftype:[n] n = p for Physical, e for Energy; Required if damage is other than 0.
damtype:[n] n = k for Killing Damage, n for Normal Damage; Required if damage is other than 0;
currammo[n] Number of current rounds/arrows for ranged weapons, number of current durability for melee weapons - i.e. currammo12; Note that if you use currammo you MUST insert also maxammo in the string - they go always together;
maxammo[n] Number of max rounds/arrows for ranged weapons, number of max durability for melee weapons - i.e. maxammo12; Note that if maxammo is not present, the weapon is considered to have the parameters "ind" and "noammo"
tocv[n] Temp OCV the maneuver linked to the use of the weapon bestows the wielder until he/she changes weapon, hence maneuver - i.e. tocv2;
tdcv[n] Temp DCV the maneuver linked to the use of the weapon bestows the wielder until he/she changes weapon, hence maneuver;
trange[n] Temp Range Modifier the maneuver linked to the use of the weapon bestows the wielder until he/she changes weapon, hence maneuver;
ap[n] Armor Piercing [n times];
pe[n] Penetrating [n times];
af[n] Autofire [n shots max, default = 3];
wr[n] Weapon Range modifier [n];
wo[n] Weapon OCV mod (positive or negative) [n];
wd[n] Weapon DCV mod (positive or negative) [n];
so Stun Only weapon;
norange For melee weapons; it says that the weapon is a hand-to-hand weapon and checks for the range before a token can attack its target
reach[n] For melee weapons, in metres; if not present, reach is 2m;
str[n] STR minimum to wield the weapon, if not present, STR Min is 0; If you want to consider bonus to damage (up to 2x base weapon damage) for really strong characters, you have to use it
ind Indestructible weapon
los No range modifiers apply
psi omcv/dmcv apply instead of OCV/DCV
nohitroll No roll to hit is required. The attack automatically hits.
end[n] END cost to use the weapon, if not presents, the end cost is considered to be 1;
noammo Ranged weapon that doesn't consume ammo;
spellroll[n] Spell that requires a roll, n = modifier to spell skill roll (i.e. -1 every 10 active points of spell); If followed by a "/" and a name, that name will be used instead of "spellroll"
self Spell is self-only (automatically hits - no need to use nohitroll);
nohitlocs No hit locations used for damage. BODYx1 and STUNx1/2d6 used instead. Locations still used for armour purposes;
nobleed Weapon causes no bleeding effect;
nostun Weapon causes no stun;
nocrits Weapon cannot cause critical hits;
stunx[n] +StunX advantage, n is the value added to the stun multiplier.
effect: Name of Effect applied on hit AND at least 1 body damage dealt; also add the parameter "effself" in case the effect is applied on attacker instead of target. If amount of effect depends on damage dealt, add also "effvar" parameter
effself:[0/1] Effect is applied on attacker instead of target;
effvar[n] Parameter to use the damage dealt with the attack as the amount for the effect applied. n = divider, ignored if no "effect:" parameter is present. Normally n = number of attributes affected. If effvar is present
the effect "spell" in the Abilities must have "[amount]" instead of a numerical value:
i.e. For a vampiric weapon that heals the wielder with an amount of body/stun equal to the body damage dealt, the string in the Character's Abilities would be:
{effect}aid:[amount]f|body/stun|hasdef:pd|freq:o|duration:0s|counter:0|on|desc:Vampiric Heal|nostatus|heal{/effect} - the name of the ability would be [vampiric], and the parameter in the weapon string would be effect:vampiric. The
weapon string would also contain "effself" and "effvar2" (see example below).
effonhit:[0/1] Effect is applied on hit instead of on at least 1 body damage dealt. Ignored if no "effect:" parameter is present.
effchance[n] Effect has a n% chance of being applied. Still needs "effonhit" in case it doesn't take a minimum damage to trigger the chance.
Examples:
{katana}2|efftype:p|damtype:k|currammo100|maxammo100|tocv2|tdcv2|end2|norange{/katana}
{firebolt}6|efftype:e|damtype:n|end3|spellroll-3{/firebolt}
{bow}1.|efftype:p|damtype:k|currammo24|maxammo24|end3|wo1|wr2{/bow}
{block}-1|tocv2|tdcv1{/block}
{dodge}-1|tdcv3{/dodge}
Weapons with effects:
{demonsword}2|efftype:p|damtype:k|ind|norange|wo1|end2|str11|effect:vampiric|effself:1|effvar2{/demonsword} **this weapon needs an Ability named [vampiric] with this content: {effect}aid:[amount]f|body/stun|hasdef:no|freq:o|duration:0s|counter:0|on|desc:Vampiric Heal|nostatus|heal{/effect}
{holysword}2|efftype:p|damtype:k|ind|norange|wo1|end2|str11|effect:heal/lightning|effself:1/0|effonhit:1/1{/demonsword} **this weapon is like the one above, but applies two effects. it will need two distinct "spells" in character's journal:
[heal] with this content (for example): {effect}aid:2d|body/stun|hasdef:no|freq:o|duration:0s|counter:0|on|desc:Heal|nostatus|heal{/effect}
and [lightning] with this: {effect}dam:2d|killing|hasdef:red|freq:o|duration:0s|counter:0|on|desc:Lightning|nostatus{/effect}
Spells with effects:
Also spells can apply Effects. See comments in effects.js
The script will look for some specific strings within GMNotes in attacker or defender Token or specific values in combathelper token's bars:
DEFENDER:
{shield}n{/shield} - n is a number between 1 and 9, it represents the DCV of the shield in use
{nostun} - token doesn't take STUN damage;
{nobleed} - token doesn't bleed;
{damagereduction}{/damagereduction} - The string in gmnotes has to be: {damagereduction}zxxx0.yy{/damagereduction} where z can be "n" or "r" (normal or resistant), xxx can be any combination of "e", "m" and "p" (energy, mental, physical
- in no specific order) and y has to be 25, 50 or 75.
Note that 0.25 means a Damage Reduction of 75%, so basically 25 and 75 are inverted. for example, a character with 25% Physical Damage Reduction, Resistant would have:
{damagereduction}rpxx0.75{/damagereduction} (the "xx" is because any letter other than "e", "m" or "p" is fine, is a filler)
{nohitlocs} - Token always takes BODYx1 and STUNx3 in case of Killing damage, and no multipliers in case of Normal damage (you can still aim at a specific location for armour purposes, though);
{mods}dcv[n]|ocv[n]|rpd[n]|red[n]|omcv[n]|dmcv[n]{/mods} - Modifier to DCV/OCV/rPD/rED/omcv/dmcv, if any (for example because of impairment, poison, a barrier or other special effects that you don't want/can to track on the character sheet)
ATTACKER:
Aim at a specific location: the Bar1_value (green) of the combathelper token has to be 0-9: 0 head, 1 hands, 2 arms, 3 shoulders, 4 chest, 5 abdomen, 6 vitals, 7 thighs, 8 legs, 9 feet.
If the value is "" then a normal hit is considered, with random location.
ARMOUR
The armour is represented by a string in token's gmnotes:
{armor}head/10/10/|7|7#hand|1|1#arm|1|1#shoulder/10/10/|6|6#chest/10/10/|6|6#abdomen/10/10/|6|6#vitals/10/10/|6|6#thigh|1|1#leg/10/10/|6|6#foot/10/10/|6|6{/armor}
Basically armour strings contain always 10 entries, one for each location. What changes is the protection value - the numbers separated by pipes "|", and the durability values, if any - the numbers separated by slashes "/"
In the example above, the head location has a durability of 10 (on a 10 max), and a protection of 7 PD and 7 ED.
So, for any location, the meaning of the numbers is:
locname/current durability/max durability/|rPD value|rED value
Durability values are optional. If not present, the armour will never degrade its protection.
Entries are separated by the "#" character.
SPELLS: to tell the script that a particular "weapon" is in fact a special Spell, put the damage to 0.
If a spell requires a spell roll, and the character has a skill in his/her character's journal called "spellroll" (containing only the value of his/her total skill), the "weapon" string needs the argument "spellroll"
followed by a number representing the skill roll modifier (usually -1 every 10 active points of spell). Without the parameter "spellroll" the spell always succeeds.
MANEUVERS: Block and Dodge can be simulated using these strings in characters journal's gmnotes (the values represented here are for the standard HERO Block and Dodge):
{block}-1|tdcv0|tocv2{/block}
{dodge}-1|tdcv3|self{/dodge}
The macroes to use the maneuvers are (respectively):
!heroHit block;@{selected|token_id};@{target|token_id};abort
!heroHit dodge;@{selected|token_id};;abort
** Due to a bug in the Roll20 API, it is not possible to retrieve journal's gmnotes content. For the time being, just put the strings in TOKEN's gmnotes.
*/
var waf = 1;
var gmLogShow = false;
function arrayHasOwnIndex(array, prop) {
return array.hasOwnProperty(prop) && /^0$|^[1-9]\d*$/.test(prop) && prop <= 4294967294; // 2^32 - 2
}
function checkTurn(attackerName){
var oAttName = attackerName[0];
if( typeof oAttName != "object")
oAttName = attackerName;
var actingID = "";
var c = Campaign();
var turn_order = JSON.parse(c.get('turnorder'));
var turn = turn_order.shift();
actingID = oAttName.get('_id');
var actingName = oAttName.get('name');
if (turn.id != actingID && !abort) { // abort maneuvers are always allowed
sendChat("GM", whisper + actingName + ", it is not your turn.");
return true;
}
}
function checkMods(attacker, modifier){
var oAttName = attacker[0];
if( typeof oAttName != "object")
oAttName = attacker;
var gmnotes = decodeURI(oAttName.get('gmnotes'));
var startPos = decodeURI(gmnotes).indexOf("{mods}");
if(startPos >= 0){
var endPos = decodeURI(gmnotes).indexOf("{/mods}");
var charMods = decodeURI(gmnotes).substr(startPos+6, (endPos-startPos)-6).split("|");
var found = -1;
for(var i=0;i<charMods.length;i++){
if(charMods[i].indexOf(modifier) != -1){ found = i; }
}
if(found >=0)
return parseInt(charMods[found].replace(modifier, ""));
else
return 0;
} else return 0;
}
function weaponEffects(damage){
applySpellEffect = false;
for(var eff=0; eff<wEffect.length; eff++)
{
if(effOnHit[eff] == "true" || effOnHit[eff] == "1" && effOnHit[eff] != null && effOnHit[eff] != undefined)
var onHit = true;
else
var onHit = false;
if(effChance[eff] != "" && !isNaN(effChance[eff]) && effChance[eff] != null && effChance[eff] != undefined)
var Chance = parseInt(effChance[eff]);
else
var Chance = 0;
if(effSelf[eff] == "true" || effSelf[eff] == "1" && effSelf[eff] != null && effSelf[eff] != undefined)
var onAttacker = true;
else
var onAttacker = false;
if(onHit || damage >= 1) // Effect is applied on hit or if at least 1 body has been inflicted
{
var otempChar = getObj("character", oAttacker.get("represents"));
var oTempObj = findObjs({name: "["+wEffect[eff]+"]",_type: "ability", _characterid: otempChar.id}, {caseInsensitive: true})[0];
if(oTempObj == "")
{
sendChat("Script", "/w gm Put the spell named '[" + wEffect[eff] + "]' into attacker's journal first!");
return;
}
var sEffect = oTempObj.get("action");
if(parseInt(effVar[eff])>0)
{
var amount = parseInt(damage/parseInt(effVar[eff]));
sEffect = sEffect.replace("[amount]", amount);
}
var oTarget = oDefender;
if(onAttacker)
oTarget = oAttacker;
if(Chance>0){
var chanceRoll = randomInteger(100);
if(chanceRoll<=Chance){
insertEffect(oTarget, sEffect, "", "");
sendChat("Script", "/w gm Effect " + wEffect[eff] + " triggers! Applied on " + oTarget.get("name"));
}
}
else{
insertEffect(oTarget, sEffect, "", "");
sendChat("Script", "/w gm Effect " + wEffect[eff] + " applied on " + oTarget.get("name"));
}
}
}
}
function parseWeapon(weaponName, attackerName, shotsFired){
var oAttName = attackerName[0];
if( typeof oAttName != "object")
oAttName = attackerName;
var unwrapped = unwrapString(weaponName, "|", oAttName, "");
var noAmmo = false;
var indestructible = false;
var gmnotes = decodeURI(oAttName.get('gmnotes'));
gmnotes = gmnotes.replace(/%23/g, '#');
gmnotes = gmnotes.replace(/%3A/g, ':');
if(unwrapped.uString == "")
{
if(weaponName == "block" || weaponName == "dodge") // if Block or Dodge and they are not present in token gmnotes, look for them in journal
unwrapped = unwrapString(weaponName, "|" , oAttName, "journal");
if(unwrapped.uString == "")
{
sendChat("parseWeapon","/w GM no '" + weaponName + "' present for " + oAttName.get("name") + " (or malformed string)!");
return -1;
}
}
var aAmmo = unwrapped.uArray;
var weaponString = unwrapped.uString;
var newWeaponString = "";
if (aAmmo.length>1){
for(var i=1;i<aAmmo.length;i++){
if(aAmmo[i].indexOf("damtype:") !== -1){ damNK = aAmmo[i].replace("damtype:", ""); }
if(aAmmo[i].indexOf("currammo") !== -1){ currAmmo = parseInt(aAmmo[i].replace("currammo", "")); }
if(aAmmo[i].indexOf("maxammo") !== -1){ maxAmmo = parseInt(aAmmo[i].replace("maxammo", "")); }
if(aAmmo[i].indexOf("af") !== -1){ waf = parseInt(aAmmo[i].replace("af", "")); }
if(aAmmo[i].indexOf("noammo") !== -1){ noAmmo = true; }
if(aAmmo[i].indexOf("ind") !== -1){ indestructible = true;}
}
}
if(maxAmmo == 0)
{
indestructible = true;
noAmmo = true;
}
if(shotsFired > 0){
if(shotsFired>waf) {AF = waf;} else if (shotsFired==0){ AF = 1;} else if(shotsFired<waf && shotsFired>1 || shotsFired == waf){ AF = waf;}
}else{
AF = waf;
}
if (currAmmo == 0){
if(noAmmo && !indestructible){
sendChat("GM", whisper + oAttName.get("name") + " Your weapon breaks!");
AF = 0;
}else if(noAmmo && indestructible)
{
return aAmmo;
}
else{
sendChat("GM", whisper + oAttName.get("name") + " Your " + weaponName + " is out of ammo!");
sendChat("parseWeapon", whisper + "gm " + oAttName.get("name") + ": " + weaponName + " is out of ammo.");
AF = 0;
}
oAttName.set('status_spanner', true);
} else // Ammo is > 0
{
if(noAmmo==false){
if(currAmmo<AF)
{
AF = currAmmo; currAmmo = 0; oAttName.set('status_spanner', true);
sendChat("GM", whisper + oAttName.get("name") + " You are out of ammo on your " + weaponName + "!");
sendChat("parseWeapon", whisper + "gm " + oAttName.get("name") + ": " + weaponName + " is out of ammo.");
}
else{
currAmmo -= AF;
}
for(var a=0;a<aAmmo.length;a++)
{
if(aAmmo[a].indexOf("currammo")>=0)
{
aAmmo[a] = "currammo" + currAmmo;
break;
}
}
for(var rs=0; rs<aAmmo.length;rs++){
newWeaponString += aAmmo[rs] + "|";
}
newWeaponString = newWeaponString.substring(0,newWeaponString.length-1);
gmnotes = gmnotes.replace("{"+weaponName+"}"+weaponString+"{/"+weaponName+"}", "{"+weaponName+"}"+newWeaponString+"{/"+weaponName+"}");
oAttName.set('gmnotes', gmnotes);
} else // Weapon doesn't use ammo
{
if(indestructible==false) // Check for weapon degradation
{
currAmmo -= AF;
for(var a=0;a<aAmmo.length;a++)
{
if(aAmmo[a].indexOf("currammo")>=0)
{
aAmmo[a] = "currammo" + currAmmo;
break;
}
}
var halfAmmo = parseInt(maxAmmo/2);
if(currAmmo==halfAmmo)
{
sendChat("Master", whisper + oAttName.get("name") + " Your weapon is starting to show signs of wear!");
for(var d=0; d<dmgClasses.length; d++)
{
if(dmgClasses[d]==aAmmo[0]) break;
}
var oldDmg = aAmmo[0];
if(damNK=="n")
aAmmo[0] = parseInt(aAmmo[0])-1;
else
aAmmo[0] = dmgClasses[d-1];
var newWeaponString = "";
//var tail = "{/"+aAmmo.pop();
aAmmo.pop();
aAmmo.push("DEG" + oldDmg);
//aAmmo.push(tail);
for(var rs=0; rs<aAmmo.length;rs++){
newWeaponString += aAmmo[rs] + "|";
}
newWeaponString = newWeaponString.substring(0,newWeaponString.length-1);
gmnotes = gmnotes.replace("{"+weaponName+"}"+weaponString+"{/"+weaponName+"}", "{"+weaponName+"}"+newWeaponString+"{/"+weaponName+"}");
oAttName.set('gmnotes', gmnotes);
}
else
{
for(var rs=0; rs<aAmmo.length;rs++){
newWeaponString += aAmmo[rs] + "|";
}
newWeaponString = newWeaponString.substring(0,newWeaponString.length-1);
gmnotes = gmnotes.replace("{"+weaponName+"}"+weaponString+"{/"+weaponName+"}", "{"+weaponName+"}"+newWeaponString+"{/"+weaponName+"}");
oAttName.set('gmnotes', gmnotes);
}
}
}
}
return aAmmo;
}
function checkArmor(target){
var aLocs = new Array();
var unwrapped = unwrapString("armor", "#", target, "");
if(unwrapped.uString == "")
{
aLocs = ["head|0|0","hand|0|0","arm|0|0","shoulder|0|0","chest|0|0","abdomen|0|0","vitals|0|0","thigh|0|0","leg|0|0","foot|0|0"];
return aLocs;
}
else
return unwrapped.uArray;
}
function updateAttacker(attacker, applyManeuver){
var oObj = attacker[0];
if( typeof oObj != "object")
oObj = attacker;
var shooterEnd = parseInt(oObj.get('bar2_value'));
var shooterStun = parseInt(oObj.get('bar1_value'));
var shooterBody = parseInt(oObj.get('bar3_value'));
if((shooterEnd - endCost)<0){
// Use Stun instead of END
var diceEndStun = Math.round((shooterEnd - endCost)/2);
if(diceEndStun<=0) diceEndStun = 1;
var damageEndStun = 0;
for(var nn=0; nn<diceEndStun; nn++){
damageEndStun += randomInteger(6);
}
if((shooterStun-damageEndStun)<=0 && (shooterStun-damageEndStun) > -11 && shooterBody >= 0){
oObj.set('status_pummeled', true);
oObj.set('status_sleepy', false);
oObj.set('bar1_value', (shooterStun-damageEndStun));
oObj.set('bar2_value', (shooterStun-damageEndStun));
}else if ((shooterStun-damageEndStun) < -10 || shooterBody <= 0){
oObj.set('status_dead', true);
oObj.set('status_pummeled', false);
oObj.set('bar1_value', (shooterStun-damageEndStun));
oObj.set('bar2_value', (shooterStun-damageEndStun));
}else{
oObj.set('bar1_value', (shooterStun-damageEndStun));
oObj.set('bar2_value', 0);
}
}
else{
oObj.set('bar2_value', (shooterEnd - endCost));
}
if(applyManeuver) // Apply temporary modifiers depending on maneuver used (taken from weapon fired)
{
var oShooter = getObj("character", oObj.get("represents"));
oShooterTOCV = findObjs({name: "tempOCV",_type: "attribute", _characterid: oShooter.id}, {caseInsensitive: true})[0];
oShooterTDCV = findObjs({name: "tempOCV",_type: "attribute", _characterid: oShooter.id}, {caseInsensitive: true})[0];
oShooterRange = findObjs({name: "tempRange",_type: "attribute", _characterid: oShooter.id}, {caseInsensitive: true})[0];
oShooterTOCV.set("current", attTOCV);
oShooterTDCV.set("current", attTDCV);
oShooterRange.set("current", attTRange);
}
}
function computeDamage(nShot){
var shots = nShot;
var armorTable = checkArmor(oDefender);
var locationHit = armorTable[locHit];
var armorPart = locationHit.split("|");
var resilience = armorPart[0].split("/");
defAP = 0;
defP = 0;
if(damType == "p") {aDef = parseInt(armorPart[1]);} else{ aDef = parseInt(armorPart[2]); }
if (armorPart.length>3){ // See whether the armor has AP or Penetrating hardness
for(var part=3;part<armorPart.length;part++){
if(armorPart[part].indexOf("ap") !== -1){ defAP = parseInt(armorPart[part].replace("ap", "")); }
if(armorPart[part].indexOf("pe") !== -1){ defP = parseInt(armorPart[part].replace("pe", "")); }
}
}
//log("aDef: "+aDef);
// Check if there is a durability value - if not, the armour is indestructible
// Durability values have to follow the name of the location. I.e.: #chest/10/10|2|2# for a chest location with a durability of 10 (standard) and a PD/ED of 2
if(resilience.length>1)
{
var armorLoss = parseInt(resilience[1])/parseInt(resilience[2]);
aDef = Math.round(aDef*armorLoss);
if(aDef == 0)
{
sendChat("Master", whisper + defName + " Your " + resilience[0] + " armour has fallen to pieces!");
sendChat("Script", "/w GM " + defName + resilience[0] + " armour has fallen to pieces!");
}
}
sImg1 = '<img src="';
sImg2 = '"/>';
var left = "";
var right = "";
if(locHit == 1 || locHit == 2 || locHit == 3 || locHit == 7 || locHit == 8 || locHit == 9){
var leftright = randomInteger(2);
if(leftright == 1){ right = "<b><(right)</b>"; left = "";} else {right = ""; left = "<b>(left)></b>";}
}
//log("shots: " + shots);
//hits
hits[shots] = new Array();
hits[shots][0] = "<div align='center'>" + left + sImg1 + locImg + sImg2 + right + "</div>";
var damageTot = 0;
var damageStun = 0;
var absoluteDamage = 0;
var bodyRolled = 0;
var stunRolled = 0;
if(damNK == "k"){ // Killing Damage
if(strDamMod>0) // In case of melee weapons, if the character's STR is higher than the STR Minimum for the weapon, increase the damage up to base damage * 2
{
for(var i=0;i<dmgClasses.length;i++){
if(dmgClasses[i] == numdice){
if(i+strDamMod > i*2)
i = i*2;
else if(strDamMod>0)
i+=strDamMod;
numdice = dmgClasses[i];
if(numdice.indexOf(".")>=0)
halfdie = true;
if(numdice.indexOf("+")>=0)
pip = 1;
if(numdice.indexOf("-")>=0)
pip = -1;
numdice = numdice.replace("-","");
numdice = numdice.replace("+","");
numdice = numdice.replace(".","");
nd = parseInt(numdice);
break;
}
}
}
if(isCrit){
//log("entered killing critical");
damageTot = nd * 6;
if (halfdie){
damageTot += 3;
}
} else {
for(var dice = 0; dice < nd; dice ++){
damageTot += randomInteger(6);
}
if (halfdie){
damageTot += parseInt(halfdieBody[randomInteger(6)]);
}
}
// Apply totals against defenses and check for AP or Penetrating
damageTot += pip; // Add 1 Pip in case it exists
gmLog += "<br/>Damage rolled: " + damageTot;
bodyRolled = damageTot;
// Armor degradation
if(damageTot>= Math.round(aDef/3)) // Check if the damage is enough to ruin the armour
{
var armorDmg = 1;
if(armorPart[0].indexOf("/") != -1) // Check if the armour is indestructible
{
var armorRes = armorPart[0].split("/");
if(damageTot >= aDef*2) armorDmg = 2;
armorRes[1] = parseInt(armorRes[1]) - armorDmg;
var newArmor = "{armor}";
var oldArmor = newArmor;
var oldArmorPart;
for(var ls=0; ls<10; ls++)
{
oldArmorPart = armorTable[ls];
if(ls == locHit) // Armor part hit
{
var armorTemp = armorTable[ls].split("/");
armorTemp[1] = armorRes[1];
armorTable[ls] = armorTemp[0] + "/" + armorTemp[1] + "/" + armorTemp[2] + "/" + armorTemp[3];
}
//log("armorpart: "+armorTable[ls]);
oldArmor += oldArmorPart + "#";
newArmor += armorTable[ls] + "#";
}
newArmor = newArmor.substr(0, newArmor.length-1) + "{/armor}";
oldArmor = oldArmor.substr(0, oldArmor.length-1) + "{/armor}";
// write the new armour string into gmnotes
var gmnotes = decodeURI(oDefender.get('gmnotes'));
gmnotes = gmnotes.replace(/%23/g, '#');
gmnotes = gmnotes.replace(oldArmor, newArmor);
oDefender.set('gmnotes', gmnotes);
}
}
// See if there are special Mods with rPD/rED or PD/ED
var whattolookfor = "";
var modsNormalDef = 0;
var modsResDef = 0;
if(damType == "p")
whattolookfor = "pd";
else
whattolookfor = "ed";
modsNormalDef = checkMods(oAttacker, whattolookfor);
modsResDef = checkMods(oAttacker, "r"+whattolookfor);
nDef += modsNormalDef;
rDef += modsResDef;
if(AP>defAP){
var numTimes = AP - defAP;
for(var h=0;h<numTimes;h++)
AP *= 2;
if(aDef>0){
aDef = Math.round(aDef/AP);
if(aDef<1)
aDef = 1;
}
if(rDef>0){
rDef = Math.round(rDef/AP);
if(rDef<1)
rDef = 1;
}
if(nDef>0){
nDef = Math.round(nDef/AP);
if(nDef<1)
nDef = 1;
}
}
var BodyMultiplier;
var StunMultiplier;
if(!noHitLocs)
{
BodyMultiplier = parseFloat(damBody[locHit]);
StunMultiplier = parseInt(damKStun[locHit]);
} else // No Hit Locations Advantage
{
BodyMultiplier = 1;
StunMultiplier = randomInteger(3);
}
if(oDefender.get("status_dead"))
StunMultiplier *= 2;
StunMultiplier += StunX; // StunX advantage
var totalDefsBody = parseInt(aDef) + parseInt(rDef);
var totalDefsStun = parseInt(aDef) + parseInt(nDef) + parseInt(rDef);
stunRolled = bodyRolled * StunMultiplier;
absoluteDamage = damageTot - totalDefsBody;
damageStun = (damageTot * StunMultiplier) - totalDefsStun;
damageTot = parseInt((damageTot - totalDefsBody) * BodyMultiplier);
if(damageTot>absoluteDamage) absoluteDamage = damageTot;
if(damageTot<0) damageTot = 0;
if(damageStun<0) damageStun = 0;
if (Penetrating>defP && damageTot < nd) damageTot = nd;
if (damageStun < damageTot) damageStun = damageTot;
} else { // Normal Damage - No Autofire possible
// Add damage mod due to str over the str min, if any (max damage = 2x base damage)
if(nd + strDamMod > nd * 2)
nd = nd * 2;
else
nd += strDamMod;
var whattolookfor = "";
var modsNormalDef = 0;
var modsResDef = 0;
if(damType == "p")
whattolookfor = "pd";
else
whattolookfor = "ed";
// See if there are special Mods with rPD/rED or PD/ED
modsNormalDef = checkMods(oAttacker, whattolookfor);
modsResDef = checkMods(oAttacker, "r"+whattolookfor);
nDef += modsNormalDef;
rDef += modsResDef;
if(isCrit){
//log("critical normal damage");
damageTot = nd * 2;
damageStun = nd * 6;
stunRolled = damageStun;
bodyRolled = damageTot;
} else {
//log("normal damage");
for(var dice = 0; dice < nd; dice ++){
temp = randomInteger(6);
damageTot += parseInt(herodieBody[temp]);
damageStun += temp;
stunRolled = damageStun;
bodyRolled = damageTot;
}
}
// Armor degradation
if(damageTot>= Math.round(aDef/3)) // Check if the damage is enough to ruin the armour
{
var armorDmg = 1;
if(armorPart[0].indexOf("/") != -1) // Check if the armour is indestructible
{
var armorRes = armorPart[0].split("/");
if(damageTot >= aDef*2) armorDmg = 2;
armorRes[1] = parseInt(armorRes[1]) - armorDmg;
var newArmor = "{armor}";
var oldArmor = newArmor;
var oldArmorPart;
for(var ls=0; ls<10; ls++)
{
oldArmorPart = armorTable[ls];
if(ls == locHit) // Armor part hit
{
var armorTemp = armorTable[ls].split("/");
armorTemp[1] = armorRes[1];
armorTable[ls] = armorTemp[0] + "/" + armorTemp[1] + "/" + armorTemp[2] + "/" + armorTemp[3];
}
//log("armorpart: "+armorTable[ls]);
oldArmor += oldArmorPart + "#";
newArmor += armorTable[ls] + "#";
}
newArmor = newArmor.substr(0, newArmor.length-1) + "{/armor}";
oldArmor = oldArmor.substr(0, oldArmor.length-1) + "{/armor}";
// write the new armour string into gmnotes
var gmnotes = decodeURI(oDefender.get('gmnotes'));
gmnotes = gmnotes.replace(/%23/g, '#');
gmnotes = gmnotes.replace(oldArmor, newArmor);
oDefender.set('gmnotes', gmnotes);
}
}
if(AP>defAP){
var numTimes = AP - defAP;
for(var h=0;h<numTimes;h++)
AP *= 2;
if(aDef>0){
aDef = Math.round(aDef/AP);
if(aDef<1)
aDef = 1;
}
if(rDef>0){
rDef = Math.round(rDef/AP);
if(rDef<1)
rDef = 1;
}
if(nDef>0){
nDef = Math.round(nDef/AP);
if(nDef<1)
nDef = 1;
}
}
var BodyMultiplier;
var StunMultiplier;
if(!noHitLocs) // No Hit Locations Advantage
{
BodyMultiplier = parseFloat(damBody[locHit]);
StunMultiplier = parseFloat(damNStun[locHit]);
} else
{
BodyMultiplier = 1;
StunMultiplier = 1;
}
if(oDefender.get("status_dead"))
StunMultiplier *= 2;
StunMultiplier += StunX;
var totalDefsBody = parseInt(aDef) + parseInt(rDef) + parseInt(nDef);
var totalDefsStun = totalDefsBody;
absoluteDamage = damageTot - totalDefsBody;
damageStun = parseInt((damageStun * StunMultiplier) - totalDefsStun);
damageTot = parseInt((damageTot * BodyMultiplier) - totalDefsBody);
if(damageTot>absoluteDamage) absoluteDamage = damageTot;
if(damageTot<0) damageTot = 0;
if(damageStun<0) damageStun = 0;
if (Penetrating>defP && damageTot < nd) damageTot = nd;
if (damageStun < damageTot) damageStun = damageTot;
}
// Check other special defenses/status like No Stun, Damage Reduction, Stun Only
if(stunOnly) damageTot = 0;
if(noStun) damageStun = 0;
if(damMultiplier < 1)
{
if(typeofReduction.indexOf(damType) >= 0)
{
if(typeofReduction.indexOf("r")>=0 || damNK == "n")
{
damageStun = parseInt(damageStun*damMultiplier);
damageTot = parseInt(damageTot*damMultiplier);
}
}
}
// Final damage:
hits[shots][1] = damageTot;
hits[shots][2] = damageStun;
// Weapon Effects, if any
if(wEffect[0]!="") // Weapon applies effect(s)
{
weaponEffects(hits[shots][1]);
}
// HIT results -----------------------------------
var damageChat = "<br/>";
var critChat = "";
if (isCrit) {critChat = " - <b>Critical Hit!</b> -";}
for (key in hits) {
if (arrayHasOwnIndex(hits, key)) {
damageChat += hits[key][0];
damageChat += critChat + "<br/><b>" + hits[key][1] + "</b> BODY, <b>" + hits[key][2] + "</b> STUN";
damageChat += "<br>(rolled " + bodyRolled + " BODY, " + stunRolled + " STUN of dice damage)";
// Applies the damage to the token/sheet
var target = oDefender;
var oTarget = getObj("character", target.get("represents"));
oCON = findObjs({name: "CON",_type: "attribute", _characterid: oTarget.id}, {caseInsensitive: true})[0];
var targetCON = parseInt(oCON.get('current'));
var targetBody = parseInt(target.get('bar3_value'));
var maxBody = parseInt(target.get('bar3_max'));
var maxStun = parseInt(target.get('bar1_max'));
var targetEnd = parseInt(target.get('bar2_value'));
var targetStun = parseInt(target.get('bar1_value'));
if(hits[key][1] > 0 && !noBleed){
target.set('status_red', true);
}
targetBody -= hits[key][1];
targetStun -= hits[key][2];
var impaired = false;
var disabled = false;
var stunned = false;
var passedout = false;
if((targetStun<=0 && targetStun > -11) && targetBody >= 0){
passedout = true;
target.set('status_pummeled', true);
target.set('status_sleepy', false);
target.set('bar2_value', targetStun);
}else if (targetStun < -10 || targetBody <= 0){
passedout = true;
target.set('status_dead', true);
target.set('status_pummeled', false);
target.set('bar2_value', targetStun);
}
if(!passedout && hits[key][2]>targetCON && !noStun){
stunned = true;
target.set('status_sleepy', true);
}
if(absoluteDamage >= maxBody){
disabled = true;
target.set('status_broken-heart', true);
}
if(!disabled && absoluteDamage > parseInt(maxBody/2)){
impaired = true;
target.set('status_half-heart', true);
}
if(isNaN(targetBody))
targetBody = 0;
if(isNaN(targetStun))
targetStun = 0;
target.set('bar3_value', targetBody);
target.set('bar1_value', targetStun);
}
}
// Apply END cost to attacker and set the temporary modifiers
updateAttacker(oAttacker, true);
sendChat("combat", "/direct " + damageChat);
return;
}
function hitRoll(stringa)
{
var stringa = stringa.split(";");
numOptions = stringa.length;
wName = stringa[0];
attName = stringa[1];
//attTDC = stringa[3]; // used as various defender DCV modifiers, if any, taken from combathelper bar3 token;
defName = stringa[2];
if(defName == "") // in case of maneuvers or other self-only stuff where it is not required to select a target
defName = attName;
enableCrits = true; // Put it to false to disable critical hits altogether
endCost = 1;
attTOCV = 0;
attTDCV = 0;
attTRange = 0;
attRangeMod = 0;
noRange = false;
weaponRange = 0;
weaponOCV = 0;
weaponDCV = 0;
stunOnly = false;
reach = 2;
strMin = 0;
aimed = "";
aimedMod = 0;
noStun = false;
noBleed = false;
noHitLocs = false;
strMin = 0;
strMinMalus = 0;
isHit = 0;
isCrit = false;
herodice = "";
totBody = 0;
totStun = 0;
halfdie = false;
pip = 0;
nd = 0;
gmLog;
damMultiplier = 1;
hits.length = 0;
targetValue = 0;
attOCVMod = 0;
defDCVMod = 0;
los = false;
psi = false;
strDamMod = 0;
spellroll = "";
spellString = "";
nohitroll = false;
attMod = 0;
distance = 0;
maxammo = 0;
selfOnly = false;
StunX = 0;
abort = false;
dodge = false;
defWeaponOCV = 0;
shield = 0;
halfDCV = false;
wEffect[0] = "";
effVar[0] = 0;
effOnHit[0] = false;
effSelf[0] = false;
effChance[0] = 0;
noCrits = false;
AF = -1;
applySpellEffect = true;
spellRollSkill = "spellroll";
manualroll = 0;
if (numOptions>3){ // Check for other important parameters
for(var i=3;i<numOptions;i++){
if(stringa[i].indexOf("shots") !== -1){ AF = parseInt(stringa[i].replace("shots", "")); }
if(stringa[i].indexOf("attmod") !== -1){ attMod = parseInt(stringa[i].replace("attmod", "")); }
if(stringa[i].indexOf("distance") !== -1){ distance = parseInt(stringa[i].replace("distance", "")); }
if(stringa[i].indexOf("abort") !== -1){ abort = true; }
if(stringa[i].indexOf("manualroll") !== -1){ manualroll = parseInt(stringa[i].replace("manualroll", "")); }
}
}
if (attTDC == "") attTDC = 0;
if(attName.indexOf("-") == 0) // Token ID
{
Attacker = getObj("graphic", attName);
attName = Attacker.get("name");
}
else
Attacker = findObjs({
_pageid: Campaign().get("playerpageid"),
_type: "graphic",
_name: attName,
});
if(defName.indexOf("-") == 0) // Token ID
{
Defender = getObj("graphic", defName);
defName = Defender.get("name");
}
else
Defender = findObjs({
_pageid: Campaign().get("playerpageid"),
_type: "graphic",
_name: defName,
});
oAttacker = Attacker[0];
if( typeof oAttacker != "object")
oAttacker = Attacker;
oDefender = Defender[0];
if( typeof oDefender != "object")
oDefender = Defender;
oCombatHelper = findObjs({
_pageid: Campaign().get("playerpageid"),
_type: "graphic",
_name: "combathelper",
});
if(oCombatHelper != ""){
aimed = oCombatHelper[0].get("bar1_value");
attTDC = parseInt(oCombatHelper[0].get("bar3_value"));
}
else
sendChat("Script", "/w GM Copy the combathelper token into this page!");
var attChar = getObj("character", oAttacker.get("represents"));
var oAttrib = findObjs({name: "OCV",_type: "attribute", _characterid: attChar.id}, {caseInsensitive: true})[0];
attOCV = parseInt(oAttrib.get("current"));
if(isNaN(attTDC) || attTDC == "NaN")
{
attTDC = 0;
}
var defChar = getObj("character", oDefender.get("represents"));
oAttrib = findObjs({name: "DCV",_type: "attribute", _characterid: defChar.id}, {caseInsensitive: true})[0];
defDCV = parseInt(oAttrib.get("current"));
oAttrib = findObjs({name: "PD",_type: "attribute", _characterid: defChar.id}, {caseInsensitive: true})[0];
defPD = parseInt(oAttrib.get("current"));
oAttrib = findObjs({name: "ED",_type: "attribute", _characterid: defChar.id}, {caseInsensitive: true})[0];
defED = parseInt(oAttrib.get("current"));
oAttrib = findObjs({name: "rPD",_type: "attribute", _characterid: defChar.id}, {caseInsensitive: true})[0];
defRPD = parseInt(oAttrib.get("current"));
oAttrib = findObjs({name: "rED",_type: "attribute", _characterid: defChar.id}, {caseInsensitive: true})[0];
defRED = parseInt(oAttrib.get("current"));
oAttrib = findObjs({name: "tempDCV",_type: "attribute", _characterid: defChar.id}, {caseInsensitive: true})[0];
defTDCV = parseInt(oAttrib.get("current"));
if(oDefender.get("status_ninja-mask")) // defender is dodging
dodge = true;
if (InitiativeCheck() == false)
{
sendChat("Master", whisper + oAttacker.get("name") + " You are not in combat.");
return -1;
}
if(checkTurn(oAttacker)) return -1;
if(distance == 0) distance = calcDistanceBetweenTokens(oAttacker, oDefender);
var aWeapon = parseWeapon(wName, oAttacker, AF);