mirror of
https://github.com/migatu/vtt_work.git
synced 2026-07-14 13:34:42 +00:00
Import gk-greyknight-0.6.4.5.zip do wg-greyknights (2025-08-23T20:41:27Z)
This commit is contained in:
@@ -168,3 +168,69 @@ Hooks.on("renderActorSheet", async (sheet, htmlEl, data) => {
|
||||
} catch (e) { console.error("gk-greyknight QoL summary:", e); }
|
||||
});
|
||||
|
||||
|
||||
// gk-greyknight 0.6.4.5 — Reliable Brotherhood notification on psychic power use
|
||||
Hooks.on("createChatMessage", async (doc, options, userId) => {
|
||||
try {
|
||||
// Heuristic detection of psychic power usage
|
||||
const flavor = (doc.flavor || "").toLowerCase();
|
||||
const contentText = (ui?.chat && doc.content) ? TextEditor?.stripHTML(doc.content)?.toLowerCase?.() : (doc.content || "").toLowerCase();
|
||||
const keyWords = ["psychic", "psychic mastery", "power", "smite", "hammerhand", "sanctuary", "shrouding", "might of titan"];
|
||||
const looksPsychic = keyWords.some(k => flavor.includes(k) || contentText.includes(k));
|
||||
if (!looksPsychic) return;
|
||||
|
||||
// Resolve actor
|
||||
let actor = null;
|
||||
const sp = doc.speaker || {};
|
||||
if (sp.actor) actor = game.actors?.get(sp.actor);
|
||||
if (!actor && canvas?.tokens) {
|
||||
const t = canvas.tokens.get(sp.token) || canvas.tokens.controlled?.[0];
|
||||
actor = t?.actor || actor;
|
||||
}
|
||||
if (!actor) return;
|
||||
|
||||
// Check Brotherhood ability on actor
|
||||
const hasBrotherhood = actor.items?.some(i => i.type === "ability" && i.name === "Brotherhood of Psykers");
|
||||
if (!hasBrotherhood) return;
|
||||
|
||||
// Count allies with Brotherhood in the scene
|
||||
const tokens = canvas?.tokens?.placeables || [];
|
||||
const allied = new Set();
|
||||
for (const t of tokens) {
|
||||
const a = t.actor; if (!a) continue;
|
||||
const ok = a.items?.some(i => i.type === "ability" && i.name === "Brotherhood of Psykers");
|
||||
if (ok) allied.add(a.id);
|
||||
}
|
||||
const total = allied.size;
|
||||
const bonus = allied.has(actor.id) ? Math.max(0, total - 1) : total;
|
||||
|
||||
// Compose message
|
||||
const msg = `<div class="gk-brotherhood-notice">
|
||||
<b>Brotherhood Focus</b>: Allies with Brotherhood here: <b>${total}</b> → bonus to <em>Psychic Mastery</em>: <b>+${bonus} dice</b>.
|
||||
<div style="opacity:.85;font-size:.9em;margin-top:.25rem;">House rule: only one linked Grey Knight should use a psychic power as their <em>Action</em> per round; subsequent powers add +1 <em>Wrath</em> die.</div>
|
||||
</div>`;
|
||||
|
||||
// Whisper to owners + GM
|
||||
const ownerIds = Object.entries(actor.ownership || {})
|
||||
.filter(([uid, lvl]) => lvl >= (CONST.DOCUMENT_OWNERSHIP_LEVELS?.OWNER ?? 3))
|
||||
.map(([uid]) => uid);
|
||||
const gmIds = game.users?.filter(u => u.isGM).map(u => u.id) ?? [];
|
||||
const whisper = Array.from(new Set([...ownerIds, ...gmIds]));
|
||||
await ChatMessage.create({content: msg, whisper, speaker: {actor: actor.id}});
|
||||
|
||||
// If in combat, enforce one-per-round reminder
|
||||
const combat = game.combat;
|
||||
if (combat) {
|
||||
const key = `gk-greyknight.usedPsychicAction.r${combat.round}`;
|
||||
const prev = combat.getFlag("gk-greyknight", key) || null;
|
||||
if (prev && prev !== actor.id) {
|
||||
ui.notifications?.warn("House rule (Brotherhood Focus): only one Grey Knight should use a psychic power as their Action this round.");
|
||||
} else if (!prev) {
|
||||
await combat.setFlag("gk-greyknight", key, actor.id);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("gk-greyknight 0.6.4.5 notification error:", e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user