From 1cdadbd9d6665c1f237c3ddf5b28b30bdcf5dcf7 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Wed, 17 Feb 2021 11:16:27 +0100 Subject: [PATCH] =?UTF-8?q?Gestion=20auto=20de=20l'=C3=A9tat=20sonn=C3=A9?= =?UTF-8?q?=20en=20combat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 49 ++++++++++++++++++++++++++++++++++++------ module/rdd-combat.js | 10 ++++++++- module/rdd-commands.js | 3 +++ system.json | 4 ++-- template.json | 1 + 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/module/actor.js b/module/actor.js index 0928318c..37025a88 100644 --- a/module/actor.js +++ b/module/actor.js @@ -345,7 +345,14 @@ export class RdDActor extends Actor { await this.update({ "data.blessures": blessures }); await this._recupererVie(message); await this.jetDeMoral('neutre'); - await this.chanceActuelleIncDec(1); + + // On ne récupère un point de chance que si aucun appel à la chance dans la journée + let utilisationChance = duplicate(this.getFlag('foundryvtt-reve-de-dragon', 'utilisationChance') ?? false); + if ( !utilisationChance ) { + await this.chanceActuelleIncDec(1); + } + await this.unsetFlag('foundryvtt-reve-de-dragon', 'utilisationChance'); // Nouveau jour, suppression du flag + this.transformerStress(); await this.retourSeuilDeReve(message); message.content = `A la fin Chateau Dormant, ${message.content}
Un nouveau jour se lève`; @@ -1250,18 +1257,41 @@ export class RdDActor extends Actor { getSonne() { return !this.isEntiteCauchemar() && (this.data.data.sante.sonne?.value ?? false); } + + /* -------------------------------------------- */ + getSonneRound() { + return !this.isEntiteCauchemar() && (this.data.data.sante.sonne?.round ?? false); + } + + /* -------------------------------------------- */ + 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 setSonne(sonne = true) { if (this.isEntiteCauchemar()) { return; } + let round = (sonne && game.combat) ? game.combat.current.round : -1; // Sauvegarde du round de sonné en cas de combat await this.setStatusSonne(sonne); - await this.setStateSonne(sonne); + await this.setStateSonne(sonne, round); } - async setStateSonne(sonne) { + + /* -------------------------------------------- */ + async setStateSonne(sonne, round = -1) { if (this.isEntiteCauchemar()) { return; } - await this.update({ "data.sante.sonne.value": sonne }); + let sonneData = duplicate(this.data.data.sante.sonne); + sonneData.value = sonne; + sonneData.round = round; + await this.update({ "data.sante.sonne": sonneData }); } /* -------------------------------------------- */ @@ -1279,15 +1309,15 @@ export class RdDActor extends Actor { RdDDice.show(roll); let result = { roll: roll, - sonne: roll.total > endurance || roll.total == 20 + sonne: roll.total > endurance || roll.total == 20 // 20 is always a failure } if (roll.total == 1) { let xp = Misc.toInt(this.data.data.carac.constitution.xp) + 1; this.update({ "data.carac.constitution.xp": xp }); // +1 XP ! - // TODO : Output to chat + ChatMessage.create( { content: `${this.name} a obenu 1 sur son Jet d'Endurance et a gagné 1 point d'Expérience en Constitution. Ce point d'XP a été ajouté automatiquement).`}); } if (result.sonne) { - // 20 is always a failure + await this.setSonne(); sante.sonne.value = true; } @@ -2249,6 +2279,10 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ async rollAppelChance(onSuccess = () => { }, onEchec = () => { }) { + // Stocke si utilisation de la chance + await this.unsetFlag('foundryvtt-reve-de-dragon', 'utilisationChance'); + await this.setFlag('foundryvtt-reve-de-dragon', 'utilisationChance', true ); + let rollData = { selectedCarac: this.getCaracByName('chance-actuelle'), surprise: '' }; const dialog = await RdDRoll.create(this, rollData, { html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html' }, @@ -2407,6 +2441,7 @@ export class RdDActor extends Actor { return RdDActor._findCaracByName(this.data.data.carac, caracName); } + /* -------------------------------------------- */ static _findCaracByName(carac, name) { name = name.toLowerCase(); switch (name) { diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 1068fa00..f78bfc02 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -18,11 +18,19 @@ export class RdDCombatManager extends Combat { turn.actor.resetItemUse() } } + + /* -------------------------------------------- */ + cleanSonne( ) { + for (let combatant of this.data.combatants) { + combatant.actor.verifierSonneRound( this.current.round ); + } + } /* -------------------------------------------- */ async nextRound() { - //console.log('New round !'); + //console.log('New round !');s this.cleanItemUse(); + this.cleanSonne(); } } diff --git a/module/rdd-commands.js b/module/rdd-commands.js index 3e5c3280..b085c758 100644 --- a/module/rdd-commands.js +++ b/module/rdd-commands.js @@ -85,10 +85,12 @@ export class RdDCommands { this.commandsTable = {}; } + /* -------------------------------------------- */ registerCommand(command) { this._addCommand(this.commandsTable, command.path, '', command); } + /* -------------------------------------------- */ _addCommand(targetTable, path, fullPath, command) { if (!this._validateCommand(targetTable, path, command)) { return; @@ -107,6 +109,7 @@ export class RdDCommands { } } + /* -------------------------------------------- */ _validateCommand(targetTable, path, command) { if (path.length > 0 && path[0] && command.descr && (path.length != 1 || targetTable[path[0]] == undefined)) { return true; diff --git a/system.json b/system.json index b6a845ba..594aab04 100644 --- a/system.json +++ b/system.json @@ -2,11 +2,11 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "1.3.21", + "version": "1.3.22", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", - "templateVersion": 94, + "templateVersion": 95, "author": "LeRatierBretonnien", "authors": [ { diff --git a/template.json b/template.json index 1fde5f9b..0035333b 100644 --- a/template.json +++ b/template.json @@ -165,6 +165,7 @@ }, "sonne": { "value": false, + "round": -1, "label": "Sonné" } },