2024-10-14 03:47:04 +02:00
|
|
|
import { ChatUtility } from "../chat-utility.js";
|
2023-01-05 00:55:04 +01:00
|
|
|
import { RdDItem } from "../item.js";
|
2023-01-07 23:28:30 +01:00
|
|
|
import { Misc } from "../misc.js";
|
2023-03-29 22:53:40 +02:00
|
|
|
import { RdDTimestamp } from "../time/rdd-timestamp.js";
|
2023-01-05 00:55:04 +01:00
|
|
|
|
|
|
|
export class RdDItemMaladie extends RdDItem {
|
|
|
|
|
|
|
|
static get defaultIcon() {
|
|
|
|
return "systems/foundryvtt-reve-de-dragon/icons/maladies_venins/maladie.webp";
|
|
|
|
}
|
|
|
|
|
|
|
|
async calculerFinPeriodeTemporel(debut) {
|
2023-01-07 23:28:30 +01:00
|
|
|
return await debut.addPeriode(this.system.periode.nombre, this.system.periode.unite);
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
|
2023-01-07 23:28:30 +01:00
|
|
|
async onFinPeriode(oldTimestamp, newTimestamp) {
|
|
|
|
await RdDItemMaladie.notifierMaladiePoison(this, oldTimestamp, newTimestamp)
|
|
|
|
}
|
|
|
|
|
|
|
|
static async notifierMaladiePoison(mal, oldTimestamp, newTimestamp) {
|
|
|
|
if (mal.actor) {
|
|
|
|
const souffrance = mal.system.identifie
|
|
|
|
? `de ${mal.name}`
|
|
|
|
: `d'un mal inconnu`
|
2024-10-14 03:47:04 +02:00
|
|
|
ChatMessage.create({
|
|
|
|
whisper: ChatUtility.getOwners(mal.actor),
|
|
|
|
content: `${mal.actor.name} souffre ${souffrance} (${Misc.typeName('Item', mal.type)}): vérifiez que les effets ne se sont pas aggravés !`
|
|
|
|
})
|
|
|
|
mal.postItemToChat('gmroll')
|
|
|
|
await RdDItemMaladie.prolongerPeriode(mal, oldTimestamp, newTimestamp)
|
2023-01-07 23:28:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static async prolongerPeriode(mal, oldTimestamp, newTimestamp) {
|
|
|
|
if (mal.actor) {
|
|
|
|
// TODO: déterminer le nombre de périodes écoulées
|
|
|
|
console.log(`${mal.actor.name}: le mal ${mal.name} a atteint la fin de sa période et été prolongé`);
|
|
|
|
const current = newTimestamp;
|
|
|
|
const finPeriode = new RdDTimestamp(mal.system.temporel.fin)
|
|
|
|
const periodeSuivante = (finPeriode.compare(current) > 0 ? finPeriode : current);
|
|
|
|
const timestampFin = await mal.calculerFinPeriodeTemporel(periodeSuivante);
|
|
|
|
|
|
|
|
await mal.actor.updateEmbeddedDocuments('Item', [{
|
|
|
|
_id: mal.id,
|
2024-05-02 14:08:02 +02:00
|
|
|
'system.temporel.fin': foundry.utils.duplicate(timestampFin),
|
2023-01-07 23:28:30 +01:00
|
|
|
}])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|