From 297c94adb765b24ddaee5cee5b9216bed8334a6e Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Fri, 30 Jun 2023 21:11:29 +0200 Subject: [PATCH] Fixes from 29th of june --- modules/hero6-actor-sheet.js | 7 ++ modules/hero6-actor.js | 28 ++++++ modules/hero6-combat.js | 93 ++++++++++++------- modules/hero6-main.js | 6 +- modules/hero6-utility.js | 5 + templates/actors/actor-sheet.hbs | 5 +- templates/apps/combat-tracker.hbs | 4 +- .../partial-actor-equipment-section.hbs | 2 +- 8 files changed, 109 insertions(+), 41 deletions(-) diff --git a/modules/hero6-actor-sheet.js b/modules/hero6-actor-sheet.js index cae244c..b369a01 100644 --- a/modules/hero6-actor-sheet.js +++ b/modules/hero6-actor-sheet.js @@ -185,6 +185,13 @@ export class Hero6ActorSheet extends ActorSheet { this.actor.rollWeapon(skillId) }); + html.find('.hold-action').click((event) => { + this.actor.holdAction() + }); + html.find('.abort-action').click((event) => { + this.actor.abortAction() + }); + html.find('.lock-unlock-sheet').click((event) => { this.options.editScore = !this.options.editScore; this.render(true); diff --git a/modules/hero6-actor.js b/modules/hero6-actor.js index a0a5362..a77bb78 100644 --- a/modules/hero6-actor.js +++ b/modules/hero6-actor.js @@ -385,11 +385,39 @@ export class Hero6Actor extends Actor { await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity } } + /* -------------------------------------------- */ + async cleanCombat() { + await this.setFlag("world", "hold-action", false) + await this.setFlag("world", "abort-action", false) + } + async holdAction() { + if (this.getFlag("world", "hold-action")) { + await this.setFlag("world", "hold-action", false) + } else { + await this.setFlag("world", "hold-action", true) + } + game.combat.rebuildInitiative() + } + async abortAction() { + if (this.getFlag("world", "abort-action")) { + await this.setFlag("world", "abort-action", false) + } else { + await this.setFlag("world", "abort-action", true) + } + game.combat.rebuildInitiative() + } + getHoldAction() { + return this.getFlag("world", "hold-action") + } + getAbortAction() { + return this.getFlag("world", "abort-action") + } /* -------------------------------------------- */ hasPhase(segmentNumber) { let index = Math.min(Math.max(this.system.characteristics.spd.value, 1), 12) // Security bounds let phases = __speed2Segments[index] + console.log("index", segmentNumber, index, phases, phases.includes(segmentNumber)) return phases.includes(segmentNumber) } /* -------------------------------------------- */ diff --git a/modules/hero6-combat.js b/modules/hero6-combat.js index 337a60b..48b4a8d 100644 --- a/modules/hero6-combat.js +++ b/modules/hero6-combat.js @@ -16,47 +16,33 @@ export class Hero6CombatTracker extends CombatTracker { export class Hero6Combat extends Combat { /* -------------------------------------------- */ - static init() { + static ready() { Hooks.on("getCombatTrackerEntryContext", (html, options) => { Hero6Combat.pushMenuOptions(html, options); }); + game.combat.settings.resource = "characteristics.spd.value"; } + /* -------------------------------------------- */ static pushMenuOptions(html, options) { - console.log(">>>>>>>>>>>>>>>>>>>>>>>< MENU OPTIONS!!!!!") let newOpt for (let i = 0; i < options.length; i++) { let option = options[i]; if (option.name == 'COMBAT.CombatantReroll') { // Replace ! - option.name = "Hold action"; + option.name = "Hold/Unhold action"; option.condition = true; option.icon = ''; option.callback = target => { Hero6Combat.holdAction(target.data('combatant-id')); } - newOpt = duplicate(option) + //newOpt = duplicate(option) } } - newOpt.name = "Abort action" - newOpt.callback = target => { - Hero6Combat.abortAction(target.data('combatant-id')); - } - options.push( newOpt) + //options.push(newOpt) } /* -------------------------------------------- */ static holdAction(combatantId) { - console.log("Combatant HOLD : ", combatantId) const combatant = game.combat.combatants.get(combatantId) - combatant.setFlag("world", "hero6-hold-action", true) - combatant.update({name: combatant.name + " (H)"}) - console.log("HOLD", combatant) - } - /* -------------------------------------------- */ - static abortAction(html, combatantId) { - console.log("Combatant ABORT : ", combatantId); - const combatant = game.combat.combatants.get(combatantId); - combatant.setFlag("world", "hero6-abort-action", true) - combatant.update({name: combatant.name + " (A)"}) - console.log("ABORT", combatant) + combatant.actor.holdAction() } /* -------------------------------------------- */ @@ -68,27 +54,69 @@ export class Hero6Combat extends Combat { } /* -------------------------------------------- */ - async computeInitiative(c) { - let id = c._id || c.id - if (c.actor.hasPhase(this.segmentNumber)) { - let baseInit = c.actor ? c.actor.getBaseInit() : - 1; - await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: baseInit }]); - } else { - await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: -1, visible: false, active: false }]); + async startCombat() { + game.combat.settings.resource = "characteristics.spd.value"; + + let updList = [] + for (let c of this.combatants) { + this.computeInitiative(c, updList) + await c.actor.cleanCombat() } - console.log("Combatant", c) + if (updList.length > 0) { + await this.updateEmbeddedDocuments("Combatant", updList); + } + + super.startCombat(); } + + /* -------------------------------------------- */ + computeInitiative(c, updList) { + let id = c._id || c.id + if (c.actor.hasPhase(this.segmentNumber) || c.actor.getHoldAction()) { + let baseInit = c.actor ? c.actor.getBaseInit() : 0; + let name = c.actor.name + if (c.actor.getHoldAction()) { + name = c.actor.name + " (H)" + } + if (c.actor.getAbortAction()) { + name = c.actor.name + " (A)" + } + updList.push({ _id: id, name: name, initiative: baseInit, holdAction: c.holdAction }) + } else { + updList.push({ _id: id, name: name, initiative: 0, holdAction: c.holdAction }) + } + } + /* -------------------------------------------- */ async rollInitiative(ids, formula = undefined, messageOptions = {}) { ids = typeof ids === "string" ? [ids] : ids; + + console.log("Roll INIT") + let updList = [] for (let cId = 0; cId < ids.length; cId++) { const c = this.combatants.get(ids[cId]) - await this.computeInitiative(c) + this.computeInitiative(c, updList) + } + + if (updList.length > 0) { + await this.updateEmbeddedDocuments("Combatant", updList); } return this; } + /* -------------------------------------------- */ + async rebuildInitiative() { + let updList = [] + for (let c of this.combatants) { + this.computeInitiative(c, updList) + } + console.log(this.combatants, updList) + if (updList.length > 0) { + await this.updateEmbeddedDocuments("Combatant", updList); + } + } + /* -------------------------------------------- */ nextRound() { let turn = this.turn === null ? null : 0; // Preserve the fact that it's no-one's turn currently. @@ -119,9 +147,7 @@ export class Hero6Combat extends Combat { this.segmentNumber = turnData.segmentNumber; // Re-compute init of actors - for (let c of this.combatants) { - this.computeInitiative(c) - } + this.rebuildInitiative() // Update the document, passing data through a hook first const updateData = { round: nextRound, turn, segmentNumber: turnData.segmentNumber, turnNumber: turnData.turnNumber }; @@ -133,7 +159,6 @@ export class Hero6Combat extends Combat { /* -------------------------------------------- */ async _onCreateEmbeddedDocuments(type, documents, result, options, userId) { - console.log(">>>>", documents) super._onCreateEmbeddedDocuments(type, documents, result, options, userId) } diff --git a/modules/hero6-main.js b/modules/hero6-main.js index 09d57d9..eb27e5d 100644 --- a/modules/hero6-main.js +++ b/modules/hero6-main.js @@ -43,8 +43,8 @@ Hooks.once("init", async function () { formula: "1d6", decimals: 3 }; - - /* -------------------------------------------- */ + + /* ------------------------------- ------------- */ game.socket.on("system.fvtt-hero-system-6", data => { Hero6Utility.onSocketMesssage(data) }); @@ -96,7 +96,7 @@ Hooks.once("ready", function () { welcomeMessage(); Hero6Utility.ready() Hero6Commands.ready() - Hero6Combat.init() + Hero6Combat.ready() }) diff --git a/modules/hero6-utility.js b/modules/hero6-utility.js index 2858b28..58108f7 100644 --- a/modules/hero6-utility.js +++ b/modules/hero6-utility.js @@ -52,6 +52,11 @@ export class Hero6Utility { } return false }) + Handlebars.registerHelper('checkInit', function (value) { + let myValue = Number(value) || 0 + return myValue > 0 + }) + this.gameSettings() diff --git a/templates/actors/actor-sheet.hbs b/templates/actors/actor-sheet.hbs index 7f84f60..6d82c0a 100644 --- a/templates/actors/actor-sheet.hbs +++ b/templates/actors/actor-sheet.hbs @@ -182,7 +182,10 @@ - +   + + +   {{system.biodata.presenceattack.displayFormula}} diff --git a/templates/apps/combat-tracker.hbs b/templates/apps/combat-tracker.hbs index 3f7e69e..1102abd 100644 --- a/templates/apps/combat-tracker.hbs +++ b/templates/apps/combat-tracker.hbs @@ -60,11 +60,11 @@
    {{#each turns}} - {{#if (ne this.initiative "-1")}} + {{#if (checkInit this.initiative)}}
  1. {{this.name}}