Vincent Vandemeulebrouck
9e6d5856b1
- raccourci soins HUD - edition rapide des Item blessure - gestion des taches de soins liées aux blessures
94 lines
2.9 KiB
JavaScript
94 lines
2.9 KiB
JavaScript
import { RdDItem } from "../item.js";
|
|
|
|
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 } },
|
|
}
|
|
|
|
export class RdDItemBlessure extends RdDItem {
|
|
|
|
static get defaultIcon() {
|
|
return "systems/foundryvtt-reve-de-dragon/icons/sante/blessure.webp";
|
|
}
|
|
|
|
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)
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
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'
|
|
}
|
|
} |