Spell and Retreat Announcement
OSE Author added spell and retreat announcement. Fixed a few bugs in his code regarding initiative settings calls.master
parent
3280d4f84a
commit
024660b6bf
37
src/acks.js
37
src/acks.js
|
@ -71,9 +71,6 @@ Hooks.once("setup", function () {
|
|||
return obj;
|
||||
}, {});
|
||||
}
|
||||
for (let l of CONFIG.ACKS.languages) {
|
||||
CONFIG.ACKS.languages[l] = game.i18n.localize(CONFIG.ACKS.languages[l]);
|
||||
}
|
||||
});
|
||||
|
||||
Hooks.once("ready", async () => {
|
||||
|
@ -96,7 +93,7 @@ Hooks.on("renderSidebarTab", async (object, html) => {
|
|||
// License text
|
||||
const template = "systems/acks/templates/chat/license.html";
|
||||
const rendered = await renderTemplate(template);
|
||||
gamesystem.append(rendered);
|
||||
gamesystem.find(".system").append(rendered);
|
||||
|
||||
// User guide
|
||||
let docs = html.find("button[data-action='docs']");
|
||||
|
@ -115,34 +112,10 @@ Hooks.on("preCreateCombatant", (combat, data, options, id) => {
|
|||
}
|
||||
});
|
||||
|
||||
Hooks.on("preUpdateCombatant", (combat, combatant, data) => {
|
||||
AcksCombat.updateCombatant(combat, combatant, data);
|
||||
});
|
||||
|
||||
Hooks.on("renderCombatTracker", (object, html, data) => {
|
||||
AcksCombat.format(object, html, data);
|
||||
});
|
||||
|
||||
Hooks.on("preUpdateCombat", async (combat, data, diff, id) => {
|
||||
let init = game.settings.get("acks", "initiative");
|
||||
let reroll = game.settings.get("acks", "rerollInitiative");
|
||||
if (!data.round) {
|
||||
return;
|
||||
}
|
||||
if (data.round !== 1) {
|
||||
if (reroll === "reset") {
|
||||
OseCombat.resetInitiative(combat, data, diff, id);
|
||||
return;
|
||||
} else if (reroll === "keep") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (init === "group") {
|
||||
AcksCombat.rollInitiative(combat, data, diff, id);
|
||||
} else if (init === "individual") {
|
||||
AcksCombat.individualInitiative(combat, data, diff, id);
|
||||
}
|
||||
});
|
||||
Hooks.on("preUpdateCombatant", AcksCombat.updateCombatant);
|
||||
Hooks.on("renderCombatTracker", AcksCombat.format);
|
||||
Hooks.on("preUpdateCombat", AcksCombat.preUpdateCombat);
|
||||
Hooks.on("getCombatTrackerEntryContext", AcksCombat.addContextEntry);
|
||||
|
||||
Hooks.on("renderChatLog", (app, html, data) => AcksItem.chatListeners(html));
|
||||
Hooks.on("getChatLogEntryContext", chat.addChatMessageContextOptions);
|
||||
|
|
|
@ -165,8 +165,6 @@
|
|||
"ACKS.Setting.Initiative": "Initiative",
|
||||
"ACKS.Setting.InitiativeHint": "Grouped or individual initiative.",
|
||||
"ACKS.Setting.InitiativeIndividual": "Individual initiative",
|
||||
|
||||
|
||||
"ACKS.Setting.InitiativeGroup": "Grouped Initiative",
|
||||
"ACKS.Setting.RerollInitiative": "Initiative persistence",
|
||||
"ACKS.Setting.RerollInitiativeHint": "Keeps, resets or rerolls initiative each round",
|
||||
|
|
|
@ -32,7 +32,7 @@ export class AcksCombat {
|
|||
}
|
||||
|
||||
static async resetInitiative(combat, data) {
|
||||
let reroll = game.settings.get("acks", "rerollInitiative");
|
||||
let reroll = game.settings.get("acks", "initiative");
|
||||
if (!["reset", "reroll"].includes(reroll)) {
|
||||
return;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ export class AcksCombat {
|
|||
|
||||
// Determine the roll mode
|
||||
let rollMode = game.settings.get("core", "rollMode");
|
||||
if ((c.token.hidden || c.hidden) && (rollMode === "roll")) rollMode = "gmroll";
|
||||
if ((c.token.hidden || c.hidden) && (rollMode === "roll")) rollMode = "gmroll";
|
||||
|
||||
// Construct chat message data
|
||||
let messageData = mergeObject({
|
||||
|
@ -88,7 +88,23 @@ export class AcksCombat {
|
|||
? '<i class="fas fa-dizzy"></i>'
|
||||
: span.innerHTML;
|
||||
});
|
||||
let init = game.settings.get("acks", "initiative") == "group";
|
||||
|
||||
html.find(".combatant").each((_, ct) => {
|
||||
// Append spellcast and retreat
|
||||
const controls = $(ct).find(".combatant-controls .combatant-control");
|
||||
const cmbtant = object.combat.getCombatant(ct.dataset.combatantId);
|
||||
const moveActive = cmbtant.flags.acks && cmbtant.flags.acks.moveInCombat ? "active" : "";
|
||||
controls.eq(1).after(
|
||||
`<a class='combatant-control move-combat ${moveActive}'><i class='fas fa-running'></i></a>`
|
||||
);
|
||||
const spellActive = cmbtant.flags.acks && cmbtant.flags.acks.prepareSpell ? "active" : "";
|
||||
controls.eq(1).after(
|
||||
`<a class='combatant-control prepare-spell ${spellActive}'><i class='fas fa-magic'></i></a>`
|
||||
);
|
||||
});
|
||||
AcksCombat.announceListener(html);
|
||||
|
||||
let init = game.settings.get("acks", "initiative") === "group";
|
||||
if (!init) {
|
||||
return;
|
||||
}
|
||||
|
@ -107,7 +123,7 @@ export class AcksCombat {
|
|||
$(ct).find(".roll").remove();
|
||||
|
||||
// Get group color
|
||||
let cmbtant = object.combat.getCombatant(ct.dataset.combatantId);
|
||||
const cmbtant = object.combat.getCombatant(ct.dataset.combatantId);
|
||||
let color = cmbtant.flags.acks.group;
|
||||
|
||||
// Append colored flag
|
||||
|
@ -145,6 +161,29 @@ export class AcksCombat {
|
|||
}
|
||||
}
|
||||
|
||||
static announceListener(html) {
|
||||
html.find(".combatant-control.prepare-spell").click((ev) => {
|
||||
ev.preventDefault();
|
||||
// Toggle spell announcement
|
||||
let id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
||||
let isActive = ev.currentTarget.classList.contains('active');
|
||||
game.combat.updateCombatant({
|
||||
_id: id,
|
||||
flags: { acks: { prepareSpell: !isActive } },
|
||||
});
|
||||
});
|
||||
html.find(".combatant-control.move-combat").click((ev) => {
|
||||
ev.preventDefault();
|
||||
// Toggle spell announcement
|
||||
let id = $(ev.currentTarget).closest(".combatant")[0].dataset.combatantId;
|
||||
let isActive = ev.currentTarget.classList.contains('active');
|
||||
game.combat.updateCombatant({
|
||||
_id: id,
|
||||
flags: { acks: { moveInCombat: !isActive } },
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
static addListeners(html) {
|
||||
// Cycle through colors
|
||||
html.find(".combatant-control.flag").click((ev) => {
|
||||
|
@ -198,4 +237,37 @@ export class AcksCombat {
|
|||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
static activateCombatant(li) {
|
||||
const turn = game.combat.turns.findIndex(turn => turn._id === li.data('combatant-id'));
|
||||
game.combat.update({turn: turn})
|
||||
}
|
||||
|
||||
static addContextEntry(html, options) {
|
||||
options.unshift({
|
||||
name: "Set Active",
|
||||
icon: '<i class="fas fa-star-of-life"></i>',
|
||||
callback: AcksCombat.activateCombatant
|
||||
});
|
||||
}
|
||||
|
||||
static async preUpdateCombat(combat, data, diff, id) {
|
||||
let init = game.settings.get("acks", "initiative");
|
||||
let reroll = game.settings.get("acks", "initiative");
|
||||
if (!data.round) {
|
||||
return;
|
||||
}
|
||||
if (data.round !== 1) {
|
||||
if (reroll === "reset") {
|
||||
AcksCombat.resetInitiative(combat, data, diff, id);
|
||||
return;
|
||||
} else if (reroll === "keep") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (init === "group") {
|
||||
AcksCombat.rollInitiative(combat, data, diff, id);
|
||||
} else if (init === "individual") {
|
||||
AcksCombat.individualInitiative(combat, data, diff, id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +1,6 @@
|
|||
export const registerSettings = function () {
|
||||
|
||||
game.settings.register("acks", "initiative", {
|
||||
name: game.i18n.localize("ACKS.Setting.Initiative"),
|
||||
hint: game.i18n.localize("ACKS.Setting.InitiativeHint"),
|
||||
default: "group",
|
||||
scope: "world",
|
||||
type: String,
|
||||
config: true,
|
||||
choices: {
|
||||
disabled: "ACKS.Setting.InitiativeOnce",
|
||||
rerolled: "ACKS.Setting.InitiativeReroll",
|
||||
reset: "ACKS.Setting.InitiativeReset",
|
||||
group: "ACKS.Setting.InitiativeGroup",
|
||||
},
|
||||
onChange: _ => window.location.reload()
|
||||
});
|
||||
|
||||
game.settings.register("acks", "ascendingAC", {
|
||||
name: game.i18n.localize("ACKS.Setting.RerollInitiative"),
|
||||
hint: game.i18n.localize("ACKS.Setting.RerollInitiativeHint"),
|
||||
default: "reset",
|
||||
|
|
|
@ -36,7 +36,7 @@ function drawTreasure(table, data) {
|
|||
return roll.total <= chance;
|
||||
};
|
||||
data.treasure = {};
|
||||
if (table.getFlag('ose', 'treasure')) {
|
||||
if (table.getFlag('acks', 'treasure')) {
|
||||
table.results.forEach((r) => {
|
||||
if (percent(r.weight)) {
|
||||
const text = table._getResultChatText(r);
|
||||
|
|
Loading…
Reference in New Issue