mirror of
https://github.com/migatu/vtt_work.git
synced 2026-07-14 13:34:42 +00:00
Final
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
// WNG-Daemonhunters 0.6.4.2 — GK autoload (single dialog, restored Archetype in pack)
|
||||
Hooks.once('ready', () => console.log("WNG-Daemonhunters | Auto-loadout ready"));
|
||||
|
||||
async function addFromPackByName(actor, packKey, name, equip=false) {
|
||||
const pack = game.packs.get(packKey);
|
||||
if (!pack) return ui.notifications?.warn(`Pack not found: ${packKey}`);
|
||||
const index = await pack.getIndex();
|
||||
const entry = index.find(e => e.name === name);
|
||||
if (!entry) return ui.notifications?.warn(`Item not in pack: ${name}`);
|
||||
const doc = await pack.getDocument(entry._id);
|
||||
const data = doc.toObject(); delete data._id;
|
||||
if (equip && data.system && ('equipped' in data.system)) data.system.equipped = true;
|
||||
const [created] = await actor.createEmbeddedDocuments('Item', [data]);
|
||||
return created;
|
||||
}
|
||||
async function addFromUuid(actor, uuid, equip=false) {
|
||||
const doc = await fromUuid(uuid);
|
||||
if (!doc) return ui.notifications?.warn(`Missing UUID: ${uuid}`);
|
||||
const data = doc.toObject(); delete data._id;
|
||||
if (equip && data.system && ('equipped' in data.system)) data.system.equipped = true;
|
||||
const [created] = await actor.createEmbeddedDocuments('Item', [data]);
|
||||
return created;
|
||||
}
|
||||
|
||||
Hooks.on('createItem', async (item, options, userId) => {
|
||||
try {
|
||||
const actor = item.parent;
|
||||
if (!actor || item.type !== 'archetype' || item.name !== 'Grey Knight') return;
|
||||
if (game.userId !== userId) return;
|
||||
if (actor.getFlag('wng-daemonhunters','gkLoaded')) return;
|
||||
|
||||
const content = `<p>Select initial loadout for <strong>Grey Knight</strong>:</p>
|
||||
<div class="form-group"><label>Loadout</label>
|
||||
<select id="gk-loadout">
|
||||
<option value="incog">Incognito — Pilgrim Astartes Plate (Disguise Armour) + Astartes Combat Knife + Bolt Pistol</option>
|
||||
<option value="power" selected>War‑Plate — Aegis Power Armour + Nemesis Force Halberd + Grey Knight Armour Integrated Storm Bolter</option>
|
||||
<option value="termi">Terminator — Terminator Aegis (Grey Knights) + Nemesis Force Halberd + Grey Knight Armour Integrated Storm Bolter</option>
|
||||
</select>
|
||||
</div>`;
|
||||
|
||||
new Dialog({
|
||||
title: "Grey Knight — Choose Loadout",
|
||||
content,
|
||||
buttons: {
|
||||
ok: { label: "Apply", callback: async (html) => {
|
||||
const choice = html.find('#gk-loadout').val();
|
||||
const PACK = "wng-daemonhunters.daemonhunters";
|
||||
|
||||
// Core abilities
|
||||
await addFromPackByName(actor, PACK, "Aegis of Titan");
|
||||
await addFromPackByName(actor, PACK, "Brotherhood of Psykers");
|
||||
await addFromPackByName(actor, PACK, "Might of Heroes");
|
||||
|
||||
if (choice === 'incog') {
|
||||
await addFromPackByName(actor, PACK, "Pilgrim Astartes Plate (Disguise Armour)", true);
|
||||
await addFromUuid(actor, "Compendium.wng-core.items.Item.4QVBQYWXXLyvFWkj", true); // Knife
|
||||
await addFromUuid(actor, "Compendium.wng-core.items.Item.7b2xcPWBB7up65PM", true); // Bolt Pistol
|
||||
} else if (choice === 'power') {
|
||||
await addFromPackByName(actor, PACK, "Aegis Power Armour", true);
|
||||
await addFromPackByName(actor, PACK, "Nemesis Force Halberd", true);
|
||||
await addFromPackByName(actor, PACK, "Grey Knight Armour Integrated Storm Bolter", true);
|
||||
} else if (choice === 'termi') {
|
||||
await addFromPackByName(actor, PACK, "Terminator Aegis (Grey Knights)", true);
|
||||
await addFromPackByName(actor, PACK, "Nemesis Force Halberd", true);
|
||||
await addFromPackByName(actor, PACK, "Grey Knight Armour Integrated Storm Bolter", true);
|
||||
}
|
||||
|
||||
await actor.setFlag('wng-daemonhunters','gkLoaded', true);
|
||||
ui.notifications?.info("Grey Knight loadout applied.");
|
||||
}}
|
||||
},
|
||||
default: "ok"
|
||||
}).render(true);
|
||||
} catch (e) { console.error("GK autoload error", e); }
|
||||
});
|
||||
@@ -1,40 +0,0 @@
|
||||
// GK – Import Items From Module into Items Directory
|
||||
(async () => {
|
||||
const FILES = [
|
||||
"fvtt-Item-archetype-grey-knight_v5.json",
|
||||
"fvtt-Item-ability-aegis-of-titan_v5.json",
|
||||
"fvtt-Item-nemesis-force-halberd_v4.json",
|
||||
"fvtt-Item-gk-armour-integrated-storm-bolter_v2.json",
|
||||
"fvtt-Item-aegis-power-armour_v2.json",
|
||||
"fvtt-Item-terminator-aegis-gk_v4.json"
|
||||
];
|
||||
const MODULE_ID = "gk-greyknight";
|
||||
const base = `modules/${MODULE_ID}/foundry`;
|
||||
|
||||
const ensureFolder = async (name, color="#4b6eaf") => {
|
||||
let f = game.folders.find(x => x.type === "Item" && x.name === name);
|
||||
if (!f) f = await Folder.create({name, type:"Item", color});
|
||||
return f;
|
||||
};
|
||||
const worldFolder = await ensureFolder("Grey Knight Pack", "#4b6eaf");
|
||||
|
||||
const fetchJSON = async (path) => {
|
||||
const res = await fetch(`/${path}`);
|
||||
if (!res.ok) throw new Error(`Nie mogę pobrać: ${path} (HTTP ${res.status})`);
|
||||
return await res.json();
|
||||
};
|
||||
|
||||
let created = 0, updated = 0;
|
||||
for (const fn of FILES) {
|
||||
const full = `${base}/${fn}`;
|
||||
try {
|
||||
const data = await fetchJSON(full);
|
||||
if (data._id) delete data._id;
|
||||
data.folder = worldFolder.id;
|
||||
const existing = game.items.getName(data.name);
|
||||
if (existing) { await existing.update(data); updated++; }
|
||||
else { await Item.create(data); created++; }
|
||||
} catch (e) { console.error("Import err", full, e); ui.notifications.warn(`Błąd importu: ${fn}`); }
|
||||
}
|
||||
ui.notifications.info(`GK Module Import: utworzono ${created}, zaktualizowano ${updated}.`);
|
||||
})();
|
||||
@@ -1,64 +0,0 @@
|
||||
// GK – Loadout Manager (module)
|
||||
(async () => {
|
||||
const NAMES = {
|
||||
archetype: "Grey Knight (Archetype)",
|
||||
ability: "Aegis of Titan (Ability)",
|
||||
nemesis: "Nemesis Force Halberd",
|
||||
storm: "Grey Knight Armour Integrated Storm Bolter",
|
||||
aegis: "Aegis Power Armour",
|
||||
term: "Terminator Aegis (Grey Knights)"
|
||||
};
|
||||
const FOLDER = "Grey Knight Pack";
|
||||
|
||||
const actor = canvas.tokens.controlled[0]?.actor ?? game.user.character;
|
||||
if (!actor) return ui.notifications.warn("Zaznacz token albo przypisz postać.");
|
||||
|
||||
const mode = await Dialog.prompt({
|
||||
title: "Grey Knight – Loadout Manager",
|
||||
content: `<p>Wybierz lub zmień loadout:</p>
|
||||
<label><input type="radio" name="m" value="incognito"> Incognito (bez Aegis)</label><br/>
|
||||
<label><input type="radio" name="m" value="war" checked> War-Plate (Aegis Power Armour)</label><br/>
|
||||
<label><input type="radio" name="m" value="term"> Terminator (Terminator Aegis)</label>`,
|
||||
label: "OK",
|
||||
callback: html => html.find('input[name="m"]:checked').val()
|
||||
});
|
||||
if (!mode) return;
|
||||
|
||||
const findWorldItem = (name) => {
|
||||
const inFolder = game.items.filter(i => i.name === name && i.folder?.name === FOLDER);
|
||||
if (inFolder.length) return inFolder[0];
|
||||
return game.items.getName(name) ?? null;
|
||||
};
|
||||
const ensureOnActor = async (name) => {
|
||||
const have = actor.items.getName(name);
|
||||
if (have) return have;
|
||||
const worldIt = findWorldItem(name);
|
||||
if (!worldIt) { ui.notifications.warn(`Brak w Items Directory: ${name} — użyj importera modułu.`); return null; }
|
||||
const created = await actor.createEmbeddedDocuments("Item", [worldIt.toObject()]);
|
||||
return created[0];
|
||||
};
|
||||
|
||||
for (const key of Object.keys(NAMES)) await ensureOnActor(NAMES[key]);
|
||||
|
||||
const setEquipped = async (name, on) => { const it = actor.items.getName(name); if (it) await it.update({"system.equipped": !!on}); };
|
||||
await setEquipped(NAMES.aegis, false);
|
||||
await setEquipped(NAMES.term, false);
|
||||
await setEquipped(NAMES.storm, false);
|
||||
await setEquipped(NAMES.nemesis, false);
|
||||
|
||||
if (mode === "war") {
|
||||
await setEquipped(NAMES.aegis, true);
|
||||
await setEquipped(NAMES.storm, true);
|
||||
await setEquipped(NAMES.nemesis, true);
|
||||
} else if (mode === "term") {
|
||||
await setEquipped(NAMES.term, true);
|
||||
await setEquipped(NAMES.storm, true);
|
||||
await setEquipped(NAMES.nemesis, true);
|
||||
}
|
||||
|
||||
const anyAegisEquipped = !!actor.items.find(i => ["armour","armor"].includes(i.type) && /Aegis/.test(i.name) && i.system?.equipped);
|
||||
const abilItem = actor.items.getName(NAMES.ability);
|
||||
if (abilItem) for (const ef of abilItem.effects ?? []) if (ef.name?.includes("Aegis Synergy")) await ef.update({ disabled: !anyAegisEquipped });
|
||||
|
||||
ui.notifications.info(`Loadout ustawiony: ${mode.toUpperCase()}.`);
|
||||
})();
|
||||
@@ -1,20 +0,0 @@
|
||||
// Auto loadout on archetype creation (hook Actor creation)
|
||||
Hooks.on("createActor", async (actor, options, userId) => {
|
||||
try {
|
||||
const arch = actor.items.find(i => i.type === "archetype" && i.name?.includes("Grey Knight"));
|
||||
if (!arch) return;
|
||||
const names = ["Nemesis Force Halberd","Aegis Power Armour","Grey Knight Armour Integrated Storm Bolter","Aegis of Titan"];
|
||||
const toAdd = [];
|
||||
for (const n of names) {
|
||||
const packItem = game.items.getName?.(n);
|
||||
if (packItem) toAdd.push(packItem.toObject());
|
||||
else {
|
||||
// fallback: create minimal items
|
||||
toAdd.push({name:n, type: n.includes("Armour") ? "armor" : (n.includes("Bolter") ? "weapon" : "ability"), img:"icons/svg/placeholder.svg", system:{}});
|
||||
}
|
||||
}
|
||||
await actor.createEmbeddedDocuments("Item", toAdd);
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user