Fix: affichage blessures et pertes
Les pertes et la récupération sont correctement gérées (en ne faisant qu'un seul render pour le personnage)
This commit is contained in:
@@ -113,9 +113,33 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
|
||||
async onAppliquerJetEncaissement(encaissement, attackerToken) {
|
||||
const santeOrig = foundry.utils.duplicate(this.system.sante);
|
||||
const blessure = await this.ajouterBlessure(encaissement, attackerToken); // Will update the result table
|
||||
const perteVie = await this.santeIncDec("vie", -encaissement.vie);
|
||||
const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, blessure?.isCritique());
|
||||
const blessure = this.nouvelleBlessure(encaissement.gravite, {
|
||||
localisation: encaissement.dmg?.loc.label ?? '',
|
||||
origine: attackerToken?.name ?? ''
|
||||
})
|
||||
if (blessure.system.gravite == encaissement.gravite) {
|
||||
blessure.system.vie = encaissement.vie
|
||||
blessure.system.endurance = encaissement.endurance
|
||||
}
|
||||
else { // aggravation du fait du nombre de blessures
|
||||
blessure.system.vie = blessure.system.vie
|
||||
const rollPerteEndurance = new Roll(blessure.system.endurance)
|
||||
await rollPerteEndurance.evaluate()
|
||||
blessure.system.endurance =rollPerteEndurance.total
|
||||
}
|
||||
const isCritique = blessure.system.gravite >= 6;
|
||||
if (isCritique){
|
||||
blessure.system.endurance = this.getEnduranceActuelle()
|
||||
}
|
||||
// Will update the result table
|
||||
if (blessure.system.gravite > 6) {
|
||||
this.setEffect(STATUSES.StatusComma, true)
|
||||
encaissement.mort = "à seconde blessure critique"
|
||||
}
|
||||
|
||||
const perteVie = await this.santeIncDec("vie", -encaissement.vie, { render: false })
|
||||
const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, { isCritique, render: false })
|
||||
await this.createEmbeddedDocuments('Item', [blessure])
|
||||
|
||||
foundry.utils.mergeObject(encaissement, {
|
||||
resteEndurance: perteEndurance.newValue,
|
||||
@@ -124,11 +148,11 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
endurance: perteEndurance.perte,
|
||||
vie: santeOrig.vie.value - perteVie.newValue,
|
||||
blessure: blessure
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async santeIncDec(name, inc, isCritique = false) {
|
||||
async santeIncDec(name, inc, options = {}) {
|
||||
if (name == 'fatigue' && !ReglesOptionnelles.isUsing("appliquer-fatigue")) {
|
||||
return
|
||||
}
|
||||
@@ -140,15 +164,16 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
const result = { sonne: false }
|
||||
let perteEndurance = 0
|
||||
let minValue = name == "vie" ? -this.getSConst() - 1 : 0;
|
||||
|
||||
|
||||
result.newValue = Math.max(minValue, Math.min(compteur.value + inc, compteur.max));
|
||||
//console.log("New value ", inc, minValue, result.newValue);
|
||||
let fatigue = 0;
|
||||
|
||||
if (name == "endurance" && result.newValue == 0 && inc < 0 && !options.isCritique) { // perte endurance et endurance devient 0 (sauf critique) -> -1 vie
|
||||
sante.vie.value--;
|
||||
result.perteVie = true;
|
||||
}
|
||||
foundry.utils.mergeObject(options, { render: true }, { overwrite: false })
|
||||
if (name == "endurance") {
|
||||
if (result.newValue == 0 && inc < 0 && !isCritique) { // perte endurance et endurance devient 0 (sauf critique) -> -1 vie
|
||||
sante.vie.value--;
|
||||
result.perteVie = true;
|
||||
}
|
||||
result.newValue = Math.max(0, result.newValue);
|
||||
if (inc > 0) { // le max d'endurance s'applique seulement à la récupération
|
||||
result.newValue = Math.min(result.newValue, this._computeEnduranceMax())
|
||||
@@ -164,17 +189,17 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
if (ReglesOptionnelles.isUsing("appliquer-fatigue") && sante.fatigue && fatigue > 0) {
|
||||
sante.fatigue.value = Math.max(sante.fatigue.value + fatigue, this.getFatigueMin());
|
||||
}
|
||||
await this.update({ "system.sante": sante }, { render: true })
|
||||
await this.update({ "system.sante": sante }, options)
|
||||
|
||||
if (perteEndurance > 1) {
|
||||
// Peut-être sonné si 2 points d'endurance perdus d'un coup
|
||||
foundry.utils.mergeObject(result, await this.jetEndurance(result.newValue));
|
||||
foundry.utils.mergeObject(result, await this.jetEndurance(result.newValue, options));
|
||||
} else if (name == "endurance" && inc > 0) {
|
||||
await this.setSonne(false);
|
||||
await this.setSonne(false, options)
|
||||
}
|
||||
|
||||
if (this.isDead()) {
|
||||
await this.setEffect(STATUSES.StatusComma, true);
|
||||
await this.setEffect(STATUSES.StatusComma, true, options)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -306,32 +331,15 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async ajouterBlessure(encaissement, attackerToken = undefined) {
|
||||
if (encaissement.gravite < 0) return;
|
||||
if (encaissement.gravite > 0) {
|
||||
while (this.countBlessures(it => it.system.gravite == encaissement.gravite) >= RdDItemBlessure.maxBlessures(encaissement.gravite) && encaissement.gravite <= 6) {
|
||||
nouvelleBlessure(gravite, options = { origine: undefined, localisation: '' }) {
|
||||
if (gravite < 0) return
|
||||
if (gravite > 0) {
|
||||
while (this.countBlessures(it => it.system.gravite == gravite) >= RdDItemBlessure.maxBlessures(gravite) && gravite <= 6) {
|
||||
// Aggravation
|
||||
encaissement.gravite += 2
|
||||
if (encaissement.gravite > 2) {
|
||||
encaissement.vie += 2;
|
||||
}
|
||||
gravite += 2
|
||||
}
|
||||
}
|
||||
const endActuelle = this.getEnduranceActuelle();
|
||||
const blessure = await RdDItemBlessure.createBlessure(this, encaissement.gravite, encaissement.dmg?.loc.label ?? '', attackerToken);
|
||||
if (blessure.isCritique()) {
|
||||
encaissement.endurance = endActuelle
|
||||
}
|
||||
|
||||
if (blessure.isMort()) {
|
||||
this.setEffect(STATUSES.StatusComma, true);
|
||||
encaissement.mort = true;
|
||||
ChatMessage.create({
|
||||
content: `<img class="chat-icon" src="icons/svg/skull.svg" data-tooltip="charge" />
|
||||
<strong>${this.getAlias()} vient de succomber à une seconde blessure critique ! Que les Dragons gardent son Archétype en paix !</strong>`
|
||||
});
|
||||
}
|
||||
return blessure;
|
||||
return RdDItemBlessure.prepareBlessure(gravite, options);
|
||||
}
|
||||
|
||||
async supprimerBlessure({ gravite }) {
|
||||
@@ -341,10 +349,10 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
}
|
||||
}
|
||||
|
||||
async supprimerBlessures(filterToDelete) {
|
||||
async supprimerBlessures(filterToDelete, options = { render: true}) {
|
||||
const toDelete = this.filterItems(filterToDelete, ITEM_TYPES.blessure)
|
||||
.map(it => it.id);
|
||||
await this.deleteEmbeddedDocuments('Item', toDelete);
|
||||
.map(it => it.id)
|
||||
await this.deleteEmbeddedDocuments('Item', toDelete, options)
|
||||
}
|
||||
|
||||
countBlessures(filter = it => !it.isContusion()) {
|
||||
@@ -391,11 +399,11 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async jetEndurance(resteEndurance = undefined) {
|
||||
async jetEndurance(resteEndurance = undefined, options) {
|
||||
const jetEndurance = (await RdDDice.roll("1d20")).total;
|
||||
const sonne = jetEndurance == 20 || jetEndurance > (resteEndurance ?? this.system.sante.endurance.value)
|
||||
if (sonne) {
|
||||
await this.setSonne();
|
||||
await this.setSonne(true, options)
|
||||
}
|
||||
return { jetEndurance, sonne }
|
||||
}
|
||||
@@ -409,12 +417,13 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
}
|
||||
}
|
||||
|
||||
async setSonne(sonne = true) {
|
||||
async setSonne(sonne = true, options = {}) {
|
||||
if (!game.combat && sonne) {
|
||||
// TODO: vérifier si comportement toujours valable
|
||||
ui.notifications.info(`${this.getAlias()} est hors combat, il ne reste donc pas sonné`);
|
||||
return;
|
||||
return
|
||||
}
|
||||
await this.setEffect(STATUSES.StatusStunned, sonne)
|
||||
await this.setEffect(STATUSES.StatusStunned, sonne, options)
|
||||
}
|
||||
|
||||
isSonne() {
|
||||
|
||||
Reference in New Issue
Block a user