-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
881 lines (790 loc) · 29 KB
/
index.html
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
<html>
<body onload="setupPage()">
<h1>Monster Challenge Rating Calculator</h1>
Base CR (Choose a base CR to give your monster some starting values)
<table>
<tr>
<td><button onclick="setBaseCR(0)">0</button></td>
<td><button onclick="setBaseCR(1/8)">1/8</button></td>
<td><button onclick="setBaseCR(1/4)">1/4</button></td>
<td><button onclick="setBaseCR(1/2)">1/2</button></td>
<td><button onclick="setBaseCR(1)">1</button></td>
<td><button onclick="setBaseCR(2)">2</button></td>
<td><button onclick="setBaseCR(3)">3</button></td>
<td><button onclick="setBaseCR(4)">4</button></td>
<td><button onclick="setBaseCR(5)">5</button></td>
<td><button onclick="setBaseCR(6)">6</button></td>
<td><button onclick="setBaseCR(7)">7</button></td>
<td><button onclick="setBaseCR(8)">8</button></td>
<td><button onclick="setBaseCR(9)">9</button></td>
<td><button onclick="setBaseCR(10)">10</button></td>
<td><button onclick="setBaseCR(11)">11</button></td>
<td><button onclick="setBaseCR(12)">12</button></td>
<td><button onclick="setBaseCR(13)">13</button></td>
<td><button onclick="setBaseCR(14)">14</button></td>
<td><button onclick="setBaseCR(15)">15</button></td>
</tr>
</table>
Defensive CR: <span id="defensiveCRDisplay">Unknown</span> <br>
Offensive CR: <span id="offensiveCRDisplay">Unknown</span> <br>
<b>Total CR: <span id="totalCRDisplay">Unknown</span></b>
<table>
<tr>
<td>Monster Name:</td>
<td><input type="text" id="monsterName" value="Name"></td>
</tr>
</table>
<h3>Monster Statistics</h3>
<table>
<tr>
<td>
<table>
<tr>
<td>Armor Class:</td>
<td><input type="text" id="armorClass" value=13 onchange="recalcTotalCR()"></td>
<td><button onclick="addValue(document.getElementById('armorClass'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('armorClass'), -1)">-</button></td>
</tr>
<tr>
<td>Hit Points:</td>
<td><input type="text" id="hitPoints" value=3 size="3" onchange="recalcTotalCR()">
Dice Code
<input type="text" id="HPDiceCode" value="-" size="10"></input></td>
<td><button onclick="addValue(document.getElementById('hitPoints'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('hitPoints'), -1)">-</button></td>
</tr>
<tr>
<td>Attack Bonus:</td>
<td><input type="text" id="attackBonus" value=3 onchange="recalcTotalCR()"></td>
<td><button onclick="addValue(document.getElementById('attackBonus'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('attackBonus'), -1)">-</button></td>
</tr>
<tr>
<td>Damage per Round:</td>
<td><input type="text" id="damagePerRound" value=1 onchange="recalcTotalCR()"></td>
<td><button onclick="addValue(document.getElementById('damagePerRound'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('damagePerRound'), -1)">-</button></td>
</tr>
<tr>
<td>Save DC:</td>
<td><input type="text" id="saveDC" value=13 onchange="recalcTotalCR()"></td>
<td><button onclick="addValue(document.getElementById('saveDC'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('saveDC'), -1)">-</button></td>
</tr>
<tr>
<td>Proficiency Bonus:</td>
<td><input type="text" id="proficiencyBonus" value=2></td>
<td><button onclick="addValue(document.getElementById('proficiencyBonus'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('proficiencyBonus'), -1)">-</button></td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>Strength:</td>
<td><input type="text" id="strength" value=13 onchange="updateAbilityModifiers()"></td>
<td><button onclick="addValue(document.getElementById('strength'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('strength'), -1)">-</button></td>
<td><input type="text" id="strengthMod"></input></td>
</tr>
<tr>
<td>Dexterity:</td>
<td><input type="text" id="dexterity" value=13 onchange="updateAbilityModifiers()"></td>
<td><button onclick="addValue(document.getElementById('dexterity'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('dexterity'), -1)">-</button></td>
<td><input type="text" id="dexterityMod"></input></td>
</tr>
<tr>
<td>Constitution:</td>
<td><input type="text" id="constitution" value=13 onchange="updateAbilityModifiers()"></td>
<td><button onclick="addValue(document.getElementById('constitution'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('constitution'), -1)">-</button></td>
<td><input type="text" id="constitutionMod"></input></td>
</tr>
<tr>
<td>Intelligence:</td>
<td><input type="text" id="intelligence" value=13 onchange="updateAbilityModifiers()"></td>
<td><button onclick="addValue(document.getElementById('intelligence'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('intelligence'), -1)">-</button></td>
<td><input type="text" id="intelligenceMod"></input></td>
</tr>
<tr>
<td>Wisdom:</td>
<td><input type="text" id="wisdom" value=13 onchange="updateAbilityModifiers()"></td>
<td><button onclick="addValue(document.getElementById('wisdom'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('wisdom'), -1)">-</button></td>
<td><input type="text" id="wisdomMod"></input></td>
</tr>
<tr>
<td>Charisma:</td>
<td><input type="text" id="charisma" value=13 onchange="updateAbilityModifiers()"></td>
<td><button onclick="addValue(document.getElementById('charisma'), 1)">+</button></td>
<td><button onclick="addValue(document.getElementById('charisma'), -1)">-</button></td>
<td><input type="text" id="charismaMod"></input></td>
</tr>
<tr>
<td>Total Skill Points:</td>
<td><span id="totalSkillPoints"></span></td>
</tr>
</table>
</td>
</tr>
</table>
<h3>Monster Size</h3>
<form>
<input type="radio" name="size" id="sizeTiny" onchange="setMonsterSize('Tiny')">Tiny</input>
<input type="radio" name="size" id="sizeSmall" onchange="setMonsterSize('Small')">Small</input>
<input type="radio" name="size" id="sizeMedium" onchange="setMonsterSize('Medium')">Medium</input>
<input type="radio" name="size" id="sizeLarge" onchange="setMonsterSize('Large')">Large</input>
<input type="radio" name="size" id="sizeHuge" onchange="setMonsterSize('Huge')">Huge</input>
<input type="radio" name="size" id="sizeGargantuan" onchange="setMonsterSize('Gargantuan')">Gargantuan</input>
</form>
<h3>Primary Attack Type</h3>
<form>
<table>
<tr>
<td><input type="radio" name="attackType" id="attackMelee" onchange="recalcAbilityScores()">Melee (STR)</input></td>
<td><input type="radio" name="attackType" id="attackRanged" onchange="recalcAbilityScores()">Ranged (DEX)</input></td>
<td><input type="radio" name="attackType" id="attackMagic" onchange="recalcAbilityScores()">Innate Magic (CHA)</input></td>
</tr>
<tr>
<td><input type="radio" name="attackType" id="attackFinesse" onchange="recalcAbilityScores()">Finesse (DEX)</input></td>
<td><input type="radio" name="attackType" id="attackThrown" onchange="recalcAbilityScores()">Thrown (STR)</input></td>
<td><input type="radio" name="attackType" id="attackPoison" onchange="recalcAbilityScores()">Poison/Disease (CON)</input></td>
</tr>
</table>
</form>
<h3>Monster Features</h3>
<table>
<tr>
<td><input type="checkbox" id="featAvoidance" onchange="recalcTotalCR()">Avoidance</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
</tr>
<tr>
<td><input type="checkbox" id="featNimbleEscape">Nimble Escape</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
<td><input type="checkbox" value="test">Test1</input></td>
</tr>
</table>
<br>
<button onclick="saveMonster()">Save</button>
<h3>Monster List</h3>
<table id="monsterList"></table>
<h3>Encounter</h3>
<b>Encounter CR: <span id="encounterCRDisplay">0</span></b><br>
<b>Encounter XP: <span id="encounterXPDisplay">0</span> Adjusted XP: <span id="adjustedXPDisplay">0</span></b>
<table id="encounterList"></table>
<script>
var defensiveCR = 0;
var offensiveCR = 0;
var totalCR = 0;
var monsterSize = "Medium";
var hitDice = 8;
var hitDiceSize = {};
hitDiceSize["Tiny"] = 4;
hitDiceSize["Small"] = 6;
hitDiceSize["Medium"] = 8;
hitDiceSize["Large"] = 10;
hitDiceSize["Huge"] = 12;
hitDiceSize["Gargantuan"] = 20;
//Average values of dice rolls
var diceAverages = {};
diceAverages[4] = 2.5;
diceAverages[6] = 3.5;
diceAverages[8] = 4.5;
diceAverages[10] = 5.5;
diceAverages[12] = 6.5;
diceAverages[20] = 10.5;
//Ability Modifier to Score
var abilityScores = {};
abilityScores[-5] = 1;
abilityScores[-4] = 2;
abilityScores[-3] = 4;
abilityScores[-2] = 6;
abilityScores[-1] = 8;
abilityScores[0] = 10;
abilityScores[1] = 12;
abilityScores[2] = 14;
abilityScores[3] = 16;
abilityScores[4] = 18;
abilityScores[5] = 20;
abilityScores[6] = 22;
abilityScores[7] = 24;
abilityScores[8] = 26;
abilityScores[9] = 28;
abilityScores[10] = 30;
//Ability Score to Ability Modifier
var abilityModifiers = {};
abilityModifiers[1] = -5;
abilityModifiers[2] = -4;
abilityModifiers[3] = -4;
abilityModifiers[4] = -3;
abilityModifiers[5] = -3;
abilityModifiers[6] = -2;
abilityModifiers[7] = -2;
abilityModifiers[8] = -1;
abilityModifiers[9] = -1;
abilityModifiers[10] = 0;
abilityModifiers[11] = 0;
abilityModifiers[12] = 1;
abilityModifiers[13] = 1;
abilityModifiers[14] = 2;
abilityModifiers[15] = 2;
abilityModifiers[16] = 3;
abilityModifiers[17] = 3;
abilityModifiers[18] = 4;
abilityModifiers[19] = 4;
abilityModifiers[20] = 5;
abilityModifiers[21] = 5;
abilityModifiers[22] = 6;
abilityModifiers[23] = 6;
abilityModifiers[24] = 7;
abilityModifiers[25] = 7;
abilityModifiers[26] = 8;
abilityModifiers[27] = 8;
abilityModifiers[28] = 9;
abilityModifiers[29] = 9;
abilityModifiers[30] = 10;
//XP at each level
var XPLevels = {};
XPLevels[0] = 0;
XPLevels[1/8] = 25;
XPLevels[1/4] = 50;
XPLevels[1/2] = 100;
XPLevels[1] = 200;
XPLevels[2] = 450;
XPLevels[3] = 700;
XPLevels[4] = 1100;
XPLevels[5] = 1800;
XPLevels[6] = 2300;
XPLevels[7] = 2900;
XPLevels[8] = 3900;
XPLevels[9] = 5000;
XPLevels[10] = 5900;
XPLevels[11] = 7200;
XPLevels[12] = 8400;
XPLevels[13] = 10000;
XPLevels[14] = 11500;
XPLevels[15] = 13000;
XPLevels[16] = 15000;
XPLevels[17] = 18000;
XPLevels[18] = 20000;
XPLevels[19] = 22000;
XPLevels[20] = 25000;
XPLevels[21] = 33000;
XPLevels[22] = 41000;
XPLevels[23] = 50000;
XPLevels[24] = 62000;
XPLevels[25] = 75000;
XPLevels[26] = 90000;
XPLevels[27] = 105000;
XPLevels[28] = 120000;
XPLevels[29] = 135000;
XPLevels[30] = 155000;
//Estimated Armor Class at each level
var ACLevels = {};
ACLevels[0] = 13;
ACLevels[1/8] = 13;
ACLevels[1/4] = 13;
ACLevels[1/2] = 13;
ACLevels[1] = 13;
ACLevels[2] = 13;
ACLevels[3] = 13;
ACLevels[4] = 14;
ACLevels[5] = 15;
ACLevels[6] = 15;
ACLevels[7] = 15;
ACLevels[8] = 16;
ACLevels[9] = 16;
ACLevels[10] = 17;
ACLevels[11] = 17;
ACLevels[12] = 17;
ACLevels[13] = 18;
ACLevels[14] = 18;
ACLevels[15] = 18;
//more
//Estimated Hit Points at each level
var HPLevels = {};
HPLevels[0] = 6;
HPLevels[1/8] = 35;
HPLevels[1/4] = 49;
HPLevels[1/2] = 70;
HPLevels[1] = 85;
HPLevels[2] = 100;
HPLevels[3] = 115;
HPLevels[4] = 130;
HPLevels[5] = 145;
HPLevels[6] = 160;
HPLevels[7] = 175;
HPLevels[8] = 190;
HPLevels[9] = 205;
HPLevels[10] = 220;
HPLevels[11] = 235;
HPLevels[12] = 250;
HPLevels[13] = 265;
HPLevels[14] = 280;
HPLevels[15] = 295;
//more
//Estimated Attack Bonus at each level
var ABLevels = {};
ABLevels[0] = 3;
ABLevels[1/8] = 3;
ABLevels[1/4] = 3;
ABLevels[1/2] = 3;
ABLevels[1] = 3;
ABLevels[2] = 3;
ABLevels[3] = 4;
ABLevels[4] = 5;
ABLevels[5] = 6;
ABLevels[6] = 6;
ABLevels[7] = 6;
ABLevels[8] = 7;
ABLevels[9] = 7;
ABLevels[10] = 7;
ABLevels[11] = 8;
ABLevels[12] = 8;
ABLevels[13] = 8;
ABLevels[14] = 8;
ABLevels[15] = 8;
//more
//Estimated Damage per Round at each level
var DPRLevels = {};
DPRLevels[0] = 1;
DPRLevels[1/8] = 3;
DPRLevels[1/4] = 5;
DPRLevels[1/2] = 8;
DPRLevels[1] = 14;
DPRLevels[2] = 20;
DPRLevels[3] = 26;
DPRLevels[4] = 32;
DPRLevels[5] = 38;
DPRLevels[6] = 44;
DPRLevels[7] = 50;
DPRLevels[8] = 56;
DPRLevels[9] = 62;
DPRLevels[10] = 68;
DPRLevels[11] = 74;
DPRLevels[12] = 80;
DPRLevels[13] = 86;
DPRLevels[14] = 92;
DPRLevels[15] = 98;
//more
//Estimated Save DC at each level
var SDCLevels = {};
SDCLevels[0] = 13;
SDCLevels[1/8] = 13;
SDCLevels[1/4] = 13;
SDCLevels[1/2] = 13;
SDCLevels[1] = 13;
SDCLevels[2] = 13;
SDCLevels[3] = 13;
SDCLevels[4] = 14;
SDCLevels[5] = 15;
SDCLevels[6] = 15;
SDCLevels[7] = 15;
SDCLevels[8] = 16;
SDCLevels[9] = 16;
SDCLevels[10] = 16;
SDCLevels[11] = 17;
SDCLevels[12] = 17;
SDCLevels[13] = 18;
SDCLevels[14] = 18;
SDCLevels[15] = 18;
//more
//Estimated Proficiency Bonus at each level
var PBLevels = {};
PBLevels[0] = 2;
PBLevels[1/8] = 2;
PBLevels[1/4] = 2;
PBLevels[1/2] = 2;
PBLevels[1] = 2;
PBLevels[2] = 2;
PBLevels[3] = 2;
PBLevels[4] = 2;
PBLevels[5] = 3;
PBLevels[6] = 3;
PBLevels[7] = 3;
PBLevels[8] = 3;
PBLevels[9] = 4;
PBLevels[10] = 4;
PBLevels[11] = 4;
PBLevels[12] = 4;
PBLevels[13] = 5;
PBLevels[14] = 5;
PBLevels[15] = 5;
//more
//Estimated Average Ability Score at each level
var ASLevels = {};
ASLevels[0] = 8;
ASLevels[1/8] = 9;
ASLevels[1/4] = 10;
ASLevels[1/2] = 10;
ASLevels[1] = 11;
ASLevels[2] = 11;
ASLevels[3] = 12;
ASLevels[4] = 12;
ASLevels[5] = 13;
ASLevels[6] = 13;
ASLevels[7] = 14;
ASLevels[8] = 14;
ASLevels[9] = 15;
ASLevels[10] = 15;
ASLevels[11] = 16;
ASLevels[12] = 16;
ASLevels[13] = 17;
ASLevels[14] = 17;
ASLevels[15] = 18;
ASLevels[16] = 18;
ASLevels[17] = 19;
ASLevels[18] = 19;
ASLevels[19] = 20;
ASLevels[20] = 20;
ASLevels[21] = 21;
ASLevels[22] = 21;
ASLevels[23] = 22;
ASLevels[24] = 22;
ASLevels[25] = 23;
ASLevels[26] = 23;
ASLevels[27] = 24;
ASLevels[28] = 24;
ASLevels[29] = 25;
ASLevels[30] = 25;
function setMonsterSize(size) {
monsterSize = size;
hitDice = hitDiceSize[monsterSize];
recalcAbilityScores();
}
function nextLowerCR(current) {
if (current == 1) return 1/2;
else if(current == 1/2) return 1/4;
else if(current == 1/4) return 1/8;
else if(current == 1/8) return 0;
else if(current == 0) return 0;
else return (current - 1);
}
function nextHigherCR(current) {
if (current == 0) return 1/8;
else if(current == 1/8) return 1/4;
else if(current == 1/4) return 1/2;
else if(current == 1/2) return 1;
else if(current == 30) return 30;
else return (current + 1);
}
function nextCR(current, diff) {
var result = current;
if(diff > 0)
{
for(var i = 0; i < diff; i++)
{
result = nextHigherCR(result);
}
}
else
{
for(var i = diff; i < 0; i++)
{
result = nextLowerCR(result);
}
}
return result;
}
function addValue(element, value) {
element.value = parseInt(element.value) + value;
element.onchange();
}
function resetAbilityScores(CR) {
document.getElementById("strength").value = ASLevels[CR];
document.getElementById("dexterity").value = ASLevels[CR];
document.getElementById("constitution").value = ASLevels[CR];
document.getElementById("intelligence").value = ASLevels[CR];
document.getElementById("wisdom").value = ASLevels[CR];
document.getElementById("charisma").value = ASLevels[CR];
}
function updateAbilityModifiers() {
document.getElementById('strengthMod').value = abilityModifiers[document.getElementById('strength').value];
document.getElementById('dexterityMod').value = abilityModifiers[document.getElementById('dexterity').value];
document.getElementById('constitutionMod').value = abilityModifiers[document.getElementById('constitution').value];
document.getElementById('intelligenceMod').value = abilityModifiers[document.getElementById('intelligence').value];
document.getElementById('wisdomMod').value = abilityModifiers[document.getElementById('wisdom').value];
document.getElementById('charismaMod').value = abilityModifiers[document.getElementById('charisma').value];
var totalSkillPoints = parseInt(document.getElementById('strength').value) + parseInt(document.getElementById('dexterity').value) + parseInt(document.getElementById('constitution').value) + parseInt(document.getElementById('intelligence').value) + parseInt(document.getElementById('wisdom').value) + parseInt(document.getElementById('charisma').value);
if (totalSkillPoints == (ASLevels[totalCR] * 6))
{
document.getElementById('totalSkillPoints').innerHTML = "<font color='green'>" + totalSkillPoints + "</font>";
}
else if (Math.abs(totalSkillPoints - (ASLevels[totalCR] * 6)) <= 6)
{
if(totalSkillPoints < ASLevels[totalCR] * 6)
{
document.getElementById('totalSkillPoints').innerHTML = "<font color='orange'>" + totalSkillPoints + "</font> A bit low!";
}
else
{
document.getElementById('totalSkillPoints').innerHTML = "<font color='orange'>" + totalSkillPoints + "</font> A bit high!";
}
}
else
{
if(totalSkillPoints < ASLevels[totalCR] * 6)
{
document.getElementById('totalSkillPoints').innerHTML = "<font color='red'>" + totalSkillPoints + "</font> Too low!";
}
else
{
document.getElementById('totalSkillPoints').innerHTML = "<font color='red'>" + totalSkillPoints + "</font> Too high!";
}
}
}
function setBaseCR(val) {
document.getElementById("armorClass").value = ACLevels[val];
document.getElementById("hitPoints").value = HPLevels[val];
document.getElementById("attackBonus").value = ABLevels[val];
document.getElementById("damagePerRound").value = DPRLevels[val];
document.getElementById("saveDC").value = SDCLevels[val];
document.getElementById("proficiencyBonus").value = PBLevels[val];
recalcTotalCR();
}
function recalcDefensiveCR() {
var HP = parseInt(document.getElementById("hitPoints").value);
var AC = parseInt(document.getElementById("armorClass").value);
//Adjust for Feats
if(document.getElementById("featAvoidance").checked)
AC += 1;
if(document.getElementById("featNimbleEscape").checked)
AC += 4;
var HPCR = 0; //HPCR is the CR based solely on the Hit Points
var ACCR = 0; //HPCR is the CR based solely on the Armor Class
//Determine defensive CR based first on Hit Points
if (1 <= HP && HP <= 6) HPCR = 0;
else if(7 <= HP && HP <= 35) HPCR = 1/8;
else if(36 <= HP && HP <= 49) HPCR = 1/4;
else if(50 <= HP && HP <= 70) HPCR = 1/2;
else if(71 <= HP && HP <= 85) HPCR = 1;
else if(86 <= HP && HP <= 100) HPCR = 2;
else if(101 <= HP && HP <= 115) HPCR = 3;
else if(116 <= HP && HP <= 130) HPCR = 4;
else if(131 <= HP && HP <= 145) HPCR = 5;
else if(146 <= HP && HP <= 160) HPCR = 6;
else if(161 <= HP && HP <= 175) HPCR = 7;
else if(176 <= HP && HP <= 190) HPCR = 8;
else if(191 <= HP && HP <= 205) HPCR = 9;
//ADD MORE FOR HIGHER LEVELS
//Adjust defensive CR based on Armor Class
var expectedAC = ACLevels[HPCR];
defensiveCR = nextCR(HPCR, ((AC - expectedAC)/2 | 0));
//Display Result
display = document.getElementById("defensiveCRDisplay");
if(defensiveCR == 0.125) display.innerHTML = "1/8";
else if(defensiveCR == 0.25) display.innerHTML = "1/4";
else if(defensiveCR == 0.5) display.innerHTML = "1/2";
else display.innerHTML = defensiveCR;
}
function recalcOffensiveCR() {
var DPR = parseInt(document.getElementById("damagePerRound").value);
var AB = parseInt(document.getElementById("attackBonus").value);
//Adjust for Feats
//if(document.getElementById("featAvoidance").checked)
//AC += 1;
if(document.getElementById("featNimbleEscape").checked)
AB += 4;
//Determine offensive CR based first on Damage per Round
if (0 <= DPR && DPR <= 1) DPRCR = 0;
else if(2 <= DPR && DPR <= 3) DPRCR = 1/8;
else if(4 <= DPR && DPR <= 5) DPRCR = 1/4;
else if(6 <= DPR && DPR <= 8) DPRCR = 1/2;
else if(9 <= DPR && DPR <= 14) DPRCR = 1;
else if(15 <= DPR && DPR <= 20) DPRCR = 2;
else if(21 <= DPR && DPR <= 26) DPRCR = 3;
else if(27 <= DPR && DPR <= 32) DPRCR = 4;
else if(33 <= DPR && DPR <= 38) DPRCR = 5;
else if(39 <= DPR && DPR <= 44) DPRCR = 6;
else if(45 <= DPR && DPR <= 50) DPRCR = 7;
else if(51 <= DPR && DPR <= 56) DPRCR = 8;
else if(57 <= DPR && DPR <= 62) DPRCR = 9;
//ADD MORE FOR HIGHER LEVELS
//Adjust offensive CR based on Attack Bonus
var expectedAB = ABLevels[DPRCR];
offensiveCR = nextCR(DPRCR, ((AB - expectedAB)/2 | 0));
//Display Result
display = document.getElementById("offensiveCRDisplay");
if(offensiveCR == 0.125) display.innerHTML = "1/8";
else if(offensiveCR == 0.25) display.innerHTML = "1/4";
else if(offensiveCR == 0.5) display.innerHTML = "1/2";
else display.innerHTML = offensiveCR;
}
function recalcTotalCR()
{
recalcDefensiveCR();
recalcOffensiveCR();
totalCR = (defensiveCR + offensiveCR)/2;
//Handle cases when totalCR is around the fractional CRs
if (0 <= totalCR && totalCR < 1/16) totalCR = 0;
else if(1/16 <= totalCR && totalCR < 3/16) totalCR = 1/8;
else if(3/16 <= totalCR && totalCR < 6/16) totalCR = 1/4;
else if(6/16 <= totalCR && totalCR < 12/16) totalCR = 1/2;
else totalCR = Math.round(totalCR);
//Display Result
display = document.getElementById("totalCRDisplay");
if(totalCR == 0.125) display.innerHTML = "1/8";
else if(totalCR == 0.25) display.innerHTML = "1/4";
else if(totalCR == 0.5) display.innerHTML = "1/2";
else display.innerHTML = totalCR;
recalcAbilityScores();
}
function recalcAbilityScores() {
resetAbilityScores(totalCR);
//Calculate Strength Score (STR MOD + Proficiency Bonus = ATK Bonus if Melee attack selected)
if(document.getElementById("attackMelee").checked == true || document.getElementById("attackThrown").checked == true)
{
document.getElementById('strength').value = parseInt(abilityScores[parseInt(document.getElementById("attackBonus").value) - parseInt(document.getElementById("proficiencyBonus").value)]);
}
else if(document.getElementById("attackRanged").checked == true || document.getElementById("attackFinesse").checked == true)
{
document.getElementById('dexterity').value = parseInt(abilityScores[parseInt(document.getElementById("attackBonus").value) - parseInt(document.getElementById("proficiencyBonus").value)]);
}
else if(document.getElementById("attackMagic").checked == true)
{
document.getElementById('charisma').value = parseInt(abilityScores[parseInt(document.getElementById("saveDC").value) - parseInt(document.getElementById("proficiencyBonus").value) - 8]);
}
//Calculate Constitution Score (Based on whether the monster has more or less HP than usual.
//Higher HP or lower AC for the current CR means higher Constitution score
var HP = parseInt(document.getElementById("hitPoints").value);
var HPCR = 0; //HPCR is the CR based solely on the Hit Points
//Determine defensive CR based first on Hit Points
if (1 <= HP && HP <= 6) HPCR = 0;
else if(7 <= HP && HP <= 35) HPCR = 1/8;
else if(36 <= HP && HP <= 49) HPCR = 1/4;
else if(50 <= HP && HP <= 70) HPCR = 1/2;
else if(71 <= HP && HP <= 85) HPCR = 1;
else if(86 <= HP && HP <= 100) HPCR = 2;
else if(101 <= HP && HP <= 115) HPCR = 3;
else if(116 <= HP && HP <= 130) HPCR = 4;
else if(131 <= HP && HP <= 145) HPCR = 5;
else if(146 <= HP && HP <= 160) HPCR = 6;
else if(161 <= HP && HP <= 175) HPCR = 7;
else if(176 <= HP && HP <= 190) HPCR = 8;
else if(191 <= HP && HP <= 205) HPCR = 9;
console.log("HPCR " + HPCR);
console.log("TOTAL CR" + totalCR);
//Find where in the range of HP for this CR we land (Lower half = +0 CON, Top half = +1 CON)
var rangeLower = HPLevels[nextLowerCR(HPCR)] + 1;
var rangeUpper = HPLevels[HPCR];
console.log("range lower" + rangeLower);
console.log("range upper" + rangeUpper);
var rangeMid = (rangeLower + rangeUpper) / 2;
console.log("range mid " + rangeMid);
if(HP > rangeMid)
{
document.getElementById('constitution').value = parseInt(document.getElementById('constitution').value) + 1;
}
document.getElementById('constitution').value = parseInt(document.getElementById('constitution').value) + 2 * Math.round(HPCR - totalCR);
updateAbilityModifiers();
//Update HP Dice Code
var numHitDice = Math.round(HP / (parseInt(diceAverages[hitDice]) + parseInt(document.getElementById('constitutionMod').value)));
var diceCode = numHitDice + "D" + hitDice + " + " + document.getElementById('constitutionMod').value*numHitDice;
document.getElementById('HPDiceCode').value = diceCode;
}
function saveMonster() {
var table = document.getElementById("monsterList");
var row = table.insertRow(-1);
var nameCell = row.insertCell(-1);
nameCell.innerHTML = document.getElementById("monsterName").value;
var CRCell = row.insertCell(-1);
CRCell.innerHTML = totalCR;
var editButtonCell = row.insertCell(-1);
editButtonCell.innerHTML = "<button>Edit</button>";
var deleteButtonCell = row.insertCell(-1);
deleteButtonCell.innerHTML = "<button onclick='deleteMonster(this.parentNode.parentNode.rowIndex)'>Delete</button>";
var addButtonCell = row.insertCell(-1);
addButtonCell.innerHTML = "<button onclick='addToEncounter(this.parentNode.parentNode.rowIndex)'>Add to Encounter</button>";
monsterData = {};
monsterData["monsterName"] = document.getElementById("monsterName").value;
monsterData["armorClass"] = document.getElementById("armorClass").value;
monsterData["hitPoints"] = document.getElementById("hitPoints").value;
monsterData["attackBonus"] = document.getElementById("attackBonus").value;
monsterData["damagePerRound"] = document.getElementById("damagePerRound").value;
monsterData["totalCR"] = totalCR;
monsterData["totalXP"] = XPLevels[totalCR];
//Edit stored list
var monsterArray = JSON.parse(localStorage.getItem('monsterArray'));
monsterArray.push(monsterData);
//Save changes to local storage
localStorage.setItem("monsterArray", JSON.stringify(monsterArray));
}
function deleteMonster(monsterIndex) {
var table = document.getElementById("monsterList");
table.deleteRow(monsterIndex);
//Edit stored list
var monsterArray = JSON.parse(localStorage.getItem('monsterArray'));
monsterArray.splice(monsterIndex, 1);
//Save changes to local storage
localStorage.setItem("monsterArray", JSON.stringify(monsterArray));
}
function addToEncounter(monsterIndex) {
//Retrieve monster data
var monsterArray = JSON.parse(localStorage.getItem('monsterArray'));
monsterData = monsterArray[monsterIndex];
//Edit stored list
var encounterArray = JSON.parse(localStorage.getItem('encounterArray'));
encounterArray.push(monsterData);
//Save changes to local storage
localStorage.setItem('encounterArray', JSON.stringify(encounterArray));
//Add to table
var table = document.getElementById("encounterList");
var row = table.insertRow(-1);
var nameCell = row.insertCell(-1);
nameCell.innerHTML = monsterData["monsterName"];
var CRCell = row.insertCell(-1);
CRCell.innerHTML = monsterData["totalCR"];
var XPCell = row.insertCell(-1);
XPCell.innerHTML = monsterData["totalXP"];
var editButtonCell = row.insertCell(-1);
editButtonCell.innerHTML = "<button>Edit</button>";
var deleteButtonCell = row.insertCell(-1);
deleteButtonCell.innerHTML = "<button onclick='deleteMonster(this.parentNode.parentNode.rowIndex)'>Delete</button>";
var addButtonCell = row.insertCell(-1);
addButtonCell.innerHTML = "<button onclick='addToEncounter(this.parentNode.parentNode.rowIndex)'>Add to Encounter</button>";
recalcEncounter();
}
function recalcEncounter() {
//Read stored list
var encounterArray = JSON.parse(localStorage.getItem('encounterArray'));
var totalXP = 0;
var adjustedXP = 0;
var monsterIndex;
for(monsterIndex in encounterArray) {
totalXP += encounterArray[monsterIndex]["totalXP"];
}
var numMonsters = encounterArray.length;
var multiplier = 1;
//Adjust XP difficulty for more monsters
if(numMonsters == 1) multiplier = 1;
else if(numMonsters == 2) multiplier = 1.5;
else if(3 <= numMonsters && numMonsters <= 6) multiplier = 2;
else if(7 <= numMonsters && numMonsters <= 10) multiplier = 2.5;
else if(11 <= numMonsters && numMonsters <= 14) multiplier = 3;
else if(15 <= numMonsters) multiplier = 4;
adjustedXP = totalXP * multiplier;
display = document.getElementById("encounterXPDisplay");
display.innerHTML = totalXP;
display = document.getElementById("adjustedXPDisplay");
display.innerHTML = adjustedXP;
}
function setupPage() {
setBaseCR(1);
var monsterArray = [];
localStorage.setItem("monsterArray", JSON.stringify(monsterArray));
var encounterArray = [];
localStorage.setItem("encounterArray", JSON.stringify(encounterArray));
}
//http://stackoverflow.com/questions/702165/how-do-i-implement-press-and-hold-button-javascript
//PC HP = 8 * (Level + 1) If monster can kill a pc in one attack, bump up one CR
</script>
</body>
</html>