diff --git a/module/actor.js b/module/actor.js index ccd83847..9e02fc6c 100644 --- a/module/actor.js +++ b/module/actor.js @@ -55,40 +55,26 @@ export class RdDActor extends RdDBaseActorSang { * Prepare Character type specific data */ prepareActorData() { - this.$computeCaracDerivee() - this.$computeIsHautRevant() - } - - /* -------------------------------------------- */ - $computeCaracDerivee() { this.system.carac.force.value = Math.min(this.system.carac.force.value, parseInt(this.system.carac.taille.value) + 4); - this.system.carac.melee.value = Math.floor((parseInt(this.system.carac.force.value) + parseInt(this.system.carac.agilite.value)) / 2); + + this.system.carac.melee.value = Math.floor((this.getForce() + parseInt(this.system.carac.agilite.value)) / 2); this.system.carac.tir.value = Math.floor((parseInt(this.system.carac.vue.value) + parseInt(this.system.carac.dexterite.value)) / 2); this.system.carac.lancer.value = Math.floor((parseInt(this.system.carac.tir.value) + parseInt(this.system.carac.force.value)) / 2); this.system.carac.derobee.value = Math.floor(parseInt(((21 - this.system.carac.taille.value)) + parseInt(this.system.carac.agilite.value)) / 2); - let bonusDomKey = Math.floor((parseInt(this.system.carac.force.value) + parseInt(this.system.carac.taille.value)) / 2); - let tailleData = RdDCarac.getCaracDerivee(bonusDomKey); - this.system.attributs.plusdom.value = tailleData.plusdom; - this.system.attributs.encombrement.value = (parseInt(this.system.carac.force.value) + parseInt(this.system.carac.taille.value)) / 2; + super.prepareActorData() - this.system.attributs.sconst.value = RdDCarac.calculSConst(this.system.carac.constitution.value); - this.system.attributs.sust.value = RdDCarac.getCaracDerivee(this.system.carac.taille.value).sust; - this.system.sante.vie.max = Math.ceil((parseInt(this.system.carac.taille.value) + parseInt(this.system.carac.constitution.value)) / 2); + this.system.attributs.sconst.value = RdDCarac.calculSConst(this.getConstitution()) + this.system.attributs.sust.value = RdDCarac.getCaracDerivee(this.getTaille()).sust - this.system.sante.vie.value = Math.min(this.system.sante.vie.value, this.system.sante.vie.max) - this.system.sante.endurance.max = Math.max(parseInt(this.system.carac.taille.value) + parseInt(this.system.carac.constitution.value), parseInt(this.system.sante.vie.max) + parseInt(this.system.carac.volonte.value)); - this.system.sante.endurance.value = Math.min(this.system.sante.endurance.value, this.system.sante.endurance.max); - this.system.sante.fatigue.max = this.getFatigueMax(); + this.system.sante.fatigue.max = this.getFatigueMax() this.system.sante.fatigue.value = Math.min(this.system.sante.fatigue.value, this.system.sante.fatigue.max); //Compteurs - this.system.reve.reve.max = this.system.carac.reve.value; - this.system.compteurs.chance.max = this.system.carac.chance.value; - } + this.system.reve.reve.max = 3 * this.getReve() + this.system.compteurs.chance.max = this.getChance() - $computeIsHautRevant() { this.system.attributs.hautrevant.value = this.itemTypes[ITEM_TYPES.tete].find(it => RdDItemTete.isDonDeHautReve(it)) ? "Haut rêvant" : ""; @@ -114,6 +100,8 @@ export class RdDActor extends RdDBaseActorSang { getChanceActuel() { return this.system.compteurs.chance?.value ?? 10 } getMoralTotal() { return this.system.compteurs.moral?.value ?? 0 } + getEnduranceMax() { return Math.max(1, Math.max(this.getTaille() + this.getConstitution(), this.getVieMax() + this.getVolonte())) } + /* -------------------------------------------- */ getEtatGeneral(options = { ethylisme: false }) { const etatGeneral = this.system.compteurs.etat?.value ?? 0 @@ -1095,9 +1083,7 @@ export class RdDActor extends RdDBaseActorSang { } /* -------------------------------------------- */ - getSConst() { - return RdDCarac.calculSConst(this.system.carac.constitution.value) - } + getSConst() { return RdDCarac.calculSConst(this.getConstitution()) } async ajoutXpConstitution(xp) { await this.update({ "system.carac.constitution.xp": Misc.toInt(this.system.carac.constitution.xp) + xp }); diff --git a/module/actor/base-actor-reve.js b/module/actor/base-actor-reve.js index fbbf03ca..72546304 100644 --- a/module/actor/base-actor-reve.js +++ b/module/actor/base-actor-reve.js @@ -19,6 +19,7 @@ import { RdDCombat, RdDCombatManager } from "../rdd-combat.js"; import { RdDConfirm } from "../rdd-confirm.js"; import { ENTITE_INCARNE, SHOW_DICE, SYSTEM_RDD } from "../constants.js"; import { RdDItemArme } from "../item-arme.js"; +import { RdDCarac } from "../rdd-carac.js"; const POSSESSION_SANS_DRACONIC = { img: 'systems/foundryvtt-reve-de-dragon/icons/entites/possession.webp', @@ -36,6 +37,13 @@ const POSSESSION_SANS_DRACONIC = { */ export class RdDBaseActorReve extends RdDBaseActor { + prepareActorData() { + super.prepareActorData() + this.system.attributs.plusdom.value = this.getBonusDegat() + this.system.sante.endurance.max = this.getEnduranceMax() + this.system.sante.endurance.value = Math.min(this.system.sante.endurance.value, this.system.sante.endurance.max) + } + getCaracChanceActuelle() { return { label: 'Chance actuelle', @@ -52,21 +60,26 @@ export class RdDBaseActorReve extends RdDBaseActor { }; } + + getTaille() { return Misc.toInt(this.system.carac.taille?.value) } + getConstitution() { return this.getReve() } + getForce() { return this.getReve() } + getAgilite() { return this.getForce() } + getReve() { return Misc.toInt(this.system.carac.reve?.value) } + getChance() { return this.getReve() } + getReveActuel() { return this.getReve() } getChanceActuel() { return this.getChance() } - getReve() { return Number(this.system.carac.reve?.value ?? 0) } - getForce() { return this.getReve() } - getTaille() { return Number(this.system.carac.taille?.value ?? 0) } - getAgilite() { return this.getForce() } - getChance() { return this.getReve() } + getEnduranceMax() { return Math.max(1, this.getTaille() + this.getConstitution()) } + getEncombrementMax() { return (this.getForce() + this.getTaille()) / 2 } + getBonusDegat() { return RdDCarac.getCaracDerivee(this.getEncombrementMax()).plusdom } + getMoralTotal() { return 0 } - getBonusDegat() { return Number(this.system.attributs?.plusdom?.value ?? 0) } getProtectionNaturelle() { return Number(this.system.attributs?.protection?.value ?? 0) } getSConst() { return 0 } /* -------------------------------------------- */ - getEncombrementMax() { return 0 } isSurenc() { return false } computeMalusSurEncombrement() { return 0 } @@ -84,7 +97,7 @@ export class RdDBaseActorReve extends RdDBaseActor { isActorCombat() { return true } getCaracInit(competence) { - if (!competence){ + if (!competence) { return 0 } if (competence.type == ITEM_TYPES.competencecreature) { diff --git a/module/actor/base-actor-sang.js b/module/actor/base-actor-sang.js index 45d84458..689273d9 100644 --- a/module/actor/base-actor-sang.js +++ b/module/actor/base-actor-sang.js @@ -6,6 +6,7 @@ import { RdDBaseActorReve } from "./base-actor-reve.js"; import { RdDDice } from "../rdd-dice.js"; import { RdDItemBlessure } from "../item/blessure.js"; import { ChatUtility } from "../chat-utility.js"; +import { Misc } from "../misc.js"; /** * Classe de base pour les acteurs qui peuvent subir des blessures @@ -14,25 +15,32 @@ import { ChatUtility } from "../chat-utility.js"; */ export class RdDBaseActorSang extends RdDBaseActorReve { + prepareActorData() { + this.system.sante.vie.max = Math.ceil((this.getTaille() + this.getConstitution()) / 2) + this.system.sante.vie.value = Math.min(this.system.sante.vie.value, this.system.sante.vie.max) + super.prepareActorData() + this.system.attributs.encombrement.value = this.getEncombrementMax() + } - getForce() { return Number(this.system.carac.force?.value ?? 0) } + getForce() { return Misc.toInt(this.system.carac.force?.value) } + getConstitution() { return Misc.toInt(this.system.carac.constitution?.value) } + getVolonte() { return Misc.toInt(this.system.carac.volonte?.value) } - getBonusDegat() { return Number(this.system.attributs?.plusdom?.value ?? 0) } - getProtectionNaturelle() { return Number(this.system.attributs?.protection?.value ?? 0) } - getSConst() { return 0 } + getVieMax() { return Misc.toInt(this.system.sante.vie?.max) } + getEnduranceMax() { return Math.max(1, this.getTaille() + this.getConstitution()) } + getFatigueMax() { return this.getEnduranceMax() * 2 } - getEnduranceMax() { return Math.max(1, Math.min(this.system.sante.endurance.max, MAX_ENDURANCE_FATIGUE)) } + getProtectionNaturelle() { return Misc.toInt(this.system.attributs?.protection?.value) } getFatigueActuelle() { if (ReglesOptionnelles.isUsing("appliquer-fatigue")) { - return Math.max(0, Math.min(this.getFatigueMax(), this.system.sante.fatigue?.value ?? 0)); + return Math.max(0, Math.min(this.getFatigueMax(), Misc.toInt(this.system.sante.fatigue?.value))) } return 0; } getFatigueRestante() { return this.getFatigueMax() - this.getFatigueActuelle() } getFatigueMin() { return this.system.sante.endurance.max - this.system.sante.endurance.value } - getFatigueMax() { return this.getEnduranceMax() * 2 } malusFatigue() { if (ReglesOptionnelles.isUsing("appliquer-fatigue")) { @@ -42,7 +50,6 @@ export class RdDBaseActorSang extends RdDBaseActorReve { } /* -------------------------------------------- */ - getEncombrementMax() { return Number(this.system.attributs?.encombrement?.value ?? 0) } isSurenc() { return this.computeMalusSurEncombrement() < 0 } computeMalusSurEncombrement() { diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index a1456895..f2482c77 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -18,6 +18,7 @@ export class RdDBaseActor extends Actor { .map(it => it[0]) .find(it => it) } + static $findCaracByName(carac, name) { const caracList = Object.entries(carac); let entry = Misc.findFirstLike(name, caracList, { mapper: it => it[0], description: 'caractéristique' }); @@ -26,6 +27,16 @@ export class RdDBaseActor extends Actor { } return entry && entry.length > 0 ? carac[entry[0]] : undefined; } + static getDefaultValue(actorType, path) { + if (path.includes('.')) { + path = path.split('.') + } + let obj = game.model.Actor[actorType] + for (let p of path) { + obj = obj ? obj[p] : undefined + } + return obj + } static getDefaultImg(itemType) { return game.system.rdd.actorClasses[itemType]?.defaultIcon ?? defaultItemImg[itemType]; @@ -178,7 +189,8 @@ export class RdDBaseActor extends Actor { this.computeEncTotal() } - async prepareActorData() { } + prepareActorData() { } + async computeEtatGeneral() { } /* -------------------------------------------- */ findPlayer() { @@ -210,6 +222,9 @@ export class RdDBaseActor extends Actor { getMonnaie(id) { return this.findItemLike(id, 'monnaie'); } getEncombrementMax() { return 0 } + /* -------------------------------------------- */ + async updateCarac(caracName, to) { + } /* -------------------------------------------- */ async onPreUpdateItem(item, change, options, id) { } async onCreateItem(item, options, id) { } diff --git a/module/actor/creature.js b/module/actor/creature.js index d0307e66..c2f51b27 100644 --- a/module/actor/creature.js +++ b/module/actor/creature.js @@ -1,6 +1,4 @@ -import { ENTITE_INCARNE } from "../constants.js"; import { ITEM_TYPES } from "../item.js"; -import { STATUSES } from "../settings/status-effects.js"; import { RdDBaseActorSang } from "./base-actor-sang.js"; export class RdDCreature extends RdDBaseActorSang { @@ -9,6 +7,7 @@ export class RdDCreature extends RdDBaseActorSang { return "systems/foundryvtt-reve-de-dragon/icons/creatures/bramart.svg"; } + getEnduranceMax() { return Math.max(1, this.getVieMax() + this.getConstitution()) } isCreature() { return true } canReceive(item) { diff --git a/module/actor/entite.js b/module/actor/entite.js index ff0ad06a..d72935c9 100644 --- a/module/actor/entite.js +++ b/module/actor/entite.js @@ -27,6 +27,7 @@ export class RdDEntite extends RdDBaseActorReve { getForce() { return this.getReve() } getAgilite() { return this.getReve() } getChance() { return this.getReve() } + getEnduranceMax() { return Math.max(1, this.getTaille() + this.getReve()) } getDraconicOuPossession() { return this.itemTypes[ITEM_TYPES.competencecreature] diff --git a/module/actor/export-scriptarium/mapping.js b/module/actor/export-scriptarium/mapping.js index 0db57523..88912f49 100644 --- a/module/actor/export-scriptarium/mapping.js +++ b/module/actor/export-scriptarium/mapping.js @@ -76,7 +76,7 @@ const MAPPING_BASE = [ { column: "derobee", rollClass: 'roll-carac', colName: 'Dérobée', getter: (actor, context) => actor.system.carac.derobee.value }, { column: "vie", getter: (actor, context) => actor.system.sante.vie.max }, { column: "endurance", getter: (actor, context) => actor.system.sante.endurance.max }, - { column: "plusdom", colName: '+dom', getter: (actor, context) => actor.system.attributs.plusdom.value }, + { column: "plusdom", colName: '+dom', getter: (actor, context) => actor.getBonusDegat() }, { column: "protectionnaturelle", colName: 'Protection naturelle', getter: (actor, context) => actor.system.attributs.protection.value > 0 ? actor.system.attributs.protection.value : '' }, { column: "description", getter: (actor, context) => Mapping.getDescription(actor) }, { column: "armure", getter: (actor, context) => Mapping.getArmure(actor, context) }, diff --git a/module/misc.js b/module/misc.js index df4301ff..9ce50ac6 100644 --- a/module/misc.js +++ b/module/misc.js @@ -58,9 +58,6 @@ export class Misc { * @param {*} value value to convert to an integer using parseInt */ static toInt(value) { - if (value == undefined) { - return 0; - } const parsed = parseInt(value); return isNaN(parsed) ? 0 : parsed; } diff --git a/module/rdd-carac.js b/module/rdd-carac.js index a2f42ce6..272f0869 100644 --- a/module/rdd-carac.js +++ b/module/rdd-carac.js @@ -64,7 +64,7 @@ export class RdDCarac { } static getCaracDerivee(value) { - return TABLE_CARACTERISTIQUES_DERIVEES[Math.min(Math.max(Number(value), 1), 32)]; + return TABLE_CARACTERISTIQUES_DERIVEES[Math.min(Math.max(Math.floor(Number(value)), 1), 32)]; } static computeTotal(carac, beaute = undefined) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 01dd562e..6397ca2a 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -20,6 +20,7 @@ import { ExperienceLog } from "./actor/experience-log.js"; import { RdDCoeur } from "./coeur/rdd-coeur.js"; import { APP_ASTROLOGIE_REFRESH } from "./sommeil/app-astrologie.js"; import { RDD_CONFIG } from "./constants.js"; +import { RdDBaseActor } from "./actor/base-actor.js"; /* -------------------------------------------- */ // This table starts at 0 -> niveau -10 @@ -288,6 +289,8 @@ export class RdDUtility { Handlebars.registerHelper('timestamp-formulesDuree', () => RdDTimestamp.formulesDuree()); Handlebars.registerHelper('timestamp-formulesPeriode', () => RdDTimestamp.formulesPeriode()); + Handlebars.registerHelper('actor-default', (actorType, ...path) => RdDBaseActor.getDefaultValue(actorType, path.slice(0, -1))); + Handlebars.registerHelper('array-includes', (array, value) => array.includes(value)); Handlebars.registerHelper('min', (...args) => Math.min(...args.slice(0, -1))); Handlebars.registerHelper('isLastIndex', (index, list) => index + 1 >= list.length); diff --git a/template.json b/template.json index 815e9a35..2fe4362d 100644 --- a/template.json +++ b/template.json @@ -112,7 +112,7 @@ "type": "string", "value": 0, "label": "Vitesse", - "derivee": true + "derivee": false }, "protection": { "type": "number", @@ -195,13 +195,13 @@ "type": "string", "value": 0, "label": "Vitesse", - "derivee": true + "derivee": false }, "encombrement": { "type": "number", "value": 0, "label": "Encombrement", - "derivee": false + "derivee": true }, "protection": { "type": "number", diff --git a/templates/actor/carac-creature.html b/templates/actor/carac-creature.html index 34905034..e16b56f3 100644 --- a/templates/actor/carac-creature.html +++ b/templates/actor/carac-creature.html @@ -1,8 +1,21 @@