diff --git a/module/rdd-main.js b/module/rdd-main.js index fc513fa7..618fe3cd 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -59,7 +59,7 @@ const _patch_initiative = () => { competence = duplicate(competenceItem); } } - rollFormula = RdDUtility.calculInitiative(competence.data.niveau, competence.data.carac_value); + rollFormula = "2+( ("+RdDUtility.calculInitiative(competence.data.niveau, competence.data.carac_value)+")/100)"; } else { for (const item of c.actor.data.items) { if (item.type == "arme" && item.data.equipe) { @@ -68,13 +68,13 @@ const _patch_initiative = () => { } let compName = (armeCombat == undefined) ? "Corps à corps" : armeCombat.data.competence; competence = RdDItemCompetence.findCompetence(c.actor.data.items, compName); - rollFormula = RdDUtility.calculInitiative(competence.data.niveau, c.actor.data.data.carac[competence.data.defaut_carac].value); + rollFormula = "2+( ("+RdDUtility.calculInitiative(competence.data.niveau, c.actor.data.data.carac[competence.data.defaut_carac].value) + ")/100)"; } } //console.log("Combatat", c); const roll = this._getInitiativeRoll(c, rollFormula); - if (roll.total <= 0) roll.total = 1; - //console.log("Compute init for", armeCombat, competence, rollFormula, roll.total); + if (roll.total <= 0) roll.total = 0.00; + console.log("Compute init for", rollFormula, roll.total); await this.updateEmbeddedEntity("Combatant", { _id: c._id, initiative: roll.total }); // Send a chat message @@ -178,8 +178,8 @@ Hooks.once("init", async function () { /* -------------------------------------------- */ // Set an initiative formula for the system CONFIG.Combat.initiative = { - formula: "1d20", - decimals: 0 + formula: "1+(1d6/10)", + decimals: 2 }; /* -------------------------------------------- */ diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 94323548..814e8779 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -649,32 +649,42 @@ export class RdDUtility { static rollInitiativeCompetence(combatantId, arme) { const combatant = game.combat.getCombatant(combatantId); const actor = combatant.actor; - - if (arme.name == "Autre action") { - game.combat.rollInitiative(combatantId, "1d6"); + + let initOffset = 0; + let caracForInit = 0; + let compNiveau = 0; + if ( actor.getSurprise() == "totale") { + initOffset = -1; // To force 0 + } else if ( actor.getSurprise() == "demi") { + initOffset = 0; + } else if (arme.name == "Autre action") { + initOffset = 2; } else if (arme.name == "Draconic") { - game.combat.rollInitiative(combatantId, "1d6+200"); + initOffset = 7; } else { - let initOffset = 0; - let caracForInit = 0; + initOffset = 2; // Melée = 3.XX let competence = RdDItemCompetence.findCompetence(combatant.actor.data.items, arme.data.competence); - + compNiveau = competence.data.niveau; + if (actor.data.type == 'creature' || actor.data.type == 'entite') { caracForInit = competence.data.carac_value; } else { caracForInit = actor.data.data.carac[competence.data.defaut_carac].value; if (competence.data.categorie == "lancer") { // Offset de principe pour les armes de jet - initOffset = 40; + initOffset = 4; } if (competence.data.categorie == "tir") { // Offset de principe pour les armes de jet - initOffset = 80; + initOffset = 5; + } + if (competence.data.categorie == "melee") { // Offset de principe pour les armes de jet + initOffset = 3; } } - initOffset -= actor.getEtatGeneral(); // Prise en compte état général - // Cas des créatures et entités vs personnages - let rollFormula = RdDUtility.calculInitiative(competence.data.niveau, caracForInit) + "+" + initOffset; - game.combat.rollInitiative(combatantId, rollFormula); } + let malus = actor.getEtatGeneral(); // Prise en compte état général + // Cas des créatures et entités vs personnages + let rollFormula = initOffset + "+ ( (" + RdDUtility.calculInitiative(compNiveau, caracForInit) + " + " + malus + ") /100)"; + game.combat.rollInitiative(combatantId, rollFormula); } /* -------------------------------------------- */