diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 8065ed41..89515d48 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -279,7 +279,7 @@ export class RdDActorSheet extends RdDBaseActorSangSheet { // On pts de reve change this.html.find('.pointsreve-value').change(async event => await this.actor.update({ "system.reve.reve.value": event.currentTarget.value })) - this.html.find('.seuil-reve-value').change(async event => await this.actor.setPointsDeSeuil(event.currentTarget.value)) + this.html.find('.seuil-reve-value').change(async event => await this.actor.update({ "system.reve.seuil.value": event.currentTarget.value })) this.html.find('.stress-test').click(async event => await this.actor.transformerStress()) this.html.find('.moral-malheureux').click(async event => await this.actor.jetDeMoral(MORAL.MALHEUREUX)) diff --git a/module/actor.js b/module/actor.js index eae5eb8c..ee5edea4 100644 --- a/module/actor.js +++ b/module/actor.js @@ -418,7 +418,7 @@ export class RdDActor extends RdDBaseActorSang { } async _recupereMoralChateauDormant(message) { - await this.update({ 'system.compteurs.bonmoments': [] }, { render: false }) + await this.update({ 'system.compteurs.bonmoments': [] }) if (!ReglesOptionnelles.isUsing("recuperation-moral")) { return } @@ -498,14 +498,14 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ async remiseANeuf() { - await this.removeEffects(e => !e.statuses?.has(STATUSES.StatusDemiReve), { render: false }) - await this.supprimerBlessures(it => true, { render: false }) + await this.removeEffects(e => !e.statuses?.has(STATUSES.StatusDemiReve)) + 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, 'system.compteurs.ethylisme': { value: 1, nb_doses: 0, jet_moral: false } - }, { render: true }) + }) await ChatMessage.create({ whisper: ChatUtility.getOwners(this), content: 'Remise à neuf de ' + this.name @@ -689,8 +689,9 @@ export class RdDActor extends RdDBaseActorSang { message.content += `
Vous n'avez bu que ${eauConsomme} doses de liquide pour une soif de ${sustNeeded}, vous avez soif! La soif devrait vous faire ${perte} points d'endurance non récupérables, notez le cumul de côté et ajustez l'endurance`; } - await this.updateCompteurValue('sust', 0); - await this.updateCompteurValue('eau', 0); + + await this.update({ 'system.compteurs.sust.value': 0 }); + await this.update({ 'system.compteurs.eau.value': 0 }); } /* -------------------------------------------- */ @@ -753,25 +754,25 @@ export class RdDActor extends RdDBaseActorSang { updates[`system.compteurs.chance.value`] = to } } - let selectedCarac = this.findCaracByName(caracName); + let selectedCarac = this.findCaracByName(caracName) const from = selectedCarac.value - updates[`system.carac.${caracName}.value`] = to; - await this.update(updates, { noHook: true }); - await ExperienceLog.add(this, XP_TOPIC.CARAC, from, to, caracName); + updates[`system.carac.${caracName}.value`] = to + await this.update(updates, { noHook: true }) + await ExperienceLog.add(this, XP_TOPIC.CARAC, from, to, caracName) } /* -------------------------------------------- */ async updateCaracXP(caracName, to) { if (caracName == 'Taille') { - return; + return } let selectedCarac = this.findCaracByName(caracName); if (!selectedCarac.derivee) { - const from = Number(selectedCarac.xp); - await this.update({ [`system.carac.${caracName}.xp`]: to }); - await ExperienceLog.add(this, XP_TOPIC.XPCARAC, from, to, caracName); + const from = Number(selectedCarac.xp) + await this.update({ [`system.carac.${caracName}.xp`]: to }) + await ExperienceLog.add(this, XP_TOPIC.XPCARAC, from, to, caracName) } - this.checkCaracXP(caracName); + this.checkCaracXP(caracName) } /* -------------------------------------------- */ @@ -792,9 +793,9 @@ export class RdDActor extends RdDBaseActorSang { } carac.xp = toXp; carac.value = toValue; - await this.update({ [`system.carac.${caracName}`]: carac }); - await ExperienceLog.add(this, XP_TOPIC.XPCARAC, fromXp, toXp, caracName); - await ExperienceLog.add(this, XP_TOPIC.CARAC, fromValue, toValue, caracName); + await this.update({ [`system.carac.${caracName}`]: carac }) + await ExperienceLog.add(this, XP_TOPIC.XPCARAC, fromXp, toXp, caracName) + await ExperienceLog.add(this, XP_TOPIC.CARAC, fromValue, toValue, caracName) } } @@ -813,7 +814,7 @@ export class RdDActor extends RdDBaseActorSang { await competence.update({ "system.xp": toXp, "system.niveau": toNiveau, - }, { render: false }) + }) await ExperienceLog.add(this, XP_TOPIC.XP, fromXp, toXp, competence.name); await ExperienceLog.add(this, XP_TOPIC.NIVEAU, fromNiveau, toNiveau, competence.name); } @@ -822,35 +823,35 @@ export class RdDActor extends RdDBaseActorSang { async updateCompetenceStress(idOrName) { const competence = this.getCompetence(idOrName); if (!competence) { - return; + return } - const fromXp = competence.system.xp; - const fromXpStress = this.system.compteurs.experience.value; - const fromNiveau = Number(competence.system.niveau); - const xpSuivant = RdDItemCompetence.getCompetenceNextXp(fromNiveau); - const xpRequis = xpSuivant - fromXp; + const fromXp = competence.system.xp + const fromXpStress = this.system.compteurs.experience.value + const fromNiveau = Number(competence.system.niveau) + const xpSuivant = RdDItemCompetence.getCompetenceNextXp(fromNiveau) + const xpRequis = xpSuivant - fromXp if (fromXpStress <= 0 || fromNiveau >= competence.system.niveau_archetype) { ui.notifications.info(`La compétence ne peut pas augmenter! stress disponible: ${fromXpStress} expérience requise: ${xpRequis} niveau : ${fromNiveau} - archétype : ${competence.system.niveau_archetype}`); + archétype : ${competence.system.niveau_archetype}`) return } - const xpUtilise = Math.max(0, Math.min(fromXpStress, xpRequis)); - const gainNiveau = (xpUtilise >= xpRequis || xpRequis <= 0) ? 1 : 0; - const toNiveau = fromNiveau + gainNiveau; - const newXp = gainNiveau > 0 ? Math.max(fromXp - xpSuivant, 0) : (fromXp + xpUtilise); + const xpUtilise = Math.max(0, Math.min(fromXpStress, xpRequis)) + const gainNiveau = (xpUtilise >= xpRequis || xpRequis <= 0) ? 1 : 0 + const toNiveau = fromNiveau + gainNiveau + const newXp = gainNiveau > 0 ? Math.max(fromXp - xpSuivant, 0) : (fromXp + xpUtilise) await competence.update({ "system.xp": newXp, "system.niveau": toNiveau, - }, { render: false }) - const toXpStress = Math.max(0, fromXpStress - xpUtilise); - await this.update({ "system.compteurs.experience.value": toXpStress }); + }) + const toXpStress = Math.max(0, fromXpStress - xpUtilise) + await this.update({ "system.compteurs.experience.value": toXpStress }) - await ExperienceLog.add(this, XP_TOPIC.TRANSFORM, fromXpStress, toXpStress, `Dépense stress`); - await ExperienceLog.add(this, XP_TOPIC.XP, fromXp, newXp, competence.name); - await ExperienceLog.add(this, XP_TOPIC.NIVEAU, fromNiveau, toNiveau, competence.name); + await ExperienceLog.add(this, XP_TOPIC.TRANSFORM, fromXpStress, toXpStress, `Dépense stress`) + await ExperienceLog.add(this, XP_TOPIC.XP, fromXp, newXp, competence.name) + await ExperienceLog.add(this, XP_TOPIC.NIVEAU, fromNiveau, toNiveau, competence.name) } /* -------------------------------------------- */ @@ -860,8 +861,8 @@ export class RdDActor extends RdDBaseActorSang { const toNiveau = compValue ?? RdDItemCompetence.getNiveauBase(competence.system.categorie, competence.getCategories()); this.notifyCompetencesTronc(competence, toNiveau); const fromNiveau = competence.system.niveau; - await competence.update({ 'system.niveau': toNiveau }, { render: true }) - await ExperienceLog.add(this, XP_TOPIC.NIVEAU, fromNiveau, toNiveau, competence.name, true); + await competence.update({ 'system.niveau': toNiveau }) + await ExperienceLog.add(this, XP_TOPIC.NIVEAU, fromNiveau, toNiveau, competence.name, true) } } @@ -882,11 +883,13 @@ export class RdDActor extends RdDBaseActorSang { async updateCompetenceXP(idOrName, toXp) { let competence = this.getCompetence(idOrName); if (competence) { - if (isNaN(toXp) || typeof (toXp) != 'number') toXp = 0; - const fromXp = competence.system.xp; - this.checkCompetenceXP(idOrName, toXp); - await competence.update({ 'system.xp': toXp }, { render: false }) - await ExperienceLog.add(this, XP_TOPIC.XP, fromXp, toXp, competence.name, true); + if (isNaN(toXp) || typeof (toXp) != 'number') { + toXp = 0 + } + const fromXp = competence.system.xp + this.checkCompetenceXP(idOrName, toXp) + await competence.update({ 'system.xp': toXp }) + await ExperienceLog.add(this, XP_TOPIC.XP, fromXp, toXp, competence.name, true) if (toXp > fromXp) { RdDUtility.checkThanatosXP(competence) } @@ -897,10 +900,12 @@ export class RdDActor extends RdDBaseActorSang { async updateCompetenceXPSort(idOrName, toXpSort) { let competence = this.getCompetence(idOrName); if (competence) { - if (isNaN(toXpSort) || typeof (toXpSort) != 'number') toXpSort = 0; - const fromXpSort = competence.system.xp_sort; - await competence.update({ 'system.xp_sort': toXpSort }, { render: false }) - await ExperienceLog.add(this, XP_TOPIC.XPSORT, fromXpSort, toXpSort, competence.name, true); + if (isNaN(toXpSort) || typeof (toXpSort) != 'number') { + toXpSort = 0 + } + const fromXpSort = competence.system.xp_sort + await competence.update({ 'system.xp_sort': toXpSort }) + await ExperienceLog.add(this, XP_TOPIC.XPSORT, fromXpSort, toXpSort, competence.name, true) if (toXpSort > fromXpSort) { RdDUtility.checkThanatosXP(competence) } @@ -917,25 +922,25 @@ export class RdDActor extends RdDBaseActorSang { async deleteExperienceLog(from, count) { if (from >= 0 && count > 0) { - let expLog = foundry.utils.duplicate(this.system.experiencelog); - expLog.splice(from, count); - await this.update({ [`system.experiencelog`]: expLog }); + let expLog = foundry.utils.duplicate(this.system.experiencelog) + expLog.splice(from, count) + await this.update({ [`system.experiencelog`]: expLog }) } } /* -------------------------------------------- */ async updateCompteurValue(fieldName, to) { const from = this.system.compteurs[fieldName].value - await this.update({ [`system.compteurs.${fieldName}.value`]: to }); - await this.addStressExperienceLog(fieldName, from, to, fieldName, true); + await this.update({ [`system.compteurs.${fieldName}.value`]: to }) + await this.addStressExperienceLog(fieldName, from, to, fieldName, true) } /* -------------------------------------------- */ async addCompteurValue(fieldName, add, raison) { - let from = this.system.compteurs[fieldName].value; - const to = Number(from) + Number(add); - await this.update({ [`system.compteurs.${fieldName}.value`]: to }); - await this.addStressExperienceLog(fieldName, from, to, raison); + let from = this.system.compteurs[fieldName].value + const to = Number(from) + Number(add) + await this.update({ [`system.compteurs.${fieldName}.value`]: to }) + await this.addStressExperienceLog(fieldName, from, to, raison) } async addStressExperienceLog(topic, from, to, raison, manuel) { @@ -948,35 +953,22 @@ export class RdDActor extends RdDBaseActorSang { } /* -------------------------------------------- */ - async distribuerStress(compteur, stress, motif) { + async distribuerStress(compteur, valeur, motif) { if (game.user.isGM && this.hasPlayerOwner) { switch (compteur) { case 'stress': case 'experience': - await this.addCompteurValue(compteur, stress, motif); - const message = `${this.name} a reçu ${stress} points ${compteur == 'stress' ? "de stress" : "d'expérience"} (raison : ${motif})`; - ui.notifications.info(message); - game.users.players.filter(player => player.active && player.character?.id == this.id) + await this.addCompteurValue(compteur, valeur, motif); + const message = `${this.name} a reçu ${valeur} points ${compteur == 'stress' ? "de stress" : "d'expérience"} (raison : ${motif})`; + game.users.players.filter(player => this.testUserPermission(player, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) .forEach(player => ChatUtility.notifyUser(player.id, 'info', message)); } } } /* -------------------------------------------- */ - async updateAttributeValue(fieldName, fieldValue) { - await this.update({ [`system.attributs.${fieldName}.value`]: fieldValue }); - } - - /* -------------------------------------------- */ - ethylisme() { - return this.system.compteurs.ethylisme?.value ?? 1; - } - malusEthylisme() { - return Math.min(0, this.ethylisme()) - } - isAlcoolise() { - return this.ethylisme() < 1 - } - + ethylisme() { return this.system.compteurs.ethylisme?.value ?? 1 } + malusEthylisme() { return Math.min(0, this.ethylisme()) } + isAlcoolise() { return this.ethylisme() < 1 } /* -------------------------------------------- */ async actionRefoulement(item) { @@ -997,15 +989,15 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ async ajouterRefoulement(value = 1, refouler) { - let refoulement = this.system.reve.refoulement.value + value; - const roll = new Roll("1d20"); - await roll.evaluate(); - await roll.toMessage({ flavor: `${this.name} refoule ${refouler} pour ${value} points de refoulement (total: ${refoulement})` }); + let refoulement = this.system.reve.refoulement.value + value + const roll = new Roll("1d20") + await roll.evaluate() + await roll.toMessage({ flavor: `${this.name} refoule ${refouler} pour ${value} points de refoulement (total: ${refoulement})` }) if (roll.total <= refoulement) { - refoulement = 0; - await this.ajouterSouffle({ chat: true }); + refoulement = 0 + await this.ajouterSouffle({ chat: true }) } - await this.update({ "system.reve.refoulement.value": refoulement }); + await this.update({ "system.reve.refoulement.value": refoulement }) return roll; } @@ -1013,14 +1005,14 @@ export class RdDActor extends RdDBaseActorSang { async ajouterSouffle(options = { chat: false }) { let souffle = await RdDRollTables.getSouffle() //souffle.id = undefined; //TBC - await this.createEmbeddedDocuments('Item', [souffle]); + await this.createEmbeddedDocuments('Item', [souffle]) if (options.chat) { ChatMessage.create({ whisper: ChatUtility.getOwners(this), content: this.name + " subit un Souffle de Dragon : " + souffle.name - }); + }) } - return souffle; + return souffle } /* -------------------------------------------- */ @@ -1028,7 +1020,7 @@ export class RdDActor extends RdDBaseActorSang { let queue; if (this.system.reve.reve.thanatosused) { queue = await RdDRollTables.getOmbre(); - await this.update({ "system.reve.reve.thanatosused": false }); + await this.update({ "system.reve.reve.thanatosused": false }) } else { queue = await RdDRollTables.getQueue(); @@ -1038,7 +1030,7 @@ export class RdDActor extends RdDBaseActorSang { ChatMessage.create({ whisper: ChatUtility.getOwners(this), content: this.name + " subit une Queue de Dragon : " + queue.name - }); + }) } return queue; } @@ -1161,26 +1153,17 @@ export class RdDActor extends RdDBaseActorSang { } /* -------------------------------------------- */ - async regainPointDeSeuil() { - const seuil = Misc.toInt(this.system.reve.seuil.value); - const seuilMax = Misc.toInt(this.system.carac.reve.value) + async recuperationSeuilReve() { + const value = Misc.toInt(this.system.reve.seuil.value); + const max = Misc.toInt(this.system.carac.reve.value) + 2 * EffetsDraconiques.countAugmentationSeuil(this); - if (seuil < seuilMax) { - await this.setPointsDeSeuil(Math.min(seuil + 1, seuilMax)); + if (value < max) { + const nouveauSeuil = Math.min(value + 1, max); + await this.update({ "system.reve.seuil.value": nouveauSeuil }); } } - /* -------------------------------------------- */ - async setPointsDeSeuil(seuil) { - await this.update({ "system.reve.seuil.value": seuil }); - } - - /* -------------------------------------------- */ - async setPointsDeChance(chance) { - await this.updateCompteurValue("chance", chance); - } - async jetEndurance(resteEndurance = undefined) { const result = super.jetEndurance(resteEndurance); if (result.jetEndurance == 1) { @@ -1191,13 +1174,9 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ getSConst() { return RdDCarac.calculSConst(this.getConstitution()) } - - async ajoutXpConstitution(xp) { - await this.update({ "system.carac.constitution.xp": Misc.toInt(this.system.carac.constitution.xp) + xp }); - } - + async _gainXpConstitutionJetEndurance() { - await this.ajoutXpConstitution(1); // +1 XP ! + await this.updateCaracXP('constitution', Misc.toInt(this.system.carac.constitution.xp) + 1) return `${this.name} a obtenu 1 sur son Jet d'Endurance et a gagné 1 point d'Expérience en Constitution. Ce point d'XP a été ajouté automatiquement.`; } @@ -1234,27 +1213,25 @@ export class RdDActor extends RdDBaseActorSang { } /* -------------------------------------------- */ - async moralIncDec(ajustementMoral, bonmoment = "") { - if (ajustementMoral != 0) { - if (ajustementMoral > 0 && bonmoment != "" && bonmoment != undefined) { - const bonmoments = [...this.system.compteurs.bonmoments, bonmoment] - await this.update({ 'system.compteurs.bonmoments': bonmoments }, { render: false }) + async moralIncDec(ajustement, bonmoment = "") { + let moral = parseInt(this.system.compteurs.moral.value) + if (ajustement != 0) { + if (ajustement > 0 && bonmoment != "" && bonmoment != undefined) { + await this.update({ 'system.compteurs.bonmoments': [...this.system.compteurs.bonmoments, bonmoment] }) } - const startMoral = parseInt(this.system.compteurs.moral.value) - const moralTheorique = startMoral + ajustementMoral + const moralTheorique = moral + ajustement if (moralTheorique > 3) { // exaltation - const ajoutExaltation = moralTheorique - 3 - const exaltation = parseInt(this.system.compteurs.exaltation.value) + ajoutExaltation - await this.updateCompteurValue('exaltation', exaltation) + const exaltation = parseInt(this.system.compteurs.exaltation.value) + moralTheorique - 3 + await this.update({ 'system.compteurs.exaltation.value': exaltation }) } if (moralTheorique < -3) { // dissolution - const ajoutDissolution = -3 - moralTheorique - const dissolution = parseInt(this.system.compteurs.dissolution.value) + ajoutDissolution - await this.updateCompteurValue('dissolution', dissolution) + const dissolution = parseInt(this.system.compteurs.dissolution.value) - 3 - moralTheorique + await this.update({ 'system.compteurs.dissolution.value': dissolution }) } - await this.updateCompteurValue('moral', Math.max(-3, Math.min(moralTheorique, 3))); + moral = Math.max(-3, Math.min(moralTheorique, 3)); + await this.update({ 'system.compteurs.moral.value': moral }) } - return this.system.compteurs.moral.value; + return moral } /* -------------------------------------------- */ @@ -1386,7 +1363,7 @@ export class RdDActor extends RdDBaseActorSang { async manger(item, doses, options = { diminuerQuantite: true }) { const sust = item.system.sust if (sust > 0) { - await this.updateCompteurValue('sust', RdDActor.$calculNewSust(this.system.compteurs.sust.value, sust, doses)); + await this.update({ 'system.compteurs.sust.value': RdDActor.$calculNewSust(this.system.compteurs.sust.value, sust, doses) }) } await item.diminuerQuantite(doses, options); } @@ -1394,9 +1371,9 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ async boire(item, doses, options = { diminuerQuantite: true }) { - const desaltere = item.system.desaltere; - if (desaltere > 0) { - await this.updateCompteurValue('eau', RdDActor.$calculNewSust(this.system.compteurs.eau.value, desaltere, doses)); + const eau = item.system.desaltere + if (eau > 0) { + await this.update({ 'system.compteurs.eau.value': RdDActor.$calculNewSust(this.system.compteurs.eau.value, eau, doses) }) } if (item.isAlcool()) { for (let i = 0; i < doses; i++) { @@ -1523,13 +1500,12 @@ export class RdDActor extends RdDBaseActorSang { const toStress = Math.max(fromStress - stressRollData.perte - 1, 0); const fromXpSress = Number(this.system.compteurs.experience.value); const toXpStress = fromXpSress + Number(stressRollData.xp); - const updates = { + await this.update({ "system.compteurs.stress.value": toStress, "system.compteurs.experience.value": toXpStress, "system.compteurs.dissolution.value": dissolution - perteDissolution, "system.compteurs.exaltation.value": 0 - } - await this.update(updates); + }) await ExperienceLog.add(this, XP_TOPIC.STRESS, fromStress, toStress, 'Transformation') await ExperienceLog.add(this, XP_TOPIC.TRANSFORM, fromXpSress, toXpStress, 'Transformation') } @@ -1792,30 +1768,30 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ async _rollUnSortResult(rollData) { - let rolled = rollData.rolled; - let selectedSort = rollData.selectedSort; + let rolled = rollData.rolled + let selectedSort = rollData.selectedSort - rollData.isSortReserve = rollData.mettreEnReserve && !selectedSort.system.isrituel; + rollData.isSortReserve = rollData.mettreEnReserve && !selectedSort.system.isrituel rollData.show = {} - rollData.depenseReve = Number(selectedSort.system.ptreve_reel); + rollData.depenseReve = Number(selectedSort.system.ptreve_reel) if (rollData.competence.name.includes('Thanatos')) { // Si Thanatos - await this.update({ "system.reve.reve.thanatosused": true }); + await this.update({ "system.reve.reve.thanatosused": true }) } let reveActuel = parseInt(this.system.reve.reve.value) if (rolled.isSuccess) { // Réussite du sort ! if (rolled.isPart) { - rollData.depenseReve = Math.max(Math.floor(rollData.depenseReve / 2), 1); + rollData.depenseReve = Math.max(Math.floor(rollData.depenseReve / 2), 1) } if (rollData.isSortReserve) { - rollData.depenseReve++; + rollData.depenseReve++ } if (reveActuel > rollData.depenseReve) { // Incrémenter/gére le bonus de case - RdDItemSort.incrementBonusCase(this, selectedSort, rollData.tmr.coord); + RdDItemSort.incrementBonusCase(this, selectedSort, rollData.tmr.coord) if (rollData.isSortReserve) { - await this.sortMisEnReserve(selectedSort, rollData.competence, rollData.tmr.coord, Number(selectedSort.system.ptreve_reel)); + await this.sortMisEnReserve(selectedSort, rollData.competence, rollData.tmr.coord, Number(selectedSort.system.ptreve_reel)) } else { console.log('lancement de sort', rollData.selectedSort) @@ -1840,16 +1816,15 @@ export class RdDActor extends RdDBaseActorSang { } } - reveActuel = Math.max(reveActuel - rollData.depenseReve, 0); - await this.update({ "system.reve.reve.value": reveActuel }); - - await RdDRollResult.displayRollData(rollData, this, 'chat-resultat-sort.hbs'); + reveActuel = Math.max(reveActuel - rollData.depenseReve, 0) + await this.update({ "system.reve.reve.value": reveActuel }) + await RdDRollResult.displayRollData(rollData, this, 'chat-resultat-sort.hbs') if (reveActuel == 0) { // 0 points de reve - ChatMessage.create({ content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }); + ChatMessage.create({ content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }) } if (!rollData.isSortReserve || !rolled.isSuccess) { - this.tmrApp?.close(); + this.tmrApp?.close() } } @@ -2210,12 +2185,11 @@ export class RdDActor extends RdDBaseActorSang { let destinee = this.system.compteurs.destinee?.value ?? 0; if (destinee > 0) { ChatMessage.create({ content: `${this.name} a fait appel à la Destinée !` }); - destinee--; - await this.updateCompteurValue("destinee", destinee); - onSuccess(); + await this.update({ 'system.compteurs.destinee.value ': destinee - 1 }) + onSuccess() } else { - onEchec(); + onEchec() } } @@ -2461,10 +2435,13 @@ export class RdDActor extends RdDBaseActorSang { async quitterTMR(message, viewOnly, cumulFatigue) { if (this.tmrApp) { this.tmrApp = undefined - const appliquerFatigue = ReglesOptionnelles.isUsing("appliquer-fatigue"); - await this.santeIncDec( - appliquerFatigue ? "fatigue" : "endurance", - (appliquerFatigue ? 1 : -1) * cumulFatigue) + if (ReglesOptionnelles.isUsing("appliquer-fatigue")) { + await this.santeIncDec("fatigue", cumulFatigue) + } + else { + await this.santeIncDec("endurance", - cumulFatigue) + + } if (!viewOnly) { await this.supprimerSignesDraconiques(it => it.system.ephemere && it.system.duree == '1 round', { render: false }) await this.setEffect(STATUSES.StatusDemiReve, false) @@ -2527,10 +2504,10 @@ export class RdDActor extends RdDBaseActorSang { async equiperObjet(item) { if (item?.isEquipable()) { const isEquipe = !item.system.equipe; - await item.update({ "system.equipe": isEquipe }); + await item.update({ "system.equipe": isEquipe }) this.computeEncTotal() if (isEquipe) - this.verifierForceMin(item); + this.verifierForceMin(item) } } @@ -2673,10 +2650,10 @@ export class RdDActor extends RdDBaseActorSang { async setPointsCoeur(subActorId, coeurs, options = { immediat: false }) { const newSuivants = foundry.utils.duplicate(this.system.subacteurs.suivants) - const amoureux = newSuivants.find(it => it.id == subActorId); + const amoureux = newSuivants.find(it => it.id == subActorId) if (amoureux) { amoureux[options.immediat ? 'coeur' : 'prochainCoeur'] = coeurs - await this.update({ 'system.subacteurs.suivants': newSuivants }); + await this.update({ 'system.subacteurs.suivants': newSuivants }) } } @@ -2730,9 +2707,9 @@ export class RdDActor extends RdDBaseActorSang { let alreadyPresent = dataArray.find(attached => attached.id == subActor.id); if (!alreadyPresent) { let newArray = [...dataArray, subActor] - await this.update({ [dataPath]: newArray }); + await this.update({ [dataPath]: newArray }) } else { - ui.notifications.warn(dataName + " est déja attaché à " + this.name); + ui.notifications.warn(dataName + " est déja attaché à " + this.name) } } @@ -2754,18 +2731,19 @@ export class RdDActor extends RdDBaseActorSang { async deleteSubActeur(actorId) { ['vehicules', 'suivants', 'montures'].forEach(async type => { - const subList = this.system.subacteurs[type]; + const subList = this.system.subacteurs[type] if (subList.find(it => it.id == actorId)) { let newList = subList.filter(it => it.id != actorId) - await this.update({ [`system.subacteurs.${type}`]: newList }, { renderSheet: false }); + await this.update({ [`system.subacteurs.${type}`]: newList }, { render: false }) } }) } /* -------------------------------------------- */ async buildPotionGuerisonList(pointsGuerison) { - const pointsGuerisonInitial = pointsGuerison; - const blessures = this.filterItems(it => it.system.gravite > 0, 'blessure').sort(Misc.descending(it => it.system.gravite)) + const pointsGuerisonInitial = pointsGuerison + const blessures = this.filterItems(it => it.system.gravite > 0, 'blessure') + .sort(Misc.descending(it => it.system.gravite)) const ids = [] const guerisonData = { list: [], pointsConsommes: 0 } for (let blessure of blessures) { @@ -2776,14 +2754,14 @@ export class RdDActor extends RdDBaseActorSang { } } if (ids.length > 0) { - await this.supprimerBlessures(it => ids.includes(it.id), { render: blessures.length != ids.length }) + await this.supprimerBlessures(it => ids.includes(it.id)) } if (blessures.length == ids.length) { let pvManquants = this.system.sante.vie.max - this.system.sante.vie.value; let pvSoignees = Math.min(pvManquants, Math.floor(pointsGuerison / 2)); pointsGuerison -= pvSoignees * 2; guerisonData.list.push(pvSoignees + " Points de Vie soignés"); - await this.santeIncDec('vie', +pvSoignees, { render: true }) + await this.santeIncDec('vie', +pvSoignees) } guerisonData.pointsConsommes = pointsGuerisonInitial - pointsGuerison; return guerisonData; diff --git a/module/actor/base-actor-reve.js b/module/actor/base-actor-reve.js index 396f8b66..734d3494 100644 --- a/module/actor/base-actor-reve.js +++ b/module/actor/base-actor-reve.js @@ -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 }) } } } diff --git a/module/actor/base-actor-sang.js b/module/actor/base-actor-sang.js index e79b6dde..58d349eb 100644 --- a/module/actor/base-actor-sang.js +++ b/module/actor/base-actor-sang.js @@ -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() { diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index 7ffada60..e6236819 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -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()) - } } /* -------------------------------------------- */ diff --git a/module/actor/creature.js b/module/actor/creature.js index 547b0c4b..e5454520 100644 --- a/module/actor/creature.js +++ b/module/actor/creature.js @@ -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() { diff --git a/module/actor/entite-sheet.js b/module/actor/entite-sheet.js index ddf96526..0cc663d4 100644 --- a/module/actor/entite-sheet.js +++ b/module/actor/entite-sheet.js @@ -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 }); } } diff --git a/module/actor/entite.js b/module/actor/entite.js index a52b50aa..9605852b 100644 --- a/module/actor/entite.js +++ b/module/actor/entite.js @@ -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) } diff --git a/module/effect/base-active-effect.js b/module/effect/base-active-effect.js new file mode 100644 index 00000000..0edf1a46 --- /dev/null +++ b/module/effect/base-active-effect.js @@ -0,0 +1,19 @@ + +export class RdDActiveEffect extends ActiveEffect { + + async _preCreate(data, options, user) { + await this.parent?.delayedRenderSheet('_preCreateEffect', data, options) + return super._preCreate(data, options, user) + } + + async _preUpdate(changed, options, user) { + await this.parent?.delayedRenderSheet('_preUpdateEffect', changed, options) + return super._preUpdate(changed, options, user) + } + + async _preDelete(options, user) { + await this.parent?.delayedRenderSheet('_preDeleteEffect', { id: this.id }, options) + return super._preDelete(options, user) + } + +} \ No newline at end of file diff --git a/module/item.js b/module/item.js index 238f455a..aaa927c5 100644 --- a/module/item.js +++ b/module/item.js @@ -116,7 +116,6 @@ export class RdDItem extends Item { return true; } - static itemTypePluriel(type) { if (ITEM_TYPES[type]) { return ITEM_TYPES_PLURIEL[type] ?? (type + 's') @@ -175,6 +174,21 @@ export class RdDItem extends Item { super(docData, context); } + async _preCreate(data, options, user) { + await this.parent?.delayedRenderSheet('_preCreateItem', data, options) + return super._preCreate(data, options, user) + } + + async _preUpdate(changed, options, user) { + await this.parent?.delayedRenderSheet('_preUpdateItem', changed, options) + return super._preUpdate(changed, options, user) + } + + async _preDelete(options, user) { + await this.parent?.delayedRenderSheet('_preDeleteItem', { id: this.id }, options) + return super._preDelete(options, user) + } + getUniteQuantite() { switch (this.type) { case ITEM_TYPES.monnaie: return "(Pièces)" diff --git a/module/item/blessure.js b/module/item/blessure.js index 9cc0e1b0..1a796ebd 100644 --- a/module/item/blessure.js +++ b/module/item/blessure.js @@ -106,11 +106,9 @@ export class RdDItemBlessure extends RdDItem { 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) - } + 'system.itemId': this.id, + 'system.difficulte': Math.min(this.system.difficulte, tache.system.difficulte), + 'system.points_de_tache_courant': Math.max(0, this.system.premierssoins.tache) }); } } @@ -162,7 +160,7 @@ export class RdDItemBlessure extends RdDItem { message.content += ` -- une blessure ${label} reste stable`; } } - await this.update(update); + await this.update(update) } } diff --git a/module/item/sheet-base-inventaire.js b/module/item/sheet-base-inventaire.js index a465d79a..5da6d2cb 100644 --- a/module/item/sheet-base-inventaire.js +++ b/module/item/sheet-base-inventaire.js @@ -77,41 +77,41 @@ export class RdDInventaireItemSheet extends RdDItemSheetV1 { } async onAddMilieu(event) { - const milieu = this.html.find('input.input-selection-milieu').val(); + const milieu = this.html.find('input.input-selection-milieu').val() if (!milieu) { - ui.notifications.warn(`Choisissez le milieu dans lequel se trouve le/la ${this.item.name}`); + ui.notifications.warn(`Choisissez le milieu dans lequel se trouve le/la ${this.item.name}`) return } - const list = this.item.getEnvironnements(); - const exists = list.find(it => it.milieu == milieu); + const list = this.item.getEnvironnements() + const exists = list.find(it => it.milieu == milieu) if (exists) { ui.notifications.warn(`${this.item.name} a déjà une rareté ${exists.rarete} en ${milieu} (fréquence: ${exists.frequence})`); return } - const rarete = RdDRaretes.rareteFrequente(); - const added = { milieu, rarete: rarete.code, frequence: rarete.frequence }; + const rarete = RdDRaretes.rareteFrequente() + const added = { milieu, rarete: rarete.code, frequence: rarete.frequence } const newList = [added, ...list].sort(Misc.ascending(it => it.milieu)) await this.item.update({ 'system.environnement': newList }) } async onDeleteMilieu(event) { - const milieu = this.$getEventMilieu(event); + const milieu = this.$getEventMilieu(event) if (milieu != undefined) { const newList = this.item.getEnvironnements().filter(it => it.milieu != milieu) - .sort(Misc.ascending(it => it.milieu)); - await this.item.update({ 'system.environnement': newList }); + .sort(Misc.ascending(it => it.milieu)) + await this.item.update({ 'system.environnement': newList }) } } async onChange(event, doMutation) { - const list = this.item.system.environnement; - const milieu = this.$getEventMilieu(event); - const updated = list.find(it => it.milieu == milieu); + const list = this.item.system.environnement + const milieu = this.$getEventMilieu(event) + const updated = list.find(it => it.milieu == milieu) if (updated) { - doMutation(updated); + doMutation(updated) const newList = [...list.filter(it => it.milieu != milieu), updated] - .sort(Misc.ascending(it => it.milieu)); - await this.item.update({ 'system.environnement': newList }); + .sort(Misc.ascending(it => it.milieu)) + await this.item.update({ 'system.environnement': newList }) } } diff --git a/module/item/sheet-faune.js b/module/item/sheet-faune.js index cf6b2b1e..5b659c4b 100644 --- a/module/item/sheet-faune.js +++ b/module/item/sheet-faune.js @@ -20,7 +20,7 @@ export class RdDFauneItemSheet extends RdDInventaireItemSheet { 'system.actor.pack': linkedActor.pack, 'system.actor.id': linkedActor._id, 'system.actor.name': linkedActor.name - }); + }) } else { ui.notifications.warn(`${linkedActor.name} ne provient pas d'un compendium. @@ -32,7 +32,7 @@ export class RdDFauneItemSheet extends RdDInventaireItemSheet { 'system.actor.pack': '', 'system.actor.id': '', 'system.actor.name': '' - }); + }) } } diff --git a/module/rdd-main.js b/module/rdd-main.js index 6aac7b8b..295ba73b 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -94,6 +94,7 @@ import ChatRollResult from "./roll/chat-roll-result.mjs" import ExportPdf from "./actor/export-pdf/export-pdf.mjs" import { DialogFlushByDate } from "./chat/dialog-flush-by-date.mjs" import { Remote } from "./remote.mjs" +import { RdDActiveEffect } from "./effect/base-active-effect.js" /** * RdD system @@ -199,6 +200,7 @@ export class SystemReveDeDragon { // Define custom Entity classes console.log(`Initializing Reve de Dragon Documents`) CONFIG.Actor.documentClass = RdDBaseActor + CONFIG.ActiveEffect.documentClass = RdDActiveEffect CONFIG.Item.documentClass = RdDItem CONFIG.Item.dataModels = { monnaie: models.RdDModelMonnaie, diff --git a/module/tmr/effets-rencontres.js b/module/tmr/effets-rencontres.js index 5a10aa08..34dfb157 100644 --- a/module/tmr/effets-rencontres.js +++ b/module/tmr/effets-rencontres.js @@ -129,7 +129,7 @@ export class EffetsRencontre { } static regain_seuil = async (dialog, context) => { - await context.actor.regainPointDeSeuil() + await context.actor.recuperationSeuilReve() } static async $reinsertion(dialog, actor, filter) { diff --git a/templates/actor/non-haut-revant.hbs b/templates/actor/non-haut-revant.hbs index bb316d76..6470ccfa 100644 --- a/templates/actor/non-haut-revant.hbs +++ b/templates/actor/non-haut-revant.hbs @@ -29,7 +29,7 @@ {{#if system.reve.reve.thanatosused}}
  • - La prochaine queue est une Ombre + La prochaine queue est une Ombre de thanatos