2023-03-10 22:37:21 +01:00
|
|
|
import { RdDItem } from "../item.js";
|
|
|
|
|
2023-03-10 22:41:11 +01:00
|
|
|
const BASE_TACHE_SOIN_BLESSURE = {
|
|
|
|
type: "tache",
|
|
|
|
img: 'systems/foundryvtt-reve-de-dragon/icons/competence_chirurgie.webp',
|
|
|
|
system: { carac: "dexterite", competence: "Chirurgie", periodicite: "1 round", fatigue: 0, }
|
|
|
|
}
|
|
|
|
const TACHES_SOIN_BLESSURE = {
|
|
|
|
'critique': { name: 'Blessure critique', system: { difficulte: -6, points_de_tache: 6 } },
|
|
|
|
'grave': { name: 'Blessure grave', system: { difficulte: -4, points_de_tache: 4 } },
|
|
|
|
'legere': { name: 'Blessure légère', system: { difficulte: -2, points_de_tache: 2 } },
|
|
|
|
6: { name: 'Blessure critique', system: { difficulte: -6, points_de_tache: 6 } },
|
|
|
|
4: { name: 'Blessure grave', system: { difficulte: -4, points_de_tache: 4 } },
|
|
|
|
2: { name: 'Blessure légère', system: { difficulte: -2, points_de_tache: 2 } },
|
|
|
|
}
|
|
|
|
|
2023-03-10 22:37:21 +01:00
|
|
|
export class RdDItemBlessure extends RdDItem {
|
|
|
|
|
|
|
|
static get defaultIcon() {
|
|
|
|
return "systems/foundryvtt-reve-de-dragon/icons/sante/blessure.webp";
|
|
|
|
}
|
|
|
|
|
2023-03-10 22:41:11 +01:00
|
|
|
static prepareTacheSoin(gravite) {
|
|
|
|
const tache = TACHES_SOIN_BLESSURE[gravite]
|
|
|
|
if (!tache) {
|
|
|
|
ui.notifications.warn(`Pas de tâche de soins pour une blessure ${gravite}`)
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return mergeObject(duplicate(BASE_TACHE_SOIN_BLESSURE), tache)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async createTacheSoinBlessure(actor, gravite) {
|
|
|
|
const tache = RdDItemBlessure.prepareTacheSoin(gravite)
|
|
|
|
if (tache) {
|
|
|
|
const taches = await actor.createEmbeddedDocuments('Item', [tache], { renderSheet: false });
|
|
|
|
return taches[0];
|
|
|
|
}
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateTacheSoinBlessure(tache) {
|
|
|
|
if (tache) {
|
|
|
|
await tache.update({
|
|
|
|
system: {
|
|
|
|
itemId: this.id,
|
|
|
|
difficulte: Math.min(this.system.difficulte, tache.system.difficulte),
|
|
|
|
points_de_tache_courant: Math.max(0, this.system.premierssoins.tache)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 22:37:21 +01:00
|
|
|
async calculerFinPeriodeTemporel(debut) {
|
|
|
|
return await debut.nouveauJour().addJours(this.system.gravite);
|
|
|
|
}
|
|
|
|
|
|
|
|
async onFinPeriode(oldTimestamp, newTimestamp) {
|
|
|
|
if (this.system.gravite <= 0) {
|
|
|
|
await super.onFinPeriode(oldTimestamp, newTimestamp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 22:41:11 +01:00
|
|
|
prepareDerivedData() {
|
|
|
|
super.prepareDerivedData();
|
|
|
|
this.system.labelGravite = this.getLabelGravite()
|
|
|
|
}
|
|
|
|
|
|
|
|
async setSoinsBlessure(systemUpdate = {}) {
|
|
|
|
systemUpdate = mergeObject(systemUpdate, this.system, { overwrite: false }),
|
|
|
|
systemUpdate.soinscomplets.done = systemUpdate.premierssoins.done && systemUpdate.soinscomplets.done
|
|
|
|
await this.update({
|
|
|
|
img: this.getImgSoins(systemUpdate.soinscomplets.done),
|
|
|
|
system: systemUpdate
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getImgSoins(soins) {
|
|
|
|
return `systems/foundryvtt-reve-de-dragon/icons/sante/${soins ? 'blessure-soins' : 'blessure'}.webp`
|
|
|
|
}
|
|
|
|
|
|
|
|
getLabelGravite() {
|
|
|
|
if (this.system.gravite >= 6) {
|
|
|
|
return 'Critique'
|
|
|
|
}
|
|
|
|
if (this.system.gravite >= 4) {
|
|
|
|
return 'Grave'
|
|
|
|
}
|
|
|
|
if (this.system.gravite >= 2) {
|
|
|
|
return 'Légère'
|
|
|
|
}
|
|
|
|
return 'Contusion/éraflure'
|
|
|
|
}
|
2023-03-10 22:37:21 +01:00
|
|
|
}
|