-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·638 lines (563 loc) · 19.2 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
<!DOCTYPE html>
<html>
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WZJ425J');</script>
<!-- End Google Tag Manager -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-147894816-1');
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0">
<title>Pathfinder 2E Stat Generator</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<style>
td{
padding: 0px;
}
.center{
margin: auto;
overflow:auto;
white-space:nowrap;
max-width: 790px;
}
.k6P78QHdUe{
width: 100%;
}
.k6P78QHdUe a{
display:inline-block;
height: 100%;
}
.center a img{
width: 100%;
height: 100%;
max-height:244.333px;
max-width:189.6px;
}
img.center-align{
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<body class="indigo lighten-4">
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WZJ425J"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<header>
<img src="imgs/pathfinder_roleplaying_game.png" class="center-align">
</header>
<main>
<div class="row">
<div class="col s1"></div>
<div class="col s10">
<div class="center">
<div id="k6P7$8QHd$Ue" class="k6P78QHdUe">
</div>
</div>
</div>
<div class="col s1"></div>
</div>
<div class="row">
<div class="input-field col s4">
<span>Ancestry:</span>
<select id="select_ancestry">
<option value="" disabled selected></option>
</select>
</div>
<div class="input-field col s4">
<span>Background:</span>
<select id="select_background">
<option value="" disabled selected></option>
</select>
</div>
<div class="input-field col s4">
<span>Class:</span>
<select id="select_class">
<option value="" disabled selected></option>
</select>
</div>
</div>
<table>
<tbody id="tbody_abilityScores">
<thead>
<tr>
<th rowspan="2">Ability Score</th>
<th colspan="5">Boosts</th>
<th>Flaws</th>
<th rowspan="2">Total</th>
</tr>
<tr>
<th>Ancestry</th>
<th>Background(Selected)</th>
<th>Background(Free)</th>
<th>Free</th>
<th>Class</th>
<th>Ancestry</th>
</tr>
</thead>
</tbody>
</table>
</main>
<footer class="page-footer center-align">
<p>
This website uses trademarks and/or copyrights owned by Paizo Inc., which are used under Paizo's Community Use Policy. We are expressly prohibited from charging you to use or access this content. This website is not published, endorsed, or specifically approved by Paizo Inc. For more information about Paizo's Community Use Policy, please visit paizo.com/communityuse. For more information about Paizo Inc. and Paizo products, please visit paizo.com.
</p>
<hr>
<p>
pathfinder2abilitycalculator.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to "amazon.com".
</p>
</footer>
</body>
</html>
<script>
function loadJSON(fileName) {
return new Promise((resolve, reject) => {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', fileName, true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
resolve(JSON.parse(xobj.responseText));
}
};
xobj.send(null);
});
}
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}
async function init(){
let k6P7$8QHd$Ue = document.getElementById('k6P7$8QHd$Ue');
let ads = await loadJSON('/amazonAffiliateAds.json');
let numAds = 6;
let selectedAds = getRandom(ads, numAds);
width = 99/numAds;
let html = '';
for(let ad of selectedAds){
html = '<a href="' + ad.url + '" style="width:'+width+'%;">';
html += '<img src="'+ad.imgSRC+'" style="height:160px;">';
html += '</a>';
k6P7$8QHd$Ue.innerHTML = k6P7$8QHd$Ue.innerHTML+html;
}
}
init();
const abilityScores = [
'Strength',
'Dexterity',
'Constitution',
'Intelligence',
'Wisdom',
'Charisma'
];
const ancestries = {
Custom: {
boosts: [],
flaws: [],
numFreeBoosts: 6,
numFreeFlaws: 6
},
Dwarf: {
boosts: ['con', 'wis'],
flaws: ['cha'],
numFreeBoosts: 1,
numFreeFlaws: 0
},
Elf: {
boosts: ['dex', 'int'],
flaws: ['con'],
numFreeBoosts: 1,
numFreeFlaws: 0
},
Gnome: {
boosts: ['con', 'cha'],
flaws: ['str'],
numFreeBoosts: 1,
numFreeFlaws: 0
},
Goblin: {
boosts: ['dex', 'cha'],
flaws: ['wis'],
numFreeBoosts: 1,
numFreeFlaws: 0
},
'Half-Elf': {
boosts: [],
flaws: [],
numFreeBoosts: 2,
numFreeFlaws: 0
},
Halfling: {
boosts: ['dex', 'wis'],
flaws: ['str'],
numFreeBoosts: 1,
numFreeFlaws: 0
},
'Half-Orc': {
boosts: [],
flaws: [],
numFreeBoosts: 2,
numFreeFlaws: 0
},
Human: {
boosts: [],
flaws: [],
numFreeBoosts: 2,
numFreeFlaws: 0
}
};
const backgrounds = {
'Custom': ['str', 'dex', 'con', 'int', 'wis', 'cha'],
'Acolyte': ['int', 'wis'],
'Acrobat': ['str', 'dex'],
'Animal Whisperer': ['wis', 'cha'],
'Artisan': ['str', 'int'],
'Artist': ['dex', 'cha'],
'Barkeep': ['con', 'cha'],
'Barrister': ['int', 'cha'],
'Bounty Hunter': ['str', 'wis'],
'Charlatan': ['int', 'cha'],
'Criminal': ['dex', 'int'],
'Demon Slayer': ['str', 'con'],
'Detective': ['int', 'wis'],
'Early Explorer': ['str', 'wis'],
'Emissary': ['int', 'cha'],
'Entertainer': ['dex', 'cha'],
'Faction Opportunist': ['int', 'wis'],
'Farmhand': ['con', 'wis'],
'Field Medic': ['con', 'wis'],
'Former Aspis Agent': ['int', 'cha'],
'Fortune Teller': ['int', 'cha'],
'Gambler': ['dex', 'cha'],
'Gladiator': ['str', 'cha'],
'Guard': ['str', 'cha'],
'Herbalist': ['con', 'wis'],
'Hermit': ['con', 'int'],
'Hunter': ['dex', 'wis'],
'Laborer': ['str', 'con'],
'Martial Disciple': ['str', 'dex'],
'Merchant': ['int', 'cha'],
'Miner': ['str', 'wis'],
'Noble': ['int', 'cha'],
'Nomad': ['con', 'wis'],
'Prisoner': ['str', 'con'],
'Ruby Pheonix Enthusisiast': ['str', 'dex'],
'Sailor': ['str', 'dex'],
'Savior of Air': ['dex', 'cha'],
'Scholar': ['int', 'wis'],
'Scholar of the Sky Key': ['con', 'int'],
'Scout': ['dex', 'wis'],
'Shadow Lodge Defector': ['dex', 'int'],
'Shadow War Survivor': ['wis', 'cha'],
'Street Urchin': ['dex', 'con'],
'Tapestry Refugee': ['con', 'wis'],
'Thassilonian Delver': ['con', 'int'],
'Tinker': ['dex', 'int'],
'Warrior': ['str', 'con']
};
classes = {
'Custom': ['str', 'dex', 'con', 'int', 'wis', 'cha'],
'Alchemist': ['int'],
'Barbarian': ['str'],
'Bard': ['cha'],
'Champion': ['str', 'dex'],
'Cleric': ['wis'],
'Druid': ['wis'],
'Fighter': ['str', 'dex'],
'Monk': ['str', 'dex'],
'Ranger': ['str', 'dex'],
'Rogue': ['str', 'dex', 'con', 'int', 'wis', 'cha'],
'Sorcerer': ['cha'],
'Wizard': ['int']
}
const tbody_abilityScores = document.getElementById('tbody_abilityScores');
function createAbilityScoreTable(){
for(let i=0;i<abilityScores.length;i++){
let scoreAbbr = abilityScores[i].substring(0,3).toLowerCase();
tbody_abilityScores.innerHTML +=
'<tr>'
+'<td>'+abilityScores[i]+':</td>'
+'<td><label><input id="input_ancestryBoost_'+scoreAbbr+'" value="'+scoreAbbr+'" class="ancestryBoost" type="checkbox" disabled><span></span></label></td>'
+'<td><label><input id="input_backgroundBoost1_'+scoreAbbr+'" value="'+scoreAbbr+'" class="backgroundBoost1" type="checkbox" disabled><span></span></label></td>'
+'<td><label><input id="input_backgroundBoost2_'+scoreAbbr+'" value="'+scoreAbbr+'" class="backgroundBoost2" type="checkbox" disabled><span></span></label></td>'
+'<td><label><input id="input_freeBoost_'+scoreAbbr+'" value="'+scoreAbbr+'" class="freeBoost" type="checkbox"><span></span></label></td>'
+'<td><label><input id="input_classBoost_'+scoreAbbr+'" value="'+scoreAbbr+'" class="classBoost" type="checkbox" disabled><span></span></label></td>'
+'<td><label><input id="input_ancestryFlaw_'+scoreAbbr+'" value="'+scoreAbbr+'" class="ancestryFlaw" type="checkbox" disabled><span></span></label></td>'
+'<td><input id="input_'+scoreAbbr+'" type="text" value=10 readonly disabled style="width:20px;"></td>'
+'</tr>';
}
}
const select_ancestry = document.getElementById('select_ancestry');
function createAncestrySelector(){
Object.entries(ancestries).forEach(function([key, value]){
select_ancestry.innerHTML +=
'<option value="'+key+'">'
+key
+'</option>';
});
}
const select_background = document.getElementById('select_background');
function createBackgroundSelector(){
Object.entries(backgrounds).forEach(function([key, value]){
select_background.innerHTML +=
'<option value="'+key+'">'
+key
+'</option>';
});
}
function changeStatTotal(id, amount){
document.getElementById(id).value = parseInt(document.getElementById(id).value)+amount;
};
numAncestryBoostsAvailable = 0;
function onAncestryChange(event){
let selectedAncestry = ancestries[select_ancestry.value];
numAncestryBoostsAvailable = selectedAncestry['numFreeBoosts'];
let elements = document.getElementsByClassName('ancestryBoost');
let isDisabled = !(numAncestryBoostsAvailable > 0);
for(let i=0;i<elements.length;i++){
if(elements[i].checked == true)
changeStatTotal('input_'+elements[i].value, -2);
elements[i].checked = false;
elements[i].disabled = isDisabled;
elements[i].classList.remove('ancestrySet');
}
numAncestryFlawsAvailable = selectedAncestry['numFreeFlaws'];
elements = document.getElementsByClassName('ancestryFlaw');
let isFlawDisabled = !(numAncestryFlawsAvailable > 0);
for(let i=0;i<elements.length;i++){
if(elements[i].checked == true)
changeStatTotal('input_'+elements[i].value, 2);
elements[i].checked = false;
elements[i].disabled = isFlawDisabled;
}
for(let boost of selectedAncestry['boosts']){
let boostElement = document.getElementById('input_ancestryBoost_'+boost)
boostElement.checked = true;
boostElement.disabled = true;
changeStatTotal('input_'+boost, 2);
boostElement.classList.add('ancestrySet');
}
for(let flaw of selectedAncestry['flaws']){
let flawElement = document.getElementById('input_ancestryFlaw_'+flaw)
flawElement.checked = true;
flawElement.disabled = true;
changeStatTotal('input_'+flaw, -2);
}
};
function onAncestryBoostChange(event){
if(this.checked){
this.classList.add('playerSet');
changeStatTotal('input_'+this.value, 2);
numAncestryBoostsAvailable -= 1;
if(numAncestryBoostsAvailable == 0){
let elements = document.querySelectorAll('.ancestryBoost:not(.ancestrySet):not(.playerSet)');
for(element of elements){
element.disabled = true;
}
}
}
else{
this.classList.remove('playerSet');
changeStatTotal('input_'+this.value, -2);
numAncestryBoostsAvailable += 1;
if(numAncestryBoostsAvailable > 0){
let elements = document.querySelectorAll('.ancestryBoost:not(.ancestrySet):not(.playerSet)');
for(element of elements){
element.disabled = false;
}
}
}
}
function onAncestryFlawChange(event){
if(this.checked)
changeStatTotal('input_'+this.value, -2);
else
changeStatTotal('input_'+this.value, 2);
}
function onBackgroundChange(event){
let selectedBackground = backgrounds[select_background.value];
let elements = document.getElementsByClassName('backgroundBoost1');
for(let i=0;i<elements.length;i++){
if(elements[i].checked == true)
changeStatTotal('input_'+elements[i].value, -2);
elements[i].checked = false;
elements[i].disabled = true;
elements[i].classList.remove('backgroundOption');
}
for(let abilityChoice of selectedBackground){
let element = document.getElementById('input_backgroundBoost1_'+abilityChoice);
element.disabled = false;
element.classList.add('backgroundOption');
}
elements = document.getElementsByClassName('backgroundBoost2');
for(let i=0;i<elements.length;i++){
if(elements[i].checked == true)
changeStatTotal('input_'+elements[i].value, -2);
elements[i].checked = false;
elements[i].disabled = false;
}
}
function onBackgroundBoost1Change(event){
let otherOptions = document.querySelectorAll('.backgroundOption:not(#'+this.id+')');
let backgroundBoost2Option = document.getElementById('input_backgroundBoost2_'+this.value);
if(this.checked){
for(let otherOption of otherOptions){
otherOption.disabled = true;
}
if(backgroundBoost2Option.checked){
backgroundBoost2Option.checked = false;
backgroundBoost2Option.dispatchEvent(new Event('change'));
}
changeStatTotal('input_'+this.value, 2);
}
else{
for(let otherOption of otherOptions){
otherOption.disabled = false;
}
changeStatTotal('input_'+this.value, -2);
}
}
function onBackgroundBoost2Change(event){
let otherOptions = document.querySelectorAll('.backgroundBoost2:not(#'+this.id+')');
let backgroundBoost1Option = document.getElementById('input_backgroundBoost1_'+this.value);
if(this.checked){
for(let i=0;i<otherOptions.length;i++){
otherOptions[i].disabled = true;
}
if(backgroundBoost1Option.checked){
backgroundBoost1Option.checked = false;
backgroundBoost1Option.dispatchEvent(new Event('change'));
}
changeStatTotal('input_'+this.value, 2);
}
else{
for(let i=0;i<otherOptions.length;i++){
otherOptions[i].disabled = false;
}
changeStatTotal('input_'+this.value, -2);
}
}
let numFreeBoosts = 4;
function onFreeBoostChange(event){
if(this.checked){
changeStatTotal('input_'+this.value, 2);
numFreeBoosts -= 1;
if(numFreeBoosts == 0){
let elements = document.querySelectorAll('.freeBoost:not(:checked)')
for(element of elements){
element.disabled=true;
}
}
}
else{
changeStatTotal('input_'+this.value, -2);
numFreeBoosts += 1;
if(numFreeBoosts > 0){
let elements = document.querySelectorAll('.freeBoost:not(:checked)')
for(element of elements){
element.disabled=false;
}
}
}
};
const select_class = document.getElementById('select_class');
function createClassSelector(){
Object.entries(classes).forEach(function([key, value]){
select_class.innerHTML +=
'<option value="'+key+'">'
+key
+'</option>';
});
};
function onClassSelectChange(event){
let selectedClass = classes[select_class.value];
let elements = document.getElementsByClassName('classBoost');
for(let i=0;i<elements.length;i++){
if(elements[i].checked == true)
changeStatTotal('input_'+elements[i].value, -2);
elements[i].checked = false;
elements[i].disabled = true;
elements[i].classList.remove('classOption');
}
for(let abilityChoice of selectedClass){
let element = document.getElementById('input_classBoost_'+abilityChoice);
element.classList.add('classOption');
if(selectedClass.length == 1){
changeStatTotal('input_'+element.value, 2);
element.checked = true;
}
else{
element.disabled = false;
}
}
};
function onClassBoostChange(event){
if(this.checked){
changeStatTotal('input_'+this.value, 2);
let elements = document.querySelectorAll('.classOption:not(:checked)');
for(element of elements){
element.disabled = true;
}
}
else{
changeStatTotal('input_'+this.value, -2);
let elements = document.querySelectorAll('.classOption:not(:checked)');
for(element of elements){
element.disabled = false;
}
}
}
createAbilityScoreTable();
createAncestrySelector();
createBackgroundSelector();
createClassSelector();
select_ancestry.onchange = onAncestryChange;
select_background.onchange = onBackgroundChange;
select_class.onchange = onClassSelectChange;
let ancestryBoostElements = document.getElementsByClassName('ancestryBoost');
for(let i=0;i<ancestryBoostElements.length;i++){
ancestryBoostElements[i].onchange = onAncestryBoostChange;
}
let ancestryFlawElements = document.getElementsByClassName('ancestryFlaw');
for(let i=0;i<ancestryFlawElements.length;i++){
ancestryFlawElements[i].onchange = onAncestryFlawChange;
}
let backgroundBoost1Elements = document.getElementsByClassName('backgroundBoost1');
for(let i=0;i<backgroundBoost1Elements.length;i++){
backgroundBoost1Elements[i].onchange = onBackgroundBoost1Change;
}
let backgroundBoost2Elements = document.getElementsByClassName('backgroundBoost2');
for(let i=0;i<backgroundBoost2Elements.length;i++){
backgroundBoost2Elements[i].onchange = onBackgroundBoost2Change;
}
let freeBoosts = document.getElementsByClassName('freeBoost');
for(let i=0;i<freeBoosts.length;i++){
freeBoosts[i].onchange = onFreeBoostChange;
}
let classBoosts = document.getElementsByClassName('classBoost');
for(let i=0;i<classBoosts.length;i++){
classBoosts[i].onchange = onClassBoostChange;
}
M.AutoInit();
</script>