Correction des updates multiples
Utilisation d'un render sur timer pour forcer le réaffichage
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, options = {}) { }
|
||||
async santeIncDec(name, inc, isCritique) { }
|
||||
|
||||
async finDeRound(options = { terminer: false }) {
|
||||
await this.finDeRoundSuppressionEffetsTermines(options)
|
||||
@@ -255,15 +255,15 @@ export class RdDBaseActorReve extends RdDBaseActor {
|
||||
if (competence) {
|
||||
function getFieldPath(fieldName) {
|
||||
switch (fieldName) {
|
||||
case "niveau": return 'system.niveau';
|
||||
case "dommages": return 'system.dommages';
|
||||
case "carac_value": return 'system.carac_value';
|
||||
case "niveau": return 'system.niveau'
|
||||
case "dommages": return 'system.dommages'
|
||||
case "carac_value": return 'system.carac_value'
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
const path = getFieldPath(fieldName);
|
||||
const path = getFieldPath(fieldName)
|
||||
if (path) {
|
||||
await competence.update({ [path]: value });
|
||||
await competence.update({ [path]: value })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,10 +125,10 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
blessure.system.vie = blessure.system.vie
|
||||
const rollPerteEndurance = new Roll(blessure.system.endurance)
|
||||
await rollPerteEndurance.evaluate()
|
||||
blessure.system.endurance =rollPerteEndurance.total
|
||||
blessure.system.endurance = rollPerteEndurance.total
|
||||
}
|
||||
const isCritique = blessure.system.gravite >= 6;
|
||||
if (isCritique){
|
||||
if (isCritique) {
|
||||
blessure.system.endurance = this.getEnduranceActuelle()
|
||||
}
|
||||
// Will update the result table
|
||||
@@ -137,8 +137,8 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
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 })
|
||||
const perteVie = await this.santeIncDec("vie", -encaissement.vie)
|
||||
const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, isCritique)
|
||||
await this.createEmbeddedDocuments('Item', [blessure])
|
||||
|
||||
foundry.utils.mergeObject(encaissement, {
|
||||
@@ -152,7 +152,7 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async santeIncDec(name, inc, options = {}) {
|
||||
async santeIncDec(name, inc, isCritique = false) {
|
||||
if (name == 'fatigue' && !ReglesOptionnelles.isUsing("appliquer-fatigue")) {
|
||||
return
|
||||
}
|
||||
@@ -164,16 +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));
|
||||
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())
|
||||
@@ -189,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 }, options)
|
||||
await this.update({ "system.sante": sante })
|
||||
|
||||
if (perteEndurance > 1) {
|
||||
// Peut-être sonné si 2 points d'endurance perdus d'un coup
|
||||
foundry.utils.mergeObject(result, await this.jetEndurance(result.newValue, options));
|
||||
foundry.utils.mergeObject(result, await this.jetEndurance(result.newValue));
|
||||
} else if (name == "endurance" && inc > 0) {
|
||||
await this.setSonne(false, options)
|
||||
await this.setSonne(false)
|
||||
}
|
||||
|
||||
if (this.isDead()) {
|
||||
await this.setEffect(STATUSES.StatusComma, true, options)
|
||||
await this.setEffect(STATUSES.StatusComma, true)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -349,10 +349,10 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
}
|
||||
}
|
||||
|
||||
async supprimerBlessures(filterToDelete, options = { render: true}) {
|
||||
async supprimerBlessures(filterToDelete) {
|
||||
const toDelete = this.filterItems(filterToDelete, ITEM_TYPES.blessure)
|
||||
.map(it => it.id)
|
||||
await this.deleteEmbeddedDocuments('Item', toDelete, options)
|
||||
await this.deleteEmbeddedDocuments('Item', toDelete)
|
||||
}
|
||||
|
||||
countBlessures(filter = it => !it.isContusion()) {
|
||||
@@ -369,7 +369,6 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
return
|
||||
}
|
||||
const jetDeVie = await RdDDice.roll("1d20");
|
||||
|
||||
const sConst = this.getSConst();
|
||||
const vie = this.system.sante.vie.value;
|
||||
const isCritique = this.nbBlessuresCritiques() > 0;
|
||||
@@ -395,15 +394,15 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
ChatMessage.create({
|
||||
content: msgText,
|
||||
whisper: ChatUtility.getOwners(this)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async jetEndurance(resteEndurance = undefined, options) {
|
||||
async jetEndurance(resteEndurance = undefined) {
|
||||
const jetEndurance = (await RdDDice.roll("1d20")).total;
|
||||
const sonne = jetEndurance == 20 || jetEndurance > (resteEndurance ?? this.system.sante.endurance.value)
|
||||
if (sonne) {
|
||||
await this.setSonne(true, options)
|
||||
await this.setSonne(true)
|
||||
}
|
||||
return { jetEndurance, sonne }
|
||||
}
|
||||
@@ -417,13 +416,13 @@ export class RdDBaseActorSang extends RdDBaseActorReve {
|
||||
}
|
||||
}
|
||||
|
||||
async setSonne(sonne = true, options = {}) {
|
||||
async setSonne(sonne = true) {
|
||||
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
|
||||
}
|
||||
await this.setEffect(STATUSES.StatusStunned, sonne, options)
|
||||
await this.setEffect(STATUSES.StatusStunned, sonne)
|
||||
}
|
||||
|
||||
isSonne() {
|
||||
|
||||
@@ -97,16 +97,7 @@ export class RdDBaseActor extends Actor {
|
||||
return actor ?? game.actors.get(actorId)
|
||||
}
|
||||
|
||||
getAlias() {
|
||||
if (this.token?.name != null && this.token != this.prototypeToken) {
|
||||
return this.token.name
|
||||
}
|
||||
return this.name
|
||||
}
|
||||
|
||||
isPersonnageJoueur() { return false }
|
||||
|
||||
static extractActorMin = (actor) => { return { id: actor?.id, type: actor?.type, name: actor?.name, img: actor?.img }; };
|
||||
static extractActorMin(actor) { return { id: actor?.id, type: actor?.type, name: actor?.name, img: actor?.img } }
|
||||
|
||||
/**
|
||||
* Cette methode surcharge Actor.create() pour ajouter si besoin des Items par défaut:
|
||||
@@ -151,6 +142,15 @@ export class RdDBaseActor extends Actor {
|
||||
super(docData, context);
|
||||
}
|
||||
|
||||
getAlias() {
|
||||
if (this.token?.name != null && this.token != this.prototypeToken) {
|
||||
return this.token.name
|
||||
}
|
||||
return this.name
|
||||
}
|
||||
|
||||
isPersonnageJoueur() { return false }
|
||||
|
||||
getCarac() {
|
||||
return foundry.utils.duplicate(this.system.carac)
|
||||
}
|
||||
@@ -216,6 +216,41 @@ export class RdDBaseActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
async _preUpdate(changed, options, user) {
|
||||
const updatedCarac = changed?.system?.carac
|
||||
if (updatedCarac && (updatedCarac.force || updatedCarac.reve || updatedCarac.taille)) {
|
||||
await this.setEffect(STATUSES.StatusSurEnc, this.isSurenc())
|
||||
}
|
||||
await this.delayedRenderSheet('_preUpdate', changed, options)
|
||||
return super._preUpdate(changed, options, user)
|
||||
}
|
||||
|
||||
_onUpdate(changed, options, userId) {
|
||||
super._onUpdate(changed, options, userId)
|
||||
if (userId == game.user.id){
|
||||
this.delayedRenderSheet('_onUpdate', changed, options)
|
||||
}
|
||||
}
|
||||
|
||||
async delayedRenderSheet(caller, data, options) {
|
||||
this.refreshDelayCounter = (this.refreshDelayCounter ?? 0)+1
|
||||
if (this.refreshDelayCounter == 1) {
|
||||
this.renderAfterDelay(this.refreshDelayCounter)
|
||||
}
|
||||
}
|
||||
|
||||
renderAfterDelay(currentCounter) {
|
||||
setTimeout(async () => {
|
||||
if (currentCounter == this.refreshDelayCounter) {
|
||||
this.sheet?.render(true)
|
||||
this.refreshDelayCounter = 0
|
||||
}
|
||||
else {
|
||||
this.renderAfterDelay(this.refreshDelayCounter)
|
||||
}
|
||||
}, 30)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareData() {
|
||||
super.prepareData()
|
||||
@@ -228,6 +263,7 @@ export class RdDBaseActor extends Actor {
|
||||
prepareActorData() { }
|
||||
|
||||
async computeEtatGeneral() { }
|
||||
|
||||
/* -------------------------------------------- */
|
||||
findPlayer() {
|
||||
return game.users.players.find(player => player.active && player.character?.id == this.id);
|
||||
@@ -322,11 +358,6 @@ export class RdDBaseActor extends Actor {
|
||||
}
|
||||
|
||||
async onUpdateActor(change, options, actorId) {
|
||||
const updatedCarac = change?.system?.carac
|
||||
if (updatedCarac && (updatedCarac.force || updatedCarac.reve || updatedCarac.taille)) {
|
||||
console.log(' onUpdateActor', change, options, actorId)
|
||||
await this.setEffect(STATUSES.StatusSurEnc, this.isSurenc())
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
@@ -15,13 +15,13 @@ export class RdDCreature extends RdDBaseActorSang {
|
||||
}
|
||||
|
||||
async remiseANeuf() {
|
||||
await this.removeEffects(e => true, { render: false })
|
||||
await this.supprimerBlessures(it => true, { render: false })
|
||||
await this.removeEffects(e => true)
|
||||
await this.supprimerBlessures(it => true)
|
||||
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() {
|
||||
|
||||
@@ -76,6 +76,6 @@ export class RdDActorEntiteSheet extends RdDBaseActorReveSheet {
|
||||
async resonanceDelete(actorId) {
|
||||
console.log('Delete : ', actorId);
|
||||
let newResonances = this.actor.system.sante.resonnance.actors.filter(id => id != actorId);
|
||||
await this.actor.update({ 'system.sante.resonnance.actors': newResonances }, { renderSheet: false });
|
||||
await this.actor.update({ 'system.sante.resonnance.actors': newResonances }, { render: false });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,7 @@ export class RdDEntite extends RdDBaseActorReve {
|
||||
|
||||
async remiseANeuf() {
|
||||
if (!this.isEntiteNonIncarnee()) {
|
||||
await this.update({
|
||||
'system.sante.endurance.value': this.system.sante.endurance.max
|
||||
});
|
||||
await this.update({ 'system.sante.endurance.value': this.system.sante.endurance.max })
|
||||
}
|
||||
await this.removeEffects(e => true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user