From 3c3be7409de3087082561a6e65f6108d1bc062f0 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 24 Feb 2023 00:38:14 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20probl=C3=A8me=20de=20nombre=20d'utilisat?= =?UTF-8?q?ions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/rdd-combat.js | 66 ++++++++++++-------------------------------- module/rdd-main.js | 1 - 2 files changed, 17 insertions(+), 50 deletions(-) diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 9aedd422..904384d6 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -39,35 +39,31 @@ export class RdDCombatManager extends Combat { static init() { /* -------------------------------------------- */ - Hooks.on("getCombatTrackerEntryContext", (html, options) => { - RdDCombatManager.pushInitiativeOptions(html, options); - }); - Hooks.on("preDeleteCombat", (combat, html, id) => { - combat.onPreDeleteCombat() - }); - } - - /* -------------------------------------------- */ - cleanItemUse() { - for (let turn of this.turns) { - turn.actor.resetItemUse() - } + 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() }); } /* -------------------------------------------- */ async nextRound() { - this.cleanItemUse(); await this.finDeRound(); return await super.nextRound(); } /* -------------------------------------------- */ async onPreDeleteCombat() { - await this.finDeRound({ terminer: true }); + if (Misc.isUniqueConnectedGM()) { + await this.finDeRound({ terminer: true }); + ChatUtility.removeChatMessageContaining(`
`) + game.messages.filter(m => ChatUtility.getMessageData(m, 'attacker-roll') != undefined && ChatUtility.getMessageData(m, 'defender-roll') != undefined) + .forEach(it => it.delete()); + } } /* -------------------------------------------- */ 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); @@ -144,9 +140,8 @@ export class RdDCombatManager extends Combat { } /* -------------------------------------------- */ - static calculInitiative(niveau, caracValue, bonusEcaille = 0) { - let base = niveau + Math.floor(caracValue / 2); - base += bonusEcaille; + static calculInitiative(niveau, caracValue, bonus = 0) { + let base = niveau + Math.floor(caracValue / 2) + bonus; return "1d6" + (base >= 0 ? "+" : "") + base; } @@ -420,18 +415,11 @@ export class RdDCombatManager extends Combat { /* -------------------------------------------- */ export class RdDCombat { - static init() { - Hooks.on("updateCombat", (combat, change, options, userId) => { RdDCombat.onUpdateCombat(combat, change, options, userId) }); - Hooks.on("preDeleteCombat", (combat, options, userId) => { RdDCombat.onPreDeleteCombat(combat, options, userId); }); - } - /* -------------------------------------------- */ static onSocketMessage(sockmsg) { switch (sockmsg.msg) { - case "msg_encaisser": - return RdDCombat.onMsgEncaisser(sockmsg.data); - case "msg_defense": - return RdDCombat.onMsgDefense(sockmsg.data); + case "msg_encaisser": return RdDCombat.onMsgEncaisser(sockmsg.data); + case "msg_defense": return RdDCombat.onMsgDefense(sockmsg.data); } } @@ -442,16 +430,6 @@ export class RdDCombat { } } - /* -------------------------------------------- */ - static onPreDeleteCombat(combat, options, userId) { - if (Misc.isUniqueConnectedGM()) { - combat.cleanItemUse(); - ChatUtility.removeChatMessageContaining(`
`) - game.messages.filter(m => ChatUtility.getMessageData(m, 'attacker-roll') != undefined && ChatUtility.getMessageData(m, 'defender-roll') != undefined) - .forEach(it => it.delete()); - } - } - /* -------------------------------------------- */ static combatNouveauTour(combat) { if (Misc.isUniqueConnectedGM()) { @@ -756,15 +734,6 @@ export class RdDCombat { /* -------------------------------------------- */ async attaque(competence, arme) { - // const nonIncarnee = this.defender.isEntite([ENTITE_NONINCARNE]) - // const blurette = this.defender.isEntite([ENTITE_BLURETTE]) - // if (nonIncarnee || blurette) { - // ChatMessage.create( { - // content: `La cible est ${nonIncarnee ? 'non incarnée' : 'une blurette'}. - // Il est impossible de l'atteindre.`, - // whisper: ChatMessage.getWhisperRecipients("GM")}) - // } - if (!await this.attacker.accorder(this.defender, 'avant-attaque')) { return; } @@ -970,9 +939,8 @@ export class RdDCombat { /* -------------------------------------------- */ _filterArmesParade(defender, competence) { let items = defender.items.filter(it => RdDItemArme.isArmeUtilisable(it) || RdDItemCompetenceCreature.isCompetenceParade(it)) - for (let item of items) { - item.system.nbUsage = defender.getItemUse(item.id); // Ajout du # d'utilisation ce round - } + items.forEach(item => item.system.nbUsage = defender.getItemUse(item.id)); // Ajout du # d'utilisation ce round + switch (competence.system.categorie) { case 'tir': case 'lancer': diff --git a/module/rdd-main.js b/module/rdd-main.js index 1ca85977..f475b64d 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -180,7 +180,6 @@ export class SystemReveDeDragon { RdDUtility.init(); RdDDice.init(); RdDCommands.init(); - RdDCombat.init(); RdDCombatManager.init(); RdDTokenHud.init(); RdDBaseActor.init();