// gk-greyknight — auto-attach loadout with clear choices Hooks.once("ready", () => { const PACK_KEY = "gk-greyknight.gk-items"; // moduleId.packName const ITEMS = { ability: "Aegis of Titan (Ability)", nemesis: "Nemesis Force Halberd", storm: "Grey Knight Armour Integrated Storm Bolter", aegisPA: "Aegis Power Armour", aegisTerm: "Terminator Aegis (Grey Knights)" }; async function fetchFromCompendium(name) { const pack = game.packs.get(PACK_KEY); if (!pack) return null; const index = await pack.getIndex(); const hit = index.find(e => e.name === name); if (!hit) return null; const doc = await pack.getDocument(hit._id); return doc?.toObject(); } async function ensureOnActor(actor, name, equip=false) { let have = actor.items.getName(name); if (have) { if (typeof have.system?.equipped !== "undefined") await have.update({"system.equipped": !!equip}); return have; } let src = await fetchFromCompendium(name); if (!src) { const world = game.items.getName(name); if (world) src = world.toObject(); } if (!src) return null; if (equip && src.system && typeof src.system.equipped !== "undefined") src.system.equipped = true; const [created] = await actor.createEmbeddedDocuments("Item", [src]); return created; } async function setEquipped(actor, name, on) { const it = actor.items.getName(name); if (it && typeof it.system?.equipped !== "undefined") await it.update({"system.equipped": !!on}); } Hooks.on("createItem", async (item, opts, userId) => { try { if (item?.type !== "archetype") return; if (item?.name !== "Grey Knight (Archetype)") return; const actor = item.parent; if (!actor || game.userId !== userId) return; // Build labeled dialog (no more "Choice1 / Choice2") const content = `