From 09365eb7440221b4d30f97d333cfe44e62f34668 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sun, 3 Nov 2024 23:31:56 +0100 Subject: [PATCH] Fix: reset des utilisations d'items --- changelog.md | 1 + module/actor.js | 2 +- module/actor/base-actor-reve.js | 9 +-- module/actor/base-actor-sang.js | 6 +- module/actor/base-actor.js | 9 +-- module/rdd-combat.js | 99 +++++++++++++++++++-------------- 6 files changed, 71 insertions(+), 55 deletions(-) diff --git a/changelog.md b/changelog.md index 9ee25acc..b5063c31 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ - Fix - les achats des commerces sont de nouveau possibles - la commande /astro fonctionne de nouveau + - le nombre d'utilisations d'items est réinitialisé à chaque round et fin de combat ## 12.0.16 - Le secret d'Astrobazzarh - Fix: les jets envoyés messages uniquement au MJ ne sont plus envoyés à tous les autres joueurs (et dupliqués) diff --git a/module/actor.js b/module/actor.js index b8e6cd10..75eec4e8 100644 --- a/module/actor.js +++ b/module/actor.js @@ -2615,7 +2615,7 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ async resetItemUse() { - await this.setFlag(SYSTEM_RDD, 'itemUse', {}); + await this.unsetFlag(SYSTEM_RDD, 'itemUse'); } /* -------------------------------------------- */ diff --git a/module/actor/base-actor-reve.js b/module/actor/base-actor-reve.js index 21d2e608..53b5604b 100644 --- a/module/actor/base-actor-reve.js +++ b/module/actor/base-actor-reve.js @@ -78,8 +78,10 @@ export class RdDBaseActorReve extends RdDBaseActor { } async jetEndurance(resteEndurance = undefined) { return { jetEndurance: 0, sonne: false } } isDead() { return false } + isSonne() { return false } blessuresASoigner() { return [] } getEtatGeneral(options = { ethylisme: false }) { return 0 } + isActorCombat() { return true } async computeArmure(attackerRoll) { return this.getProtectionNaturelle() } async remiseANeuf() { } @@ -405,12 +407,7 @@ export class RdDBaseActorReve extends RdDBaseActor { return RdDItemArme.getCompetenceArme(arme, competenceName) } - verifierForceMin(item) { - } - /* -------------------------------------------- */ - async resetItemUse() { } - async incDecItemUse(itemId, inc = 1) { } - getItemUse(itemId) { return 0; } + verifierForceMin(item) { } /* -------------------------------------------- */ async encaisser() { await RdDEncaisser.encaisser(this) } diff --git a/module/actor/base-actor-sang.js b/module/actor/base-actor-sang.js index 48e5299a..26a58350 100644 --- a/module/actor/base-actor-sang.js +++ b/module/actor/base-actor-sang.js @@ -276,11 +276,11 @@ export class RdDBaseActorSang extends RdDBaseActorReve { ui.notifications.info(`${this.name} est hors combat, il ne reste donc pas sonné`); return; } - await this.setEffect(STATUSES.StatusStunned, sonne); + await this.setEffect(STATUSES.StatusStunned, sonne) } - getSonne() { - return this.getEffect(STATUSES.StatusStunned); + isSonne() { + return this.getEffect(STATUSES.StatusStunned) } isEffectAllowed(effectId) { return true } diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index b7553c68..7d8b64ab 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -205,11 +205,8 @@ export class RdDBaseActor extends Actor { /* -------------------------------------------- */ async onPreUpdateItem(item, change, options, id) { } - async onCreateItem(item, options, id) { } - async onDeleteItem(item, options, id) { } - async onUpdateActor(update, options, actorId) { } async onTimeChanging(oldTimestamp, newTimestamp) { @@ -708,5 +705,9 @@ export class RdDBaseActor extends Actor { } return undefined } - + async resetItemUse() { } + async incDecItemUse(itemId, inc = 1) { } + getItemUse(itemId) { return 0; } + async finDeRound(options = { terminer: false }) { } + isActorCombat() { return false } } \ No newline at end of file diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 22cca49a..fb10350e 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -42,7 +42,8 @@ export class RdDCombatManager extends Combat { /* -------------------------------------------- */ Hooks.on("getCombatTrackerEntryContext", (html, options) => { RdDCombatManager.pushInitiativeOptions(html, options); }); Hooks.on("updateCombat", (combat, change, options, userId) => { RdDCombat.onUpdateCombat(combat, change, options, userId) }); - Hooks.on("preDeleteCombat", (combat, html, id) => { combat.onPreDeleteCombat() }); + Hooks.on("preDeleteCombat", (combat, html, id) => { combat.onPreDeleteCombat() }) + Hooks.on("deleteCombat", (combat, html, id) => { combat.onDeleteCombat() }) } /* -------------------------------------------- */ @@ -61,20 +62,31 @@ export class RdDCombatManager extends Combat { RdDEmpoignade.deleteAllEmpoignades() } } - - /* -------------------------------------------- */ - async finDeRound(options = { terminer: false }) { - this.turns.forEach(turn => turn.actor.resetItemUse()); - - for (let combatant of this.combatants) { - if (combatant.actor) { - await combatant.actor.finDeRound(options); - } - else { - ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur!`) + async onDeleteCombat() { + if (Misc.isFirstConnectedGM()) { + if (game.combats.size <= 1) { + game.actors.forEach(actor => actor.resetItemUse()) } } } + + /* -------------------------------------------- */ + async finDeRound(options = { terminer: false }) { + + for (let combatant of this.combatants) { + if (!combatant.actor) { + ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur!`) + } + else if (!combatant.actor.isActorCombat()) { + ui.notifications.warn(`Le combatant ${combatant.name} ne peut pas combattre!`) + } + else { + await combatant.actor.finDeRound(options) + await combatant.actor.resetItemUse() + } + } + } + static calculAjustementInit(actor, arme) { const efficacite = (arme?.system.magique) ? arme.system.ecaille_efficacite : 0 const etatGeneral = actor.getEtatGeneral() ?? 0 @@ -125,7 +137,6 @@ export class RdDCombatManager extends Combat { } } } - //console.log("Combatat", c); const roll = combatant.getInitiativeRoll(rollFormula); if (!roll.total) { await roll.evaluate(); @@ -236,29 +247,12 @@ export class RdDCombatManager extends Combat { return attaque; } - static listActionsCreature(competences) { - return competences - .filter(it => RdDItemCompetenceCreature.isCompetenceAttaque(it)) - .map(it => RdDItemCompetenceCreature.armeCreature(it)) - .filter(it => it != undefined); - } - - static listActionsPossessions(actor) { - return RdDCombatManager._indexActions(actor.getPossessions().map(p => { - return { - name: p.name, - action: 'possession', - system: { - competence: p.name, - possessionid: p.system.possessionid, - } - } - })); - } - /* -------------------------------------------- */ static listActionsCombat(combatant) { const actor = combatant.actor; + if (!actor.isActorCombat()) { + return + } let actions = RdDCombatManager.listActionsPossessions(actor); if (actions.length > 0) { return actions; @@ -281,6 +275,26 @@ export class RdDCombatManager extends Combat { return RdDCombatManager._indexActions(actions); } + static listActionsCreature(competences) { + return competences + .filter(it => RdDItemCompetenceCreature.isCompetenceAttaque(it)) + .map(it => RdDItemCompetenceCreature.armeCreature(it)) + .filter(it => it != undefined); + } + + static listActionsPossessions(actor) { + return RdDCombatManager._indexActions(actor.getPossessions().map(p => { + return { + name: p.name, + action: 'possession', + system: { + competence: p.name, + possessionid: p.system.possessionid, + } + } + })); + } + static _indexActions(actions) { for (let index = 0; index < actions.length; index++) { actions[index].index = index; @@ -457,8 +471,8 @@ export class RdDCombat { if (Misc.isFirstConnectedGM()) { let turn = combat.turns.find(t => t.token?.id == combat.current.tokenId); if (turn?.actor) { - RdDCombat.displayActorCombatStatus(combat, turn.actor, turn.token); // TODO Playaudio for player?? + RdDCombat.displayActorCombatStatus(combat, turn.actor, turn.token); } } } @@ -574,15 +588,15 @@ export class RdDCombat { static $extractAttackerTokenData(attacker, attackerTokenId) { const token = canvas.tokens.get(attackerTokenId); - return token ? Targets.extractTokenData(token) : Targets.buildActorTokenData(attackerTokenId, attacker) + return token ? Targets.extractTokenData(token) : Targets.buildActorTokenData(attackerTokenId, attacker) } - + static $extractDefenderTokenData(defender, defenderTokenId, target) { if (target) { return Targets.extractTokenData(target) } const token = canvas.tokens.get(defenderTokenId); - return token ? Targets.extractTokenData(token) : Targets.buildActorTokenData(defenderTokenId, defender) + return token ? Targets.extractTokenData(token) : Targets.buildActorTokenData(defenderTokenId, defender) } @@ -811,7 +825,7 @@ export class RdDCombat { dialog.render(true); } - + /* -------------------------------------------- */ _prepareAttaque(competence, arme) { let rollData = { @@ -825,7 +839,7 @@ export class RdDCombat { targetToken: this.defenderToken, essais: {} }; - + if (this.attacker.isCreatureEntite()) { RdDItemCompetenceCreature.setRollDataCreature(rollData); } @@ -978,7 +992,7 @@ export class RdDCombat { } /* -------------------------------------------- */ - _filterArmesParade(defender, competence) { + _filterArmesParade(defender, competence, arme) { let items = defender.items.filter(it => RdDItemArme.isArmeUtilisable(it) || RdDItemCompetenceCreature.isCompetenceParade(it)) items.forEach(item => item.system.nbUsage = defender.getItemUse(item.id)); // Ajout du # d'utilisation ce round @@ -1335,11 +1349,14 @@ export class RdDCombat { /* -------------------------------------------- */ static async displayActorCombatStatus(combat, actor, token) { + if (!actor?.isActorCombat()) { + return + } let formData = { combatId: combat._id, alias: token.name ?? actor.name, etatGeneral: actor.getEtatGeneral(), - isSonne: actor.getSonne(), + isSonne: actor.isSonne(), blessuresStatus: actor.computeResumeBlessure(), SConst: actor.getSConst(), actorId: actor.id,