Fix v11/v12

This commit is contained in:
2024-05-02 09:27:16 +02:00
parent 69a2f81ede
commit fac158e0ad
83 changed files with 314 additions and 298 deletions

View File

@@ -67,22 +67,22 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
prepareArme(arme) {
arme = duplicate(arme)
arme = foundry.utils.duplicate(arme)
let combat = this.getCombatValues()
if (arme.system.typearme == "contact" || arme.system.typearme == "contactjet") {
let bonusDefense = this.getBonusDefenseFromTalents()
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée"))
arme.system.competence = foundry.utils.duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée"))
arme.system.attrKey = "pui"
arme.system.totalDegats = arme.system.degats + "+" + combat.bonusDegatsTotal
arme.system.totalOffensif = this.system.attributs.pui.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff + (this.system.combat.monte ? 3 : 0 )
arme.system.totalDefensif = combat.defenseTotal + arme.system.competence.system.niveau + arme.system.seuildefense + bonusDefense + (this.system.combat.monte ? 3 : 0 )
arme.system.totalOffensif = this.system.attributs.pui.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff + (this.system.combat.monte ? 3 : 0)
arme.system.totalDefensif = combat.defenseTotal + arme.system.competence.system.niveau + arme.system.seuildefense + bonusDefense + (this.system.combat.monte ? 3 : 0)
console.log("Arme", arme.system.totalDefensif, combat, arme.system.competence.system.niveau, arme.system.seuildefense, bonusDefense)
arme.system.isdefense = true
arme.system.isMelee = true
arme.system.isDistance = false
}
if (arme.system.typearme == "jet" || arme.system.typearme == "tir") {
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "armes à distance"))
arme.system.competence = foundry.utils.duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "armes à distance"))
arme.system.attrKey = "adr"
arme.system.totalOffensif = this.system.attributs.adr.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff
arme.system.totalDegats = arme.system.degats
@@ -146,7 +146,7 @@ export class HawkmoonActor extends Actor {
getSkills() {
let comp = []
for (let item of this.items) {
item = duplicate(item)
item = foundry.utils.duplicate(item)
if (item.type == "competence") {
item.system.attribut1total = item.system.niveau + (this.system.attributs[item.system.attribut1]?.value || 0)
item.system.attribut2total = item.system.niveau + (this.system.attributs[item.system.attribut2]?.value || 0)
@@ -168,7 +168,7 @@ export class HawkmoonActor extends Actor {
/* ----------------------- --------------------- */
addMember(actorId) {
let members = duplicate(this.system.members)
let members = foundry.utils.duplicate(this.system.members)
members.push({ id: actorId })
this.update({ 'system.members': members })
}
@@ -249,7 +249,7 @@ export class HawkmoonActor extends Actor {
getItemById(id) {
let item = this.items.find(item => item.id == id);
if (item) {
item = duplicate(item)
item = foundry.utils.duplicate(item)
}
return item;
}
@@ -282,7 +282,7 @@ export class HawkmoonActor extends Actor {
checkAttribut(attribut, minLevel) {
let attr = this.system.attributs.find(at => at.labelnorm == attribut.toLowerCase())
if (attr && attr.value >= minLevel) {
return { isValid: true, attr: duplicate(attr) }
return { isValid: true, attr: foundry.utils.duplicate(attr) }
}
return { isValid: false }
}
@@ -290,11 +290,11 @@ export class HawkmoonActor extends Actor {
checkAttributOrCompetenceLevel(compName, minLevel) {
let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase() && i.system.niveau >= minLevel)
if (comp) {
return { isValid: true, item: duplicate(comp) }
return { isValid: true, item: foundry.utils.duplicate(comp) }
} else {
for (let attrKey in this.system.attributs) {
if (this.system.attributs[attrKey].label.toLowerCase() == compName.toLowerCase() && this.system.attributs[attrKey].value >= minLevel) {
return { isValid: true, item: duplicate(this.system.attributs[attrKey]) }
return { isValid: true, item: foundry.utils.duplicate(this.system.attributs[attrKey]) }
}
}
}
@@ -304,7 +304,7 @@ export class HawkmoonActor extends Actor {
addCompetenceBonus(compName, bonus, baCost) {
let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase())
if (comp) {
comp = duplicate(comp)
comp = foundry.utils.duplicate(comp)
comp.system.bonus = bonus
comp.system.baCost = baCost
return { isValid: true, item: comp }
@@ -388,10 +388,10 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
changeEtatCombativite(value) {
if ( value === "vaincu") {
if (value === "vaincu") {
value = 200
}
let sante = duplicate(this.system.sante)
let sante = foundry.utils.duplicate(this.system.sante)
sante.etat += Number(value)
sante.etat = Math.max(sante.etat, 0)
sante.etat = Math.min(sante.etat, 5)
@@ -400,10 +400,10 @@ export class HawkmoonActor extends Actor {
ChatMessage.create({ content: `<strong>${this.name} est vaincu !</strong>` })
}
// 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")) {
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"))) {
} 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>` })
} else {
ChatMessage.create({ content: `<strong>${this.name} subit 2 adversités rouge !</strong>` })
@@ -425,13 +425,13 @@ export class HawkmoonActor extends Actor {
getSubActors() {
let subActors = [];
for (let id of this.system.subactors) {
subActors.push(duplicate(game.actors.get(id)));
subActors.push(foundry.utils.duplicate(game.actors.get(id)));
}
return subActors;
}
/* -------------------------------------------- */
async addSubActor(subActorId) {
let subActors = duplicate(this.system.subactors);
let subActors = foundry.utils.duplicate(this.system.subactors);
subActors.push(subActorId);
await this.update({ 'system.subactors': subActors });
}
@@ -453,7 +453,7 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
async incDecAdversite(adv, incDec = 0) {
let adversite = duplicate(this.system.adversite)
let adversite = foundry.utils.duplicate(this.system.adversite)
adversite[adv] += Number(incDec)
adversite[adv] = Math.max(adversite[adv], 0)
this.update({ 'system.adversite': adversite })
@@ -500,7 +500,7 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
async setPredilectionUsed(compId, predIdx) {
let comp = this.items.get(compId)
let pred = duplicate(comp.system.predilections)
let pred = foundry.utils.duplicate(comp.system.predilections)
pred[predIdx].used = true
await this.updateEmbeddedDocuments('Item', [{ _id: compId, 'system.predilections': pred }])
}
@@ -522,7 +522,7 @@ export class HawkmoonActor extends Actor {
}
if (arme.system.totalDefensif > maxDef) {
maxDef = arme.system.totalDefensif
bestArme = duplicate(arme)
bestArme = foundry.utils.duplicate(arme)
}
}
return bestArme
@@ -537,7 +537,7 @@ export class HawkmoonActor extends Actor {
for (let auto of talent.system.automations) {
if (auto.eventtype === "prepare-roll") {
if (auto.competence.toLowerCase() == competence.name.toLowerCase()) {
talent = duplicate(talent)
talent = foundry.utils.duplicate(talent)
talent.system.bonus = auto.bonus
talent.system.baCost = auto.baCost
talents.push(talent)
@@ -569,26 +569,33 @@ export class HawkmoonActor extends Actor {
rollData.nbAdversites = this.getTotalAdversite()
rollData.talents = []
rollData.attrKey2 = "none"
rollData.coupDevastateur = this.items.find(it => it.type =="talent" && it.name.toLowerCase() == "coup dévastateur" && !it.system.used)
rollData.coupDevastateur = this.items.find(it => it.type == "talent" && it.name.toLowerCase() == "coup dévastateur" && !it.system.used)
rollData.hasAmbidextre = this.items.find(it => it.type == "talent" && it.name.toLowerCase() == "ambidextre")
rollData.hasFeinte = this.system.bonneaventure.actuelle >0 && this.items.find(it => it.type == "talent" && it.name.toLowerCase() == "feinte")
rollData.hasFeinte = this.system.bonneaventure.actuelle > 0 && this.items.find(it => it.type == "talent" && it.name.toLowerCase() == "feinte")
rollData.isMonte = this.system.combat.monte
rollData.config = game.system.hawkmoon.config
if (attrKey) {
rollData.attrKey = attrKey
if (attrKey != "tochoose") {
rollData.actionImg = "systems/fvtt-hawkmoon-cyd/assets/icons/" + this.system.attributs[attrKey].labelnorm + ".webp"
rollData.attr = duplicate(this.system.attributs[attrKey])
rollData.attr = foundry.utils.duplicate(this.system.attributs[attrKey])
}
}
if (compId) {
rollData.competence = duplicate(this.items.get(compId) || {})
rollData.maitrises = rollData.competence.system.predilections.filter(p => p.maitrise)
rollData.competence = foundry.utils.duplicate(this.items.get(compId) || {})
let maitrises = [ { key: "none", label: "Aucune" } ]
rollData.competence.system.predilections.forEach(function(item){
if (item.maitrise ) {
maitrises.push({key: item.id, label: item.name});
}
})
rollData.maitrises = maitrises // rollData.competence.system.predilections.filter(p => p.maitrise)
rollData.actionImg = rollData.competence?.img
rollData.talents = this.searchRelevantTalents(rollData.competence)
}
if (compName) {
rollData.competence = duplicate(this.items.find(item => item.name.toLowerCase() == compName.toLowerCase()) || {})
rollData.competence = foundry.utils.duplicate(this.items.find(item => item.name.toLowerCase() == compName.toLowerCase()) || {})
rollData.actionImg = rollData.competence?.img
}
return rollData
@@ -672,7 +679,7 @@ export class HawkmoonActor extends Actor {
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
rollDialog.render(true)
}
/* -------------------------------------------- */
async rollArmeDegats(armeId, targetVigueur = undefined, rollDataInput = undefined) {
let arme = this.items.get(armeId)
@@ -687,7 +694,7 @@ export class HawkmoonActor extends Actor {
if (rollDataInput?.applyCoupDevastateur) {
bonus2 = Math.floor(this.system.attributs.pui.value / 2)
let talent = this.items.find(item => item.type == "talent" && item.name.toLowerCase() == "coup dévastateur")
this.updateEmbeddedDocuments('Item', [{ _id: talent.id, 'system.used': true }])
this.updateEmbeddedDocuments('Item', [{ _id: talent.id, 'system.used': true }])
}
if (rollDataInput?.isHeroique) {
@@ -697,7 +704,7 @@ export class HawkmoonActor extends Actor {
if (rollDataInput?.chargeCavalerie) {
bonus = 6
}
roll = new Roll("2d10rr10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll({ async: false })
roll = await new Roll("2d10rr10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll()
} else {
if (rollDataInput?.attaqueCharge) {
bonus = 3
@@ -705,13 +712,13 @@ export class HawkmoonActor extends Actor {
if (rollDataInput?.chargeCavalerie) {
bonus = 4
}
roll = new Roll("1d10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll({ async: false })
roll = await new Roll("1d10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll()
}
await HawkmoonUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"));
let nbEtatPerdus = 0
if (targetVigueur) {
nbEtatPerdus = Math.floor(roll.total / targetVigueur)
}
}
//console.log(roll)
let rollData = {
arme: arme,