From ece9ab6f64b391a7bdce5f313d2720f8dd678995 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 3 Nov 2023 20:21:17 +0100 Subject: [PATCH] =?UTF-8?q?S=C3=A9paration=20de=20l'Actor=20Vehicule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 2 + module/actor.js | 85 ++++++++----------- module/actor/base-actor.js | 13 +-- module/actor/commerce.js | 5 +- .../vehicule-sheet.js} | 22 ++++- module/actor/vehicule.js | 28 ++++++ module/rdd-main.js | 5 +- module/rdd-utility.js | 31 ++----- 8 files changed, 98 insertions(+), 93 deletions(-) rename module/{actor-vehicule-sheet.js => actor/vehicule-sheet.js} (64%) create mode 100644 module/actor/vehicule.js diff --git a/changelog.md b/changelog.md index 02f5147d..2091c096 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,8 @@ ## v11.0.29 - Les choix de Krachtoum - Les options suivantes peuvent être désactivées: - La transformation de stress à Château Dormant +- Séparation des véhicules dans leur propre acteur + ## v11.0.28 - les fractures de Khrachtchoum - La gravité de la blessure est affichée dans le résumé de l'encaissement - Lors du changement d'acteur pendant le round diff --git a/module/actor.js b/module/actor.js index d38072a1..a4f18547 100644 --- a/module/actor.js +++ b/module/actor.js @@ -67,12 +67,10 @@ export class RdDActor extends RdDBaseActor { // TODO: separate derived/base data preparation // TODO: split by actor class - // Make separate methods for each Actor type (character, npc, etc.) to keep - // things organized. + // Make separate methods for each Actor type (character, npc, etc.) to keep things organized. if (this.isPersonnage()) this._prepareCharacterData(this) if (this.isCreatureEntite()) this._prepareCreatureData(this) - if (this.isVehicule()) this._prepareVehiculeData(this) - this.computeEtatGeneral(); + this.recompute(); } /* -------------------------------------------- */ @@ -80,11 +78,6 @@ export class RdDActor extends RdDBaseActor { this.computeEncTotal(); } - /* -------------------------------------------- */ - _prepareVehiculeData(actorData) { - this.computeEncTotal(); - } - /* -------------------------------------------- */ /** * Prepare Character type specific data @@ -114,9 +107,6 @@ export class RdDActor extends RdDBaseActor { if (this.isEntite()) { return item.type == 'competencecreature'; } - if (this.isVehicule()) { - return item.isInventaire(); - } if (this.isPersonnage()) { switch (item.type) { case 'competencecreature': case 'tarot': case 'service': @@ -153,7 +143,6 @@ export class RdDActor extends RdDBaseActor { case 'creature': case 'entite': return Misc.toInt(this.system.carac.reve?.value) - case 'vehicule': default: return 0; } @@ -709,11 +698,11 @@ export class RdDActor extends RdDBaseActor { jetsReve.push(-1); return 'eveil'; } - else { - await this.reveActuelIncDec(reve); - jetsReve.push(reve); + else { + await this.reveActuelIncDec(reve); + jetsReve.push(reve); + } } - } return 'dort'; } @@ -1125,7 +1114,7 @@ export class RdDActor extends RdDBaseActor { /* -------------------------------------------- */ computeMalusSurEncombrement() { switch (this.type) { - case 'entite': case 'vehicule': + case 'entite': return 0; } return Math.min(0, Math.floor(this.getEncombrementMax() - this.encTotal)); @@ -1138,8 +1127,6 @@ export class RdDActor extends RdDBaseActor { /* -------------------------------------------- */ getEncombrementMax() { switch (this.type) { - case 'vehicule': - return this.system.capacite_encombrement; case 'entite': return 0; default: @@ -1184,29 +1171,40 @@ export class RdDActor extends RdDBaseActor { return resume; } - recompute() { - this.computeEtatGeneral(); - } - /* -------------------------------------------- */ - computeEtatGeneral() { - // Pas d'état général pour les entités forçage à 0 - if (this.type == 'vehicule') { - return - } + recompute() { if (this.type == 'entite') { + // Pas d'état général pour les entités forçage à 0 this.system.compteurs.etat.value = 0; return } - // Pour les autres - let state = Math.min(this.system.sante.vie.value - this.system.sante.vie.max, 0); - if (ReglesOptionnelles.isUsing("appliquer-fatigue") && this.system.sante.fatigue) { - state += RdDUtility.currentFatigueMalus(this.system.sante.fatigue.value, this.system.sante.endurance.max); - } - // Ajout de l'éthylisme - state += Math.min(0, (this.system.compteurs.ethylisme?.value ?? 0)); + this.system.compteurs.etat.value = this.$malusVie() + this.$malusFatigue() + this.$malusEthylisme(); + } - this.system.compteurs.etat.value = state; + $malusVie() { + return Math.min(this.system.sante.vie.value - this.system.sante.vie.max, 0); + } + + $malusEthylisme() { + return Math.min(0, (this.system.compteurs.ethylisme?.value ?? 0)); + } + + /* -------------------------------------------- */ + $malusFatigue() { + if (ReglesOptionnelles.isUsing("appliquer-fatigue") && this.system.sante.fatigue) { + const max = Math.max(1, Math.min(this.system.sante.endurance.max, 60)); + + let fatigueTab = RdDUtility.getSegmentsFatigue(max); + let reste = Math.min(max * 2, Math.max(0, this.system.sante.fatigue.value)); + for (let idx = 0; idx < fatigueTab.length; idx++) { + reste -= fatigueTab[idx]; + if (reste <= 0) { + return fatigueMalus[idx]; + } + } + return -7; // This is the max ! + } + return 0; } /* -------------------------------------------- */ @@ -1579,17 +1577,6 @@ export class RdDActor extends RdDBaseActor { return result; } - async vehicleIncDec(name, inc) { - if (!this.isVehicule() || !['resistance', 'structure'].includes(name)) { - return - } - const value = this.system.etat[name].value; - const max = this.system.etat[name].max; - const newValue = value + inc; - if (0 <= newValue && newValue <= max) { - await this.update({ [`system.etat.${name}.value`]: newValue }) - } - } isDead() { return !this.isEntite() && this.system.sante.vie.value < -this.getSConst() @@ -3772,7 +3759,7 @@ export class RdDActor extends RdDBaseActor { /* -------------------------------------------- */ async setEffect(statusId, status) { - if (this.isEntite() || this.isVehicule()) { + if (this.isEntite()) { return; } console.log("setEffect", statusId, status) diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index f8521926..c1fda4b4 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -145,8 +145,11 @@ export class RdDBaseActor extends Actor { } getMonnaie(id) { return this.findItemLike(id, 'monnaie'); } - + getReveActuel() { return 0 } + computeMalusSurEncombrement() { return 0 } + getEncombrementMax() { return 0 } recompute() { } + async setEffect(statusId, status) { } /* -------------------------------------------- */ @@ -388,14 +391,6 @@ export class RdDBaseActor extends Actor { } /* -------------------------------------------- */ - computeMalusSurEncombrement() { - return 0; - } - - getEncombrementMax() { - return 0; - } - async computeEncTotal() { if (!this.pack) { this.encTotal = this.items.map(it => it.getEncTotal()).reduce(Misc.sum(), 0); diff --git a/module/actor/commerce.js b/module/actor/commerce.js index a03030fd..65c5bcdf 100644 --- a/module/actor/commerce.js +++ b/module/actor/commerce.js @@ -15,10 +15,7 @@ export class RdDCommerce extends RdDBaseActor { } canReceive(item) { - if (item.isInventaire('all')) { - return true; - } - return super.canReceive(item); + return item.isInventaire('all'); } getQuantiteDisponible(item) { diff --git a/module/actor-vehicule-sheet.js b/module/actor/vehicule-sheet.js similarity index 64% rename from module/actor-vehicule-sheet.js rename to module/actor/vehicule-sheet.js index 0124de0c..fcd4dcf6 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor/vehicule-sheet.js @@ -1,8 +1,8 @@ -import { RdDUtility } from "./rdd-utility.js"; -import { RdDActorSheet } from "./actor-sheet.js"; +import { RdDUtility } from "../rdd-utility.js"; +import { RdDBaseActorSheet } from "./base-actor-sheet.js"; /* -------------------------------------------- */ -export class RdDActorVehiculeSheet extends RdDActorSheet { +export class RdDActorVehiculeSheet extends RdDBaseActorSheet { /** @override */ static get defaultOptions() { @@ -18,6 +18,22 @@ export class RdDActorVehiculeSheet extends RdDActorSheet { }); } + /* -------------------------------------------- */ + async getData() { + let formData = await super.getData(); + mergeObject(formData, + { + editable: this.isEditable, + cssClass: this.isEditable ? "editable" : "locked", + effects: this.actor.effects.map(e => foundry.utils.deepClone(e)), + limited: this.actor.limited, + owner: this.actor.isOwner, + }); + + this.timerRecherche = undefined; + return formData; + } + activateListeners(html) { super.activateListeners(html); if (!this.options.editable) return; diff --git a/module/actor/vehicule.js b/module/actor/vehicule.js new file mode 100644 index 00000000..4cd8edde --- /dev/null +++ b/module/actor/vehicule.js @@ -0,0 +1,28 @@ +import { RdDBaseActor } from "./base-actor.js"; + +export class RdDVehicule extends RdDBaseActor { + + static get defaultIcon() { + return "systems/foundryvtt-reve-de-dragon/icons/vehicules/charette.webp"; + } + isVehicule() { return true } + + canReceive(item) { + return item.isInventaire(); + } + + getEncombrementMax() { + return this.system.capacite_encombrement; + } + + async vehicleIncDec(name, inc) { + if (!['resistance', 'structure'].includes(name)) { + return + } + const newValue = this.system.etat[name].value + inc; + if (0 <= newValue && newValue <= this.system.etat[name].max) { + await this.update({ [`system.etat.${name}.value`]: newValue }) + } + } + +} diff --git a/module/rdd-main.js b/module/rdd-main.js index b70dea0c..3f016727 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -29,11 +29,12 @@ import { Environnement } from "./environnement.js"; import { RdDActor } from "./actor.js"; import { RdDBaseActor } from "./actor/base-actor.js"; import { RdDCommerce } from "./actor/commerce.js"; +import { RdDVehicule } from "./actor/vehicule.js"; import { RdDActorSheet } from "./actor-sheet.js"; import { RdDCommerceSheet } from "./actor/commerce-sheet.js"; import { RdDActorCreatureSheet } from "./actor-creature-sheet.js"; -import { RdDActorVehiculeSheet } from "./actor-vehicule-sheet.js"; import { RdDActorEntiteSheet } from "./actor-entite-sheet.js"; +import { RdDActorVehiculeSheet } from "./actor/vehicule-sheet.js"; import { RdDItem } from "./item.js"; import { RdDItemBlessure } from "./item/blessure.js"; @@ -94,7 +95,7 @@ export class SystemReveDeDragon { creature: RdDActor, entite: RdDActor, personnage: RdDActor, - vehicule: RdDActor, + vehicule: RdDVehicule, } } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index b3b188a9..4d625da0 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -28,7 +28,7 @@ const ajustementsEncaissement = Misc.intArray(-10, 26); /* -------------------------------------------- */ function _buildAllSegmentsFatigue(max) { const cycle = [5, 2, 4, 1, 3, 0]; - let fatigue = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]; + const fatigue = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]; for (let i = 0; i <= max; i++) { const ligneFatigue = duplicate(fatigue[i]); const caseIncrementee = cycle[i % 6]; @@ -55,7 +55,7 @@ function _cumulSegmentsFatigue(matrix) { } /* -------------------------------------------- */ -const fatigueMatrix = _buildAllSegmentsFatigue(60); +export const fatigueMatrix = _buildAllSegmentsFatigue(60); const cumulFatigueMatrix = _cumulSegmentsFatigue(fatigueMatrix); const fatigueMalus = [0, 0, 0, -1, -1, -1, -2, -3, -4, -5, -6, -7]; // Provides the malus for each segment of fatigue @@ -460,10 +460,8 @@ export class RdDUtility { } /* -------------------------------------------- */ - static getSegmentsFatigue(maxEnd) { - maxEnd = Math.max(maxEnd, 1); - maxEnd = Math.min(maxEnd, fatigueMatrix.length); - return fatigueMatrix[maxEnd]; + static getSegmentsFatigue(maxEndurance) { + return fatigueMatrix[Math.min(Math.max(maxEndurance, 1), fatigueMatrix.length)]; } /* -------------------------------------------- */ @@ -491,7 +489,7 @@ export class RdDUtility { // Build the nice (?) html table used to manage fatigue. // max should be the endurance max value static makeHTMLfatigueMatrix(fatigue, maxEndurance) { - let segments = this.getSegmentsFatigue(maxEndurance); + const segments = this.getSegmentsFatigue(maxEndurance); return this.makeHTMLfatigueMatrixForSegment(fatigue, segments); } @@ -625,25 +623,6 @@ export class RdDUtility { return perte.total; } - /* -------------------------------------------- */ - static currentFatigueMalus(value, max) { - if (ReglesOptionnelles.isUsing("appliquer-fatigue")) { - max = Math.max(1, Math.min(max, 60)); - value = Math.min(max * 2, Math.max(0, value)); - - let fatigueTab = fatigueMatrix[max]; - let fatigueRem = value; - for (let idx = 0; idx < fatigueTab.length; idx++) { - fatigueRem -= fatigueTab[idx]; - if (fatigueRem <= 0) { - return fatigueMalus[idx]; - } - } - return -7; // This is the max ! - } - return 0; - } - /* -------------------------------------------- */ static async responseNombreAstral(callData) { let actor = game.actors.get(callData.id);