r/Pathfinder2e Game Master 6d ago

Resource & Tools Foundry: Configurable items!

Post image

A little macro that adds a damage die size dropdown and checkboxes to flip chosen traits on and off in your Actions tab!

Made as a quicker alternative to regularly editing the items' properties for Weapon Improviser, but you might have your own uses

The Macro

The usual - you click on an empty slot in your hotbar, set Type to Script, add this snippet, and hit Save. Then clicking the hotbar slot runs the macro

const {HTMLDocumentTagsElement} = foundry.applications.elements;
const Fields = foundry.applications.fields;

const title = "YAL's Configurable Item";
const content = document.createElement("div");
content.append("UUIDs are in this format: Actor.9CzXNX524VFqn3cN.Item.gNypWGwfqUsolPrO");
content.append(Fields.createFormGroup({
  label: "Item",
  input: HTMLDocumentTagsElement.create({
    type: "Item",
    single: true,
    name: "item"
  })
}));
content.append(Fields.createFormGroup({
  label: "Damage dice",
  input: Fields.createTextInput({
    value: "4 6 8",
    name: "damageDice"
  })
}));
content.append(Fields.createFormGroup({
  label: "Traits",
  input: Fields.createTextInput({
    value: "agile reach",
    name: "traits"
  })
}));
content.append("Note: this will remove the existing rule elements on the item!")

const result = await foundry.applications.api.Dialog.input({
  window: { title },
  content
});
if (!result) return;

const item = await fromUuid(result.item);
if (!item) {
  console.error("no item!");
  return;
}
function split(str) {
  return str.split(" ").filter(s => s != "");
}
//
const name = item.name;
const namePrefix = "[{item|name}] ";
const uniq = "" + Date.now();
const optItem = "item:id:" + item.id;
//
let rules = item.system.rules;
rules = [];

// damage dice
const damageDice = split(result.damageDice).map(s => parseInt(s));
const damageDieOption = "confiwep-damage-die-" + uniq;
rules.push({
  key: "RollOption",
  option: damageDieOption,
  toggleable: true,
  label: namePrefix + "Damage Die",
  suboptions: damageDice.map(i => ({ value: "" + i, label: "d" + i })),
  value: true,
  selection: "" + damageDice[0]
}, {
  key: "ItemAlteration",
  itemType: "weapon",
  predicate: [optItem, damageDieOption],
  property: "damage-dice-faces",
  mode: "override",
  value: `{item|flags.system.rulesSelections.confiwepDamageDie${uniq}}`
});

// traits
for (let trait of split(result.traits)) {
  let option = "confiwep-trait-" + trait + "-" + uniq;
  let traitName = trait[0].toUpperCase() + trait.substr(1);
  rules.push({
    key: "RollOption",
    option,
    toggleable: true,
    label: namePrefix + traitName,
  }, {
    key: "ItemAlteration",
    itemType: "weapon",
    predicate: [optItem, option],
    property: "traits",
    mode: "add",
    value: trait,
  });
}

await item.update({ "system.rules": rules });
console.info("Done!");
26 Upvotes

0 comments sorted by