Fix init et ref circulaire #279

Merged
vincent.vandeme merged 1 commits from fix-init-ref-circulaire into dev_1.1 2020-12-09 08:25:16 +01:00
3 changed files with 12 additions and 6 deletions

View File

@ -96,7 +96,7 @@ export class RdDActorSheet extends ActorSheet {
if (melee.name == "Esquive")
data.data.combat.push( { name: "Esquive", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: "-", competence: "Esquive", dommages: 0} } );
if (melee.name == "Corps à corps") {
let cc_init = "1d6" + melee.data.niveau + "+" + Math.ceil(data.data.carac['melee'].value / 2 );
let cc_init = RdDUtility.calculInitiative(melee.data.niveau, data.data.carac['melee'].value);
data.data.combat.push( { name: "Corps à corps", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: cc_init, competence: "Corps à corps", dommages: data.data.attributs.plusdom.value } } );
}
}

View File

@ -54,7 +54,7 @@ const _patch_initiative = () => {
competence = duplicate(competenceItem);
}
}
rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(competence.data.carac_value / 2);
rollFormula = RdDUtility.calculInitiative(competence.data.niveau, competence.data.carac_value);
} else {
for (const item of c.actor.data.items) {
if (item.type == "arme" && item.data.equipe) {
@ -63,7 +63,7 @@ const _patch_initiative = () => {
}
let compName = ( armeCombat == undefined ) ? "Corps à corps" : armeCombat.data.competence;
competence = RdDUtility.findCompetence( c.actor.data.items, compName );
rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(c.actor.data.data.carac[competence.data.defaut_carac].value/2);
rollFormula = RdDUtility.calculInitiative(competence.data.niveau, c.actor.data.data.carac[competence.data.defaut_carac].value);
}
}
//console.log("Combatat", c);

View File

@ -3,6 +3,7 @@
import { TMRUtility } from "./tmr-utility.js";
import { RdDRollTables } from "./rdd-rolltables.js";
import { ChatUtility } from "./chat-utility.js";
import { Misc } from "./misc.js";
/* -------------------------------------------- */
const level_category = {
@ -425,7 +426,7 @@ export class RdDUtility {
let arme2mains = []; // Tableau contenant la duplication des armes 1m/2m
for (const arme of armeList) {
let comp = competenceList.find(c => c.name == arme.data.competence);
arme.data.initiative = "1d6+" + arme.data.niveau + "+" + Math.ceil(carac[comp.data.defaut_carac].value/2);
arme.data.initiative = RdDUtility.calculInitiative(arme.data.niveau, carac[comp.data.defaut_carac].value);
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
if (arme.data.unemain && arme.data.deuxmains) {
let arme2main = duplicate(arme);
@ -433,7 +434,7 @@ export class RdDUtility {
arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace !
let comp = competenceList.find(c => c.name == arme2main.data.competence);
arme2main.data.niveau = comp.data.niveau;
arme2main.data.initiative = "1d6+" + arme2main.data.niveau + "+" + Math.ceil(carac[comp.data.defaut_carac].value/2);
arme2main.data.initiative = RdDUtility.calculInitiative(arme2main.data.niveau, carac[comp.data.defaut_carac].value);
arme2mains.push(arme2main);
}
}
@ -442,6 +443,11 @@ export class RdDUtility {
return armeList
}
static calculInitiative(niveau, caracValue) {
let base = niveau + Math.floor(caracValue/2);
return "1d6" + (base >= 0 ? "+" : "") + base;
}
/* -------------------------------------------- */
static computeCarac( data)
{
@ -786,7 +792,7 @@ export class RdDUtility {
}
}
// Cas des créatures et entités vs personnages
let rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(caracForInit/2) + "+" + initOffset;
let rollFormula = RdDUtility.calculInitiative(competence.data.niveau, caracForInit) + "+" + initOffset;
game.combat.rollInitiative(combatantId, rollFormula );
}
}