Fix: problème de nombre d'utilisations

This commit is contained in:
Vincent Vandemeulebrouck 2023-02-24 00:38:14 +01:00
parent f97345e407
commit 3c3be7409d
2 changed files with 17 additions and 50 deletions

View File

@ -39,35 +39,31 @@ export class RdDCombatManager extends Combat {
static init() { static init() {
/* -------------------------------------------- */ /* -------------------------------------------- */
Hooks.on("getCombatTrackerEntryContext", (html, options) => { Hooks.on("getCombatTrackerEntryContext", (html, options) => { RdDCombatManager.pushInitiativeOptions(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()
});
}
/* -------------------------------------------- */
cleanItemUse() {
for (let turn of this.turns) {
turn.actor.resetItemUse()
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async nextRound() { async nextRound() {
this.cleanItemUse();
await this.finDeRound(); await this.finDeRound();
return await super.nextRound(); return await super.nextRound();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async onPreDeleteCombat() { async onPreDeleteCombat() {
await this.finDeRound({ terminer: true }); if (Misc.isUniqueConnectedGM()) {
await this.finDeRound({ terminer: true });
ChatUtility.removeChatMessageContaining(`<div data-combatid="${this.id}" data-combatmessage="actor-turn-summary">`)
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 }) { async finDeRound(options = { terminer: false }) {
this.turns.forEach(turn => turn.actor.resetItemUse());
for (let combatant of this.combatants) { for (let combatant of this.combatants) {
if (combatant.actor) { if (combatant.actor) {
await combatant.actor.finDeRound(options); await combatant.actor.finDeRound(options);
@ -144,9 +140,8 @@ export class RdDCombatManager extends Combat {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static calculInitiative(niveau, caracValue, bonusEcaille = 0) { static calculInitiative(niveau, caracValue, bonus = 0) {
let base = niveau + Math.floor(caracValue / 2); let base = niveau + Math.floor(caracValue / 2) + bonus;
base += bonusEcaille;
return "1d6" + (base >= 0 ? "+" : "") + base; return "1d6" + (base >= 0 ? "+" : "") + base;
} }
@ -420,18 +415,11 @@ export class RdDCombatManager extends Combat {
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDCombat { 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) { static onSocketMessage(sockmsg) {
switch (sockmsg.msg) { switch (sockmsg.msg) {
case "msg_encaisser": case "msg_encaisser": return RdDCombat.onMsgEncaisser(sockmsg.data);
return RdDCombat.onMsgEncaisser(sockmsg.data); case "msg_defense": return RdDCombat.onMsgDefense(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(`<div data-combatid="${combat.id}" data-combatmessage="actor-turn-summary">`)
game.messages.filter(m => ChatUtility.getMessageData(m, 'attacker-roll') != undefined && ChatUtility.getMessageData(m, 'defender-roll') != undefined)
.forEach(it => it.delete());
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static combatNouveauTour(combat) { static combatNouveauTour(combat) {
if (Misc.isUniqueConnectedGM()) { if (Misc.isUniqueConnectedGM()) {
@ -756,15 +734,6 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async attaque(competence, arme) { async attaque(competence, arme) {
// const nonIncarnee = this.defender.isEntite([ENTITE_NONINCARNE])
// const blurette = this.defender.isEntite([ENTITE_BLURETTE])
// if (nonIncarnee || blurette) {
// ChatMessage.create( {
// content: `<strong>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')) { if (!await this.attacker.accorder(this.defender, 'avant-attaque')) {
return; return;
} }
@ -970,9 +939,8 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
_filterArmesParade(defender, competence) { _filterArmesParade(defender, competence) {
let items = defender.items.filter(it => RdDItemArme.isArmeUtilisable(it) || RdDItemCompetenceCreature.isCompetenceParade(it)) let items = defender.items.filter(it => RdDItemArme.isArmeUtilisable(it) || RdDItemCompetenceCreature.isCompetenceParade(it))
for (let item of items) { items.forEach(item => item.system.nbUsage = defender.getItemUse(item.id)); // Ajout du # d'utilisation ce round
item.system.nbUsage = defender.getItemUse(item.id); // Ajout du # d'utilisation ce round
}
switch (competence.system.categorie) { switch (competence.system.categorie) {
case 'tir': case 'tir':
case 'lancer': case 'lancer':

View File

@ -180,7 +180,6 @@ export class SystemReveDeDragon {
RdDUtility.init(); RdDUtility.init();
RdDDice.init(); RdDDice.init();
RdDCommands.init(); RdDCommands.init();
RdDCombat.init();
RdDCombatManager.init(); RdDCombatManager.init();
RdDTokenHud.init(); RdDTokenHud.init();
RdDBaseActor.init(); RdDBaseActor.init();