DAtaModels + Appv2 migration : OK
This commit is contained in:
@@ -145,6 +145,12 @@ export class MournbladeCYD2Actor extends Actor {
|
||||
getRunes() {
|
||||
return this.getItemSorted(["rune"])
|
||||
}
|
||||
getRuneEffects() {
|
||||
return this.getItemSorted(["runeeffect"])
|
||||
}
|
||||
getProfil() {
|
||||
return this.getProfils()[0] ?? null
|
||||
}
|
||||
getTraitsChaotiques() {
|
||||
return this.getItemSorted(["traitchaotique"])
|
||||
}
|
||||
@@ -220,6 +226,9 @@ export class MournbladeCYD2Actor extends Actor {
|
||||
}
|
||||
return equipProtection // Uniquement la protection des armures + boucliers
|
||||
}
|
||||
getProtectionTotal() {
|
||||
return this.getProtection()
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCombatValues() {
|
||||
@@ -267,12 +276,13 @@ export class MournbladeCYD2Actor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_preUpdate(changed, options, user) {
|
||||
if (changed?.system?.sante?.etat && changed?.system?.sante?.etat != this.system.sante.etat) {
|
||||
if (changed?.system?.sante?.etat !== undefined && changed.system.sante.etat != this.system.sante.etat) {
|
||||
const oldEtat = this.system.sante.etat
|
||||
setTimeout(() => {
|
||||
this.processCombativite(changed.system.sante)
|
||||
this.processCombativite(changed.system.sante, oldEtat)
|
||||
}, 800)
|
||||
}
|
||||
if (changed?.system?.ame?.etat && changed?.system?.ame?.etat != this.system.ame.etat) {
|
||||
if (changed?.system?.ame?.etat !== undefined && changed.system.ame.etat != this.system.ame.etat) {
|
||||
// L'état d'Âme ne peut pas être inférieur au minimum (max dans le système)
|
||||
let minAme = this.system.ame.max !== undefined ? this.system.ame.max : 0
|
||||
if (changed.system.ame.etat < minAme) {
|
||||
@@ -282,8 +292,9 @@ export class MournbladeCYD2Actor extends Actor {
|
||||
if (changed.system.ame.etat > this.system.ame.nbame) {
|
||||
changed.system.ame.etat = this.system.ame.nbame
|
||||
}
|
||||
const oldEtat = this.system.ame.etat
|
||||
setTimeout(() => {
|
||||
this.processAme(changed.system.ame)
|
||||
this.processAme(changed.system.ame, oldEtat)
|
||||
}, 800)
|
||||
}
|
||||
// Si le max d'Âme change, ajuster l'état actuel si nécessaire
|
||||
@@ -500,38 +511,57 @@ export class MournbladeCYD2Actor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
processCombativite(sante) {
|
||||
processCombativite(sante, oldEtat = undefined) {
|
||||
sante = sante || foundry.utils.duplicate(this.system.sante)
|
||||
// Gestion des états affaibli et très affaibli
|
||||
if (sante.etat == this.system.sante.nbcombativite - 2 || sante.etat == this.system.sante.nbcombativite - 1) {
|
||||
if (sante.etat == this.system.sante.nbcombativite - 2 && this.items.find(item => item.type == "talent" && item.name.toLowerCase() == "encaissement")) {
|
||||
ChatMessage.create({ content: `<strong>${this.name} ne subit pas les 2 adversités rouge grâce à Encaissement. Pensez à les ajouter à la fin de la scène !</strong>` })
|
||||
} else if (sante.etat == this.system.sante.nbcombativite - 1 && this.items.find(item => item.type == "talent" && item.name.toLowerCase().includes("vaillant"))) {
|
||||
ChatMessage.create({ content: `<strong>${this.name} ne subit pas les 2 adversités rouge grâce à Vaillant. Pensez à les ajouter à la fin de la scène !</strong>` })
|
||||
const affaibli = this.system.sante.nbcombativite - 2
|
||||
const tresAffaibli = this.system.sante.nbcombativite - 1
|
||||
// oldEtat permet de détecter les sauts qui franchissent Affaibli ou Très Affaibli
|
||||
// sans y atterrir exactement (ex: 0 → 5 doit déclencher les deux seuils)
|
||||
const prev = oldEtat !== undefined ? oldEtat : sante.etat
|
||||
const curr = sante.etat
|
||||
|
||||
const passedAffaibli = curr >= affaibli && prev < affaibli
|
||||
const passedTresAffaibli = curr >= tresAffaibli && prev < tresAffaibli
|
||||
|
||||
if (passedAffaibli) {
|
||||
if (this.items.find(item => item.type == "talent" && item.name.toLowerCase() == "encaissement")) {
|
||||
ChatMessage.create({ content: `<strong>${this.name} ne subit pas les 2 adversités rouge (Affaibli) grâce à Encaissement. Pensez à les ajouter à la fin de la scène !</strong>` })
|
||||
} else {
|
||||
ChatMessage.create({ content: `<strong>${this.name} subit 2 adversités rouge !</strong>` })
|
||||
ChatMessage.create({ content: `<strong>${this.name} est Affaibli et subit 2 adversités rouge !</strong>` })
|
||||
this.incDecAdversite("rouge", 2)
|
||||
}
|
||||
}
|
||||
if (passedTresAffaibli) {
|
||||
if (this.items.find(item => item.type == "talent" && item.name.toLowerCase().includes("vaillant"))) {
|
||||
ChatMessage.create({ content: `<strong>${this.name} ne subit pas les 2 adversités rouge (Très Affaibli) grâce à Vaillant. Pensez à les ajouter à la fin de la scène !</strong>` })
|
||||
} else {
|
||||
ChatMessage.create({ content: `<strong>${this.name} est Très Affaibli et subit 2 adversités rouge supplémentaires !</strong>` })
|
||||
this.incDecAdversite("rouge", 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
processAme(ame) {
|
||||
processAme(ame, oldEtat = undefined) {
|
||||
ame = ame || foundry.utils.duplicate(this.system.ame)
|
||||
let traumatiseValue = this.system.ame.nbame - 2
|
||||
let tresTraumatiseValue = this.system.ame.nbame - 1
|
||||
let briseValue = this.system.ame.nbame
|
||||
const traumatiseValue = this.system.ame.nbame - 2
|
||||
const tresTraumatiseValue = this.system.ame.nbame - 1
|
||||
const briseValue = this.system.ame.nbame
|
||||
const prev = oldEtat !== undefined ? oldEtat : ame.etat
|
||||
const curr = ame.etat
|
||||
|
||||
// Gestion des états Traumatisé, Très Traumatisé et Brisé
|
||||
if (ame.etat == traumatiseValue) {
|
||||
// Déclencher pour chaque seuil franchi ou atteint, même en cas de saut
|
||||
if (curr >= traumatiseValue && prev < traumatiseValue) {
|
||||
ChatMessage.create({ content: `<strong>${this.name} est Traumatisé et subit 1 adversité bleue et 1 adversité noire !</strong>` })
|
||||
this.incDecAdversite("bleue", 1)
|
||||
this.incDecAdversite("noire", 1)
|
||||
} else if (ame.etat == tresTraumatiseValue) {
|
||||
}
|
||||
if (curr >= tresTraumatiseValue && prev < tresTraumatiseValue) {
|
||||
ChatMessage.create({ content: `<strong>${this.name} est Très Traumatisé et subit 1 adversité bleue et 1 adversité noire !</strong>` })
|
||||
this.incDecAdversite("bleue", 1)
|
||||
this.incDecAdversite("noire", 1)
|
||||
} else if (ame.etat >= briseValue) {
|
||||
}
|
||||
if (curr >= briseValue && prev < briseValue) {
|
||||
ChatMessage.create({ content: `<strong>${this.name} est Brisé et subit 1 adversité noire !</strong>` })
|
||||
this.incDecAdversite("noire", 1)
|
||||
}
|
||||
@@ -858,14 +888,11 @@ export class MournbladeCYD2Actor extends Actor {
|
||||
roll = await new Roll("1d10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll()
|
||||
}
|
||||
await MournbladeCYD2Utility.showDiceSoNice(roll, game.settings.get("core", "rollMode"));
|
||||
// CYD 2.0: dégâts ≥ SV → -2 combativité; ≥ 2×SV → -3 combativité
|
||||
// CYD 2.0: états SUPPLÉMENTAIRES au-delà du -1 automatique à la réussite.
|
||||
// Math.floor(total/SV) = 0 (<SV), 1 (≥SV), 2 (≥2×SV) → totaux finaux : 1, 2, 3
|
||||
let nbEtatPerdus = 0
|
||||
if (targetVigueur) {
|
||||
if (roll.total >= 2 * targetVigueur) {
|
||||
nbEtatPerdus = 3
|
||||
} else if (roll.total >= targetVigueur) {
|
||||
nbEtatPerdus = 2
|
||||
}
|
||||
nbEtatPerdus = Math.floor(roll.total / targetVigueur)
|
||||
}
|
||||
//console.log(roll)
|
||||
let rollData = {
|
||||
|
||||
Reference in New Issue
Block a user