2023-03-10 22:37:21 +01:00
|
|
|
import { RdDItem } from "../item.js";
|
2023-03-14 02:38:21 +01:00
|
|
|
import { Misc } from "../misc.js";
|
2023-03-29 22:53:40 +02:00
|
|
|
import { RdDTimestamp } from "../time/rdd-timestamp.js";
|
2024-01-28 20:41:00 +01:00
|
|
|
import { ChatUtility } from "../chat-utility.js";
|
2023-03-10 22:37:21 +01:00
|
|
|
|
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 = {
|
|
|
|
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-14 02:38:21 +01:00
|
|
|
const definitionsBlessures = [
|
2024-01-28 20:41:00 +01:00
|
|
|
{ type: "contusion", gravite: 0, endurance: "1d4", vie: 0, label: 'Contusion/éraflure', max: 100, icon: "systems/foundryvtt-reve-de-dragon/icons/sante/eraflure.webp" },
|
|
|
|
{ type: "legere", gravite: 2, endurance: "1d6", vie: 0, label: 'Légère', max: 5, icon: "systems/foundryvtt-reve-de-dragon/icons/sante/blessure.webp" },
|
|
|
|
{ type: "grave", gravite: 4, endurance: "2d6", vie: -2, label: 'Grave', max: 2, icon: "systems/foundryvtt-reve-de-dragon/icons/sante/blessure.webp" },
|
|
|
|
{ type: "critique", gravite: 6, endurance: "-100", vie: -4, label: 'Critique', max: 1, icon: "systems/foundryvtt-reve-de-dragon/icons/sante/blessure.webp" },
|
2023-03-30 00:19:12 +02:00
|
|
|
{ type: "mort", gravite: 8, label: 'Mort', max: 1, icon: "systems/foundryvtt-reve-de-dragon/icons/sante/mort.webp" }
|
2023-03-14 02:38:21 +01:00
|
|
|
]
|
|
|
|
|
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-14 02:38:21 +01:00
|
|
|
prepareDerivedData() {
|
|
|
|
super.prepareDerivedData();
|
2023-03-30 00:19:12 +02:00
|
|
|
this.system.label = this.getLabelGravite()
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2024-06-01 01:53:14 +02:00
|
|
|
return foundry.utils.mergeObject(BASE_TACHE_SOIN_BLESSURE, tache, { inplace: false })
|
2023-03-10 22:41:11 +01:00
|
|
|
}
|
2024-01-28 20:41:00 +01:00
|
|
|
|
|
|
|
static async applyFullBlessure(actor, gravite) {
|
|
|
|
const definition = RdDItemBlessure.getDefinition(gravite)
|
|
|
|
|
|
|
|
let lostEndurance = 0
|
|
|
|
let lostVie = 0
|
|
|
|
if (definition.endurance) {
|
|
|
|
lostEndurance = new Roll(definition.endurance).roll({async: false}).total;
|
|
|
|
actor.santeIncDec("endurance", -Number(lostEndurance));
|
|
|
|
}
|
|
|
|
if (definition.vie) {
|
|
|
|
lostVie = definition.vie
|
|
|
|
actor.santeIncDec("vie", definition.vie)
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.createBlessure(actor, gravite)
|
|
|
|
|
|
|
|
ChatMessage.create({
|
|
|
|
content: `Blessure ${definition.label} appliquée à ${actor.name}`+
|
|
|
|
`<br>Perte d'endurance : ${lostEndurance}`+
|
|
|
|
`<br>Perte de Vie : ${lostVie}`,
|
|
|
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(actor.name)
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:19:12 +02:00
|
|
|
static async createBlessure(actor, gravite, localisation = '', attacker) {
|
2023-03-14 02:38:21 +01:00
|
|
|
const definition = RdDItemBlessure.getDefinition(gravite)
|
|
|
|
const blessure = {
|
2023-03-30 00:19:12 +02:00
|
|
|
name: definition.label,
|
2023-03-14 02:38:21 +01:00
|
|
|
type: 'blessure',
|
|
|
|
img: definition.icon,
|
|
|
|
system: {
|
|
|
|
gravite: gravite,
|
|
|
|
difficulte: - gravite,
|
2023-03-30 00:19:12 +02:00
|
|
|
localisation: localisation,
|
|
|
|
origine: attacker?.name ?? ""
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const blessures = await actor.createEmbeddedDocuments('Item', [blessure])
|
|
|
|
return blessures[0]
|
|
|
|
}
|
2023-03-10 22:41:11 +01:00
|
|
|
|
|
|
|
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-14 02:38:21 +01:00
|
|
|
async setSoinsBlessure(systemUpdate = {}) {
|
2024-06-01 01:53:14 +02:00
|
|
|
systemUpdate = foundry.utils.mergeObject(systemUpdate, this.system, { overwrite: false })
|
|
|
|
systemUpdate.soinscomplets.done = systemUpdate.premierssoins.done && systemUpdate.soinscomplets.done
|
2023-03-14 02:38:21 +01:00
|
|
|
await this.update({
|
|
|
|
img: this.getImgSoins(systemUpdate.gravite, systemUpdate.soinscomplets.done),
|
|
|
|
system: systemUpdate
|
2024-06-01 01:53:14 +02:00
|
|
|
})
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async recuperationBlessure({ actor, timestamp, message, isMaladeEmpoisonne, blessures }) {
|
|
|
|
if (this.parent != actor || actor == undefined) {
|
2023-03-20 23:28:25 +01:00
|
|
|
return
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|
2023-03-20 23:28:25 +01:00
|
|
|
if (new RdDTimestamp(this.system.temporel.fin).compare(timestamp) > 0) {
|
2023-03-14 02:38:21 +01:00
|
|
|
// attente periode
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (this.system.gravite > 0) {
|
2023-03-20 23:28:25 +01:00
|
|
|
const update = { system: { premierssoins: { bonus: 0 }, soinscomplets: { bonus: 0 } } }
|
2023-03-14 02:38:21 +01:00
|
|
|
const gravite = this.system.gravite;
|
|
|
|
const graviteMoindre = gravite - 2;
|
|
|
|
const moindres = blessures.filter(it => it.system.gravite == graviteMoindre, 'blessures').length
|
2023-03-30 00:19:12 +02:00
|
|
|
const label = this.getLabelGravite();
|
2023-03-14 02:38:21 +01:00
|
|
|
|
2023-03-20 23:28:25 +01:00
|
|
|
let rolled = await actor.jetRecuperationConstitution(this.system.soinscomplets.bonus, message);
|
2023-03-14 02:38:21 +01:00
|
|
|
|
|
|
|
if (rolled.isETotal) {
|
2023-03-30 00:19:12 +02:00
|
|
|
message.content += ` -- une blessure ${label} s'infecte (temps de guérison augmenté de ${gravite} jours, perte de vie)`;
|
2023-03-14 02:38:21 +01:00
|
|
|
await actor.santeIncDec("vie", -1);
|
2024-05-01 09:13:21 +02:00
|
|
|
foundry.utils.mergeObject(update, {
|
2023-03-20 23:28:25 +01:00
|
|
|
system: { fin: { indexDate: timestamp.addJours(gravite).indexDate } }
|
|
|
|
});
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!isMaladeEmpoisonne && rolled.isSuccess && this.peutRetrograder(graviteMoindre, moindres)) {
|
2023-03-30 00:19:12 +02:00
|
|
|
message.content += ` -- une blessure ${label} cicatrise`;
|
2024-05-01 09:13:21 +02:00
|
|
|
foundry.utils.mergeObject(update, {
|
2023-11-12 19:52:57 +01:00
|
|
|
system: {
|
|
|
|
gravite: graviteMoindre,
|
|
|
|
temporel: { fin: { indexDate: timestamp.addJours(graviteMoindre).indexDate } }
|
|
|
|
}
|
2023-03-20 23:28:25 +01:00
|
|
|
});
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|
|
|
|
else {
|
2023-03-30 00:19:12 +02:00
|
|
|
message.content += ` -- une blessure ${label} reste stable`;
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
await this.update(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
peutRetrograder(graviteMoindre, moindres) {
|
|
|
|
return moindres < RdDItemBlessure.getDefinition(graviteMoindre).max
|
|
|
|
}
|
|
|
|
|
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-14 02:38:21 +01:00
|
|
|
getImgSoins(gravite, soins) {
|
|
|
|
let img = 'blessure'
|
|
|
|
if (gravite > 6) {
|
|
|
|
img = 'mort'
|
|
|
|
}
|
|
|
|
if (gravite <= 0) {
|
|
|
|
img = 'eraflure'
|
|
|
|
}
|
|
|
|
return `systems/foundryvtt-reve-de-dragon/icons/sante/${soins ? 'blessure-soins' : img}.webp`
|
2023-03-10 22:41:11 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 02:38:21 +01:00
|
|
|
getLabelGravite() {
|
2023-03-30 00:19:12 +02:00
|
|
|
return RdDItemBlessure.getDefinition(this.system.gravite).label
|
2023-03-10 22:41:11 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 02:38:21 +01:00
|
|
|
static getDefinition(gravite) {
|
|
|
|
return definitionsBlessures.sort(Misc.ascending(it => it.gravite))
|
|
|
|
.find(it => it.gravite >= gravite);
|
|
|
|
}
|
|
|
|
static maxBlessures(gravite) {
|
|
|
|
return RdDItemBlessure.getDefinition(gravite).max
|
2023-03-10 22:41:11 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 02:38:21 +01:00
|
|
|
isContusion() {
|
|
|
|
return this.system.gravite <= 0
|
|
|
|
}
|
|
|
|
isLegere() {
|
|
|
|
return this.system.gravite > 0 && this.system.gravite <= 2
|
|
|
|
}
|
|
|
|
isGrave() {
|
|
|
|
return this.system.gravite > 2 && this.system.gravite <= 4
|
2023-03-10 22:41:11 +01:00
|
|
|
}
|
2023-03-14 02:38:21 +01:00
|
|
|
isCritique() {
|
|
|
|
return this.system.gravite > 4 && this.system.gravite <= 6
|
|
|
|
}
|
|
|
|
isMort() {
|
|
|
|
return this.system.gravite > 6
|
|
|
|
}
|
2023-03-30 00:19:12 +02:00
|
|
|
|
|
|
|
getProprietes() {
|
|
|
|
return [
|
|
|
|
RdDItem.propertyIfDefined('Causée par', this.system.origine, this.system.origine),
|
|
|
|
`<b>Heure et Date</b>: ${new RdDTimestamp(this.system.temporel.debut).formatDateHeure()}`,
|
|
|
|
RdDItem.propertyIfDefined('Blessé', this.parent?.name, this.parent),
|
|
|
|
`<b>Localisation</b>: ${this.system.localisation}`,
|
|
|
|
`<b>Gravité</b>: ${RdDItemBlessure.getDefinition(this.system.gravite).label}`,
|
|
|
|
`<b>Difficulté des soins</b>: ${this.system.difficulte}`,
|
|
|
|
(this.system.soinscomplets.done ?
|
|
|
|
`<b>Bonus soins complets</b>: ${this.system.soinscomplets.bonus}` :
|
|
|
|
(this.system.premierssoins.done ?
|
|
|
|
`<b>Bonus premiers soins</b>: ${this.system.premierssoins.bonus}` :
|
|
|
|
`<b>Points de tâche</b>: ${this.system.premierssoins.tache}`
|
|
|
|
)
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2023-03-14 02:38:21 +01:00
|
|
|
}
|