Fix détérioration d'armure

This commit is contained in:
Vincent Vandemeulebrouck 2021-01-19 22:50:02 +01:00
parent 3cfeeadbb6
commit 0e5495c6c4

View File

@ -2177,36 +2177,18 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
computeArmure(attackerRoll) { computeArmure(attackerRoll) {
let dmg = attackerRoll.dmg.dmgArme + attackerRoll.dmg.dmgActor; let dmg = (attackerRoll.dmg.dmgArme ??0) + (attackerRoll.dmg.dmgActor ?? 0);
let arme = attackerRoll.arme; let arme = attackerRoll.arme;
// TODO: arc ignore armure
let protection = 0; let protection = 0;
for (const item of this.data.items) { const armures = this.data.items.filter(it => it.type == "armure" && it.data.equipe);
if (item.type == "armure" && item.data.equipe) { for (const item of armures) {
let update = duplicate(item); protection += new Roll(item.data.protection.toString()).roll().total;
protection += new Roll(update.data.protection.toString()).roll().total; if (dmg > 0) {
update.data.deterioration = Misc.toInt(update.data.deterioration) + dmg; this._deteriorerArmure(item, dmg);
dmg = 0; // Reset it dmg = 0;
if (update.data.deterioration >= 10) {
update.data.deterioration = 0;
let res = /\d+/.exec(update.data.protection);
if (res)
update.data.protection = "1d" + update.data.protection;
// if ( update.data.protection.toString().length == 1 )
// update.data.protection = "1d"+update.data.protection;
else if (res = /(\d+d\d+)(\-\d+)?/.exec(update.data.protection)) {
let malus = Misc.toInt(res[2]) - 1;
update.data.protection = res[1] + malus;
}
else {
ui.notifications.warn(`La valeur d'armure de votre ${item.name} est incorrecte`)
}
ChatMessage.create({ content: "Détérioration d'armure: " + update.data.protection });
}
this.updateEmbeddedEntity("OwnedItem", update);
} }
} }
// TODO: max armure (chutes) // TODO: max armure sur chutes...
const penetration = arme ? Misc.toInt(arme.data.penetration) : 0; const penetration = arme ? Misc.toInt(arme.data.penetration) : 0;
protection = Math.max(protection - penetration, 0); protection = Math.max(protection - penetration, 0);
protection += this.getProtectionNaturelle(); protection += this.getProtectionNaturelle();
@ -2214,6 +2196,27 @@ export class RdDActor extends Actor {
return protection; return protection;
} }
_deteriorerArmure(item, dmg) {
let update = duplicate(item);
update.data.deterioration = (update.data.deterioration ?? 0) + dmg;
if (update.data.deterioration >= 10) {
update.data.deterioration = 0;
let res = /\d+/.exec(update.data.protection);
if (!res) {
update.data.protection = "1d" + update.data.protection;
}
else if (res = /(\d+d\d+)(\-\d+)?/.exec(update.data.protection)) {
let malus = Misc.toInt(res[2]) - 1;
update.data.protection = res[1] + malus;
}
else {
ui.notifications.warn(`La valeur d'armure de votre ${item.name} est incorrecte`);
}
ChatMessage.create({ content: "Votre armure s'est détériorée, elle protège maintenant de " + update.data.protection });
}
this.updateEmbeddedEntity("OwnedItem", update);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async encaisser() { async encaisser() {
let data = { ajustementsEncaissement: RdDUtility.getAjustementsEncaissement() }; let data = { ajustementsEncaissement: RdDUtility.getAjustementsEncaissement() };