From c857def3608c5921de3288d076239418c84b7e52 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 30 Jun 2021 01:01:24 +0200 Subject: [PATCH] =?UTF-8?q?Sonn=C3=A9=20est=20un=20StatusEffect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor-sheet.js | 3 -- module/actor.js | 48 ++++++++++++++--------------- module/misc.js | 4 +++ module/rdd-combat.js | 27 ++++++++++------ module/rdd-roll-encaisser.js | 5 +-- module/status-effects.js | 2 +- template.json | 9 ------ templates/actor-creature-sheet.html | 4 --- templates/actor-sheet.html | 6 ---- 9 files changed, 49 insertions(+), 59 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 5f02626f..b092334c 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -527,9 +527,6 @@ export class RdDActorSheet extends ActorSheet { html.find('#endurance-moins').click(async event => { this.actor.santeIncDec("endurance", -1); }); - html.find('.data-sante-sonne').click(async event => { - this.actor.setSonne(event.currentTarget.checked); - }); html.find('#ptreve-actuel-plus').click(async event => { this.actor.reveActuelIncDec(1); }); diff --git a/module/actor.js b/module/actor.js index d52d29eb..0dbda8a0 100644 --- a/module/actor.js +++ b/module/actor.js @@ -428,7 +428,7 @@ export class RdDActor extends Actor { if (niveauSurprise > 1) { return 'totale'; } - if (niveauSurprise == 1 || this.getSonne()) { + if (niveauSurprise == 1) { return 'demi'; } return ''; @@ -1509,28 +1509,30 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - getSonneRound() { - return Misc.templateData(this).sante.sonne?.round ?? -1; - } - - /* -------------------------------------------- */ - async verifierSonneRound(round) { - if (this.getSonne()) { - if (round > this.getSonneRound() + 1) { - await this.setSonne(false, -1); // Nettoyer l'état sonné - ChatMessage.create({ content: `${this.name} n'est plus sonné ce round !` }); + async finDeRound(options = {terminer:false}) { + for (let effect of this.getActiveEffects()) { + if (effect.duration.type !== 'none' && (effect.duration.remaining <= 0 || options.terminer)) { + if (effect.data.origin) { + await effect.update({ 'disabled': true }); + } + else { + await effect.delete(); + } + ChatMessage.create({ content: `${this.name} n'est plus ${Misc.lowerFirst(game.i18n.localize(effect.data.label))} !` }); } } } /* -------------------------------------------- */ async setSonne(sonne = true) { - if (!game.combat || this.isEntiteCauchemar()) { + if (this.isEntiteCauchemar()) { return; } - await this.setStatusEffect("EFFECT.StatusStunned", sonne, { - duration: (sonne && game.combat) ? { rounds: 2 } : undefined - }); + if (!game.combat && sonne){ + ui.notifications.info("Le personnage est hors combat, il ne reste donc pas sonné"); + return; + } + await this.setStatusEffect("EFFECT.StatusStunned", sonne); } /* -------------------------------------------- */ @@ -1557,12 +1559,11 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ - async testSiSonne(sante, endurance) { + async testSiSonne(endurance) { const result = await this._jetEndurance(endurance); if (result.roll.total == 1) { ChatMessage.create({ content: await this._gainXpConstitutionJetEndurance() }); } - sante.sonne.value ||= result.sonne; return result; } @@ -1631,7 +1632,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async santeIncDec(name, inc, options = { isCritique: false, ethylisme: false }) { + async santeIncDec(name, inc, isCritique = false) { if (name == 'fatigue' && !ReglesOptionelles.isUsing("appliquer-fatigue")) { return; } @@ -1650,7 +1651,7 @@ export class RdDActor extends Actor { //console.log("New value ", inc, minValue, result.newValue); let fatigue = 0; if (name == "endurance" && !this.isEntiteCauchemar()) { - if (result.newValue == 0 && inc < 0 && !options.isCritique) { // perte endurance et endurance devient 0 (sauf critique) -> -1 vie + if (result.newValue == 0 && inc < 0 && !isCritique) { // perte endurance et endurance devient 0 (sauf critique) -> -1 vie sante.vie.value--; result.perteVie = true; } @@ -1660,14 +1661,13 @@ export class RdDActor extends Actor { } const perte = compteur.value - result.newValue; result.perte = perte; - if (perte > 1 && !options.ethylisme) { + if (perte > 1) { // Peut-être sonné si 2 points d'endurance perdus d'un coup - const testIsSonne = await this.testSiSonne(sante, result.newValue); + const testIsSonne = await this.testSiSonne(result.newValue); result.sonne = testIsSonne.sonne; result.jetEndurance = testIsSonne.roll.total; } else if (inc > 0) { await this.setSonne(false); - sante.sonne.value = false; } if (sante.fatigue && inc < 0) { // Each endurance lost -> fatigue lost fatigue = perte; @@ -1934,7 +1934,7 @@ export class RdDActor extends Actor { ethylisme.nb_doses = 0; let perte = await RdDDice.rollTotal("1d6", { showDice: true }); - ethylismeData.perteEndurance = await this.santeIncDec("endurance", -perte, { ethylisme: true }); + ethylismeData.perteEndurance = await this.santeIncDec("endurance", -perte); if (!ethylisme.jet_moral) { ethylismeData.jetMoral = await this._jetMoral('heureuse'); @@ -3229,7 +3229,7 @@ export class RdDActor extends Actor { const perteVie = this.isEntiteCauchemar() ? { newValue: 0 } : await this.santeIncDec("vie", - encaissement.vie); - const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, { critiques: encaissement.critiques > 0 }); + const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, encaissement.critiques > 0); this.computeEtatGeneral(); diff --git a/module/misc.js b/module/misc.js index 3c115740..da74c589 100644 --- a/module/misc.js +++ b/module/misc.js @@ -13,6 +13,10 @@ export class Misc { return text.charAt(0).toUpperCase() + text.slice(1); } + static lowerFirst(text) { + return text.charAt(0).toLowerCase() + text.slice(1); + } + static toSignedString(number) { const value = parseInt(number) const isPositiveNumber = value != NaN && value > 0; diff --git a/module/rdd-combat.js b/module/rdd-combat.js index b7904ac6..c317a5ce 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -38,6 +38,9 @@ export class RdDCombatManager extends Combat { Hooks.on("getCombatTrackerEntryContext", (html, options) => { RdDCombatManager.pushInitiativeOptions(html, options); }); + Hooks.on("preDeleteCombat", (combat, html, id) => { + combat.onPreDeleteCombat() + }); } /* -------------------------------------------- */ @@ -48,10 +51,22 @@ export class RdDCombatManager extends Combat { } /* -------------------------------------------- */ - cleanSonne() { + async nextRound() { + this.cleanItemUse(); + await this.finDeRound(); + return await super.nextRound(); + } + + /* -------------------------------------------- */ + async onPreDeleteCombat() { + await this.finDeRound({ terminer: true }); + } + + /* -------------------------------------------- */ + async finDeRound(options = { terminer: false }) { for (let combatant of this.data.combatants) { if (combatant.actor) { - combatant.actor.verifierSonneRound(this.current.round); + await combatant.actor.finDeRound(options); } else { ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur!`) @@ -59,14 +74,6 @@ export class RdDCombatManager extends Combat { } } - /* -------------------------------------------- */ - async nextRound() { - //console.log('New round !');s - this.cleanItemUse(); - this.cleanSonne(); - return super.nextRound(); - } - /************************************************************************************/ async rollInitiative(ids, formula = undefined, messageOptions = {}) { console.log(`${game.data.system.data.title} | Combat.rollInitiative()`, ids, formula, messageOptions); diff --git a/module/rdd-roll-encaisser.js b/module/rdd-roll-encaisser.js index a8e0d6e5..8e87e284 100644 --- a/module/rdd-roll-encaisser.js +++ b/module/rdd-roll-encaisser.js @@ -8,8 +8,9 @@ export class RdDEncaisser extends Dialog { constructor(html, actor) { // Common conf const buttonsCreatures = { - "mortel": { label: "mortel", callback: html => this.performEncaisser("mortel") }, - "non-mortel": { label: "non-mortel", callback: html => this.performEncaisser("non-mortel") }, + "mortel": { label: "Mortel", callback: html => this.performEncaisser("mortel") }, + "non-mortel": { label: "Non-mortel", callback: html => this.performEncaisser("non-mortel") }, + "sonne": { label: "Sonné", callback: html => this.actor.setSonne() }, }; const buttonsEntitesCauchemar = { "cauchemar": { label: "cauchemar", callback: html => this.performEncaisser("cauchemar") } diff --git a/module/status-effects.js b/module/status-effects.js index 59319ab1..b8f838c1 100644 --- a/module/status-effects.js +++ b/module/status-effects.js @@ -1,6 +1,6 @@ const rddStatusEffects = [ - { rdd: true, id: 'stun', label: 'EFFECT.StatusStunned', icon: 'icons/svg/stoned.svg' }, + { rdd: true, id: 'stun', label: 'EFFECT.StatusStunned', icon: 'icons/svg/stoned.svg', "duration.rounds": 1 }, { rdd: true, id: 'bleeding', label: 'EFFECT.StatusBleeding', icon: 'icons/svg/blood.svg' }, { rdd: true, id: 'prone', label: 'EFFECT.StatusProne', icon: 'icons/svg/falling.svg' }, { rdd: true, id: 'grappling', tint: '#33cc33', label: 'EFFECT.StatusGrappling', icon: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp' }, diff --git a/template.json b/template.json index c5bee0fa..14df291c 100644 --- a/template.json +++ b/template.json @@ -164,11 +164,6 @@ "value": 10, "label": "Endurance", "derivee": false - }, - "sonne": { - "value": false, - "round": -1, - "label": "Sonné" } }, "blessures": { @@ -374,10 +369,6 @@ "value": 0, "label": "Fatigue", "derivee": true - }, - "sonne": { - "value": false, - "label": "Sonné" } }, "blessures": { diff --git a/templates/actor-creature-sheet.html b/templates/actor-creature-sheet.html index c7f2395e..2ba0ebca 100644 --- a/templates/actor-creature-sheet.html +++ b/templates/actor-creature-sheet.html @@ -82,10 +82,6 @@ -
  • - Sonné - -
  • Etat Général diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index a02afb10..42ec06ab 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -37,12 +37,6 @@ +
  • -
  • - -