import { RdDCarac } from "./rdd-carac.js"; import { RdDPossession } from "./rdd-possession.js"; const conditionsTactiques = [ { type: '', descr: '', dmg: 0, attaque: 0, parade: 0, esquive: true }, { type: 'charge', descr: 'Charge', dmg: 2, attaque: 4, parade: -4, esquive: false }, { type: 'feinte', descr: 'Feinte', dmg: 1, attaque: 1, parade: 0, esquive: true }, { type: 'pret', descr: 'prêt', dmg: 0, attaque: 0, parade: 0, esquive: true }, { type: 'demi', descr: 'Demi-surprise', dmg: 1, attaque: 0, parade: 0, esquive: true }, { type: 'totale', descr: 'Surprise totale', dmg: 10, attaque: 6, parade: 0, esquive: true }, ]; /* -------------------------------------------- */ export class RdDBonus { /* -------------------------------------------- */ static find(condition) { return conditionsTactiques.find(e => e.type == condition) || conditionsTactiques.find(e => e.type == 'pret'); } /* -------------------------------------------- */ static isDefenseAttaqueFinesse(rollData) { if (rollData.isEmpoignade && rollData.rolled?.isPart) { return true } if (RdDPossession.isDefensePossession(rollData)) { return RdDPossession.isPossessionFinesse(rollData) } return rollData.attackerRoll?.particuliere == 'finesse'; } /* -------------------------------------------- */ static dmg(rollData, actor, isEntiteIncarnee = false) { const dmgArme = RdDBonus.dmgArme(rollData.arme) let dmg = { total: 0, dmgArme: dmgArme, penetration: RdDBonus._peneration(rollData), dmgTactique: RdDBonus.dmgBonus(rollData.tactique), dmgParticuliere: RdDBonus._dmgParticuliere(rollData), dmgSurprise: RdDBonus.dmgBonus(rollData.ajustements?.attaqueDefenseurSurpris.used), mortalite: RdDBonus._calculMortalite(rollData, isEntiteIncarnee), dmgActor: RdDBonus.bonusDmg(actor, rollData.selectedCarac?.label.toLowerCase(), dmgArme) } dmg.total = dmg.dmgSurprise + dmg.dmgTactique + dmg.dmgArme + dmg.dmgActor + dmg.dmgParticuliere; return dmg; } /* -------------------------------------------- */ static description(condition) { return RdDBonus.find(condition).descr; } /* -------------------------------------------- */ static dmgBonus(condition) { return RdDBonus.find(condition).dmg; } /* -------------------------------------------- */ static bonusAttaque(condition) { return RdDBonus.find(condition).attaque; } /* -------------------------------------------- */ static _calculMortalite(rollData, isEntiteIncarnee) { return isEntiteIncarnee ? "entiteincarnee" : rollData.dmg?.mortalite ?? rollData.arme?.system.mortalite ?? "mortel"; } /* -------------------------------------------- */ 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, arme.system.magique ? arme.system.ecaille_efficacite : 0); } return 0; } /* -------------------------------------------- */ static _peneration(rollData) { return parseInt(rollData.arme?.system.penetration ?? 0); } /* -------------------------------------------- */ 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)); } return dmgActor; } /* -------------------------------------------- */ static _dmgParticuliere(rollData) { return rollData.particuliere == 'force' ? 5 : 0; } }