Extraction des calculs de dommages
Préparation pour le Mapping des armes
This commit is contained in:
parent
75507f3eca
commit
538cf5bdbf
@ -33,12 +33,12 @@ export class RdDItemArme extends Item {
|
||||
return RdDItemArme.mainsNues();
|
||||
}
|
||||
|
||||
static getCompetenceArme(arme, competenceName) {
|
||||
static getCompetenceArme(arme, maniement) {
|
||||
switch (arme.type) {
|
||||
case ITEM_TYPES.competencecreature:
|
||||
return arme.name
|
||||
case ITEM_TYPES.arme:
|
||||
switch (competenceName) {
|
||||
switch (maniement) {
|
||||
case 'competence': return arme.system.competence;
|
||||
case 'unemain': return RdDItemArme.competence1Mains(arme);
|
||||
case 'deuxmains': return RdDItemArme.competence2Mains(arme);
|
||||
@ -148,30 +148,32 @@ export class RdDItemArme extends Item {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static armeUneOuDeuxMains(armeData, aUneMain) {
|
||||
if (armeData && !armeData.system.cac) {
|
||||
armeData.system.unemain = armeData.system.unemain || !armeData.system.deuxmains;
|
||||
const uneOuDeuxMains = armeData.system.unemain && armeData.system.deuxmains;
|
||||
const containsSlash = !Number.isInteger(armeData.system.dommages) && armeData.system.dommages.includes("/");
|
||||
if (containsSlash) { // Sanity check
|
||||
armeData = foundry.utils.duplicate(armeData);
|
||||
|
||||
const tableauDegats = armeData.system.dommages.split("/");
|
||||
if (aUneMain)
|
||||
armeData.system.dommagesReels = Number(tableauDegats[0]);
|
||||
else // 2 mains
|
||||
armeData.system.dommagesReels = Number(tableauDegats[1]);
|
||||
}
|
||||
else {
|
||||
armeData.system.dommagesReels = Number(armeData.system.dommages);
|
||||
}
|
||||
|
||||
if (uneOuDeuxMains != containsSlash) {
|
||||
ui.notifications.info("Les dommages de l'arme à 1/2 mains " + armeData.name + " ne sont pas corrects (ie sous la forme X/Y)");
|
||||
}
|
||||
static dommagesReels(arme, maniement) {
|
||||
switch (maniement) {
|
||||
case 'tir':
|
||||
case 'lancer':
|
||||
case 'competence':
|
||||
return Number(arme.system.dommages)
|
||||
}
|
||||
return armeData;
|
||||
if (arme.system.unemain && arme.system.deuxmains) {
|
||||
const containsSlash = !Number.isInteger(arme.system.dommages) && arme.system.dommages.includes("/")
|
||||
if (!containsSlash) {
|
||||
ui.notifications.info("Les dommages de l'arme à 1/2 mains " + arme.name + " ne sont pas corrects (ie sous la forme X/Y)");
|
||||
return Number(arme.system.dommages)
|
||||
}
|
||||
const tableauDegats = arme.system.dommages.split("/");
|
||||
return Number(tableauDegats[maniement == 'unemain' ? 0 : 1])
|
||||
}
|
||||
return Number(arme.system.dommages);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static armeUneOuDeuxMains(arme, aUneMain) {
|
||||
if (arme && !arme.system.cac) {
|
||||
arme = foundry.utils.duplicate(arme);
|
||||
arme.system.dommagesReels = RdDItemArme.dommagesReels(arme, aUneMain ? 'unemain' : 'deuxmains')
|
||||
}
|
||||
return arme;
|
||||
}
|
||||
|
||||
static competence1Mains(arme) {
|
||||
@ -197,7 +199,7 @@ export class RdDItemArme extends Item {
|
||||
|
||||
static corpsACorps(actor) {
|
||||
let competence = actor?.getCompetenceCorpsACorps() ?? { system: { niveau: -6 } };
|
||||
let melee = actor? actor.system.carac['melee'].value : 0
|
||||
let melee = actor ? actor.system.carac['melee'].value : 0
|
||||
return {
|
||||
_id: competence?.id,
|
||||
name: 'Corps à corps',
|
||||
|
@ -31,8 +31,8 @@ export class RdDBonus {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static dmg(rollData, dmgActor, isEntiteIncarnee = false) {
|
||||
const dmgArme = RdDBonus._dmgArme(rollData)
|
||||
static dmg(rollData, actor, isEntiteIncarnee = false) {
|
||||
const dmgArme = RdDBonus.dmgArme(rollData.arme)
|
||||
let dmg = {
|
||||
total: 0,
|
||||
dmgArme: dmgArme,
|
||||
@ -41,7 +41,7 @@ export class RdDBonus {
|
||||
dmgParticuliere: RdDBonus._dmgParticuliere(rollData),
|
||||
dmgSurprise: RdDBonus.dmgBonus(rollData.ajustements?.attaqueDefenseurSurpris.used),
|
||||
mortalite: RdDBonus._calculMortalite(rollData, isEntiteIncarnee),
|
||||
dmgActor: RdDBonus._dmgPerso(dmgActor, rollData.selectedCarac?.label, dmgArme)
|
||||
dmgActor: RdDBonus.bonusDmg(actor, rollData.selectedCarac?.label.toLowerCase(), dmgArme)
|
||||
}
|
||||
dmg.total = dmg.dmgSurprise + dmg.dmgTactique + dmg.dmgArme + dmg.dmgActor + dmg.dmgParticuliere;
|
||||
return dmg;
|
||||
@ -71,11 +71,11 @@ export class RdDBonus {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _dmgArme(rollData) {
|
||||
if (rollData.arme) {
|
||||
let dmgBase = rollData.arme.system.dommagesReels ?? Number(rollData.arme.system.dommages ?? 0);
|
||||
static dmgArme(arme) {
|
||||
if (arme) {
|
||||
let dmgBase = arme.system.dommagesReels ?? Number(arme.system.dommages ?? 0);
|
||||
//Le bonus dégats magiques ne peut pas faire dépasser le bonus de l'arme (cf p.278)
|
||||
return dmgBase + Math.min(dmgBase, rollData.arme.system.magique ? rollData.arme.system.ecaille_efficacite : 0);
|
||||
return dmgBase + Math.min(dmgBase, arme.system.magique ? arme.system.ecaille_efficacite : 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -86,13 +86,14 @@ export class RdDBonus {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _dmgPerso(dmgActor, categorie, dmgArme) {
|
||||
static bonusDmg(actor, categorie, dmgArme) {
|
||||
const dmgActor = actor.getBonusDegat()
|
||||
if (categorie == undefined) {
|
||||
return 0
|
||||
}
|
||||
switch (categorie) {
|
||||
case "Tir": return 0;
|
||||
case "Lancer": return Math.max(0, Math.min(dmgArme, dmgActor));
|
||||
case "tir": return 0;
|
||||
case "lancer": return Math.max(0, Math.min(dmgArme, dmgActor));
|
||||
}
|
||||
return dmgActor;
|
||||
}
|
||||
|
@ -864,7 +864,7 @@ export class RdDCombat {
|
||||
async _onAttaqueNormale(attackerRoll) {
|
||||
console.log("RdDCombat.onAttaqueNormale >>>", attackerRoll);
|
||||
|
||||
attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntite());
|
||||
attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker, this.defender.isEntite());
|
||||
let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} }
|
||||
attackerRoll.show = {
|
||||
cible: this.target ? this.defender.name : 'la cible',
|
||||
|
@ -307,7 +307,7 @@ export class RdDRoll extends Dialog {
|
||||
async updateRollResult(html) {
|
||||
const rollData = this.rollData;
|
||||
|
||||
rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, this.actor.getBonusDegat())
|
||||
rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, this.actor)
|
||||
rollData.caracValue = parseInt(rollData.selectedCarac.value)
|
||||
rollData.dmg.mortalite = rollData.dmg.mortalite ?? 'mortel';
|
||||
rollData.use.appelAuMoral = this.actor.isPersonnage() && RdDCarac.isActionPhysique(rollData.selectedCarac);
|
||||
|
Loading…
Reference in New Issue
Block a user