forked from Doctor-Unspeakable/foundry-pathbuilder2e-import
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpathbuilder-import.js
More file actions
2210 lines (2127 loc) · 75.3 KB
/
pathbuilder-import.js
File metadata and controls
2210 lines (2127 loc) · 75.3 KB
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
var fbpiDebug = false;
const fpbi = "0.10.2";
const reportDomain = "https://www.pf2player.com/";
const pbcolor1 = "color: #7bf542"; //bright green
const pbcolor2 = "color: #d8eb34"; //yellow green
const pbcolor3 = "color: #ffffff"; //white
const pbcolor4 = "color: #cccccc"; //gray
const pbcolor5 = "color: #ff0000"; //red
var applyChanges = false;
var finishedFeats = false;
var finishedActions = false;
var finishedClassFeatures = false;
var finishedAncestryFeatures = false;
var finishedEquipment = false;
var finishedSpells = false;
var addFeats = false;
var addEquipment = false;
var addMoney = false;
var addSpellcasters = false;
var deleteAll = false;
var heroVaultExport = false;
var reportMissedItems = false;
var buildID;
var allItems = [];
var jsonBuild = [];
var addedItems = [];
var pbButton = true;
var pcAlign;
var focusPool=0;
var focusWarning=0;
async function doHVExport(hero, act) {
game.modules.get("herovaultfoundry")?.api?.exportToHVFromPBHLO(hero, act);
return;
}
Hooks.on("herovaultfoundryReady", (api) => {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %cDisabling pathbuilder button since herovault is loaded",
pbcolor1,
pbcolor4
);
pbButton = false;
});
Hooks.on("renderActorSheet", async function (obj, html) {
// Only inject the link if the actor is of type "character" and the user has permission to update it
const actor = obj.actor;
if (!(actor.type === "character")) {
return;
}
if (actor.canUserModify(game.user, "update") == false) {
return;
}
if (pbButton) {
let element = html.find(".window-header .window-title");
if (element.length != 1) return;
let button = $(
`<a class="popout" style><i class="fas fa-book"></i>Import from Pathbuilder 2e</a>`
);
button.on("click", () => beginPathbuilderImport(obj.object));
element.after(button);
}
});
export async function beginPathbuilderImport(targetActor, isHV = false) {
applyChanges = false;
finishedFeats = false;
finishedActions = false;
finishedClassFeatures = false;
finishedAncestryFeatures = false;
finishedEquipment = false;
finishedSpells = false;
allItems = [];
let heroVault = "";
if (isHV)
heroVault =
'<input type="checkbox" id="checkBoxHVExport" name="checkBoxHVExport" ><label for="checkBoxHVExport"> Export this PC to my HeroVau.lt</label><br><br>';
new Dialog({
title: `Pathbuilder Import`,
content: `
<div>
<p><strong>It is strongly advised to import to a blank PC and not overwrite an existing PC.</strong></p>
<hr>
<p>Step 1: Refresh this browser page!</p>
<p>Step 2: Export your character from Pathbuilder 2e via the app menu</p>
<p>Step 3: Enter the 6 digit user ID number from the pathbuilder export dialog below</p>
<br>
<p>Please note - items which cannot be matched to the Foundry database will not be imported!</p>
<p><strong>All inventory items will be removed upon import.</strong> The option to turn this off will return in the future. If you need to keep items, I recommend creating a new PC, importing via Pathbuilder to the new PC, then dragging inventory items from old PC to new PC.</p>
<div>
<hr/>
<form>
<input type="checkbox" id="checkBoxFeats" name="checkBoxFeats" checked>
<label for="checkBoxFeats"> Import Feats and Specials?</label><br><br>
<input type="checkbox" id="checkBoxEquipment" name="checkBoxEquipment" checked>
<label for="checkBoxEquipment"> Import Equipment?</label><br>
<input type="checkbox" id="checkBoxMoney" name="checkBoxMoney" checked>
<label for="checkBoxMoney"> Import Money?</label><br><br>
<!--input type="checkbox" id="checkBoxDeleteAll" name="checkBoxDeleteAll" checked>
< label for="checkBoxDeleteAll"> Delete all existing items before import (including spells)?</label><br><br -->
<input type="checkbox" id="checkBoxSpells" name="checkBoxSpells" checked>
<label for="checkBoxSpells"> Import Spells? (Always deletes existing)</label><br><br>
${heroVault}
</form>
<div id="divCode">
Enter your pathbuilder user ID number<br>
<div id="divOuter">
<div id="divInner">
<input id="textBoxBuildID" type="number" maxlength="6" />
</div>
</div>
</div>
<br><br>
<style>
#textBoxBuildID {
border: 0px;
padding-left: 15px;
letter-spacing: 42px;
background-image: linear-gradient(to left, black 70%, rgba(255, 255, 255, 0) 0%);
background-position: bottom;
background-size: 50px 1px;
background-repeat: repeat-x;
background-position-x: 35px;
width: 330px;
min-width: 330px;
}
#divInner{
left: 0;
position: sticky;
}
#divOuter{
width: 285px;
overflow: hidden;
}
#divCode{
border: 1px solid black;
width: 300px;
margin: 0 auto;
padding: 5px;
}
#checkBoxMoney{
margin-left: 35px;
}
</style>
`,
buttons: {
yes: {
icon: "<i class='fas fa-check'></i>",
label: `Import`,
callback: () => (applyChanges = true),
},
no: {
icon: "<i class='fas fa-times'></i>",
label: `Cancel`,
},
},
default: "yes",
close: (html) => {
if (applyChanges) {
buildID = html.find('[id="textBoxBuildID"]')[0].value;
if (!isNormalInteger(buildID)) {
ui.notifications.warn("Build ID must be a positive integer!");
return;
}
addFeats = html.find('[name="checkBoxFeats"]')[0].checked;
addEquipment = html.find('[name="checkBoxEquipment"]')[0].checked;
addMoney = html.find('[name="checkBoxMoney"]')[0].checked;
addSpellcasters = html.find('[name="checkBoxSpells"]')[0].checked;
//deleteAll = html.find('[name="checkBoxDeleteAll"]')[0].checked;
deleteAll = true;
if (isHV)
heroVaultExport = html.find('[name="checkBoxHVExport"]')[0].checked;
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %cGot heroVaultExport:" + heroVaultExport,
pbcolor1,
pbcolor4
);
fetchPathbuilderBuild(targetActor, buildID);
}
},
}).render(true);
}
function isNormalInteger(str) {
var n = Math.floor(Number(str));
return n !== Infinity && String(n) === str && n >= 0;
}
function fetchPathbuilderBuild(targetActor, buildID) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
let responseJSON = JSON.parse(this.responseText);
if (fbpiDebug) console.log(responseJSON);
if (responseJSON.success) {
jsonBuild = responseJSON.build;
checkCharacterIsCorrect(targetActor, responseJSON.build);
} else {
ui.notifications.warn("Unable to find a character with this build id!");
return;
}
}
};
xmlhttp.open(
"GET",
"https://www.pathbuilder2e.com/json.php?id=" + buildID,
true
);
xmlhttp.send();
}
function checkCharacterIsCorrect(targetActor, jsonBuild) {
let correctCharacter = false;
new Dialog({
title: jsonBuild.name,
content:
`
<div>Importing ` +
jsonBuild.name +
`, level ` +
jsonBuild.level +
`<div><br><br>
`,
buttons: {
yes: {
icon: "<i class='fas fa-check'></i>",
label: `Proceed`,
callback: () => (correctCharacter = true),
},
no: {
icon: "<i class='fas fa-times'></i>",
label: `Cancel`,
},
},
default: "yes",
close: (html) => {
if (correctCharacter) {
ui.notifications.info(
"Please be patient while " + jsonBuild.name + " is imported."
);
ui.notifications.info(
"The import can take up to 1 minute on slower systems."
);
importCharacter(targetActor, jsonBuild);
}
},
}).render(true);
}
function shouldBeManuallyDeleted(i) {
// if (i.type=="ancestry"){
// return false;
// }
if (i.type == "feat") {
if (i.featType.value == "ancestryfeature") {
return false;
}
}
if (i.type == "spell") {
return false;
}
if (i.type == "spellcastingEntry") {
return false;
}
return true;
}
async function importCharacter(targetActor, jsonBuild) {
if (deleteAll) {
// const items = targetActor.items.filter(i => shouldBeManuallyDeleted(i));
// const deletions = items.map(i => i.id);
// console.log(deletions)
// const updated = await targetActor.deleteEmbeddedDocuments("Item", deletions);
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %cDeleting all items",
pbcolor1,
pbcolor4
);
// let deletions = targetActor.items.map((i) => i.id);
// let updated = await targetActor.deleteEmbeddedDocuments("Item", deletions);
let updated = await targetActor.deleteEmbeddedDocuments("Item", ["123"], {
deleteAll: true,
});
} else if (addMoney) {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %cDeleting money",
pbcolor1,
pbcolor4
);
let items = targetActor.items.filter(
(i) =>
i.name === "Platinum Pieces" ||
i.name === "Gold Pieces" ||
i.name === "Silver Pieces" ||
i.name === "Copper Pieces"
);
let deletions = items.map((i) => i.id);
let updated = await targetActor.deleteEmbeddedDocuments("Item", deletions);
}
let arrayFeats = jsonBuild.feats;
let arrayEquipment = jsonBuild.equipment;
let arrayWeapons = jsonBuild.weapons;
let arrayArmor = jsonBuild.armor;
let arraySpecials = jsonBuild.specials;
let arrayLores = jsonBuild.lores;
let specialClassFeatures = [];
const castingArcane = jsonBuild.proficiencies.castingArcane;
const castingDivine = jsonBuild.proficiencies.castingDivine;
const castingOccult = jsonBuild.proficiencies.castingOccult;
const castingPrimal = jsonBuild.proficiencies.castingPrimal;
pcAlign = jsonBuild.alignment;
// lower case languages fix
for (var ref in jsonBuild.languages) {
if (jsonBuild.languages.hasOwnProperty(ref)) {
jsonBuild.languages[ref] = jsonBuild.languages[ref].toLowerCase();
}
}
for (var ref in arrayEquipment) {
arrayEquipment[ref][0] = mapItemToFoundryName(arrayEquipment[ref][0]);
}
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c Working on arraySpecials: " + arraySpecials,
pbcolor1,
pbcolor4
);
for (var ref in arraySpecials) {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c Checking arraySpecials[ref]: " + arraySpecials[ref],
pbcolor1,
pbcolor4
);
if (typeof arraySpecials[ref][0] !== 'undefined')
arraySpecials[ref] = mapSpecialToFoundryName(arraySpecials[ref]);
}
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c Finished arraySpecials: " + arraySpecials,
pbcolor1,
pbcolor4
);
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c Working on arrayFeats: " + arrayFeats,
pbcolor1,
pbcolor4
);
for (var ref in arrayFeats) {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c Checking arrayFeats[ref][0]: " + arrayFeats[ref][0],
pbcolor1,
pbcolor4
);
if (typeof arrayFeats[ref][0] !== 'undefined')
arrayFeats[ref][0] = mapSpecialToFoundryName(arrayFeats[ref][0]);
}
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c Finished arrayFeats: " + arrayFeats,
pbcolor1,
pbcolor4
);
[arraySpecials, arrayFeats, specialClassFeatures] = findSpecialThings(
arraySpecials,
arrayFeats,
specialClassFeatures
);
// senses
var senses = [];
for (var ref in arraySpecials) {
if (arraySpecials.hasOwnProperty(ref)) {
if (arraySpecials[ref] == "Low-Light Vision") {
senses.push({
exceptions: "",
label: "Low-Light Vision",
type: "lowLightVision",
value: "",
});
} else if (arraySpecials[ref] == "Darkvision") {
senses.push({
exceptions: "",
label: "Darkvision",
type: "darkvision",
value: "",
});
/*} else if (arraySpecials[ref]=="Scent") {
senses[1]={
exceptions: '',
label: 'Scent',
type: "scent",
value: ''
} */
}
}
}
let conEven =
(jsonBuild.abilities.con % 2 == 0
? jsonBuild.abilities.con
: jsonBuild.abilities.con - 1) - 10;
let conBonus = 0;
if (conEven > 0) conBonus = conEven / 2;
else conBonus = ((conEven * -1) / 2) * -1;
const currentHP =
jsonBuild.attributes.bonushp +
jsonBuild.attributes.classhp * jsonBuild.level +
jsonBuild.attributes.ancestryhp +
conBonus * jsonBuild.level;
await targetActor.update({
name: jsonBuild.name,
"token.name": jsonBuild.name,
"system.details.level.value": jsonBuild.level,
"system.details.age.value": jsonBuild.age,
"system.details.gender.value": jsonBuild.gender,
"system.details.alignment.value": jsonBuild.alignment,
"system.details.keyability.value": jsonBuild.keyability,
"system.details.deity.value": jsonBuild.deity,
"system.traits.size.value": getSizeValue(jsonBuild.size),
"system.traits.languages.value": jsonBuild.languages,
"system.traits.senses": senses,
"system.abilities.str.value": jsonBuild.abilities.str,
"system.abilities.dex.value": jsonBuild.abilities.dex,
"system.abilities.con.value": jsonBuild.abilities.con,
"system.abilities.int.value": jsonBuild.abilities.int,
"system.abilities.wis.value": jsonBuild.abilities.wis,
"system.abilities.cha.value": jsonBuild.abilities.cha,
"system.saves.fortitude.rank": jsonBuild.proficiencies.fortitude / 2,
"system.saves.reflex.rank": jsonBuild.proficiencies.reflex / 2,
"system.saves.will.rank": jsonBuild.proficiencies.will / 2,
"system.martial.advanced.rank": jsonBuild.proficiencies.advanced / 2,
"system.martial.heavy.rank": jsonBuild.proficiencies.heavy / 2,
"system.martial.light.rank": jsonBuild.proficiencies.light / 2,
"system.martial.medium.rank": jsonBuild.proficiencies.medium / 2,
"system.martial.unarmored.rank": jsonBuild.proficiencies.unarmored / 2,
"system.martial.martial.rank": jsonBuild.proficiencies.martial / 2,
"system.martial.simple.rank": jsonBuild.proficiencies.simple / 2,
"system.martial.unarmed.rank": jsonBuild.proficiencies.unarmed / 2,
"system.skills.acr.rank": jsonBuild.proficiencies.acrobatics / 2,
"system.skills.arc.rank": jsonBuild.proficiencies.arcana / 2,
"system.skills.ath.rank": jsonBuild.proficiencies.athletics / 2,
"system.skills.cra.rank": jsonBuild.proficiencies.crafting / 2,
"system.skills.dec.rank": jsonBuild.proficiencies.deception / 2,
"system.skills.dip.rank": jsonBuild.proficiencies.diplomacy / 2,
"system.skills.itm.rank": jsonBuild.proficiencies.intimidation / 2,
"system.skills.med.rank": jsonBuild.proficiencies.medicine / 2,
"system.skills.nat.rank": jsonBuild.proficiencies.nature / 2,
"system.skills.occ.rank": jsonBuild.proficiencies.occultism / 2,
"system.skills.prf.rank": jsonBuild.proficiencies.performance / 2,
"system.skills.rel.rank": jsonBuild.proficiencies.religion / 2,
"system.skills.soc.rank": jsonBuild.proficiencies.society / 2,
"system.skills.ste.rank": jsonBuild.proficiencies.stealth / 2,
"system.skills.sur.rank": jsonBuild.proficiencies.survival / 2,
"system.skills.thi.rank": jsonBuild.proficiencies.thievery / 2,
"system.attributes.perception.rank": jsonBuild.proficiencies.perception / 2,
"system.attributes.classDC.rank": jsonBuild.proficiencies.classDC / 2,
});
if (
targetActor.background == null ||
targetActor.background.value != jsonBuild.background
) {
/* if (deleteAll) {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %cDeleting background",
pbcolor1,
pbcolor4
);
const items = targetActor.items.filter(
(i) => i.type === "background"
);
const deletions = items.map((i) => i.id);
const updated = await targetActor.deleteEmbeddedDocuments(
"Item",
deletions
); // Deletes multiple EmbeddedEntity objects
} */
if (jsonBuild.background.includes("Scholar (")) {
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(jsonBuild.background);
jsonBuild.background = "Scholar";
arrayFeats.push({ 0: "Assurance", 1: matches[1] });
} else if (jsonBuild.background.includes("Squire (")) {
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(jsonBuild.background);
jsonBuild.background = "Squire";
}
if (!jsonBuild.background.includes("Artisan")) {
let packBackground = await game.packs
.get("pf2e.backgrounds")
.getDocuments();
for (const item of packBackground) {
if (item.slug == getSlug(jsonBuild.background) || item.slug == getSlugNoQuote(jsonBuild.background)) {
allItems.push(item.toObject());
for (const backgroundFeat in item.system.items) {
let newFeat = [
item.system.items[backgroundFeat].name,
null,
"Background Feat",
1,
];
// try to fix this at some point ^
arrayFeats.push(newFeat);
}
}
}
}
}
let classFeatures = [];
// //class
if (targetActor.class != jsonBuild.class) {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %cSetting class to: " + jsonBuild.class,
pbcolor1,
pbcolor4
);
let packClasses = await game.packs.get("pf2e.classes").getDocuments({name: jsonBuild.class});
for (const item of packClasses) {
if (item.slug == getSlug(jsonBuild.class) || item.slug == getSlugNoQuote(jsonBuild.class)) {
await targetActor.createEmbeddedDocuments("Item", [item.toObject()]);
// console.log(item.system.items);
for (const classFeatureItem in item.system.items) {
// console.log("Class feature:");
// console.log(classFeatureItem);
// console.log(
// `jsonBuild.level ${jsonBuild.level} >= classFeatureItem.level ${item.system.items[classFeatureItem].level}? `
// );
if (jsonBuild.level >= item.system.items[classFeatureItem].level) {
let newFeature = {
id: item.system.items[classFeatureItem].id,
pack: item.system.items[classFeatureItem].pack,
name: item.system.items[classFeatureItem].name,
};
classFeatures.push(newFeature);
}
}
}
}
}
// // //ancestry
if (targetActor.ancestry != jsonBuild.ancestry) {
/* if (deleteAll) {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %cdeleting ancestry",
pbcolor1,
pbcolor4
);
const items = targetActor.items.filter((i) => i.type === "ancestry");
const deletions = items.map((i) => i.id);
const updated = await targetActor.deleteEmbeddedDocuments(
"Item",
deletions
); // Deletes multiple EmbeddedEntity objects
} */
let packAncestry = await game.packs.get("pf2e.ancestries").getDocuments();
for (const item of packAncestry) {
if (item.slug == getSlug(jsonBuild.ancestry) || item.slug == getSlugNoQuote(jsonBuild.ancestry)) {
allItems.push(item.toObject());
}
}
}
if (targetActor.heritage !== jsonBuild.heritage) {
let heritage = await game.packs.get('pf2e.heritages')?.getDocuments({name: jsonBuild.heritage})
if (heritage?.length) heritage = heritage[0]
if (heritage) {
allItems.push(heritage.toObject())
addedItems.push(jsonBuild.heritage)
}
}
//clean up some specials that are handled by Foundry:
let blacklist = [
"Great Fortitude",
"Divine Spellcasting",
"Divine Ally (Blade)",
"Divine Ally (Shield)",
"Divine Ally (Steed)",
"Divine Smite (Antipaladin)",
"Divine Smite (Paladin)",
"Divine Smite (Desecrator)",
"Divine Smite (Liberator)",
"Divine Smite (Redeemer)",
"Divine Smite (Tyrant)",
"Exalt (Antipaladin)",
"Exalt (Paladin)",
"Exalt (Desecrator)",
"Exalt (Redeemer)",
"Exalt (Liberator)",
"Exalt (Tyrant)",
"Intimidation",
"Axe",
"Sword",
"Water",
"Sword Cane",
"Battle Axe",
"Bane",
"Air",
"Occultism",
"Performance",
"Alchemy",
"Nature",
"Red",
"Shark",
"Green",
"Divine",
"Sun",
"Fire",
"Might",
"Mace",
"Bronze",
"Spirit",
"Zeal",
"Battledancer",
"Light Armor Expertise",
"Religion",
"Polearm",
"Longsword",
"Moon",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"Hammer",
"Athletics",
"Deception",
"Society",
"Occultism",
"Arcane",
"Simple Weapon Expertise",
"Defensive Robes",
"Magical Fortitude",
"Occult",
"Acrobatics",
"Medicine",
"Diplomacy",
"Might",
"Reflex",
"Evasion",
"Vigilant Senses",
"Iron Will",
"Lightning Reflexes",
"Alertness",
"Shield Block",
"Anathema",
"Druidic Language",
"Weapon Expertise",
"Armor Expertise",
"Armor Mastery",
"Darkvision",
"Stealth",
"Divine",
"Shield",
"Survival",
"Arcana",
"Will",
"Fortitude",
"Signature Spells",
"Low-Light Vision",
"Powerful Fist",
"Mystic Strikes",
"Incredible Movement",
"Claws",
"Wild Empathy",
"Aquatic Adaptation",
"Resolve",
"Expert Spellcaster",
"Master Spellcaster",
"Legendary Spellcaster",
"Weapon Specialization",
"Mighty Rage",
"Deny Advantage",
"Critical Brutality",
"Juggernaut",
"Medium Armor Expertise",
"Weapon Specialization (Barbarian)",
"Greater Weapon Specialization",
"Diplomacy",
"Improved Evasion",
"Weapon Mastery",
"Incredible Senses",
];
for (const cf in classFeatures) {
blacklist.push(classFeatures[cf].name);
}
arraySpecials = arraySpecials.filter((val) => !blacklist.includes(val));
jsonBuild.specials = uniq(arraySpecials);
if (addFeats) {
finishedAncestryFeatures = true;
finishedClassFeatures = true;
// console.log("%cPathbuilder2e Import | %cdoing feat items",pbcolor1,pbcolor4)
await addFeatItems(targetActor, arrayFeats);
// console.log("%cPathbuilder2e Import | %cdoing feat items on specials",pbcolor1,pbcolor4)
await addFeatItems(targetActor, arraySpecials);
// console.log("%cPathbuilder2e Import | %cdoing AncestryFeaturefeat items on feats",pbcolor1,pbcolor4)
// addAncestryFeatureFeatItems(targetActor, arrayFeats);
// console.log("%cPathbuilder2e Import | %cdoing AncestryFeaturefeat items on specials",pbcolor1,pbcolor4)
// addAncestryFeatureFeatItems(targetActor, arraySpecials);
// console.log("%cPathbuilder2e Import | %cdoing action items",pbcolor1,pbcolor4)
await addActionItems(targetActor, arraySpecials);
await addAncestryFeatureItems(targetActor, arraySpecials);
await addClassFeatureItems(targetActor, arraySpecials, specialClassFeatures, classFeatures);
} else {
finishedFeats = true;
finishedAncestryFeatures = true;
finishedActions = true;
finishedClassFeatures = true;
checkAllFinishedAndCreate(targetActor);
}
blacklist = ["Bracers of Armor", "", "", "", "", ""];
for (const cf in allItems) {
blacklist.push(allItems[cf].name);
}
// const uniqueItems = Array.from(new Set(allItems.map(a => a._id))).map(id=>{return allItems.find(a=>a._id==id)})
const uniqueItems = allItems.filter(function (a) {
return !this[a._id] && (this[a._id] = true);
}, Object.create(null));
allItems = uniqueItems;
if (addEquipment) {
let pack = game.packs.get("pf2e.equipment-srd");
let content = await game.packs.get("pf2e.equipment-srd").getDocuments();
let backpackData = await pack.getDocuments({name: "Backpack"});
let backpackInstance = {};
let arrayKit = [];
if (hasAdventurersPack(arrayEquipment)) {
// adventurers kit hack since pathbuilder allows unexploded kits and foundry doesn't
backpackInstance = await targetActor.createEmbeddedDocuments(
"Item",
backpackData
);
backpackInstance = backpackInstance?.length ? backpackInstance[0] : backpackInstance
arrayKit.push(["bedroll", 1]);
arrayKit.push(["chalk", 10]);
arrayKit.push(["flint-and-steel", 1]);
arrayKit.push(["rope", 1]);
arrayKit.push(["rations", 14]);
arrayKit.push(["torch", 5]);
arrayKit.push(["waterskin", 1]);
}
// CURRENTLY DISABLED AS THE PATHFINDER MODULE NOW AUTOMATICALLY ADDS SPECIFIC WEAPON PROFICIENCIES
// specific proficiencies
// let specificTrained = jsonBuild.specificProficiencies.trained;
// let specificExpert = jsonBuild.specificProficiencies.expert;
// let specificMaster = jsonBuild.specificProficiencies.master;
// let specificLegendary = jsonBuild.specificProficiencies.legendary;
// let specificTrainedInstance =[];
// let specificExpertInstance =[];
// let specificMasterInstance =[];
// let specificLegendaryInstance =[];
// if (specificTrained.length>0 && needsNewInstanceofItem(targetActor, 'Specific Trained' )){
// specificTrainedInstance = await targetActor.createEmbeddedDocuments('Item', {
// name: 'Specific Trained',
// type: 'martial',
// data: { proficient: { value: 1 }}
// });
// }
// if (specificExpert.length>0 && needsNewInstanceofItem(targetActor, 'Specific Expert' )){
// specificExpertInstance = await targetActor.createEmbeddedDocuments('Item', {
// name: 'Specific Expert',
// type: 'martial',
// data: { proficient: { value: 2 }}
// });
// }
// if (specificMaster.length>0 && needsNewInstanceofItem(targetActor, 'Specific Master' )){
// specificMasterInstance = await targetActor.createEmbeddedDocuments('Item', {
// name: 'Specific Master',
// type: 'martial',
// data: { proficient: { value: 3 }}
// });
// }
// if (specificLegendary.length>0 && needsNewInstanceofItem(targetActor, 'Specific Legendary' )){
// specificLegendaryInstance = await targetActor.createEmbeddedDocuments('Item', {
// name: 'Specific Legendary',
// type: 'martial',
// data: { proficient: { value: 4 }}
// });
// }
for (const action of content.filter((item) =>
equipmentIsRequired(
item,
arrayEquipment,
arrayWeapons,
arrayArmor,
arrayKit,
addMoney
)
)) {
for (var ref in arrayEquipment) {
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c arrayEquipment[ref]: " + arrayEquipment[ref],
pbcolor1,
pbcolor4
);
if (arrayEquipment.hasOwnProperty(ref)) {
var itemName = arrayEquipment[ref][0];
// console.log(itemName)
if (
isNameMatch(itemName, action.slug) &&
needsNewInstanceofItem(targetActor, arrayEquipment[ref][0])
) {
var itemAmount = arrayEquipment[ref][1];
arrayEquipment[ref].added = true;
const clonedData = action.clone().toObject();
if (clonedData.type != "kit") {
clonedData.system.quantity = itemAmount;
allItems.push(clonedData);
}
}
}
}
for (var ref in arrayKit) {
if (arrayKit.hasOwnProperty(ref)) {
var itemSlug = arrayKit[ref][0];
if (
itemSlug === action.slug &&
needsNewInstanceofItem(targetActor, itemName)
) {
var itemAmount = arrayKit[ref][1];
const clonedData = action.clone().toObject();
clonedData.system.quantity = itemAmount;
clonedData.system.containerId = backpackInstance?.id;
allItems.push(clonedData);
}
}
}
for (var ref in arrayWeapons) {
if (arrayWeapons.hasOwnProperty(ref)) {
var weaponDetails = arrayWeapons[ref];
// console.log(weaponDetails.name);
if (
isNameMatch(weaponDetails.name, action.slug) &&
needsNewInstanceofItem(targetActor, weaponDetails.name)
) {
weaponDetails.added = true;
const clonedData = action.clone().toObject();
clonedData.system.quantity = weaponDetails.qty;
// if (specificTrained.includes(weaponDetails.name)){
// clonedData.weaponType.value = specificTrainedInstance.id;
// } else if (specificExpert.includes(weaponDetails.name)){
// clonedData.weaponType.value = specificExpertInstance.id;
// } else if (specificMaster.includes(weaponDetails.name)){
// clonedData.weaponType.value = specificMasterInstance.id;
// } else if (specificLegendary.includes(weaponDetails.name)){
// clonedData.weaponType.value = specificLegendaryInstance.id;
// } else {
// clonedData.weaponType.value = weaponDetails.prof;
// }
clonedData.system.damage.die = weaponDetails.die;
clonedData.system.potencyRune.value = weaponDetails.pot;
clonedData.system.strikingRune.value = weaponDetails.str;
if (weaponDetails.runes[0]) {
clonedData.system.propertyRune1.value = camelCase(
weaponDetails.runes[0]
);
}
if (weaponDetails.runes[1]) {
clonedData.system.propertyRune2.value = camelCase(
weaponDetails.runes[1]
);
}
if (weaponDetails.runes[2]) {
clonedData.system.propertyRune3.value = camelCase(
weaponDetails.runes[2]
);
}
if (weaponDetails.runes[3]) {
clonedData.system.propertyRune4.value = camelCase(
weaponDetails.runes[3]
);
}
if (weaponDetails.mat) {
let material = weaponDetails.mat.split(" (")[0];
clonedData.system.preciousMaterial.value = camelCase(material);
clonedData.system.preciousMaterialGrade.value = getMaterialGrade(
weaponDetails.mat
);
}
if (weaponDetails.display) {
// console.log("%cPathbuilder2e Import | %cdisplay name: "+weaponDetails.display,pbcolor1,pbcolor4)
clonedData.name = weaponDetails.display;
}
allItems.push(clonedData);
}
}
}
for (var ref in arrayArmor) {
if (arrayArmor.hasOwnProperty(ref)) {
var armorDetails = arrayArmor[ref];
if (fbpiDebug)
console.log(
"%cPathbuilder2e Import | %c armorDetails.name: " + armorDetails.name,
pbcolor1,
pbcolor4
);
if (
isNameMatch(armorDetails.name, action.slug) &&
needsNewInstanceofItem(targetActor, armorDetails.name)
) {
armorDetails.added = true;
const clonedData = action.clone().toObject();
if (notBracersOfArmor(armorDetails.name)) {
clonedData.system.quantity = armorDetails.qty;
clonedData.system.category = armorDetails.prof;
clonedData.system.potencyRune.value = armorDetails.pot;
clonedData.system.resiliencyRune.value = armorDetails.res;
// this will also catch the nulls from early json data which did not have this value
if (armorDetails.worn) {
clonedData.system.equipped.value = true;
} else {
clonedData.system.equipped.value = false;
}
if (armorDetails.runes[0]) {
clonedData.system.propertyRune1.value = camelCase(
armorDetails.runes[0]
);
}
if (armorDetails.runes[1]) {
clonedData.system.propertyRune2.value = camelCase(
armorDetails.runes[1]
);
}
if (armorDetails.runes[2]) {
clonedData.system.propertyRune3.value = camelCase(
armorDetails.runes[2]
);
}
if (armorDetails.runes[3]) {
clonedData.system.propertyRune4.value = camelCase(
armorDetails.runes[3]
);
}
if (armorDetails.mat) {
let material = armorDetails.mat.split(" (")[0];
clonedData.system.preciousMaterial.value = camelCase(material);
clonedData.system.preciousMaterialGrade.value = getMaterialGrade(
armorDetails.mat
);
}
if (armorDetails.display) {
clonedData.name = armorDetails.display;
}
}
allItems.push(clonedData);
}
}
}
if (addMoney) {
if (action.slug === "platinum-pieces") {
const clonedData = JSON.parse(JSON.stringify(action));
clonedData.system.quantity = jsonBuild.money.pp;
allItems.push(clonedData);
} else if (action.slug === "gold-pieces") {
const clonedData = JSON.parse(JSON.stringify(action));
clonedData.system.quantity = jsonBuild.money.gp;