Import gk-greyknight-0.6.4.3.zip do wg-greyknights (2025-08-23T19:48:54Z)

This commit is contained in:
2025-08-23 19:48:54 +00:00
parent 47a0250f2a
commit 0e417ca6cb
2 changed files with 73 additions and 1 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"id": "gk-greyknight", "id": "gk-greyknight",
"title": "Grey Knights — Compendium (Wrath & Glory)", "title": "Grey Knights — Compendium (Wrath & Glory)",
"version": "0.6.4.2", "version": "0.6.4.3",
"compatibility": { "compatibility": {
"minimum": "11", "minimum": "11",
"verified": "13" "verified": "13"
+72
View File
@@ -70,3 +70,75 @@ Hooks.on("preCreateChatMessage", (doc, data, options, userId) => {
else if (!prev) combat.setFlag("gk-greyknight", key, actor.id); else if (!prev) combat.setFlag("gk-greyknight", key, actor.id);
} catch (e) { console.error("gk-greyknight helpers (house-rule reminder):", e); } } catch (e) { console.error("gk-greyknight helpers (house-rule reminder):", e); }
}); });
// === gk-greyknight 0.6.4.3 — Brotherhood discipline prompt + starter grants ===
Hooks.once("ready", () => {
const FLAG_SCOPE = "gk-greyknight";
// Prevent duplicate hook registration on hot-reload
if (window._gkBroHookId) { Hooks.off("createItem", window._gkBroHookId); window._gkBroHookId = null; }
async function findItemInAllPacksByName(name, type=null) {
for (const pack of game.packs) {
if (pack.documentName !== "Item") continue;
const index = await pack.getIndex();
const hit = index.find(e => e.name === name && (!type || e.type === type));
if (hit) return await pack.getDocument(hit._id);
}
return null;
}
async function ensureHasItemByName(actor, name, type=null) {
const existing = actor.items?.find(i => i.name === name && (!type || i.type === type));
if (existing) return existing;
const doc = await findItemInAllPacksByName(name, type);
if (!doc) return null;
const data = doc.toObject(); delete data._id;
const [created] = await actor.createEmbeddedDocuments("Item", [data]);
return created;
}
async function promptDiscipline(actor) {
const existing = await actor.getFlag(FLAG_SCOPE, "discipline");
if (existing) return existing;
return await new Promise(resolve => {
new Dialog({
title: "Brotherhood of Psykers — Choose Discipline",
content: `<p>Select a discipline for this character:</p>
<label style='display:block;margin-top:.5rem'><input type="radio" name="disc" value="sanctic" checked> Sanctic</label>
<label style='display:block'><input type="radio" name="disc" value="librarius"> Librarius</label>`,
buttons: {
ok: { label: "Confirm", icon: "<i class='fas fa-check'></i>", callback: html => resolve(html.find('input[name="disc"]:checked').val() || "sanctic") },
cancel: { label: "Cancel", callback: () => resolve(null) }
},
default: "ok"
}).render(true);
});
}
window._gkBroHookId = Hooks.on("createItem", async (item, opts, userId) => {
try {
if (game.userId !== userId) return;
if (item?.type !== "ability" || item?.name !== "Brotherhood of Psykers") return;
const actor = item.parent; if (!actor) return;
const chosen = await promptDiscipline(actor);
if (!chosen) return;
await actor.setFlag(FLAG_SCOPE, "discipline", chosen);
// Ensure PSYKER keyword so powers are available
const psyker = await ensureHasItemByName(actor, "PSYKER", "keyword");
if (!psyker) ui.notifications?.warn("PSYKER keyword not found in loaded packs. Add it manually from wng-core.");
// Starter power by discipline
if (chosen === "sanctic") {
const ok = await ensureHasItemByName(actor, "Hammerhand (Sanctic)", "psychicPower");
if (!ok) ui.notifications?.warn("Couldn't auto-add Hammerhand (Sanctic). Drag a Sanctic power from the GK pack.");
} else {
const ok = await ensureHasItemByName(actor, "Smite", "psychicPower");
if (!ok) {
ui.notifications?.warn("Smite not found in available packs. Please add a Librarius power manually.");
game.ui?.sidebar?.tabs?.compendium?.activate();
}
}
} catch (e) { console.error("gk-greyknight — Brotherhood prompt:", e); }
});
});