simplification pre-update checkCompetence
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
|
||||
import { ChatUtility } from "./chat-utility.js";
|
||||
import { Grammar } from "./grammar.js";
|
||||
import { RdDInitiative } from "./initiative.mjs";
|
||||
import { RdDItem } from "./item.js";
|
||||
@@ -71,6 +71,36 @@ export class RdDItemCompetence extends RdDItem {
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
async _preUpdate(changed, options, user) {
|
||||
await this.checkCompetenceXP(changed.system?.xp)
|
||||
return super._preUpdate(changed, options, user)
|
||||
}
|
||||
|
||||
async checkCompetenceXP(newXP, display = true) {
|
||||
if (this.actor?.isPersonnage() && newXP && newXP != this.system.xp && newXP > 0) {
|
||||
const newNiv = this.system.niveau + 1
|
||||
let needed = RdDItemCompetence.getCompetenceNextXp(newNiv)
|
||||
if (newXP >= needed) {
|
||||
const xpData = {
|
||||
alias: this.actor.getAlias(),
|
||||
competence: this.name,
|
||||
niveau: newNiv,
|
||||
xp: newXP,
|
||||
archetype: this.system.niveau_archetype,
|
||||
archetypeWarning: newNiv > this.system.niveau_archetype
|
||||
}
|
||||
if (display) {
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getOwners(this.actor),
|
||||
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.hbs`, xpData)
|
||||
})
|
||||
}
|
||||
return xpData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getLabelCategorie(category) {
|
||||
return CATEGORIES_COMPETENCES[category].label;
|
||||
|
||||
Reference in New Issue
Block a user