From f52575f41314f58c3b548013036b097bb40b9c93 Mon Sep 17 00:00:00 2001 From: fabres Date: Fri, 17 Jul 2026 10:16:47 +0200 Subject: [PATCH] =?UTF-8?q?fix(rations):=20consomme=20assez=20d'unit=C3=A9?= =?UTF-8?q?s=20pour=20remplir=20sust/eau=20en=201=20clic=20+=20alerte=20si?= =?UTF-8?q?=20vide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/module/actor.js b/module/actor.js index 2a688e7e..a71567ad 100644 --- a/module/actor.js +++ b/module/actor.js @@ -34,7 +34,7 @@ import { DialogChoixXpCarac } from "./dialog-choix-xp-carac.js"; import { ATTAQUE_TYPE, RdDItemArme } from "./item/arme.js"; import { RdDItemBlessure } from "./item/blessure.js"; -import { RdDItemTete } from "./item/tete.js"; +import { RdDItemTete } from "./documents/_module.mjs"; import { RdDItemSort } from "./item-sort.js"; import { RdDItemRace } from "./item/race.js"; import { RdDItemCompetence } from "./item-competence.js"; @@ -657,6 +657,68 @@ export class RdDActor extends RdDBaseActorSang { return cumul; } + /* -------------------------------------------- */ + async mangerExterne() { + const besoin = this.system.attributs.sust.value + await this.update({ + 'system.compteurs.sust.value': besoin, + 'system.compteurs.eau.value': besoin + }) + ChatUtility.tellToUserAndGM(`${this.name} a mangé et bu pour la journée (repas externe)`) + } + + async mangerRations() { + const besoin = this.system.attributs.sust.value + let restantSust = besoin - this.system.compteurs.sust.value + let restantEau = besoin - this.system.compteurs.eau.value + let totalSust = 0, totalEau = 0 + let foundAny = false + + for (const item of this.items) { + if (item.type !== 'nourritureboisson') continue + if (restantSust <= 0 && restantEau <= 0) break + + const qty = item.system.quantite + if (!qty || qty <= 0) continue + const sustUnit = item.system.sust || 0 + const eauUnit = item.system.desaltere || 0 + if (sustUnit <= 0 && eauUnit <= 0) continue + + foundAny = true + let unitNeeded = 0 + if (restantSust > 0 && sustUnit > 0) { + unitNeeded = Math.max(unitNeeded, Math.ceil(restantSust / sustUnit)) + } + if (restantEau > 0 && eauUnit > 0) { + unitNeeded = Math.max(unitNeeded, Math.ceil(restantEau / eauUnit)) + } + const take = Math.min(unitNeeded, qty) + + totalSust += Math.min(sustUnit * take, restantSust) + totalEau += Math.min(eauUnit * take, restantEau) + restantSust -= Math.min(sustUnit * take, restantSust) + restantEau -= Math.min(eauUnit * take, restantEau) + + await item.diminuerQuantite(take) + } + + if (!foundAny) { + ChatUtility.tellToUserAndGM(`${this.name} n'a rien à manger dans ses rations !`) + return + } + + if (totalSust > 0) { + await this.update({ 'system.compteurs.sust.value': this.system.compteurs.sust.value + totalSust }) + } + if (totalEau > 0) { + await this.update({ 'system.compteurs.eau.value': this.system.compteurs.eau.value + totalEau }) + } + + ChatUtility.tellToUserAndGM( + `${this.name} a mangé ${totalSust}/${besoin} sust, bu ${totalEau}/${besoin} eau (rations)` + ) + } + /* -------------------------------------------- */ async retourSeuilDeReve(message) { const seuil = this.system.reve.seuil.value;