Gestion auto de l'état sonné en combat

This commit is contained in:
sladecraven 2021-02-17 11:16:27 +01:00
parent 98c6133938
commit 1cdadbd9d6
5 changed files with 57 additions and 10 deletions

View File

@ -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}<br>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) {

View File

@ -19,10 +19,18 @@ export class RdDCombatManager extends Combat {
}
}
/* -------------------------------------------- */
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();
}
}

View File

@ -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;

View File

@ -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": [
{

View File

@ -165,6 +165,7 @@
},
"sonne": {
"value": false,
"round": -1,
"label": "Sonné"
}
},