/
GroupInitiative.js
1944 lines (1785 loc) · 90.4 KB
/
GroupInitiative.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: https://github.com/shdwjk/Roll20API/blob/master/GroupInitiative/GroupInitiative.js
// By: The Aaron, Arcane Scriptomancer
// Contact: https://app.roll20.net/users/104025/the-aaron
const GroupInitiative = (() => { // eslint-disable-line no-unused-vars
const scriptName = "GroupInitiative";
const version = '0.9.36';
const lastUpdate = 1643852555;
const schemaVersion = 1.3;
const isString = (s)=>'string'===typeof s || s instanceof String;
const isFunction = (f)=>'function'===typeof f;
let observers = {
turnOrderChange: []
};
const sorters = {
'None': {
desc: `No sorting is applied.`,
func: (to)=>to
},
'Ascending': {
desc: `Sorts the Turn Order from highest to lowest`,
func: (to,preserveFirst) => {
let first = to[0];
const sorter_asc = (a, b) => a.pr - b.pr;
let newTo = to.sort(sorter_asc);
if(preserveFirst){
let idx = newTo.findIndex(e=>e===first);
newTo = [...newTo.slice(idx),...newTo.slice(0,idx)];
}
return newTo;
}
},
'Descending': {
desc: `Sorts the Turn Order from lowest to highest.`,
func: (to,preserveFirst) => {
let first = to[0];
const sorter_desc = (a, b) => b.pr - a.pr;
let newTo = to.sort(sorter_desc);
if(preserveFirst){
let idx = newTo.findIndex(e=>e===first);
newTo = [...newTo.slice(idx),...newTo.slice(0,idx)];
}
return newTo;
}
}
};
const ch = (c) => {
const entities = {
'<' : 'lt',
'>' : 'gt',
'&' : 'amp',
"'" : '#39',
'@' : '#64',
'{' : '#123',
'|' : '#124',
'}' : '#125',
'[' : '#91',
']' : '#93',
'"' : 'quot',
'*' : 'ast',
'/' : 'sol',
' ' : 'nbsp'
};
if( entities.hasOwnProperty(c) ){
return `&${entities[c]};`;
}
return '';
};
const standardConfigs = {
'dnd5eogl': {
title: `D${ch('&')}D 5E by Roll20`,
desc: `This is standard Roll20 provided 5th edition character sheet. It is the one used by default in most 5th edition Modules and all Official Dungeons and Dragons Modules and Addons.`,
func: ()=>{
state[scriptName].bonusStatGroups = [
[
{
"attribute": "initiative_bonus"
},
{
"adjustments": [
"tie-breaker"
],
"attribute": "initiative_bonus"
}
]
];
state[scriptName].dieSize = 20;
state[scriptName].diceCount = 1;
}
},
'dnd5eshaped2': {
title: `D${ch('&')}D 5e Shaped Sheet`,
desc: `This is the high-powered and very customizable Dungeons and Dragons 5e Shaped Sheet. You'll know you're using it because you had to manually install it (probably) and it has a nice heart shaped hit-point box. This is not the default sheet for DnD Modules on Roll20, if you aren't sure if you're using this sheet, you aren't.`,
func: ()=>{
state[scriptName].bonusStatGroups = [
[
{
"attribute": "initiative_formula"
}
]
];
state[scriptName].dieSize = 20;
state[scriptName].diceCount = 0;
}
},
'stargaterpgofficial': {
title: `Stargate RPG by Wyvern Gaming`,
desc: `This will configure GroupInitiative to work with the Official Stargate RPG sheet. It adds Initiative & Moxie options for rolling, with Initiative enabled by default. You can swap between using Initiative and Moxie by issuing the command "!group-init --promote 2" in the chat, with subsequent calls again reversing the selection.`,
func: ()=>{
state[scriptName].bonusStatGroups = [
[
{
"attribute": "init"
}
],
[
{
"attribute": "moxie"
}
]
];
state[scriptName].dieSize = 20;
state[scriptName].diceCount = 1;
}
}
};
const HE = (() => {
const esRE = (s) => s.replace(/(\\|\/|\[|\]|\(|\)|\{|\}|\?|\+|\*|\||\.|\^|\$)/g,'\\$1');
const e = (s) => `&${s};`;
const entities = {
'<' : e('lt'),
'>' : e('gt'),
"'" : e('#39'),
'@' : e('#64'),
'{' : e('#123'),
'|' : e('#124'),
'}' : e('#125'),
'[' : e('#91'),
']' : e('#93'),
'"' : e('quot')
};
const re = new RegExp(`(${Object.keys(entities).map(esRE).join('|')})`,'g');
return (s) => s.replace(re, (c) => (entities[c] || c) );
})();
const observeTurnOrderChange = function(handler){
if(handler && _.isFunction(handler)){
observers.turnOrderChange.push(handler);
}
};
const notifyObservers = function(event,obj,prev){
_.each(observers[event],function(handler){
handler(obj,prev);
});
};
const formatDieRoll = function(rollData) {
var critFail = _.reduce(rollData.rolls,function(m,r){
return m || _.contains(r.rolls,1);
},false),
critSuccess = _.reduce(rollData.rolls,function(m,r){
return m || _.contains(r.rolls,r.sides);
},false),
highlight = ( (critFail && critSuccess) ?
'#4A57ED' :
( critFail ?
'#B31515' :
( critSuccess ?
'#3FB315' :
'#FEF68E'
)
)
),
dicePart = _.reduce(rollData.rolls, function(m,r){
_.reduce(r.rolls,function(dm,dr){
var dielight=( 1 === dr ?
'#ff0000' :
( r.sides === dr ?
'#00ff00' :
'white'
)
);
dm.push('<span style="font-weight:bold;color:'+dielight+';">'+dr+'</span>');
return dm;
},m);
return m;
},[]).join(' + ');
return '<span class="inlinerollresult showtip tipsy" style="min-width:1em;display: inline-block; border: 2px solid '+
highlight+
'; background-color: #FEF68E;color: #404040; font-weight:bold;padding: 0px 3px;cursor: help"'+
' title="'+
HE(HE(
'<span style="color:white;">'+
dicePart+' [init] '+
(rollData.bonus>=0 ? '+' :'-')+' <span style="font-weight:bold;">'+Math.abs(rollData.bonus)+'</span> [bonus]'+
'</span>'
))+'">'+
rollData.total+
'</span>';
};
const buildAnnounceGroups = function(l) {
var groupColors = {
npc: '#eef',
character: '#efe',
gmlayer: '#aaa'
};
return _.reduce(l,function(m,s){
var type= ('gmlayer' === s.token.get('layer') ?
'gmlayer' : (
(s.character && _.filter(s.character.get('controlledby').split(/,/),function(c){
return 'all' === c || ('' !== c && !playerIsGM(c) );
}).length>0) || false ?
'character' :
'npc'
));
if('graphic'!==s.token.get('type') || 'token' !==s.token.get('subtype')) {
return m;
}
m[type].push('<div style="float: left;display: inline-block;border: 1px solid #888;border-radius:5px; padding: 1px 3px;background-color:'+groupColors[type]+';">'+
'<div style="font-weight:bold; font-size: 1.3em;">'+
'<img src="'+(s.token && s.token.get('imgsrc'))+'" style="height: 2.5em;float:left;margin-right:2px;">'+
((s.token && s.token.get('name')) || (s.character && s.character.get('name')) || '(Creature)')+
'</div>'+
'<div>'+
formatDieRoll(s.rollResults)+
'</div>'+
'<div style="clear: both;"></div>'+
'</div>');
return m;
},{npc:[],character:[],gmlayer:[]});
};
const announcers = {
'None': {
desc: `Shows nothing in chat when a roll is made.`,
func: () => {}
},
'Hidden': {
desc: `Whispers all rolls to the GM, regardless of who controls the tokens.`,
func: (l) => {
let groups = buildAnnounceGroups(l);
if(groups.npc.length || groups.character.length || groups.gmlayer.length){
sendChat(scriptName,'/w gm '+
'<div>'+
groups.character.join('')+
groups.npc.join('')+
groups.gmlayer.join('')+
'<div style="clear:both;"></div>'+
'</div>');
}
}
},
'Partial': {
desc: `Character rolls are shown in chat (Player controlled tokens), all others are whispered to the GM.`,
func: (l) => {
let groups = buildAnnounceGroups(l);
if(groups.character.length){
sendChat(scriptName,'/direct '+
'<div>'+
groups.character.join('')+
'<div style="clear:both;"></div>'+
'</div>');
}
if(groups.npc.length || groups.gmlayer.length){
sendChat(scriptName,'/w gm '+
'<div>'+
groups.npc.join('')+
groups.gmlayer.join('')+
'<div style="clear:both;"></div>'+
'</div>');
}
}
},
'Visible': {
desc: `Rolls for tokens on the Objects Layer are shown to all in chat. Tokens on the GM Layer have their rolls whispered to the GM. `,
func: (l) => {
let groups=buildAnnounceGroups(l);
if(groups.npc.length || groups.character.length){
sendChat(scriptName,'/direct '+
'<div>'+
groups.character.join('')+
groups.npc.join('')+
'<div style="clear:both;"></div>'+
'</div>');
}
if(groups.gmlayer.length){
sendChat(scriptName,'/w gm '+
'<div>'+
groups.gmlayer.join('')+
'<div style="clear:both;"></div>'+
'</div>');
}
}
}
};
const adjustments = {
STAT: 'stat',
TOKEN: 'token'
};
const statAdjustments = {
'stat-dnd': {
type: adjustments.STAT,
func: function(v) {
return 'floor((('+v+')-10)/2)';
},
desc: 'Calculates the bonus as if the value were a DnD Stat.'
},
'negative': {
type: adjustments.STAT,
func: function(v) {
return '(-1*('+v+'))';
},
desc: 'Returns the negative version of the stat'
},
'bare': {
type: adjustments.STAT,
func: function(v) {
return v;
},
desc: 'No Adjustment.'
},
'floor': {
type: adjustments.STAT,
func: function(v) {
return 'floor('+v+')';
},
desc: 'Rounds down to the nearest integer.'
},
'tie-breaker': {
type: adjustments.STAT,
func: function(v) {
return '(0.01*('+v+'))';
},
desc: 'Adds the accompanying attribute as a decimal (0.01)'
},
'ceiling': {
type: adjustments.STAT,
func: function(v) {
return 'ceil('+v+')';
},
desc: 'Rounds up to the nearest integer.'
},
'token_bar': {
type: adjustments.TOKEN,
func: function(t,idx) {
return parseFloat(t.get(`bar${idx}_value`))||0;
},
desc: 'Takes the bonus from the numbered bar on the token. Use 1, 2, or 3. Defaults to 0 in the absense of a number.'
},
'token_bar_max': {
type: adjustments.TOKEN,
func: function(t,idx) {
return parseFloat(t.get(`bar${idx}_max`))||0;
},
desc: 'Takes the bonus from the max value of the numbered bar on the token. Use 1, 2, or 3. Defaults to 0 in the absense of a number.'
},
'token_aura': {
type: adjustments.TOKEN,
func: function(t,idx) {
return parseFloat(t.get(`aura${idx}_radius`))||0;
},
desc: 'Takes the bonus from the radius of the token aura. Use 1 or 2. Defaults to 0 in the absense of a number.'
}
};
const buildInitDiceExpression = function(s){
var stat=(''!== state[scriptName].config.diceCountAttribute && s.character && getAttrByName(s.character.id, state[scriptName].config.diceCountAttribute, 'current'));
if(stat ) {
stat = (_.isString(stat) ? stat : stat+'');
if('0' !== stat) {
stat = stat.replace(/@\{([^|]*?|[^|]*?\|max|[^|]*?\|current)\}/g, '@{'+(s.character.get('name'))+'|$1}');
return '('+stat+')d'+state[scriptName].config.dieSize;
}
}
return state[scriptName].config.diceCount+'d'+state[scriptName].config.dieSize+state[scriptName].config.diceMod;
};
const rollers = {
'Individual-Roll': {
mutator: function(l){
return l;
},
func: function(s){
return buildInitDiceExpression(s);
},
desc: 'Sets the initiative individually for each member of the group.'
},
'Least-All-Roll':{
mutator: function(l){
var min=_.reduce(l,function(m,r){
if(!m || (r.total < m.total)) {
return r;
}
return m;
},false);
return _.times(l.length, function(){
return min;
});
},
func: function(s){
return buildInitDiceExpression(s);
},
desc: 'Sets the initiative to the lowest of all initiatives rolled for the group.'
},
'Mean-All-Roll':{
mutator: function(l){
var mean = l[Math.round((l.length/2)-0.5)];
return _.times(l.length, function(){
return mean;
});
},
func: function(s){
return buildInitDiceExpression(s);
},
desc: 'Sets the initiative to the mean (average) of all initiatives rolled for the group.'
},
'Constant-By-Stat': {
mutator: function(l){
return l;
},
func: function(){
return '0';
},
desc: 'Sets the initiative individually for each member of the group to their bonus with no roll.'
}
};
const assureHelpHandout = (create = false) => {
const helpIcon = "https://s3.amazonaws.com/files.d20.io/images/127392204/tAiDP73rpSKQobEYm5QZUw/thumb.png?15878425385";
// find handout
let props = {type:'handout', name:`Help: ${scriptName}`};
let hh = findObjs(props)[0];
if(!hh) {
hh = createObj('handout',Object.assign(props, {avatar: helpIcon}));
create = true;
}
if(create || version !== state[scriptName].lastHelpVersion){
hh.set({
notes: helpParts.helpDoc({who:'handout',playerid:'handout'})
});
state[scriptName].lastHelpVersion = version;
log(' > Updating Help Handout to v'+version+' <');
}
};
const checkForNoConfig = () => {
if(state[scriptName].config.checkForNoConfig && (0 === state[scriptName].bonusStatGroups.length)){
setTimeout(()=>{
sendChat(scriptName,`/w gm ${helpParts.helpNoConfig()}`);
},1000);
}
};
const checkInstall = function() {
log(`-=> ${scriptName} v${version} <=- [${new Date(lastUpdate*1000)}]`);
if( ! _.has(state,scriptName) || state[scriptName].version !== schemaVersion) {
log(' > Updating Schema to v'+schemaVersion+' <');
switch(state[scriptName] && state[scriptName].version) {
case 0.5:
state[scriptName].replaceRoll = false;
/* break; // intentional dropthrough */ /* falls through */
case 0.6:
state[scriptName].config = {
rollType: state[scriptName].rollType,
replaceRoll: state[scriptName].replaceRoll,
dieSize: 20,
autoOpenInit: true,
sortOption: 'Descending'
};
delete state[scriptName].replaceRoll;
delete state[scriptName].rollType;
/* break; // intentional dropthrough */ /* falls through */
case 0.7:
state[scriptName].config.announcer = 'Partial';
/* break; // intentional dropthrough */ /* falls through */
case 0.8:
state[scriptName].config.diceCount = 1;
state[scriptName].config.maxDecimal = 2;
/* break; // intentional dropthrough */ /* falls through */
case 0.9:
state[scriptName].config.diceCountAttribute = '';
/* break; // intentional dropthrough */ /* falls through */
case 0.10:
if(_.has(state[scriptName].config,'dieCountAttribute')){
delete state[scriptName].config.dieCountAttribute;
state[scriptName].config.diceCountAttribute = '';
}
if(_.has(state[scriptName].config,'dieCount')){
delete state[scriptName].config.dieCount;
state[scriptName].config.diceCount = 1;
}
/* break; // intentional dropthrough */ /* falls through */
case 1.0:
state[scriptName].savedTurnOrders =[];
/* break; // intentional dropthrough */ /* falls through */
case 1.1:
state[scriptName].config.diceMod='';
/* break; // intentional dropthrough */ /* falls through */
case 1.2:
state[scriptName].lastHelpVersion=version;
state[scriptName].config.checkForNoConfig = true;
/* break; // intentional dropthrough */ /* falls through */
case 1.3:
state[scriptName].config.preserveFirst=false;
/* break; // intentional dropthrough */ /* falls through */
case 'UpdateSchemaVersion':
state[scriptName].version = schemaVersion;
break;
default:
state[scriptName] = {
version: schemaVersion,
lastHelpVersion: version,
bonusStatGroups: [],
savedTurnOrders: [],
config: {
rollType: 'Individual-Roll',
replaceRoll: false,
dieSize: 20,
diceCount: 1,
maxDecimal: 2,
diceCountAttribute: '',
diceMod: '',
checkForNoConfig: true,
autoOpenInit: true,
sortOption: 'Descending',
preserveFirst: true,
announcer: 'Partial'
}
};
break;
}
}
assureHelpHandout();
checkForNoConfig();
};
const _h = {
outer: (...o) => `<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">${o.join(' ')}</div>`,
title: (t,v) => `<div style="font-weight: bold; border-bottom: 1px solid black;font-size: 130%;">${t} v${v}</div>`,
subhead: (...o) => `<b>${o.join(' ')}</b>`,
minorhead: (...o) => `<u>${o.join(' ')}</u>`,
optional: (...o) => `${ch('[')}${o.join(` ${ch('|')} `)}${ch(']')}`,
required: (...o) => `${ch('<')}${o.join(` ${ch('|')} `)}${ch('>')}`,
header: (...o) => `<div style="padding-left:10px;margin-bottom:3px;">${o.join(' ')}</div>`,
section: (s,...o) => `${_h.subhead(s)}${_h.inset(...o)}`,
paragraph: (...o) => `<p>${o.join(' ')}</p>`,
items: (o) => o.map(i=>`<li>${i}</li>`).join(''),
ol: (...o) => `<ol>${_h.items(o)}</ol>`,
ul: (...o) => `<ul>${_h.items(o)}</ul>`,
grid: (...o) => `<div style="padding: 12px 0;">${o.join('')}<div style="clear:both;"></div></div>`,
cell: (o) => `<div style="width: 130px; padding: 0 3px; float: left;">${o}</div>`,
inset: (...o) => `<div style="padding-left: 10px;padding-right:20px">${o.join(' ')}</div>`,
join: (...o) => o.join(' '),
pre: (...o) =>`<div style="border:1px solid #e1e1e8;border-radius:4px;padding:8.5px;margin-bottom:9px;font-size:12px;white-space:normal;word-break:normal;word-wrap:normal;background-color:#f7f7f9;font-family:monospace;overflow:auto;">${o.join(' ')}</div>`,
preformatted: (...o) =>_h.pre(o.join('<br>').replace(/\s/g,ch(' '))),
code: (...o) => `<code>${o.join(' ')}</code>`,
attr: {
bare: (o)=>`${ch('@')}${ch('{')}${o}${ch('}')}`,
selected: (o)=>`${ch('@')}${ch('{')}selected${ch('|')}${o}${ch('}')}`,
target: (o)=>`${ch('@')}${ch('{')}target${ch('|')}${o}${ch('}')}`,
char: (o,c)=>`${ch('@')}${ch('{')}${c||'CHARACTER NAME'}${ch('|')}${o}${ch('}')}`
},
bold: (...o) => `<b>${o.join(' ')}</b>`,
italic: (...o) => `<i>${o.join(' ')}</i>`,
font: {
command: (...o)=>`<b><span style="font-family:serif;">${o.join(' ')}</span></b>`
},
ui : {
float: (t) => `<div style="display:inline-block;float:right">${t}</div>`,
clear: () => `<div style="clear:both;"></div>`,
bubble: (label) => `<span style="display:inline-block;border:1px solid #999; border-radius: 1em; padding: .1em 1em; font-weight:bold; background-color: #009688;color:white">${label}</span>`,
button: (label,link) => `<a href="${link}">${label}</a>`
}
};
const helpParts = {
helpBody: (context) => _h.join(
_h.header(
_h.paragraph(
`Rolls initiative for the selected tokens and adds them to the Turn Order if they don${ch("'")}t have a turn yet.`
),
_h.paragraph(
`The calculation of initiative is handled by the combination of Roller (See ${_h.bold("Roller Options")} below) and a Bonus. The Bonus is determined based on an ordered list of Stat Groups (See ${_h.bold("Bonus Stat Groups")} below). Stat Groups are evaluated in order. The bonus computed by the first Stat Group for which all attributes exist and have a numeric value is used. This allows you to have several Stat Groups that apply to different types of characters. In practice you will probably only have one, but more are there if you need them.`
)
),
helpParts.commands(context)
),
rollingCommands: (/*context*/) => _h.section('Commands for Rolling',
_h.paragraph(`GroupInitiative's primary role is rolling initiative. It has many options for performing the roll, most of which operate on the selected tokens.`),
_h.inset(
_h.font.command(
`!group-init`
),
_h.paragraph(
`This command uses the configured Roller to dtermine the initiative order for all the selected tokens.`
),
_h.font.command(
`!group-init`,
`--bonus`,
_h.required('bonus')
),
_h.paragraph(
`This command is just line the bare !group-init roll, but will add the supplied bonus to all rolls. The bonus can be from an inline roll.`
),
_h.font.command(
`!group-init`,
`--reroll`,
_h.optional('bonus')
),
_h.paragraph(
`This command rerolls all of the tokens currently in the turn order as if they were selected when you executed !group-init. An optional bonus can be supplied, which can be the result of an inline roll.`
),
_h.font.command(
`!group-init`,
`--ids`,
_h.optional('...')
),
_h.paragraph(
`This command uses the configured Roller to determine the initiative order for all tokens whose ids are specified.`
),
_h.font.command(
`!group-init`,
`--adjust`,
_h.required('adjustment'),
_h.optional('minimum')
),
_h.paragraph(
`Applies an adjustment to all the current Turn Order tokens (Custom entries ignored). The required adjustment value will be applied to the current value of all Turn Order entries. The optional minium value will be used if the value after adjustiment is lower, which can end up raising Turn Order values even if they were already lower.`
),
_h.font.command(
`!group-init`,
`--adjust-current`,
_h.required('adjustment'),
_h.optional('minimum')
),
_h.paragraph(
`This is identical to --adjust, save that it is only applied to the top entry in the Turn Order.`
)
)
),
helpCommands: (/*context*/) => _h.section('Help and Configuration',
_h.paragraph(
`All of these commands are documented in the build in help. Additionally, there are many configuration options that can only be accessed there.`
),
_h.inset(
_h.font.command(
`!group-init`,
`--help`
),
_h.paragraph(`This command displays the help and configuration options.`)
)
),
buildStatAdjustmentRows: ( /* context */) => _h.ul(
...Object.keys(statAdjustments).map(k=>`${_h.bold(k)} -- ${statAdjustments[k].desc}`)
),
showStandardConfigOptions: ( /* context */ ) => _h.ul(
...Object.keys(standardConfigs).map(c=>_h.join(
_h.ui.float(_h.ui.button(`Apply Config`,`!group-init-config --apply-standard-config|${c}`)),
_h.subhead(standardConfigs[c].title),
_h.paragraph(`${standardConfigs[c].desc}${_h.ui.clear()}`)
))
),
statGroupCommands: (/*context*/) => _h.section('Commands for Stat Groups',
_h.paragraph(
`Stat Groups are the method through which GroupInitiative knows what to do to create the initiative value for a token. Generally, they will be some combination of attributes and adjustments to look up on each token and character.`
),
_h.inset(
_h.font.command(
`!group-init`,
`--add-group --${_h.required('adjustment')} ${_h.optional('arguments')}`,
_h.optional(
`--add-group --${_h.required('adjustment')} ${_h.optional('arguments')}`,
`...`
)
),
_h.paragraph(
`Adds a new Bonus Stat Group to the end of the list. Each adjustment operation can be followed by another adjustment operation, but eventually must end in an attriute name. Adjustment operations are applied to the result of the adjustment operations that follow them.`
),
_h.minorhead('Available Stat Adjustment Options:'),
helpParts.buildStatAdjustmentRows(),
_h.font.command(
`!group-init`,
`--promote`,
_h.required('index')
),
_h.paragraph(
`This command increases the importants of the Bonus Stat Group at the supplied index.`
),
_h.font.command(
`!group-init`,
`--del-group`,
_h.required('index')
),
_h.paragraph(
`This command removes the Bonus Stat Group at the supplied index.`
)
)
),
stackCommands: (/*context*/) => _h.section('Commands for Stacks of Initiative',
_h.paragraph(
`GroupInitiative provides a system called ${_h.bold('Stacks')} which lets you store collections of prerolled initiative values and combine or cycle them as desired.`
),
_h.inset(
_h.font.command(
`!group-init`,
`--stack`,
_h.optional('operation'),
_h.optional('label')
),
_h.inset(
_h.minorhead('Available Operations:'),
_h.ul(
`${_h.bold('list')} -- Displays the stack of saved Turn Orders. (default)`,
`${_h.bold('clear')} -- Clears the stack of saved Turn Orders.`,
`${_h.bold(`copy${ch('|')}dup ${ch('[')}label${ch(']')}`)} -- Adds a copy of the current Turn Order to the stack.`,
`${_h.bold(`push ${ch('[')}label${ch(']')}`)} -- Adds a copy of the current Turn Order to the stack and clears the Turn Order. Anything after the command will be used as a label for the entry.`,
`${_h.bold('pop')} -- Replaces the current Turn Order with the last entry in the stack removing it from the stack.`,
`${_h.bold('apply')} -- Replaces the current Turn Order with the last entry in the stack leaving it on the stack.`,
`${_h.bold(`swap ${ch('[')}label${ch(']')}`)} -- Swaps the current Turn Order with the last entry in the stack. Anything after the command will be used as a label for the entry placed in the stack.`,
`${_h.bold(`tswap${ch('|')}tail-swap ${ch('[')}label${ch(']')}`)} -- Swaps the current Turn Order with the first entry in the stack. Anything after the command will be used as a label for the entry placed in the stack.`,
`${_h.bold('merge')} -- Removes the last entry in the stack and adds it to the current Turn Order and sorts the new Turn Order with the configured sort method.`,
`${_h.bold(`apply-merge${ch('|')}amerge`)} -- Merges the last entry in the stack with the current Turn Order and sorts the new Turn Order with the configured sort method, leaving the stack unchanged.`,
`${_h.bold(`rotate${ch('|')}rot ${ch('[')}label${ch(']')}`)} -- Pushes the current Turn Order onto the end of the stack and restores the first entry from the stack to the Turn Order. Anything after the command will be used as a label for the entry placed in the stack.`,
`${_h.bold(`reverse-rotate${ch('|')}rrot ${ch('[')}label${ch(']')}`)} -- Pushes the current Turn Order onto the beginning of the stack and restores the last entry from the stack to the Turn Order. Anything after the command will be used as a label for the entry placed in the stack.`
)
)
)
),
turnOrderCommands: (/*context*/) => _h.section('Commands for Turn Order Management',
_h.paragraph(
`The Turn Order is an integral part of initiative, so GroupInitiative provides soem methodes for manipulating it.`
),
_h.inset(
_h.font.command(
`!group-init`,
`--toggle-turnorder`
),
_h.paragraph(
`Opens or closes the Turn Order window.`
),
_h.font.command(
`!group-init`,
`--sort`
),
_h.paragraph(
`Applies the configured sort operation to the current Turn Order.`
),
_h.font.command(
`!group-init`,
`--clear`
),
_h.paragraph(
`Removes all tokens from the Turn Order. If Auto Open Init is enabled it will also close the Turn Order box.`
))
),
commands: (context) => _h.join(
_h.subhead('Commands'),
helpParts.rollingCommands(context),
helpParts.helpCommands(context),
helpParts.statGroupCommands(context),
helpParts.turnOrderCommands(context),
helpParts.stackCommands(context)
),
rollerConfig: (/*context*/) => _h.section('Roller Options',
_h.paragraph(
`The Roller determines how token rolls are performed for groups of tokens.`
),
_h.inset(
_h.ul(
...Object.keys(rollers).map(r=>`${_h.ui.float(
( r === state[scriptName].config.rollType)
? _h.ui.bubble(_h.bold('Selected'))
: _h.ui.button(`Use ${r}`,`!group-init-config --set-roller|${r}`)
)}${_h.bold(r)} -- ${rollers[r].desc}${_h.ui.clear()}` )
)
)
),
sortOptionsConfig: ( /* context */ ) => _h.section('Sorter Options',
_h.paragraph(
`The Sorter is used to determine how to reorder entries in the Turn Order whenever GroupInitiative performs a sort. Sorting occurs when the sort command (${_h.code('!group-init --sort')}) is issued, when stack entries are merged into the current Turn Order, and when new entries are added to the Turn Order with a GroupInitiative command (like ${_h.code('!group-init')}).`
),
_h.inset(
_h.ul(
...Object.keys(sorters).map(s=>`${_h.ui.float(
(s === state[scriptName].config.sortOption)
? _h.ui.bubble(_h.bold('Selected'))
: _h.ui.button(`Use ${s}`,`!group-init-config --sort-option|${s}`)
)}${_h.bold(s)} -- ${sorters[s].desc}${_h.ui.clear()}`)
)
)
),
dieSizeConfig: ( /* context */ ) => _h.section('Initiative Die Size',
_h.paragraph(
`The Initiative Die sets the size of the die that GroupInitiative will roll for each initiative value.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button('Set Die Size', `!group-init-config --set-die-size|?{Number of sides the initiative die has:|${state[scriptName].config.dieSize}}`))}Initiative Die Size is currently set to ${_h.bold(state[scriptName].config.dieSize)}. ${_h.ui.clear()}`)
)
),
diceCountConfig: ( /* context */ ) => _h.section('Initiative Dice Count',
_h.paragraph(
`The Initiative Dice Count sets the number of dice GroupInitiative will roll for each initiative value. You can set this number to 0 to prevent any dice from being rolled.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button('Set Dice Count', `!group-init-config --set-dice-count|?{Number of initiative dice to roll:|${state[scriptName].config.diceCount}}`))}Initiative Dice Count is currently set to ${_h.bold(state[scriptName].config.diceCount)}. ${_h.ui.clear()}`)
)
),
diceCountAttributeConfig: ( /* context */ ) => _h.section('Dice Count Attribute',
_h.paragraph(
`If this attribute is set, it will be used to determine the number of dice to roll for each initiatitve value. If the value is not set, or not a valid number, the Intiative Dice Count is used instead.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button('Set Attribute', `!group-init-config --set-dice-count-attribute|?{Attribute to use for number of initiative dice to roll (Blank to disable):|${state[scriptName].config.diceCountAttribute}}`))}Dice Count Attribute is currently set to ${_h.bold((state[scriptName].config.diceCountAttribute.length ? state[scriptName].config.diceCountAttribute : 'DISABLED'))}. ${_h.ui.clear()}`)
)
),
diceModConfig: ( /* context */ ) => _h.section('Dice Modifier String',
_h.paragraph(
`The Dice Modifier String is appended to the roll made by GroupInitiative for each Initiative. It can be used for rerolling 1s or dropping the lower roll, etc.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button('Set Dice Modifiers', `!group-init-config --set-dice-mod|?{Dice Modifiers to be appended to roll (Blank to disable):|${state[scriptName].config.diceMod}}`))}Dice Modifier String is currently set to ${_h.bold((state[scriptName].config.diceMod.length ? state[scriptName].config.diceMod : 'DISABLED'))}. ${_h.ui.clear()}`)
)
),
maxDecimalConfig: ( /* context */ ) => _h.section('Maximum Decimal Places',
_h.paragraph(
`This is the Maximum number of decimal places to show in the Initiative when Tie-Breakers are rolled.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button('Set Max Decimal', `!group-init-config --set-max-decimal|?{Maximum number of decimal places:|${state[scriptName].config.maxDecimal}}`))}Maximum Decimal Places is currently set to ${_h.bold(state[scriptName].config.maxDecimal)}. ${_h.ui.clear()}`)
)
),
autoOpenInitConfig: ( /* context */ ) => _h.section('Auto Open Turn Order',
_h.paragraph(
`This option causes GroupInitiative to open the Turn Order whenever it makes an initiative roll.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button((state[scriptName].config.autoOpenInit ? 'Disable' : 'Enable'), `!group-init-config --toggle-auto-open-init`))}Auto Open Turn Order is currently ${_h.bold( (state[scriptName].config.autoOpenInit ? 'On' : 'Off') )}. ${_h.ui.clear()}`)
)
),
replaceRollConfig: ( /* context */ ) => _h.section('Replace Roll',
_h.paragraph(
`This option causes GroupInitiative to replace a roll in the Turn Order if a token is already present there when it makes a roll for it. Otherwise, the token is ignored and the current roll is retained.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button((state[scriptName].config.replaceRoll ? 'Disable' : 'Enable'), `!group-init-config --toggle-replace-roll`))}Replace Roll is currently ${_h.bold( (state[scriptName].config.replaceRoll ? 'On' : 'Off') )}. ${_h.ui.clear()}`)
)
),
checkForNoConfigConfig: ( /* context */ ) => _h.section('Check For No Configuration',
_h.paragraph(
`This option causes GroupInitiative to prompt with standard configuration options when it starts up and there are no Stat Groups. You can suppress it by turning it off, in the case that your game is just dice and you don't need Stat Groups.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button((state[scriptName].config.checkForNoConfig ? 'Disable' : 'Enable'), `!group-init-config --toggle-check-for-no-config`))}No Configuration Checking is currently ${_h.bold( (state[scriptName].config.checkForNoConfig ? 'On' : 'Off') )}. ${_h.ui.clear()}`)
)
),
preserveFirstConfig: ( /* context */ ) => _h.section('Preserve First on Sorted Add',
_h.paragraph(
`This option causes GroupInitiative to preserve the first Turn Order entry when sorting the Turn Order after adding creatures.`
),
_h.inset(
_h.paragraph(`${_h.ui.float(_h.ui.button((state[scriptName].config.preserveFirst ? 'Disable' : 'Enable'), `!group-init-config --toggle-preserve-first`))}Preserve First on Sorted Add is currently ${_h.bold( (state[scriptName].config.preserveFirst ? 'On' : 'Off') )}. ${_h.ui.clear()}`)
)
),
announcerConfig: (/*context*/) => _h.section('Announcer Options',
_h.paragraph(
`The Announcer controls what is shown in chat when a roll is performed.`
),
_h.inset(
_h.ul(
...Object.keys(announcers).map(a=>`${_h.ui.float(
(a === state[scriptName].config.announcer)
? _h.ui.bubble(_h.bold('Selected'))
: _h.ui.button(`Use ${a}`,`!group-init-config --set-announcer|${a}`)
)}${_h.bold(a)} -- ${announcers[a].desc}${_h.ui.clear()}` )
)
)
),
standardConfig: (context) => _h.join(
_h.subhead('Configuration'),
_h.paragraph(
`Standard Configurations give you some quick options for certain character sheets. If you${ch("'")}re using one of these sheets in a pretty standard game, look no further than one of these options.`
),
_h.inset(
_h.minorhead('Available Standard Configuration Options:'),
helpParts.showStandardConfigOptions(context)
)
),
showBonusStatGroupsConfig: (/*context*/) => _h.section('Bonus Stat Groups',
_h.inset(
_h.ol(
...state[scriptName].bonusStatGroups.map((a,n)=>`${
_h.ui.float(_h.ui.button(`+`,`!group-init --promote ${n+1}`))
}${
_h.ui.float(_h.ui.button(`X`,`!group-init --del-group ${n+1}`))
}${
a.map(e=>_h.ui.bubble((e.adjustments||[]).reduce((m,adj)=>`${adj}( ${m} )`,`${e.attribute}|${e.type||'current'}`))).join(' + ')
}${_h.ui.clear()}` )
)
)
),
configuration: (context) => _h.join(
_h.subhead('Configuration'),
_h.inset(
helpParts.rollerConfig(context),
helpParts.sortOptionsConfig(context),
helpParts.preserveFirstConfig(context),
helpParts.dieSizeConfig(context),
helpParts.diceCountConfig(context),
helpParts.diceCountAttributeConfig(context),
helpParts.diceModConfig(context),
helpParts.maxDecimalConfig(context),
helpParts.autoOpenInitConfig(context),
helpParts.replaceRollConfig(context),
helpParts.checkForNoConfigConfig(context),
helpParts.announcerConfig(context),
helpParts.showBonusStatGroupsConfig(context)
)
),
helpDoc: (context) => _h.join(
_h.title(scriptName, version),
helpParts.helpBody(context)
),
helpChat: (context) => _h.outer(
_h.title(scriptName, version),
helpParts.helpBody(context),
helpParts.standardConfig(context),
helpParts.configuration(context)
),
helpNoConfig: (context) => _h.outer(
_h.title(scriptName, version),
_h.paragraph(`You do not have any Bonus Stat Groups configured right now. Usually that means this is the first time you have used GroupInitiative. If you would like, you can try one of the Standard Configurations below to configure GroupInitiative for some popular character sheets. If you want to configure a different sheet or without a sheet at all, see the extensive ${_h.ui.button('Online Help',`!group-init --help`)}. If you do not want to see this message again, you can ${_h.ui.button('Hide it',`!group-init-config --toggle-check-for-no-config`)}.`),
_h.inset(
_h.minorhead('Available Standard Configuration Options:'),
helpParts.showStandardConfigOptions(context)
)
),
helpConfig: (context) => _h.outer(
_h.title(scriptName, version),
helpParts.configuration(context)
)
};
const showHelp = (playerid) => {
const who=(getObj('player',playerid)||{get:()=>'API'}).get('_displayname');
let context = {
who,
playerid
};
sendChat('', '/w "'+who+'" '+ helpParts.helpChat(context));
};