forked from xmasscthulhu/xmasscthulhu.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdolmenwoodNPCGenerator.js
619 lines (589 loc) · 23.7 KB
/
dolmenwoodNPCGenerator.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
//returns a random number between max and min with both max and min included
function dieRoller (max, min) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
//input number of dice and highest value of die-type (e.g. 3d6 would be num = 3, hiVal = 6)
function dice (num, hiVal) {
let roll = 0;
for (i = 0; i < num; i++) {
roll += dieRoller (hiVal,1);
}
return roll;
}
function arrayItemGrabber(max, min) {
return Math.floor(Math.random() * (max - min)) + min;
}
//LOADERS
//combines given names and surnames for nameLoader
function givenPlusSurname (given, surname) {
let rndGiven = given[arrayItemGrabber(given.length,0)];
let rndSur = surname[arrayItemGrabber(surname.length,0)];
return rndGiven + " " + rndSur;
}
function nameLoader(npcClass){
let cls = npcClass;
let rndElfName = arrayItemGrabber(npcNames.elf_names.length,0);
let rndMossDwarfName = arrayItemGrabber(npcNames.mossDwarf_name.length,0);
let name = "";
if (cls === friar || cls === hunter || cls === knight || cls === minstrel) {
name = givenPlusSurname(npcNames.human_givenName,npcNames.human_surname)
} else if (cls === elf) {
name = npcNames.elf_names[rndElfName];
} else if (cls === goatfolk) {
name = givenPlusSurname(npcNames.goatfolk_givenName,npcNames.goatfolk_surname);
} else if (cls === mossDwarf) {
name = npcNames.mossDwarf_name[rndMossDwarfName];
} else if (cls === grimalkin) {
name = givenPlusSurname(npcNames.grimalkin_givenName,npcNames.grimalkin_surname)
} else if (cls === woodgrue) {
name = givenPlusSurname(npcNames.woodgrue_givenNames,npcNames.woodgrue_surnames);
}
return name;
}
function abilityScoreLoader() {
return `<strong>STR</strong> ${dice(3,6)} <strong>INT</strong> ${dice(3,6)} <strong>WIS</strong> ${dice(3,6)} <br> <strong>DEX</strong> ${dice(3,6)} <strong>CON</strong> ${dice(3,6)} <strong>CHA</strong> ${dice(3,6)}`;
}
function traitLoader() {
}
function armourLoader(cls) {
let armMax = cls.armor.length;
let armRnd = dieRoller (armMax-1,0);
let armour = cls.armor[armRnd];
return armour;
}
function mundaneItems() {
d4 = dice (1,4);
mndItems = randomItems[dieRoller(randomItems.length-1,0)];
for (i = 0; i < d4; i++) {
mndItems += ", " + randomItems[dieRoller(randomItems.length-1,0)];
}
return mndItems;
}
function commaSperator(array) {
arr = array.length;
if (arr < 1) {
return "";
} else if (arr >= 1) {
return ", ";
}
}
function magicItemLoader(npcLevel) {
let lvl = npcLevel
let d20 = 0;
let items = "";
let mundane = mundaneItems();
//let itemA = "";
//let itemA = dieRoller(magicItems.magicItemsI.length-1,0);
let itemB = dieRoller(magicItems.magicItemsII.length-1,0);
let itemC = dieRoller(magicItems.magicItemsIII.length-1,0);
let itemD = dieRoller(magicItems.magicItemsIV.length-1,0);
for (let i = 0; i < lvl; i++) {
d20 = dieRoller(20,1);
if (d20 === 20) {
items += _.shuffle(magicItems.magicItemsI).slice(0,1)
}
}
for (let i = 0; i < lvl; i++) {
d20 = dieRoller(20,1);
if (d20 === 20) {
items += commaSperator(items) + _.shuffle(magicItems.magicItemsII).slice(0,1);
}
}
for (let i = 0; i < lvl; i++) {
d20 = dieRoller(20,1);
if (d20 === 20) {
items += commaSperator(items) + _.shuffle(magicItems.magicItemsIII).slice(0,1);
}
}
for (let i = 0; i < lvl; i++) {
d20 = dieRoller(20,1);
if (d20 === 20) {
items += commaSperator(items) + _.shuffle(magicItems.magicItemsIV).slice(0,1);
}
}
if (items.length === 0) {
return `<strong>Mundane Items:</strong> <em>${mundane}</em>`;
} else {
return `<strong>Magic Items:</strong> <em>${items}</em> <br> <strong>Mundane Items:</strong> <em>${mundane}</em>`;
}
}
function hornLoader (cls,lvl) {
if (cls === goatfolk) {
if (lvl <= 3) {
return ", or horns (1d4)";
} else if (lvl >= 4 && lvl <= 6) {
return ", or horns (1d6)";
} else if (lvl >= 7 && lvl <= 9) {
return ", or horns (1d8)";
} else {
return ", or horns (1d10)";
}
} else {
return "";
}
}
function weaponLoader(cls,lvl) {
let wpnMax = cls.weapons.length;
let wpnRnd = cls.weapons[dieRoller(wpnMax-1,0)]
let isWpnMgc = magicWeaponChecker(lvl);
let mgcWpn = "";
let wpn = ""
let horns = hornLoader(cls,lvl);
if (isWpnMgc === true) {
mgcWpn = magicWeaponLoader(cls);
return mgcWpn + horns;
} else {
wpn = wpnRnd;
console.log(wpn);
return wpn + horns;
}
}
//magic weapon loaders
//if magic item is sword, this defines its type
function magicSwordTypifier() {
let x = dieRoller(6,1);
if (x > 5) {
return "Two-handed Sword (1d10)";
} else if (x > 2 && x < 6) {
return "Sword (1d8)";
} else {
return "Short Sword (1d6)";
}
}
function magicWeaponLoader(npcClass) {
let cls = npcClass;
let mgcMeleeRnd = dieRoller(49,32);
let mgcWpnRndFriar = dieRoller(58,58); //randomly selects from "friar-safe" weapons
let mgcSwdRnd = dieRoller(31,0);
let mgcWpnRnd = dieRoller(magicWeaponTables.length,33);
let mgcWpn = magicWeaponTables[mgcWpnRnd];
let swordType = magicSwordTypifier();
let isItASword = magicSwordChecker();
if (cls === friar) {
mgcWpn = magicWeaponTables[mgcWpnRndFriar];
console.log(mgcWpn);
} else if (cls === knight) {
if (isItASword === false) {
mgcWpn = magicWeaponTables[mgcMeleeRnd];
console.log(mgcWpn);
} else {
mgcWpn = swordType + magicWeaponTables[mgcSwdRnd];
console.log(mgcWpn);
}
} else {
if (isItASword === false) {
mgcWpn = magicWeaponTables[mgcWpnRnd];
console.log(mgcWpn);
} else {
mgcWpn = swordType + magicWeaponTables[mgcSwdRnd];
console.log(mgcWpn);
}
}
return mgcWpn;
}
function hitPointLoader(npcClass, npcLevel) {
let cls = npcClass;
let lvl = npcLevel;
console.log("cls is " + cls);
console.log("lvl is " + lvl);
let hp = 0;
let hd = lvl+1;
let i = 0;
if (cls === friar){
while (i <= lvl) {
hp += dieRoller(4,1);
console.log(hp)
i++;
}
} if (cls === hunter || cls === knight) {
while (i <= lvl) {
hp += dieRoller(8,1);
i++;
}
} else {
while (i <= lvl) {
hp += dieRoller(6,1);
i++;
}
}
console.log("HP " + hp);
return hp;
}
function spellLoader(npcClass,npcLevel) {
let cls = npcClass;
let lvl = npcLevel;
let spellsKnown = "";
let glamours = glamourList;
let glamoursKnown = "";
let knacks = mossDwarf.knacks;
let knackKnown = "";
if (cls === friar) {
switch (lvl) {
case 0 : //npc lvl 1
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
break;
case 1 : //npc lvl 2
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
break;
case 2 : //npc lvl 3
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
break;
case 3 : //npc lvl 4
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
break;
case 4 : //npc lvl 5
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
break;
case 5 : //npc lvl 6
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[4].length-1,0)];
break;
case 6 : //npc lvl 7
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[4][dieRoller(cls.spells[4].length-1,0)];
break;
case 7 : //npc lvl 8
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[4][dieRoller(cls.spells[4].length-1,0)];
spellsKnown += ", " + cls.spells[4][dieRoller(cls.spells[4].length-1,0)];
break;
case 8 : //npc lvl 9
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[3][dieRoller(cls.spells[3].length-1,0)];
spellsKnown += ", " + cls.spells[4][dieRoller(cls.spells[4].length-1,0)];
spellsKnown += ", " + cls.spells[4][dieRoller(cls.spells[4].length-1,0)];
}
return `<strong>Spells:</strong> <em>${spellsKnown}</em>`;
} else if (cls === elf) {
switch (lvl) {
case 0 : //lvl 1
glamoursKnown = _.shuffle(glamours).slice(0,1);
break;
case 1 : //lvl 2
glamoursKnown = _.shuffle(glamours).slice(0,2);
break;
case 2 : case 3 ://lvl 3 and 4
glamoursKnown = _.shuffle(glamours).slice(0,3);
break;
case 4 : //lvl 5
glamoursKnown = _.shuffle(glamours).slice(0,4);
break;
case 5 : //lvl 6
glamoursKnown = _.shuffle(glamours).slice(0,5);
break;
case 6 : case 7 : //lvl 7 and 8
glamoursKnown = _.shuffle(glamours).slice(0,6);
break;
case 8 : //lvl 9
glamoursKnown = _.shuffle(glamours).slice(0,7);
break;
case 9 : //lvl 10
glamoursKnown = _.shuffle(glamours).slice(0,8);
break;
}
return `<strong>Glamours:</strong><em>${glamoursKnown}</em>`;
} else if (cls === grimalkin) {
switch (lvl) {
case 0 : //lvl 1
glamoursKnown = _.shuffle(glamours).slice(0,1);
break;
case 1 : //lvl 2
glamoursKnown = _.shuffle(glamours).slice(0,2);
break;
case 2 : case 3 : //lvl 3 and 4
glamoursKnown = _.shuffle(glamours).slice(0,3);
break;
case 4 : //lvl 5
glamoursKnown = _.shuffle(glamours).slice(0,4);
break;
case 5 : //lvl 6
glamoursKnown = _.shuffle(glamours).slice(0,5);
break;
case 6 : case 7 : //lvl 7 and 8
glamoursKnown = _.shuffle(glamours).slice(0,6);
break;
case 8 : case 9 : //lvl 9 and 10
glamoursKnown = _.shuffle(glamours).slice(0,7);
break;
} return `<strong>Glamours:</strong><em>${glamoursKnown}</em>`;
} else if (cls === mossDwarf) {
knackKnown += knacks[dieRoller(6,1)-1];
return `<strong>Knack:</strong> <em>${knackKnown}</em>`;
} else if (cls === goatfolk) {
switch (lvl) {
case 0 : case 1 : case 2 :
spellsKnown = "";
break;
case 3 :
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
break;
case 4 :
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
break;
case 5 :
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
break;
case 6 :
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
break;
case 7 :
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
break;
case 8 :
spellsKnown = cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[0][dieRoller(cls.spells[0].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[1][dieRoller(cls.spells[1].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
spellsKnown += ", " + cls.spells[2][dieRoller(cls.spells[2].length-1,0)];
break;
} return `<strong>Spells:</strong> <em>${spellsKnown}</em>`;
} else {
return "";
}
}
//loads saves and thac0 based on level and character class
function statsLoader(npcClass, npcLevel) {
let cls = npcClass;
let lvl = npcLevel+1;
let thac0 = "";
let saves = "";
if (cls === elf) {
if (lvl <= 3) {
saves = "D12 W13 P13 B15 S12";
thac0 = "19 [0]";
} else if (lvl >= 4 || lvl <= 7) {
saves = " D10 W11 P11 B13 S10";
thac0 = " 17 [+2]";
} else if (lvl >= 9) {
saves = "D8 W9 P9 B10 S8";
thac0 = "14 [+5]";
}
} else if (cls === friar){
if (lvl <= 4) {
saves = 'D11 W12 P14 B16 S15';
thac0 = '19 [0]';
} else if (lvl >= 5 || lvl <= 8) {
saves = 'D9 W10 P12 B14 S12';
thac0 = '17 [+2]';
} else if (lvl >=9) {
saves = 'D6 W7 P9 B11 S9';
thac0 = '14 [+5]';
}
} else if (cls === goatfolk || cls === hunter || cls === knight) {
if (lvl <= 3) {
saves = "D12 W13 P14 B15 S16";
thac0 = "19[0]";
} else if (lvl >= 4 || lvl <= 6){
saves = "D10 W11 P12 B13 S14";
thac0 = "17 [+2]";
} else if (lvl >= 7){
saves = "D8 W9 P10 B10 S12";
thac0 = "14 [+5]";
}
} else if (cls === grimalkin) {
if (lvl <= 4) {
saves = "D11 W12 P14 B16 S15";
thac0 = "19 [0]";
} else if (lvl >= 5 || lvl <= 8) {
saves = "D9 W10 P12 B14 S12";
thac0 = "17 [+2]";
} else if (lvl > 9) {
saves = "D7 W8 P10 B12 S10";
thac0 = "14 [+5]";
}
} else if (cls === minstrel) {
if (lvl <= 4) {
saves = "D13 W14 P13 B16 S15";
thac0 = "19 [0]";
} else if (lvl >= 5 || lvl <= 8) {
saves = "D12 W13 P11 B14 S13";
thac0 = "17 [+2]";
} else if (lvl >= 9) {
saves = "D10 W11 P9 B12 S10";
thac0 = "14 [+5]";
}
} else if (cls === mossDwarf) {
if (lvl <= 3) {
saves = "D8 W9 P10 B13 S12";
thac0 = "19 [0]";
} else if (lvl >= 4 || lvl <= 6) {
saves = "D6 W7 P8 B10 S10";
thac0 = "17 [+2]";
} else if (lvl >= 7) {
saves = "D4 W5 P6 B7 S8";
thac0 = "14 [+5]";
}
}
console.log("THAC0 " + thac0 + " Saves " + saves);
return [thac0, saves];
}
function traitLoader() {
let rndPers1 = _.shuffle(npcDesc.personality).slice(0,1);
let rndPers2 = _.shuffle(npcDesc.personality).slice(0,1);
let rndDesc = _.shuffle(npcDesc.description).slice(0,1);
return `${rndPers1}, ${rndPers2}, ${rndDesc}`
}
//checkers
//checks if NPC has a magic weapon
function magicWeaponChecker(lvl) {
let d20 = 0;
let isWpnMgc = 0;
for (let i = 0; i < lvl; i++) {
d20 = dieRoller(20,1);
isWpnMgc = Boolean(d20 == 20);
if (d20 === 20) { break }
}
return isWpnMgc;
}
//checks if magic weapon is a sword
function magicSwordChecker() {
let x = dieRoller(5,1);
if (x < 5) {
return true;
} else {
return false;
}
}
function speedChecker(armor) {
let light = armor.includes("Leather");
let unarmored = armor.includes("Cloth");
if (light === true) {
return "90 (30)";
} else if (unarmored === true) {
return "120 (40)";
} else {
return "60 (20)";
}
}
function submission() {
document.getElementById("npcPartyText").style.display = "block";
let x = document.getElementById('classChoice');
let y = document.getElementById('levelChoice');
let classValue = JSON.parse(x.value);
let classObj = eval(classValue.class);
let classTitle = classValue.class;
console.log(classValue.class);
let levelValue = parseInt(y.value)-1;
npcGenerator(classObj,levelValue,classTitle);
}
function npcGenerator(npcClass,npcLevel,npcTitle) {
let cls = npcClass;
let lvl = npcLevel;
let title = npcTitle;
let name = nameLoader(cls);
let traits = traitLoader();
let ac = armourLoader(cls);
let mv = speedChecker(ac);
let hp = hitPointLoader(cls,lvl);
let wpn = weaponLoader(cls,lvl);
let stats = statsLoader(cls,lvl);
let items = magicItemLoader(lvl);
let spls = spellLoader(cls,lvl);
let ability = abilityScoreLoader();
document.getElementById("npcStatBlock").innerHTML += `${name}<br><em>${traits}</em><br><strong>Level ${lvl+1} ${title}</strong> <br>
${ability} <br> <strong>AC</strong> ${ac} <strong>HP</strong> ${hp} <strong>Att</strong> 1 x ${wpn}
<strong>THAC0</strong> ${stats[0]} <strong>MV</strong> ${mv} <strong>SV</strong> ${stats[1]} ${spls} ${items} <br>
<br>`;
}
function partyLevel() {
d12 = dice(1,12);
if (d12 <= 3) {
return 1;
} else if (d12 === 4 || d12 === 5) {
return 2;
} else if (d12 === 6 || d12 === 7) {
return 3;
} else if (d12 === 8) {
return 4;
} else if (d12 === 9) {
return 5;
}else if (d12 === 10) {
return 6;
} else if (d12 === 11) {
return 7;
}else if (d12 === 12) {
return 8;
}
}
function partyGenerator() {
document.getElementById("npcPartyText").style.display = "block";
let partySize = dieRoller(4,1)+4;
console.log("party size is " + partySize);
let levelValue = 5;
let classOptions = document.getElementById('classChoice')
let classValue = JSON.parse(classOptions[dieRoller(8,0)].value);
let classObj = eval(classValue.class);
let classTitle = classValue.class;
for (let i = 0; i < partySize; i++) {
levelValue = partyLevel();
classOptions = document.getElementById('classChoice')
classValue = JSON.parse(classOptions[dieRoller(8,0)].value);
classObj = eval(classValue.class);
classTitle = classValue.class;
npcGenerator(classObj,levelValue,classTitle);
}
}
function copyToClipboard(){
let copyText = document.getElementById("npcStatBlock").innerText;
navigator.clipboard.writeText(copyText);
alert("Copied the text: " + copyText);
}