- `,buttons:{yes:{icon:"
",label:`Proceed`,callback:()=>correctCharacter=true},no:{icon:"
",label:`Cancel`},},default:"yes",close:html=>{if(correctCharacter){ui.notifications.info("Please be patient while "+jsonBuild.name+" is imported.");importCharacter(targetActor,jsonBuild);}}}).render(true);}
-function shouldBeManuallyDeleted(i){if(i.data.type=="feat"){if(i.data.data.featType.value=="ancestryfeature"){return false;}}
-if(i.data.type=="spell"){return false;}
-if(i.data.type=="spellcastingEntry"){return false;}
-return true;}
-async function importCharacter(targetActor,jsonBuild){if(deleteAll){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cDeleting all items",pbcolor1,pbcolor4)
-let deletions=targetActor.data.items.map(i=>i.id);let updated=await targetActor.deleteEmbeddedDocuments("Item",deletions);}else if(addMoney){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cDeleting money",pbcolor1,pbcolor4)
-let items=targetActor.data.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;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]);}
-for(var ref in arraySpecials){arraySpecials[ref]=mapSpecialToFoundryName(arraySpecials[ref]);}
-for(var ref in arrayFeats){arrayFeats[ref][0]=mapSpecialToFoundryName(arrayFeats[ref][0]);}
-var senses=[];for(var ref in arraySpecials){if(arraySpecials.hasOwnProperty(ref)){if(arraySpecials[ref]=="Low-Light Vision"){senses[0]={exceptions:'',label:'Low-Light Vision',type:"lowLightVision",value:''}}else if(arraySpecials[ref]=="Darkvision"){senses[1]={exceptions:'',label:'Darkvision',type:"darkvision",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);targetActor.update({'name':jsonBuild.name,'data.details.level.value':jsonBuild.level,'data.details.heritage.value':jsonBuild.heritage,'data.details.age.value':jsonBuild.age,'data.details.gender.value':jsonBuild.gender,'data.details.keyability.value':jsonBuild.keyability,'data.traits.size.value':getSizeValue(jsonBuild.size),'data.traits.languages.value':jsonBuild.languages,'data.traits.senses':senses,'data.abilities.str.value':jsonBuild.abilities.str,'data.abilities.dex.value':jsonBuild.abilities.dex,'data.abilities.con.value':jsonBuild.abilities.con,'data.abilities.int.value':jsonBuild.abilities.int,'data.abilities.wis.value':jsonBuild.abilities.wis,'data.abilities.cha.value':jsonBuild.abilities.cha,'data.attributes.ancestryhp':jsonBuild.attributes.ancestryhp,'data.attributes.classhp':jsonBuild.attributes.classhp,'data.attributes.speed.value':jsonBuild.attributes.speed,'data.attributes.flatbonushp':jsonBuild.attributes.bonushp,'data.attributes.hp.value':currentHP,'data.saves.fortitude.rank':jsonBuild.proficiencies.fortitude/2,'data.saves.reflex.rank':jsonBuild.proficiencies.reflex/2,'data.saves.will.rank':jsonBuild.proficiencies.will/2,'data.martial.advanced.rank':jsonBuild.proficiencies.advanced/2,'data.martial.heavy.rank':jsonBuild.proficiencies.heavy/2,'data.martial.light.rank':jsonBuild.proficiencies.light/2,'data.martial.medium.rank':jsonBuild.proficiencies.medium/2,'data.martial.unarmored.rank':jsonBuild.proficiencies.unarmored/2,'data.martial.martial.rank':jsonBuild.proficiencies.martial/2,'data.martial.simple.rank':jsonBuild.proficiencies.simple/2,'data.martial.unarmed.rank':jsonBuild.proficiencies.unarmed/2,'data.skills.acr.rank':jsonBuild.proficiencies.acrobatics/2,'data.skills.arc.rank':jsonBuild.proficiencies.arcana/2,'data.skills.ath.rank':jsonBuild.proficiencies.athletics/2,'data.skills.cra.rank':jsonBuild.proficiencies.crafting/2,'data.skills.dec.rank':jsonBuild.proficiencies.deception/2,'data.skills.dip.rank':jsonBuild.proficiencies.diplomacy/2,'data.skills.itm.rank':jsonBuild.proficiencies.intimidation/2,'data.skills.med.rank':jsonBuild.proficiencies.medicine/2,'data.skills.nat.rank':jsonBuild.proficiencies.nature/2,'data.skills.occ.rank':jsonBuild.proficiencies.occultism/2,'data.skills.prf.rank':jsonBuild.proficiencies.performance/2,'data.skills.rel.rank':jsonBuild.proficiencies.religion/2,'data.skills.soc.rank':jsonBuild.proficiencies.society/2,'data.skills.ste.rank':jsonBuild.proficiencies.stealth/2,'data.skills.sur.rank':jsonBuild.proficiencies.survival/2,'data.skills.thi.rank':jsonBuild.proficiencies.thievery/2,'data.attributes.perception.rank':jsonBuild.proficiencies.perception/2,'data.attributes.classDC.rank':jsonBuild.proficiencies.classDC/2});if(targetActor.data.data.details.background==null||targetActor.data.data.details.background.value!=jsonBuild.background){if(deleteAll){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cDeleting background",pbcolor1,pbcolor4);const items=targetActor.data.items.filter(i=>i.type==="background");const deletions=items.map(i=>i.id);const updated=await targetActor.deleteEmbeddedDocuments("Item",deletions);}
-let packBackground=await game.packs.get('pf2e.backgrounds').getDocuments();for(const item of packBackground){if(item.data.data.slug==getSlug(jsonBuild.background)){allItems.push(item.data);}}}
-if(targetActor.data.data.details.ancestry!=jsonBuild.ancestry){if(deleteAll){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cdeleting ancestry",pbcolor1,pbcolor4);const items=targetActor.data.items.filter(i=>i.type==="ancestry");const deletions=items.map(i=>i.id);const updated=await targetActor.deleteEmbeddedDocuments("Item",deletions);}
-let packAncestry=await game.packs.get('pf2e.ancestries').getDocuments();for(const item of packAncestry){if(item.data.data.slug==getSlug(jsonBuild.ancestry)){allItems.push(item.data);}}}
-if(targetActor.data.data.details.class!=jsonBuild.class){if(deleteAll){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cDeleting class",pbcolor1,pbcolor4)
-const items=targetActor.data.items.filter(i=>i.type==="class");const deletions=items.map(i=>i.id);const updated=await targetActor.deleteEmbeddedDocuments("Item",deletions);}
-let packClasses=await game.packs.get('pf2e.classes').getDocuments();for(const item of packClasses){if(item.data.data.slug==getSlug(jsonBuild.class)){allItems.push(item.data);}}}
-const blacklist=[jsonBuild.heritage,"Great Fortitude","Intimidation","Axe","Lightning Reflexes","Alertness","Shield Block","Anathema","Druidic Language","Darkvision","Stealth","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"];arraySpecials=arraySpecials.filter(val=>!blacklist.includes(val));jsonBuild.specials=arraySpecials;if(addFeats){finishedAncestryFeatures=true;finishedClassFeatures=true;addFeatItems(targetActor,arrayFeats);addFeatItems(targetActor,arraySpecials);addActionItems(targetActor,arraySpecials);addAncestryFeatureItems(targetActor,arraySpecials);addClassFeatureItems(targetActor,arraySpecials);}else{finishedFeats=true;finishedAncestryFeatures=true;finishedActions=true;finishedClassFeatures=true;checkAllFinishedAndCreate(targetActor);}
-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('3lgwjrFEsQVKzhh7');let backpackInstance=[];let arrayKit=[];if(hasAdventurersPack(arrayEquipment)){backpackInstance=await targetActor.createEmbeddedDocuments("Item",backpackData);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]);}
-for(const action of content.filter(item=>equipmentIsRequired(item,arrayEquipment,arrayWeapons,arrayArmor,arrayKit,addMoney))){for(var ref in arrayEquipment){if(arrayEquipment.hasOwnProperty(ref)){var itemName=arrayEquipment[ref][0];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofItem(targetActor,arrayEquipment[ref][0])){var itemAmount=arrayEquipment[ref][1];arrayEquipment[ref].added=true;const clonedData=JSON.parse(JSON.stringify(action.data));if(clonedData.type!="kit"){clonedData.data.quantity.value=itemAmount;allItems.push(clonedData);}}}}
-for(var ref in arrayKit){if(arrayKit.hasOwnProperty(ref)){var itemSlug=arrayKit[ref][0];if(itemSlug===action.data.data.slug&&needsNewInstanceofItem(targetActor,itemName)){var itemAmount=arrayKit[ref][1];const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=itemAmount;clonedData.data.containerId.value=backpackInstance.id;allItems.push(clonedData);}}}
-for(var ref in arrayWeapons){if(arrayWeapons.hasOwnProperty(ref)){var weaponDetails=arrayWeapons[ref];if(isNameMatch(weaponDetails.name,action.data.data.slug)&&needsNewInstanceofItem(targetActor,weaponDetails.name)){weaponDetails.added=true;const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=weaponDetails.qty;clonedData.data.damage.die=weaponDetails.die;clonedData.data.potencyRune.value=weaponDetails.pot;clonedData.data.strikingRune.value=weaponDetails.str;if(weaponDetails.runes[0]){clonedData.data.propertyRune1.value=camelCase(weaponDetails.runes[0]);}
-if(weaponDetails.runes[1]){clonedData.data.propertyRune2.value=camelCase(weaponDetails.runes[1]);}
-if(weaponDetails.runes[2]){clonedData.data.propertyRune3.value=camelCase(weaponDetails.runes[2]);}
-if(weaponDetails.runes[3]){clonedData.data.propertyRune4.value=camelCase(weaponDetails.runes[3]);}
-if(weaponDetails.mat){let material=weaponDetails.mat.split(" (")[0];clonedData.data.preciousMaterial.value=camelCase(material);clonedData.data.preciousMaterialGrade.value=getMaterialGrade(weaponDetails.mat);}
-if(weaponDetails.display){clonedData.name=weaponDetails.display;}
-allItems.push(clonedData);}}}
-for(var ref in arrayArmor){if(arrayArmor.hasOwnProperty(ref)){var armorDetails=arrayArmor[ref];if(isNameMatch(armorDetails.name,action.data.data.slug)&&needsNewInstanceofItem(targetActor,armorDetails.name)){armorDetails.added=true;const clonedData=JSON.parse(JSON.stringify(action.data));if(notBracersOfArmor(armorDetails.name)){clonedData.data.quantity.value=armorDetails.qty;clonedData.data.armorType.value=armorDetails.prof;clonedData.data.potencyRune.value=armorDetails.pot.toString();clonedData.data.resiliencyRune.value=armorDetails.res;if(armorDetails.worn){clonedData.data.equipped.value=true;}else{clonedData.data.equipped.value=false;}
-if(armorDetails.runes[0]){clonedData.data.propertyRune1.value=camelCase(armorDetails.runes[0]);}
-if(armorDetails.runes[1]){clonedData.data.propertyRune2.value=camelCase(armorDetails.runes[1]);}
-if(armorDetails.runes[2]){clonedData.data.propertyRune3.value=camelCase(armorDetails.runes[2]);}
-if(armorDetails.runes[3]){clonedData.data.propertyRune4.value=camelCase(armorDetails.runes[3]);}
-if(armorDetails.mat){let material=armorDetails.mat.split(" (")[0];clonedData.data.preciousMaterial.value=camelCase(material);clonedData.data.preciousMaterialGrade.value=getMaterialGrade(armorDetails.mat);}
-if(armorDetails.display){clonedData.name=armorDetails.display;}}
-allItems.push(clonedData);}}}
-if(addMoney){if(action.data.data.slug==='platinum-pieces'){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.pp;allItems.push(clonedData);}else if(action.data.data.slug==='gold-pieces'){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.gp;allItems.push(clonedData);}else if(action.data.data.slug==='silver-pieces'){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.sp;allItems.push(clonedData);}else if(action.data.data.slug==='copper-pieces'){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.cp;allItems.push(clonedData);}}}
-finishedEquipment=true;checkAllFinishedAndCreate(targetActor);}else{finishedEquipment=true;checkAllFinishedAndCreate(targetActor);}
-if(addSpellcasters){setSpellcasters(targetActor,jsonBuild.spellCasters,deleteAll);}else{finishedSpells=true;checkAllFinishedAndCreate(targetActor);}
-addLores(targetActor,arrayLores);}
-function getExistingAncestrySlug(targetActor){for(var ref in targetActor.data.items){if(targetActor.data.items.hasOwnProperty(ref)){let item=targetActor.data.items[ref];if(item.type=="ancestry"){return item.data.slug;}}}
-return null;}
-function notBracersOfArmor(name){return!name.toLowerCase().includes("bracers of armor");}
-function camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index)
-{return index==0?word.toLowerCase():word.toUpperCase();}).replace(/\s+/g,'');}
-function getMaterialGrade(material){if(material.toLowerCase().includes("high-grade")){return"high";}else if(material.toLowerCase().includes("standard-grade")){return"standard";}
-return"low";}
-async function addFeatItems(targetActor,arrayFeats){var usedLocations=[];let content=await game.packs.get('pf2e.feats-srd').getDocuments();for(const action of content.filter(item=>featIsRequired(item,arrayFeats))){for(var ref in arrayFeats){if(arrayFeats.hasOwnProperty(ref)){let pathbuilderFeatItem=arrayFeats[ref];var itemName=pathbuilderFeatItem[0];var itemExtra=pathbuilderFeatItem[1];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofFeat(targetActor,itemName,itemExtra)){var displayName=itemName;addedItems.push(itemName);if(itemExtra!=null){displayName+=" ("+itemExtra+")";}
-const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.name=displayName;try{if(pathbuilderFeatItem[2]&&pathbuilderFeatItem[3]){let location=getFoundryFeatLocation(pathbuilderFeatItem[2],pathbuilderFeatItem[3]);if(!usedLocations.includes(location)){clonedData.data.location=location;usedLocations.push(location);}}}catch(err){console.log(err);}
-allItems.push(clonedData);}}}}
-content=await game.packs.get('pf2e.ancestryfeatures').getDocuments();for(const action of content.filter(item=>featIsRequired(item,arrayFeats))){for(var ref in arrayFeats){if(arrayFeats.hasOwnProperty(ref)){let pathbuilderFeatItem=arrayFeats[ref];var itemName=pathbuilderFeatItem[0];var itemExtra=pathbuilderFeatItem[1];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofFeat(targetActor,itemName,itemExtra)){var displayName=itemName;addedItems.push(itemName);if(itemExtra!=null){displayName+=" ("+itemExtra+")";}
-const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.name=displayName;try{if(pathbuilderFeatItem[2]&&pathbuilderFeatItem[3]){let location=getFoundryFeatLocation(pathbuilderFeatItem[2],pathbuilderFeatItem[3]);if(!usedLocations.includes(location)){clonedData.data.location=location;usedLocations.push(location);}}}catch(err){console.log(err);}
-allItems.push(clonedData);}}}}
-finishedFeats=true;checkAllFinishedAndCreate(targetActor);}
-function isNameMatch(pathbuilderItemName,foundryItemSlug){if(getSlug(pathbuilderItemName)==foundryItemSlug)return true;if(getSlugNoQuote(pathbuilderItemName)==foundryItemSlug)return true;if(getSlug(getClassAdjustedSpecialNameLowerCase(pathbuilderItemName))==foundryItemSlug)return true;if(getSlug(getAncestryAdjustedSpecialNameLowerCase(pathbuilderItemName))==foundryItemSlug)return true;if(getSlug(getHeritageAdjustedSpecialNameLowerCase(pathbuilderItemName))==foundryItemSlug)return true;return false;}
-async function addActionItems(targetActor,arraySpecials){let content=await game.packs.get('pf2e.actionspf2e').getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials))){for(var ref in arraySpecials){if(arraySpecials.hasOwnProperty(ref)){var itemName=arraySpecials[ref];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)){addedItems.push(itemName);allItems.push(action.data);}}}}
-finishedActions=true;checkAllFinishedAndCreate(targetActor);}
-async function addAncestryFeatureItems(targetActor,arraySpecials){let content=await game.packs.get('pf2e.ancestryfeatures').getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials))){for(var ref in arraySpecials){if(arraySpecials.hasOwnProperty(ref)){var itemName=arraySpecials[ref];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)){addedItems.push(itemName);allItems.push(action.data);}}}}
-finishedAncestryFeatures=true;checkAllFinishedAndCreate(targetActor);}
-async function addAncestryFeatureFeatItems(targetActor,arraySpecials){let content=await game.packs.get('pf2e.ancestryfeatures').getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials))){for(var ref in arraySpecials){if(arraySpecials.hasOwnProperty(ref)){var itemName=arraySpecials[ref];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)){addedItems.push(itemName);allItems.push(action.data);}}}}
-finishedAncestryFeatureFeats=true;checkAllFinishedAndCreate(targetActor);}
-async function addClassFeatureItems(targetActor,arraySpecials){let content=await game.packs.get('pf2e.classfeatures').getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials))){for(var ref in arraySpecials){if(arraySpecials.hasOwnProperty(ref)){var itemName=arraySpecials[ref];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)){addedItems.push(itemName);allItems.push(action.data);}}}}
-finishedClassFeatures=true;checkAllFinishedAndCreate(targetActor);}
-function hasAdventurersPack(arrayEquipment){for(var ref in arrayEquipment){if(arrayEquipment.hasOwnProperty(ref)){var itemName=arrayEquipment[ref][0];if(itemName==="Adventurer's Pack"){arrayEquipment[ref].added=true;return true;}}}
-return false;}
-function isSpecialsPack(packName){return packName==='actionspf2e'||packName==='ancestryfeatures'||packName==='classfeatures';}
-function featIsRequired(item,arrayFeats){for(var featDetails in arrayFeats){if(arrayFeats.hasOwnProperty(featDetails)){if(getSlug(arrayFeats[featDetails][0])==item.data.data.slug)return true;if(getSlugNoQuote(arrayFeats[featDetails][0])==item.data.data.slug)return true;if(getSlug(getClassAdjustedSpecialNameLowerCase(arrayFeats[featDetails][0]))==item.data.data.slug)return true;if(getSlug(getAncestryAdjustedSpecialNameLowerCase(arrayFeats[featDetails][0]))==item.data.data.slug)return true;if(getSlug(getHeritageAdjustedSpecialNameLowerCase(arrayFeats[featDetails][0]))==item.data.data.slug)return true;}}
-return false;}
-function specialIsRequired(item,arraySpecials){for(var ref in arraySpecials){if(arraySpecials.hasOwnProperty(ref)){if(getSlug(arraySpecials[ref])==item.data.data.slug)return true;if(getSlug(getClassAdjustedSpecialNameLowerCase(arraySpecials[ref]))==item.data.data.slug)return true;if(getSlug(getAncestryAdjustedSpecialNameLowerCase(arraySpecials[ref]))==item.data.data.slug)return true;if(getSlug(getHeritageAdjustedSpecialNameLowerCase(arraySpecials[ref]))==item.data.data.slug)return true;}}
-return false;}
-function equipmentIsRequired(item,arrayEquipment,arrayWeapons,arrayArmor,arrayKit,addMoney){for(var ref in arrayEquipment){if(arrayEquipment.hasOwnProperty(ref)){if(getSlug(arrayEquipment[ref][0])===item.data.data.slug)return true;if(getSlugNoQuote(arrayEquipment[ref][0])===item.data.data.slug)return true;}}
-for(var ref in arrayWeapons){if(arrayWeapons.hasOwnProperty(ref)){if(getSlug(arrayWeapons[ref].name)===item.data.data.slug)return true;if(getSlugNoQuote(arrayWeapons[ref].name)===item.data.data.slug)return true;}}
-for(var ref in arrayArmor){if(arrayArmor.hasOwnProperty(ref)){if(getSlug(arrayArmor[ref].name)===item.data.data.slug)return true;if(getSlugNoQuote(arrayArmor[ref].name)===item.data.data.slug)return true;}}
-for(var ref in arrayKit){if(arrayKit.hasOwnProperty(ref)){if(arrayKit[ref][0]===item.data.data.slug)return true;}}
-if(addMoney&&(item.data.data.slug==="platinum-pieces"||item.data.data.slug==="gold-pieces"||item.data.data.slug==="silver-pieces"||item.data.data.slug==="copper-pieces")){return true;}
-return false;}
-function getClassAdjustedSpecialNameLowerCase(specialName){var name=specialName+" ("+jsonBuild.class+")";return name.toLowerCase();}
-function getAncestryAdjustedSpecialNameLowerCase(specialName){var name=specialName+" ("+jsonBuild.ancestry+")";return name.toLowerCase();}
-function getHeritageAdjustedSpecialNameLowerCase(specialName){var name=specialName+" ("+jsonBuild.heritage+")";return name.toLowerCase();}
-function needsNewInstanceofFeat(targetActor,itemName,itemExtra){for(const existingItem of targetActor.data.items){var displayName=itemName;if(itemExtra!=null)displayName+=" ("+itemExtra+")";if(existingItem.data.name===displayName)return false;}
-return true;}
-function needsNewInstanceofItem(targetActor,itemName){for(var ref in targetActor.data.items){if(targetActor.data.items.hasOwnProperty(ref)){if(targetActor.data.items[ref].name===itemName)return false;}}
-return true;}
-function getSizeValue(size){switch(size){case 0:return"tiny";case 1:return"sm";case 3:return"lg";}
-return"med";}
-async function setSpellcasters(targetActor,arraySpellcasters,deleteAll){if(deleteAll){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cDeleting all spells",pbcolor1,pbcolor4)
-let items=targetActor.data.items.filter(i=>i.type==="spellcastingEntry");let deletions=items.map(i=>i.id);let updated=await targetActor.deleteEmbeddedDocuments("Item",deletions);}
-let requiredSpells=[];for(var ref in arraySpellcasters){if(arraySpellcasters.hasOwnProperty(ref)){let spellCaster=arraySpellcasters[ref];spellCaster.instance=await addSpecificCasterAndSpells(targetActor,spellCaster,spellCaster.magicTradition,spellCaster.spellcastingType);for(var ref in spellCaster.spells){if(spellCaster.spells.hasOwnProperty(ref)){let spellListObject=spellCaster.spells[ref];requiredSpells=requiredSpells.concat(spellListObject.list);}}}}
-game.packs.filter(pack=>pack.metadata.name==='spells-srd').forEach(async(pack)=>{const content=await pack.getDocuments();for(const action of content.filter(item=>spellIsRequired(item,requiredSpells))){arraySpellcasters.forEach(spellCaster=>{for(var ref in spellCaster.spells){if(spellCaster.spells.hasOwnProperty(ref)){let spellListObject=spellCaster.spells[ref];for(var ref in spellListObject.list){if(spellListObject.list.hasOwnProperty(ref)){if(getSlug(spellListObject.list[ref])==action.data.data.slug){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.location.value=spellCaster.instance[0].id;clonedData.data.level.value=spellListObject.spellLevel;allItems.push(clonedData);break;}}}}}});}
-finishedSpells=true;checkAllFinishedAndCreate(targetActor);});}
-function spellIsRequired(item,arraySpells){for(var ref in arraySpells){if(arraySpells.hasOwnProperty(ref)){if(getSlug(arraySpells[ref])==item.data.data.slug)return true;}}
-return false;}
-async function addSpecificCasterAndSpells(targetActor,spellCaster,magicTradition,spellcastingType){const spellcastingEntity={ability:{type:'String',label:'Spellcasting Ability',value:spellCaster.ability,},focus:{pool:spellCaster.focusPoints,},proficiency:{value:spellCaster.proficiency/2,},spelldc:{type:'String',label:'Class DC',item:0,},tradition:{type:'String',label:'Magic Tradition',value:magicTradition,},prepared:{type:'String',label:'Spellcasting Type',value:spellcastingType,},slots:{slot0:{max:spellCaster.perDay[0],prepared:[],value:spellCaster.perDay[0]},slot1:{max:spellCaster.perDay[1],prepared:[],value:spellCaster.perDay[1]},slot2:{max:spellCaster.perDay[2],prepared:[],value:spellCaster.perDay[2]},slot3:{max:spellCaster.perDay[3],prepared:[],value:spellCaster.perDay[3]},slot4:{max:spellCaster.perDay[4],prepared:[],value:spellCaster.perDay[4]},slot5:{max:spellCaster.perDay[5],prepared:[],value:spellCaster.perDay[5],},slot6:{max:spellCaster.perDay[6],prepared:[],value:spellCaster.perDay[6],},slot7:{max:spellCaster.perDay[7],prepared:[],value:spellCaster.perDay[7],},slot8:{max:spellCaster.perDay[8],prepared:[],value:spellCaster.perDay[8],},slot9:{max:spellCaster.perDay[9],prepared:[],value:spellCaster.perDay[9],},slot10:{max:spellCaster.perDay[10],prepared:[],value:spellCaster.perDay[10],},},showUnpreparedSpells:{value:true}};var fake=[];const data={name:spellCaster.name,type:'spellcastingEntry',data:spellcastingEntity};fake.push(data);let spellCasterInstance=await targetActor.createEmbeddedDocuments('Item',fake);if(fbpiDebug)
-console.log(spellCasterInstance);return spellCasterInstance;}
-async function addLores(targetActor,arrayLores){const arrayLoreData=[];for(var ref in arrayLores){if(arrayLores.hasOwnProperty(ref)){let loreName=arrayLores[ref][0];let loreProf=arrayLores[ref][1];if(needsNewInstanceOfLore(targetActor,loreName)){const loreData={proficient:{value:loreProf/2,},featType:"",mod:{value:0},item:{value:0}};const data={name:loreName,type:'lore',data:loreData,};arrayLoreData.push(data);}else{for(var ref in targetActor.data.items){if(targetActor.data.items.hasOwnProperty(ref)){if(targetActor.data.items[ref].name===loreName){const update={id:targetActor.data.items[ref].id,'data.proficient.value':loreProf/2};targetActor.updateEmbeddedEntity("Item",update);}}}}}}
-if(arrayLoreData.length>0){targetActor.createEmbeddedDocuments('Item',arrayLoreData);}}
-function needsNewInstanceOfLore(targetActor,loreName){for(var ref in targetActor.data.items){if(targetActor.data.items.hasOwnProperty(ref)){if(targetActor.data.items[ref].name===loreName)return false;}}
-return true;}
-function checkAllFinishedAndCreate(targetActor){if(finishedFeats&&finishedEquipment&&finishedSpells&&finishedActions&&finishedAncestryFeatures&&finishedClassFeatures){let finished=targetActor.createEmbeddedDocuments("Item",allItems);if(finished){let notAddedCount=0;let warning="
The following items could not be added. They may have already have been added in a previous import or cannot be matched to a foundry item. You may be able to find them with a manual search.
";if(addEquipment){for(var ref in jsonBuild.equipment){if(jsonBuild.equipment.hasOwnProperty(ref)){var item=jsonBuild.equipment[ref];if(!item.added){notAddedCount++;warning+="- Equipment: "+item[0]+"
";if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cdid not add "+item[0],pbcolor1,pbcolor4);}}}}
-if(addFeats){for(var ref in jsonBuild.feats){if(jsonBuild.feats.hasOwnProperty(ref)){var item=jsonBuild.feats[ref];if(!addedItems.includes(item[0])){notAddedCount++;warning+="- Feat: "+item[0]+"
";if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cdid not add "+item[0],pbcolor1,pbcolor4);}}}
-targetActor.update({'flags.exportSource.world':game.world.id,'flags.exportSource.system':game.system.id,'flags.exportSource.systemVersion':game.system.data.version,'flags.exportSource.coreVersion':game.data.version});for(var ref in jsonBuild.specials){if(jsonBuild.specials.hasOwnProperty(ref)){var item=jsonBuild.specials[ref];if(!addedItems.includes(item)){notAddedCount++;warning+="- Special: "+item+"
";if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cdid not add "+item,pbcolor1,pbcolor4);}}}}
-warning+="
";if(notAddedCount>0){ui.notifications.warn("Import completed with some warnings.");new Dialog({title:`Pathbuilder Import Warning`,content:warning,buttons:{yes:{icon:"
",label:`Finished`},},default:"yes",close:html=>{if(heroVaultExport){let heroJSON=JSON.stringify(targetActor.data);if(fbpiDebug)
-console.log(heroJSON);doHVExport(heroJSON,targetActor);}}}).render(true);}else{ui.notifications.info("Import completed successfully.");if(heroVaultExport){let heroJSON=JSON.stringify(targetActor.data);if(fbpiDebug)
-console.log(heroJSON);doHVExport(heroJSON,targetActor);}}}}}
-function getSlug(itemName){return itemName.toString().toLowerCase().replace(/[^a-z0-9]+/gi,' ').trim().replace(/\s+|-{2,}/g,'-');}
-function getSlugNoQuote(itemName){return itemName.toString().toLowerCase().replace(/[\']+/gi,'').replace(/[^a-z0-9]+/gi,' ').trim().replace(/\s+|-{2,}/g,'-');}
-function mapItemToFoundryName(itemName){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cChecking map for '"+itemName+"'",pbcolor1,pbcolor4)
-const changeNames=[{'name':'Chain','newname':'Chain (10 feet)'}]
-const newNameIdx=changeNames.findIndex(function(item){return item.name==itemName});return(newNameIdx>-1)?changeNames[newNameIdx]['newname']:itemName;}
-function mapSpecialToFoundryName(itemName){if(fbpiDebug)
-console.log("%cPathbuilder2e Import | %cChecking map for '"+itemName+"'",pbcolor1,pbcolor4)
-const changeNames=[{'name':'Deflect Arrows','newname':'Deflect Arrow'},{'name':'Maestro','newname':'Maestro Muse'},{"name":"Duelist Dedication (LO)","newname":"Aldori Duelist Dedication"},{"name":"Parry","newname":"Aldori Parry"},{"name":"Riposte","newname":"Aldori Riposte"},{"name":"Sentry Dedication","newname":"Lastwall Sentry Dedication"},{"name":"Wary Eye","newname":"Eye of Ozem"},{"name":"Warden","newname":"Lastwall Warden"},{"name":"Heavenseeker Dedication","newname":"Jalmeri Heavenseeker Dedication"},{"name":"Mantis God's Grip","newname":"Achaekek's Grip"},{"name":"High Killer Training","newname":"Vernai Training"},{"name":"Guild Agent Dedication","newname":"Pathfinder Agent Dedication"},{"name":"Wayfinder Resonance Infiltrator","newname":"Westyr's Wayfinder Repository"},{"name":"Collegiate Attendant Dedication","newname":"Magaambyan Attendant Dedication"},{"name":"Scholarly Storytelling","newname":"Uzunjati Storytelling"},{"name":"Scholarly Recollection","newname":"Uzunjati Recollection"},{"name":"Secret Lesson","newname":"Janatimo's Lessons"},{"name":"Lumberjack Dedication","newname":"Turpin Rowe Lumberjack Dedication"},{"name":"Fourberie","newname":"Fane's Fourberie"},{"name":"Escape","newname":"Fane's Escape"},{"name":"Stab and Snag","newname":"Stella's Stab and Snag"},{"name":"Cognitive Crossover","newname":"Kreighton's Cognitive Crossover"}]
-const newNameIdx=changeNames.findIndex(function(item){return item.name==itemName});return(newNameIdx>-1)?changeNames[newNameIdx]['newname']:itemName;}
-function getFoundryFeatLocation(pathbuilderFeatType,pathbuilderFeatLevel){if(pathbuilderFeatType=="Ancestry Feat"){return"ancestry-"+pathbuilderFeatLevel;}else if(pathbuilderFeatType=="Class Feat"){return"class-"+pathbuilderFeatLevel;}else if(pathbuilderFeatType=="Skill Feat"){return"skill-"+pathbuilderFeatLevel;}else if(pathbuilderFeatType=="General Feat"){return"general-"+pathbuilderFeatLevel;}
-return null;}
-Hooks.on('init',()=>{game.modules.get('pathbuilder2e-import').api={beginPathbuilderImport:beginPathbuilderImport};Hooks.callAll('pathbuilder2eimportReady',game.modules.get('pathbuilder2e-import').api);});
\ No newline at end of file
+ `,buttons:{yes:{icon:"
",label:"Import",callback:()=>applyChanges=!0},no:{icon:"
",label:"Cancel"}},default:"yes",close:html=>{applyChanges&&(isNormalInteger(buildID=html.find('[id="textBoxBuildID"]')[0].value)?(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,isHV&&(heroVaultExport=html.find('[name="checkBoxHVExport"]')[0].checked),fbpiDebug&&console.log("%cPathbuilder2e Import | %cGot heroVaultExport:"+heroVaultExport,pbcolor1,pbcolor4),fetchPathbuilderBuild(targetActor,buildID)):ui.notifications.warn("Build ID must be a positive integer!"))}}).render(!0)}function isNormalInteger(str){var n=Math.floor(Number(str));return n!==1/0&&String(n)===str&&0<=n}function fetchPathbuilderBuild(targetActor,buildID){var xmlhttp=new XMLHttpRequest;xmlhttp.onreadystatechange=function(){var responseJSON;4==this.readyState&&200==this.status&&(responseJSON=JSON.parse(this.responseText),fbpiDebug&&console.log(responseJSON),responseJSON.success?(jsonBuild=responseJSON.build,checkCharacterIsCorrect(targetActor,responseJSON.build)):ui.notifications.warn("Unable to find a character with this build id!"))},xmlhttp.open("GET","https://www.pathbuilder2e.com/json.php?id="+buildID,!0),xmlhttp.send()}function checkCharacterIsCorrect(targetActor,jsonBuild){let correctCharacter=!1;new Dialog({title:jsonBuild.name,content:`
+
Importing `+jsonBuild.name+", level "+jsonBuild.level+`
+ `,buttons:{yes:{icon:"
",label:"Proceed",callback:()=>correctCharacter=!0},no:{icon:"
",label:"Cancel"}},default:"yes",close:html=>{correctCharacter&&(ui.notifications.info("Please be patient while "+jsonBuild.name+" is imported."),importCharacter(targetActor,jsonBuild))}}).render(!0)}function shouldBeManuallyDeleted(i){return("feat"!=i.data.type||"ancestryfeature"!=i.data.data.featType.value)&&("spell"!=i.data.type&&"spellcastingEntry"!=i.data.type)}async function importCharacter(targetActor,jsonBuild){if(deleteAll){fbpiDebug&&console.log("%cPathbuilder2e Import | %cDeleting all items",pbcolor1,pbcolor4);await targetActor.deleteEmbeddedDocuments("Item",["123"],{deleteAll:!0})}else if(addMoney){fbpiDebug&&console.log("%cPathbuilder2e Import | %cDeleting money",pbcolor1,pbcolor4);let items=targetActor.data.items.filter(i=>"Platinum Pieces"===i.name||"Gold Pieces"===i.name||"Silver Pieces"===i.name||"Copper Pieces"===i.name);var backpackData=items.map(i=>i.id);await targetActor.deleteEmbeddedDocuments("Item",backpackData)}let arrayFeats=jsonBuild.feats,arrayEquipment=jsonBuild.equipment,arrayWeapons=jsonBuild.weapons,arrayArmor=jsonBuild.armor,arraySpecials=jsonBuild.specials;var arrayLores=jsonBuild.lores;for(ref in jsonBuild.languages)jsonBuild.languages.hasOwnProperty(ref)&&(jsonBuild.languages[ref]=jsonBuild.languages[ref].toLowerCase());for(ref in arrayEquipment)arrayEquipment[ref][0]=mapItemToFoundryName(arrayEquipment[ref][0]);for(ref in arraySpecials)arraySpecials[ref]=mapSpecialToFoundryName(arraySpecials[ref]);for(ref in arrayFeats)arrayFeats[ref][0]=mapSpecialToFoundryName(arrayFeats[ref][0]);var senses=[];for(ref in arraySpecials)arraySpecials.hasOwnProperty(ref)&&("Low-Light Vision"==arraySpecials[ref]?senses[0]={exceptions:"",label:"Low-Light Vision",type:"lowLightVision",value:""}:"Darkvision"==arraySpecials[ref]&&(senses[1]={exceptions:"",label:"Darkvision",type:"darkvision",value:""}));backpackData=(jsonBuild.abilities.con%2==0?jsonBuild.abilities.con:jsonBuild.abilities.con-1)-10;let conBonus=0;conBonus=0
=item.data.data.items[classFeatureItem].level&&(newFeature={id:item.data.data.items[classFeatureItem].id,pack:item.data.data.items[classFeatureItem].pack,name:item.data.data.items[classFeatureItem].name},classFeatures.push(newFeature))}}if(targetActor.data.data.details.ancestry!=jsonBuild.ancestry)for(const item of await game.packs.get("pf2e.ancestries").getDocuments())item.data.data.slug==getSlug(jsonBuild.ancestry)&&allItems.push(item.data);let blacklist=[jsonBuild.heritage,"Great Fortitude","Intimidation","Axe","Lightning Reflexes","Alertness","Shield Block","Anathema","Druidic Language","Darkvision","Stealth","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)"];for(const cf in classFeatures)blacklist.push(classFeatures[cf].name);if(arraySpecials=arraySpecials.filter(val=>!blacklist.includes(val)),jsonBuild.specials=uniq(arraySpecials),addFeats?(finishedClassFeatures=finishedAncestryFeatures=!0,addFeatItems(targetActor,arrayFeats),addFeatItems(targetActor,arraySpecials),addActionItems(targetActor,arraySpecials),addAncestryFeatureItems(targetActor,arraySpecials),addClassFeatureItems(targetActor,arraySpecials,classFeatures)):(finishedClassFeatures=finishedActions=finishedAncestryFeatures=finishedFeats=!0,checkAllFinishedAndCreate(targetActor)),addEquipment){let pack=game.packs.get("pf2e.equipment-srd"),content=await game.packs.get("pf2e.equipment-srd").getDocuments();backpackData=await pack.getDocuments("3lgwjrFEsQVKzhh7");let backpackInstance=[],arrayKit=[];hasAdventurersPack(arrayEquipment)&&(backpackInstance=await targetActor.createEmbeddedDocuments("Item",backpackData),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]));for(const action of content.filter(item=>equipmentIsRequired(item,arrayEquipment,arrayWeapons,arrayArmor,arrayKit,addMoney))){for(var ref in arrayEquipment)if(arrayEquipment.hasOwnProperty(ref)){var itemName=arrayEquipment[ref][0];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofItem(targetActor,arrayEquipment[ref][0])){var itemAmount=arrayEquipment[ref][1];arrayEquipment[ref].added=!0;const clonedData=JSON.parse(JSON.stringify(action.data));"kit"!=clonedData.type&&(clonedData.data.quantity.value=itemAmount,allItems.push(clonedData))}}for(var ref in arrayKit)if(arrayKit.hasOwnProperty(ref))if(arrayKit[ref][0]===action.data.data.slug&&needsNewInstanceofItem(targetActor,itemName)){itemAmount=arrayKit[ref][1];const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=itemAmount,clonedData.data.containerId.value=backpackInstance.id,allItems.push(clonedData)}for(var ref in arrayWeapons)if(arrayWeapons.hasOwnProperty(ref)){var material,weaponDetails=arrayWeapons[ref];if(isNameMatch(weaponDetails.name,action.data.data.slug)&&needsNewInstanceofItem(targetActor,weaponDetails.name)){weaponDetails.added=!0;const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=weaponDetails.qty,clonedData.data.damage.die=weaponDetails.die,clonedData.data.potencyRune.value=weaponDetails.pot,clonedData.data.strikingRune.value=weaponDetails.str,weaponDetails.runes[0]&&(clonedData.data.propertyRune1.value=camelCase(weaponDetails.runes[0])),weaponDetails.runes[1]&&(clonedData.data.propertyRune2.value=camelCase(weaponDetails.runes[1])),weaponDetails.runes[2]&&(clonedData.data.propertyRune3.value=camelCase(weaponDetails.runes[2])),weaponDetails.runes[3]&&(clonedData.data.propertyRune4.value=camelCase(weaponDetails.runes[3])),weaponDetails.mat&&(material=weaponDetails.mat.split(" (")[0],clonedData.data.preciousMaterial.value=camelCase(material),clonedData.data.preciousMaterialGrade.value=getMaterialGrade(weaponDetails.mat)),weaponDetails.display&&(clonedData.name=weaponDetails.display),allItems.push(clonedData)}}for(var ref in arrayArmor)if(arrayArmor.hasOwnProperty(ref)){var armorDetails=arrayArmor[ref];if(isNameMatch(armorDetails.name,action.data.data.slug)&&needsNewInstanceofItem(targetActor,armorDetails.name)){armorDetails.added=!0;const clonedData=JSON.parse(JSON.stringify(action.data));if(notBracersOfArmor(armorDetails.name)){if(clonedData.data.quantity.value=armorDetails.qty,clonedData.data.armorType.value=armorDetails.prof,clonedData.data.potencyRune.value=armorDetails.pot.toString(),clonedData.data.resiliencyRune.value=armorDetails.res,armorDetails.worn?clonedData.data.equipped.value=!0:clonedData.data.equipped.value=!1,armorDetails.runes[0]&&(clonedData.data.propertyRune1.value=camelCase(armorDetails.runes[0])),armorDetails.runes[1]&&(clonedData.data.propertyRune2.value=camelCase(armorDetails.runes[1])),armorDetails.runes[2]&&(clonedData.data.propertyRune3.value=camelCase(armorDetails.runes[2])),armorDetails.runes[3]&&(clonedData.data.propertyRune4.value=camelCase(armorDetails.runes[3])),armorDetails.mat){let material=armorDetails.mat.split(" (")[0];clonedData.data.preciousMaterial.value=camelCase(material),clonedData.data.preciousMaterialGrade.value=getMaterialGrade(armorDetails.mat)}armorDetails.display&&(clonedData.name=armorDetails.display)}allItems.push(clonedData)}}if(addMoney)if("platinum-pieces"===action.data.data.slug){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.pp,allItems.push(clonedData)}else if("gold-pieces"===action.data.data.slug){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.gp,allItems.push(clonedData)}else if("silver-pieces"===action.data.data.slug){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.sp,allItems.push(clonedData)}else if("copper-pieces"===action.data.data.slug){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.quantity.value=jsonBuild.money.cp,allItems.push(clonedData)}}finishedEquipment=!0,checkAllFinishedAndCreate(targetActor)}else finishedEquipment=!0,checkAllFinishedAndCreate(targetActor);addSpellcasters?setSpellcasters(targetActor,jsonBuild.spellCasters):(finishedSpells=!0,checkAllFinishedAndCreate(targetActor)),addLores(targetActor,arrayLores)}function getExistingAncestrySlug(targetActor){for(var item in targetActor.data.items)if(targetActor.data.items.hasOwnProperty(item)){item=targetActor.data.items[item];if("ancestry"==item.type)return item.data.slug}return null}function notBracersOfArmor(name){return!name.toLowerCase().includes("bracers of armor")}function camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index){return 0==index?word.toLowerCase():word.toUpperCase()}).replace(/\s+/g,"")}function getMaterialGrade(material){return material.toLowerCase().includes("high-grade")?"high":material.toLowerCase().includes("standard-grade")?"standard":"low"}async function addFeatItems(targetActor,arrayFeats){var usedLocations=[];let content=await game.packs.get("pf2e.feats-srd").getDocuments();for(const action of content.filter(item=>featIsRequired(item,arrayFeats)))for(var ref in arrayFeats)if(arrayFeats.hasOwnProperty(ref)){var pathbuilderFeatItem=arrayFeats[ref],itemName=pathbuilderFeatItem[0],itemExtra=pathbuilderFeatItem[1];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofFeat(targetActor,itemName,itemExtra)){var location,displayName=itemName;addedItems.push(itemName),null!=itemExtra&&(displayName+=" ("+itemExtra+")");const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.name=displayName;try{pathbuilderFeatItem[2]&&pathbuilderFeatItem[3]&&(location=getFoundryFeatLocation(pathbuilderFeatItem[2],pathbuilderFeatItem[3]),usedLocations.includes(location)||(clonedData.data.location=location,usedLocations.push(location)))}catch(err){console.log(err)}allItems.push(clonedData)}}content=await game.packs.get("pf2e.ancestryfeatures").getDocuments();for(const action of content.filter(item=>featIsRequired(item,arrayFeats)))for(var ref in arrayFeats)if(arrayFeats.hasOwnProperty(ref)){let pathbuilderFeatItem=arrayFeats[ref];itemName=pathbuilderFeatItem[0],itemExtra=pathbuilderFeatItem[1];if(isNameMatch(itemName,action.data.data.slug)&&needsNewInstanceofFeat(targetActor,itemName,itemExtra)){displayName=itemName;addedItems.push(itemName),null!=itemExtra&&(displayName+=" ("+itemExtra+")");const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.name=displayName;try{if(pathbuilderFeatItem[2]&&pathbuilderFeatItem[3]){let location=getFoundryFeatLocation(pathbuilderFeatItem[2],pathbuilderFeatItem[3]);usedLocations.includes(location)||(clonedData.data.location=location,usedLocations.push(location))}}catch(err){console.log(err)}allItems.push(clonedData)}}finishedFeats=!0,checkAllFinishedAndCreate(targetActor)}function isNameMatch(pathbuilderItemName,foundryItemSlug){return getSlug(pathbuilderItemName)==foundryItemSlug||(getSlugNoQuote(pathbuilderItemName)==foundryItemSlug||(getSlug(getClassAdjustedSpecialNameLowerCase(pathbuilderItemName))==foundryItemSlug||(getSlug(getAncestryAdjustedSpecialNameLowerCase(pathbuilderItemName))==foundryItemSlug||getSlug(getHeritageAdjustedSpecialNameLowerCase(pathbuilderItemName))==foundryItemSlug)))}async function addActionItems(targetActor,arraySpecials){let content=await game.packs.get("pf2e.actionspf2e").getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials)))for(var itemName in arraySpecials)!arraySpecials.hasOwnProperty(itemName)||isNameMatch(itemName=arraySpecials[itemName],action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)&&(addedItems.push(itemName),allItems.push(action.data));finishedActions=!0,checkAllFinishedAndCreate(targetActor)}async function addAncestryFeatureItems(targetActor,arraySpecials){let content=await game.packs.get("pf2e.ancestryfeatures").getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials)))for(var itemName in arraySpecials)!arraySpecials.hasOwnProperty(itemName)||isNameMatch(itemName=arraySpecials[itemName],action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)&&(addedItems.push(itemName),allItems.push(action.data));finishedAncestryFeatures=!0,checkAllFinishedAndCreate(targetActor)}async function addAncestryFeatureFeatItems(targetActor,arraySpecials){let content=await game.packs.get("pf2e.ancestryfeatures").getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials)))for(var itemName in arraySpecials)!arraySpecials.hasOwnProperty(itemName)||isNameMatch(itemName=arraySpecials[itemName],action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)&&(addedItems.push(itemName),allItems.push(action.data));finishedAncestryFeatureFeats=!0,checkAllFinishedAndCreate(targetActor)}async function addClassFeatureItems(targetActor,arraySpecials,arrayCF){let content=await game.packs.get("pf2e.classfeatures").getDocuments();for(const action of content.filter(item=>specialIsRequired(item,arraySpecials)))for(var ref in arraySpecials)arraySpecials.hasOwnProperty(ref)&&isNameMatch(itemName=arraySpecials[ref],action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)&&(addedItems.push(itemName),allItems.push(action.data));let classFeatures=arrayCF.map(a=>a.name);for(const action of content.filter(item=>specialIsRequired(item,classFeatures)))for(var ref in classFeatures){var itemName;isNameMatch(itemName=classFeatures[ref],action.data.data.slug)&&needsNewInstanceofItem(targetActor,itemName)&&(addedItems.push(itemName),allItems.push(action.data))}finishedClassFeatures=!0,checkAllFinishedAndCreate(targetActor)}function hasAdventurersPack(arrayEquipment){for(var ref in arrayEquipment)if(arrayEquipment.hasOwnProperty(ref))if("Adventurer's Pack"===arrayEquipment[ref][0])return arrayEquipment[ref].added=!0;return!1}function isSpecialsPack(packName){return"actionspf2e"===packName||"ancestryfeatures"===packName||"classfeatures"===packName}function featIsRequired(item,arrayFeats){for(var featDetails in arrayFeats)if(arrayFeats.hasOwnProperty(featDetails)){if(getSlug(arrayFeats[featDetails][0])==item.data.data.slug)return!0;if(getSlugNoQuote(arrayFeats[featDetails][0])==item.data.data.slug)return!0;if(getSlug(getClassAdjustedSpecialNameLowerCase(arrayFeats[featDetails][0]))==item.data.data.slug)return!0;if(getSlug(getAncestryAdjustedSpecialNameLowerCase(arrayFeats[featDetails][0]))==item.data.data.slug)return!0;if(getSlug(getHeritageAdjustedSpecialNameLowerCase(arrayFeats[featDetails][0]))==item.data.data.slug)return!0}return!1}function specialIsRequired(item,arraySpecials){for(var ref in arraySpecials)if(arraySpecials.hasOwnProperty(ref)){if(getSlug(arraySpecials[ref])==item.data.data.slug)return!0;if(getSlug(getClassAdjustedSpecialNameLowerCase(arraySpecials[ref]))==item.data.data.slug)return!0;if(getSlug(getAncestryAdjustedSpecialNameLowerCase(arraySpecials[ref]))==item.data.data.slug)return!0;if(getSlug(getHeritageAdjustedSpecialNameLowerCase(arraySpecials[ref]))==item.data.data.slug)return!0}return!1}function equipmentIsRequired(item,arrayEquipment,arrayWeapons,arrayArmor,arrayKit,addMoney){for(var ref in arrayEquipment)if(arrayEquipment.hasOwnProperty(ref)){if(getSlug(arrayEquipment[ref][0])===item.data.data.slug)return!0;if(getSlugNoQuote(arrayEquipment[ref][0])===item.data.data.slug)return!0}for(var ref in arrayWeapons)if(arrayWeapons.hasOwnProperty(ref)){if(getSlug(arrayWeapons[ref].name)===item.data.data.slug)return!0;if(getSlugNoQuote(arrayWeapons[ref].name)===item.data.data.slug)return!0}for(var ref in arrayArmor)if(arrayArmor.hasOwnProperty(ref)){if(getSlug(arrayArmor[ref].name)===item.data.data.slug)return!0;if(getSlugNoQuote(arrayArmor[ref].name)===item.data.data.slug)return!0}for(var ref in arrayKit)if(arrayKit.hasOwnProperty(ref)&&arrayKit[ref][0]===item.data.data.slug)return!0;return!(!addMoney||"platinum-pieces"!==item.data.data.slug&&"gold-pieces"!==item.data.data.slug&&"silver-pieces"!==item.data.data.slug&&"copper-pieces"!==item.data.data.slug)}function getClassAdjustedSpecialNameLowerCase(specialName){return(specialName+" ("+jsonBuild.class+")").toLowerCase()}function getAncestryAdjustedSpecialNameLowerCase(specialName){return(specialName+" ("+jsonBuild.ancestry+")").toLowerCase()}function getHeritageAdjustedSpecialNameLowerCase(specialName){return(specialName+" ("+jsonBuild.heritage+")").toLowerCase()}function needsNewInstanceofFeat(targetActor,itemName,itemExtra){for(const existingItem of targetActor.data.items){var displayName=itemName;if(null!=itemExtra&&(displayName+=" ("+itemExtra+")"),existingItem.data.name===displayName)return!1}return!0}function needsNewInstanceofItem(targetActor,itemName){for(var ref in targetActor.data.items)if(targetActor.data.items.hasOwnProperty(ref)&&targetActor.data.items[ref].name===itemName)return!1;return!0}function getSizeValue(size){switch(size){case 0:return"tiny";case 1:return"sm";case 3:return"lg"}return"med"}async function setSpellcasters(targetActor,arraySpellcasters){fbpiDebug&&console.log("%cPathbuilder2e Import | %cDeleting all spells",pbcolor1,pbcolor4);let items=targetActor.data.items.filter(i=>"spell"===i.type);var spellListObject,deletions=items.map(i=>i.id);await targetActor.deleteEmbeddedDocuments("Item",deletions);items=targetActor.data.items.filter(i=>"spellcastingEntry"===i.type),deletions=items.map(i=>i.id),await targetActor.deleteEmbeddedDocuments("Item",deletions);let requiredSpells=[];for(ref in arraySpellcasters)if(arraySpellcasters.hasOwnProperty(ref)){let spellCaster=arraySpellcasters[ref];for(var ref in spellCaster.instance=await addSpecificCasterAndSpells(targetActor,spellCaster,spellCaster.magicTradition,spellCaster.spellcastingType),spellCaster.spells)spellCaster.spells.hasOwnProperty(ref)&&(spellListObject=spellCaster.spells[ref],requiredSpells=requiredSpells.concat(spellListObject.list))}game.packs.filter(pack=>"spells-srd"===pack.metadata.name).forEach(async pack=>{const content=await pack.getDocuments();for(const action of content.filter(item=>spellIsRequired(item,requiredSpells)))arraySpellcasters.forEach(spellCaster=>{for(var ref in spellCaster.spells)if(spellCaster.spells.hasOwnProperty(ref)){let spellListObject=spellCaster.spells[ref];for(var ref in spellListObject.list)if(spellListObject.list.hasOwnProperty(ref)&&getSlug(spellListObject.list[ref])==action.data.data.slug){const clonedData=JSON.parse(JSON.stringify(action.data));clonedData.data.location.value=spellCaster.instance[0].id,clonedData.data.level.value=spellListObject.spellLevel,allItems.push(clonedData);break}}});finishedSpells=!0,checkAllFinishedAndCreate(targetActor)})}function spellIsRequired(item,arraySpells){for(var ref in arraySpells)if(arraySpells.hasOwnProperty(ref)&&getSlug(arraySpells[ref])==item.data.data.slug)return!0;return!1}async function addSpecificCasterAndSpells(targetActor,spellCaster,data,spellCasterInstance){data={ability:{type:"String",label:"Spellcasting Ability",value:spellCaster.ability},focus:{pool:spellCaster.focusPoints},proficiency:{value:spellCaster.proficiency/2},spelldc:{type:"String",label:"Class DC",item:0},tradition:{type:"String",label:"Magic Tradition",value:data},prepared:{type:"String",label:"Spellcasting Type",value:spellCasterInstance},slots:{slot0:{max:spellCaster.perDay[0],prepared:[],value:spellCaster.perDay[0]},slot1:{max:spellCaster.perDay[1],prepared:[],value:spellCaster.perDay[1]},slot2:{max:spellCaster.perDay[2],prepared:[],value:spellCaster.perDay[2]},slot3:{max:spellCaster.perDay[3],prepared:[],value:spellCaster.perDay[3]},slot4:{max:spellCaster.perDay[4],prepared:[],value:spellCaster.perDay[4]},slot5:{max:spellCaster.perDay[5],prepared:[],value:spellCaster.perDay[5]},slot6:{max:spellCaster.perDay[6],prepared:[],value:spellCaster.perDay[6]},slot7:{max:spellCaster.perDay[7],prepared:[],value:spellCaster.perDay[7]},slot8:{max:spellCaster.perDay[8],prepared:[],value:spellCaster.perDay[8]},slot9:{max:spellCaster.perDay[9],prepared:[],value:spellCaster.perDay[9]},slot10:{max:spellCaster.perDay[10],prepared:[],value:spellCaster.perDay[10]}},showUnpreparedSpells:{value:!0}},spellCasterInstance=[],data={name:spellCaster.name,type:"spellcastingEntry",data:data};spellCasterInstance.push(data);spellCasterInstance=await targetActor.createEmbeddedDocuments("Item",spellCasterInstance);return fbpiDebug&&console.log(spellCasterInstance),spellCasterInstance}async function addLores(targetActor,arrayLores){const arrayLoreData=[];for(var ref in arrayLores)if(arrayLores.hasOwnProperty(ref)){var update,loreName=arrayLores[ref][0],loreProf=arrayLores[ref][1];if(needsNewInstanceOfLore(targetActor,loreName))arrayLoreData.push({name:loreName,type:"lore",data:{proficient:{value:loreProf/2},featType:"",mod:{value:0},item:{value:0}}});else for(var ref in targetActor.data.items)targetActor.data.items.hasOwnProperty(ref)&&targetActor.data.items[ref].name===loreName&&(update={id:targetActor.data.items[ref].id,"data.proficient.value":loreProf/2},targetActor.updateEmbeddedEntity("Item",update))}0The following items could not be added. They may have already have been added in a previous import or cannot be matched to a foundry item. You may be able to find them with a manual search.";if(addEquipment)for(var ref in jsonBuild.equipment)jsonBuild.equipment.hasOwnProperty(ref)&&((item=jsonBuild.equipment[ref]).added||(notAddedCount++,warning+="- Equipment: "+item[0]+"
",warningList+="Equipment: "+item[0]+"|",fbpiDebug&&console.log("%cPathbuilder2e Import | %cdid not add "+item[0],pbcolor1,pbcolor4)));if(addFeats){for(var ref in jsonBuild.feats)jsonBuild.feats.hasOwnProperty(ref)&&(item=jsonBuild.feats[ref],addedItems.includes(item[0])||(notAddedCount++,warning+="- Feat: "+item[0]+"
",warningList+="Feat: "+item[0]+"|",fbpiDebug&&console.log("%cPathbuilder2e Import | %cdid not add "+item[0],pbcolor1,pbcolor4)));for(var ref in targetActor.update({"flags.exportSource.world":game.world.id,"flags.exportSource.system":game.system.id,"flags.exportSource.systemVersion":game.system.data.version,"flags.exportSource.coreVersion":game.data.version}),jsonBuild.specials)jsonBuild.specials.hasOwnProperty(ref)&&(item=jsonBuild.specials[ref],addedItems.includes(item)||(notAddedCount++,warning+="- Special: "+item+"
",warningList+="Special: "+item+"|",fbpiDebug&&console.log("%cPathbuilder2e Import | %cdid not add "+item,pbcolor1,pbcolor4)))}warning+="
",reportMissedItems&&reportWarnings(warningList),0",label:"Finished"}},default:"yes",close:html=>{var heroJSON;heroVaultExport&&(heroJSON=JSON.stringify(targetActor.data),fbpiDebug&&console.log(heroJSON),doHVExport(heroJSON,targetActor))}}).render(!0)):(ui.notifications.info("Import completed successfully."),heroVaultExport&&(heroJSON=JSON.stringify(targetActor.data),fbpiDebug&&console.log(heroJSON),doHVExport(heroJSON,targetActor)))}}function reportWarnings(warnings){var xmlhttp=new XMLHttpRequest;xmlhttp.open("POST",reportDomain+"/pbreport.php",!0),xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"),xmlhttp.send("buildID="+buildID+"&warnings="+encodeURIComponent(warnings))}function getSlug(itemName){return itemName.toString().toLowerCase().replace(/[^a-z0-9]+/gi," ").trim().replace(/\s+|-{2,}/g,"-")}function getSlugNoQuote(itemName){return itemName.toString().toLowerCase().replace(/[\']+/gi,"").replace(/[^a-z0-9]+/gi," ").trim().replace(/\s+|-{2,}/g,"-")}function mapItemToFoundryName(itemName){fbpiDebug&&console.log("%cPathbuilder2e Import | %cChecking map for '"+itemName+"'",pbcolor1,pbcolor4);const changeNames=[{name:"Chain",newname:"Chain (10 feet)"}];var newNameIdx=changeNames.findIndex(function(item){return item.name==itemName});return-1{fbpiDebug&&console.log("%cPathbuilder2e Import | %cDisabling pathbuilder button since herovault is loaded",pbcolor1,pbcolor4),pbButton=!1}),Hooks.on("renderActorSheet",async function(obj,html){const actor=obj.actor;if("character"===actor.data.type&&0!=actor.canUserModify(game.user,"update")&&pbButton){let element=html.find(".window-header .window-title");if(1==element.length){let button=$('Import from Pathbuilder 2e');button.on("click",()=>beginPathbuilderImport(obj.object)),element.after(button)}}}),Hooks.on("init",()=>{game.modules.get("pathbuilder2e-import").api={beginPathbuilderImport:beginPathbuilderImport},Hooks.callAll("pathbuilder2eimportReady",game.modules.get("pathbuilder2e-import").api)}),Hooks.on("ready",function(){console.log("%cPathbuilder2e Import | %cinitializing",pbcolor1,pbcolor4),game.settings.register("pathbuilder2e-import","reportMissedItems",{name:"Report missed items?",hint:"Having this checked will send me the error report generated during an import. Please keep this enabled so that I can continue to improve the module. It sends the following data: pathbuilder character ID and error messages presented post-import.",scope:"client",config:!0,type:Boolean,default:!0,onChange:value=>reportMissedItems=value}),game.settings.register("pathbuilder2e-import","debugEnabled",{name:"Enable debug mode",hint:"Debug output will be written to the js console.",scope:"client",config:!0,type:Boolean,default:!1,onChange:value=>fbpiDebug=value}),reportMissedItems=game.settings.get("pathbuilder2e-import","reportMissedItems"),fbpiDebug=game.settings.get("pathbuilder2e-import","debugEnabled")});export{beginPathbuilderImport};
\ No newline at end of file
diff --git a/pathbuilder-import.js b/pathbuilder-import.js
index 2710932..28bf45b 100644
--- a/pathbuilder-import.js
+++ b/pathbuilder-import.js
@@ -1,5 +1,5 @@
var fbpiDebug = false;
-const fpbi = "0.4.0";
+const fpbi = "0.5.0";
const reportDomain = "https://www.pf2player.com/";
const pbcolor1 = "color: #7bf542"; //bright green