fix(rations): consomme assez d'unités pour remplir sust/eau en 1 clic + alerte si vide

This commit is contained in:
fabres
2026-07-22 00:26:52 +02:00
parent 5969009eb1
commit f52575f413
+63 -1
View File
@@ -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;