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:
@@ -158,7 +158,7 @@ export class RdDBaseActorReve extends RdDBaseActor {
|
||||
|
||||
computeResumeBlessure() { }
|
||||
countBlessures(filter = it => !it.isContusion()) { return 0 }
|
||||
async santeIncDec(name, inc, isCritique = false) { }
|
||||
async santeIncDec(name, inc, options = {}) { }
|
||||
|
||||
async finDeRound(options = { terminer: false }) {
|
||||
await this.finDeRoundSuppressionEffetsTermines(options)
|
||||
@@ -577,7 +577,7 @@ export class RdDBaseActorReve extends RdDBaseActor {
|
||||
async rollArme(arme, maniement = 'competence', token = undefined) {
|
||||
token = token ?? RdDUtility.getSelectedToken(this)
|
||||
const compToUse = RdDItemArme.getCompetenceArme(arme, maniement)
|
||||
|
||||
|
||||
if (!RdDItemArme.isUtilisable(arme)) {
|
||||
ui.notifications.warn(`Arme inutilisable: ${arme.name} non équipée ou avec une résistance de 0 ou moins`)
|
||||
return
|
||||
@@ -656,26 +656,21 @@ export class RdDBaseActorReve extends RdDBaseActor {
|
||||
jet => this.$onEncaissement(jet, show, attackerToken, defenderToken));
|
||||
}
|
||||
}
|
||||
|
||||
async $onEncaissement(jet, show, attackerToken, defenderToken) {
|
||||
await this.onAppliquerJetEncaissement(jet, attackerToken);
|
||||
await this.$afficherEncaissement(jet, show, defenderToken);
|
||||
}
|
||||
|
||||
async onAppliquerJetEncaissement(encaissement, attackerToken) { }
|
||||
|
||||
async $afficherEncaissement(encaissement, show, defenderToken) {
|
||||
async $onEncaissement(encaissement, show, attackerToken, defenderToken) {
|
||||
await this.onAppliquerJetEncaissement(encaissement, attackerToken);
|
||||
|
||||
foundry.utils.mergeObject(encaissement, {
|
||||
alias: defenderToken?.name ?? this.getAlias(),
|
||||
hasPlayerOwner: this.hasPlayerOwner,
|
||||
show: show ?? {}
|
||||
}, { overwrite: false });
|
||||
|
||||
await ChatUtility.createChatWithRollMode(
|
||||
{
|
||||
roll: encaissement.roll,
|
||||
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-resultat-encaissement.hbs', encaissement)
|
||||
},
|
||||
await ChatUtility.createChatWithRollMode({
|
||||
roll: encaissement.roll,
|
||||
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-resultat-encaissement.hbs', encaissement)
|
||||
},
|
||||
this
|
||||
)
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -285,14 +285,14 @@ export class RdDBaseActor extends Actor {
|
||||
return this.getEffects().filter(it => it.statuses.has(effectId))
|
||||
}
|
||||
|
||||
async setEffect(effectId, status) {
|
||||
async setEffect(effectId, status, options = {render: true}) {
|
||||
if (this.isEffectAllowed(effectId)) {
|
||||
const effects = this.getEffectsByStatus(effectId)
|
||||
if (!status && effects.length > 0) {
|
||||
await this.deleteEmbeddedDocuments('ActiveEffect', effects.map(it => it.id), { render: true })
|
||||
await this.deleteEmbeddedDocuments('ActiveEffect', effects.map(it => it.id), options)
|
||||
}
|
||||
if (status && effects.length == 0) {
|
||||
await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.prepareActiveEffect(effectId)], { render: true })
|
||||
await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.prepareActiveEffect(effectId)], options)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,13 +301,13 @@ export class RdDBaseActor extends Actor {
|
||||
this.removeEffects(it => it.id == id)
|
||||
}
|
||||
|
||||
async removeEffects(filter = e => true) {
|
||||
async removeEffects(filter = e => true, options = {render: true}) {
|
||||
if (game.user.isGM) {
|
||||
const ids = this.getEffects(filter)
|
||||
.filter(it => this.canRemoveEffects(it))
|
||||
.map(it => it.id)
|
||||
if (ids.length > 0) {
|
||||
await this.deleteEmbeddedDocuments('ActiveEffect', ids)
|
||||
await this.deleteEmbeddedDocuments('ActiveEffect', ids, options)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ export class RdDCreature extends RdDBaseActorSang {
|
||||
}
|
||||
|
||||
async remiseANeuf() {
|
||||
await this.removeEffects(e => true);
|
||||
await this.supprimerBlessures(it => true);
|
||||
await this.removeEffects(e => true, { render: false })
|
||||
await this.supprimerBlessures(it => true, { render: false })
|
||||
await this.update({
|
||||
'system.sante.endurance.value': this.system.sante.endurance.max,
|
||||
'system.sante.vie.value': this.system.sante.vie.max,
|
||||
'system.sante.fatigue.value': 0
|
||||
});
|
||||
}, { render: true });
|
||||
}
|
||||
|
||||
async finDeRoundBlessures() {
|
||||
|
||||
@@ -86,11 +86,7 @@ export class RdDEntite extends RdDBaseActorReve {
|
||||
return
|
||||
}
|
||||
const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance);
|
||||
foundry.utils.mergeObject(encaissement, {
|
||||
resteEndurance: perteEndurance.newValue,
|
||||
endurance: perteEndurance.perte,
|
||||
blessure: RdDItemBlessure.prepareBlessure(encaissement.gravite, encaissement.dmg?.loc.label ?? '', attackerToken)
|
||||
})
|
||||
foundry.utils.mergeObject(encaissement, { resteEndurance: perteEndurance.newValue, endurance: perteEndurance.perte })
|
||||
}
|
||||
|
||||
isEntiteAccordee(attacker) {
|
||||
|
||||
@@ -103,11 +103,10 @@ export class RdDActorExportSheet extends RdDActorSheet {
|
||||
gravite: this.html.find(event.currentTarget).data('gravite')
|
||||
})
|
||||
)
|
||||
this.html.find('.click-blessure-add').click(async event =>
|
||||
await this.actor.ajouterBlessure({
|
||||
gravite: this.html.find(event.currentTarget).data('gravite')
|
||||
})
|
||||
)
|
||||
this.html.find('.click-blessure-add').click(async event => {
|
||||
const blessure = this.actor.nouvelleBlessure(this.html.find(event.currentTarget).data('gravite'))
|
||||
await actor.createEmbeddedDocuments('Item', [blessure])
|
||||
})
|
||||
this.html.find('.button-export').click(async event => await
|
||||
ExportScriptarium.INSTANCE.exportActors([this.actor],
|
||||
`${this.actor.uuid}-${this.actor.name}`
|
||||
|
||||
Reference in New Issue
Block a user