Gestion de l'armure
Correction de la détérioration d'une armure variable Séparation du code d'armure dans l'Item RdDArmureItem
This commit is contained in:
parent
7b1fa009bb
commit
4d7317b964
@ -3149,8 +3149,8 @@ export class RdDActor extends RdDBaseActor {
|
|||||||
const armures = this.items.filter(it => it.type == "armure" && it.system.equipe);
|
const armures = this.items.filter(it => it.type == "armure" && it.system.equipe);
|
||||||
for (const armure of armures) {
|
for (const armure of armures) {
|
||||||
protection += await RdDDice.rollTotal(armure.system.protection.toString());
|
protection += await RdDDice.rollTotal(armure.system.protection.toString());
|
||||||
if (dmg > 0) {
|
if (dmg > 0 && attackerRoll.dmg.encaisserSpecial != "noarmure") {
|
||||||
this._deteriorerArmure(armure, dmg);
|
armure.deteriorerArmure(dmg);
|
||||||
dmg = 0;
|
dmg = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3168,35 +3168,6 @@ export class RdDActor extends RdDBaseActor {
|
|||||||
return protection;
|
return protection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
|
||||||
_deteriorerArmure(armure, dmg) {
|
|
||||||
armure = duplicate(armure);
|
|
||||||
if (!ReglesOptionelles.isUsing('deteriorationArmure') || armure.system.protection == '0') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
armure.system.deterioration = (armure.system.deterioration ?? 0) + dmg;
|
|
||||||
if (armure.system.deterioration >= 10) {
|
|
||||||
armure.system.deterioration -= 10;
|
|
||||||
let res = /(\d+)?d(\d+)(\-\d+)?/.exec(armure.system.protection);
|
|
||||||
if (res) {
|
|
||||||
let malus = Misc.toInt(res[3]) - 1;
|
|
||||||
let armure = Misc.toInt(res[2]);
|
|
||||||
if (armure + malus <= 0) {
|
|
||||||
armure.system.protection = 0;
|
|
||||||
} else {
|
|
||||||
armure.system.protection = '' + (res[1] ?? '1') + 'd' + armure + malus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (/\d+/.exec(armure.system.protection)) {
|
|
||||||
armure.system.protection = "1d" + armure.system.protection;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ui.notifications.warn(`La valeur d'armure de votre ${armure.name} est incorrecte`);
|
|
||||||
}
|
|
||||||
ChatMessage.create({ content: "Votre armure s'est détériorée, elle protège maintenant de " + armure.system.protection });
|
|
||||||
}
|
|
||||||
this.updateEmbeddedDocuments('Item', [armure]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async encaisser() {
|
async encaisser() {
|
||||||
|
51
module/item/armure.js
Normal file
51
module/item/armure.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { RdDItem } from "../item.js";
|
||||||
|
import { Misc } from "../misc.js";
|
||||||
|
import { ReglesOptionelles } from "../settings/regles-optionelles.js";
|
||||||
|
|
||||||
|
export class RdDItemArmure extends RdDItem {
|
||||||
|
|
||||||
|
static get defaultIcon() {
|
||||||
|
return "systems/foundryvtt-reve-de-dragon/icons/armes_armures/armure_plaques.webp";
|
||||||
|
}
|
||||||
|
|
||||||
|
deteriorerArmure(dmg) {
|
||||||
|
if (!ReglesOptionelles.isUsing('deteriorationArmure') || this.system.protection == '0') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let deterioration = (this.system.deterioration ?? 0) + dmg;
|
||||||
|
let protection = this.system.protection;
|
||||||
|
|
||||||
|
if (deterioration >= 10) {
|
||||||
|
deterioration -= 10;
|
||||||
|
protection = this.calculProtectionDeterioree();
|
||||||
|
ChatMessage.create({ content: `Votre armure ${this.name} s'est détériorée, elle protège maintenant de ${protection}` });
|
||||||
|
}
|
||||||
|
this.update({
|
||||||
|
system: {
|
||||||
|
deterioration: deterioration,
|
||||||
|
protection: protection
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
calculProtectionDeterioree() {
|
||||||
|
const protectionCourante = this.system.protection;
|
||||||
|
let res = /(\d+)?d(\d+)(\-\d+)?/.exec(protectionCourante);
|
||||||
|
if (res) {
|
||||||
|
let protection = Misc.toInt(res[2]);
|
||||||
|
let malus = Misc.toInt(res[3]) - 1;
|
||||||
|
if (protection + malus <= 0) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return `1d${protection}${malus}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (/\d+/.exec(protectionCourante)) {
|
||||||
|
return `1d${protectionCourante}`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui.notifications.warn(`La valeur d'armure de votre ${this.name} est incorrecte`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -58,6 +58,7 @@ import { RdDConteneurItemSheet } from "./item/sheet-conteneur.js";
|
|||||||
import { RdDSigneDraconiqueItemSheet } from "./item/sheet-signedraconique.js";
|
import { RdDSigneDraconiqueItemSheet } from "./item/sheet-signedraconique.js";
|
||||||
import { RdDItemInventaireSheet } from "./item/sheet-base-inventaire.js";
|
import { RdDItemInventaireSheet } from "./item/sheet-base-inventaire.js";
|
||||||
import { AppAstrologie } from "./sommeil/app-astrologie.js";
|
import { AppAstrologie } from "./sommeil/app-astrologie.js";
|
||||||
|
import { RdDItemArmure } from "./item/armure.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RdD system
|
* RdD system
|
||||||
@ -76,6 +77,7 @@ export class SystemReveDeDragon {
|
|||||||
this.RdDUtility = RdDUtility;
|
this.RdDUtility = RdDUtility;
|
||||||
this.RdDHotbar = RdDHotbar;
|
this.RdDHotbar = RdDHotbar;
|
||||||
this.itemClasses = {
|
this.itemClasses = {
|
||||||
|
armure: RdDItemArmure,
|
||||||
blessure: RdDItemBlessure,
|
blessure: RdDItemBlessure,
|
||||||
maladie: RdDItemMaladie,
|
maladie: RdDItemMaladie,
|
||||||
ombre: RdDItemOmbre,
|
ombre: RdDItemOmbre,
|
||||||
|
Loading…
Reference in New Issue
Block a user