diff --git a/module/rdd-main.js b/module/rdd-main.js
index 0db900d7..bbc31000 100644
--- a/module/rdd-main.js
+++ b/module/rdd-main.js
@@ -27,7 +27,7 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
const _patch_initiative = () => {
Combat.prototype.rollInitiative = async function (
ids,
- formula = null,
+ formula = undefined,
messageOptions = {}
) {
console.log(
@@ -39,31 +39,32 @@ const _patch_initiative = () => {
// Structure input data
ids = typeof ids === "string" ? [ids] : ids;
const currentId = this.combatant._id;
-
// calculate initiative
for ( let cId = 0; cId < ids.length; cId++) {
const c = this.getCombatant( ids[cId] );
//if (!c) return results;
-
- let armeCombat, rollFormula, competence;
- if ( c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
- for (const competenceItem of c.actor.data.items) {
- if ( competenceItem.data.iscombat) {
- competence = duplicate(competenceItem);
+
+ let rollFormula = formula; // Init per default
+ if ( !rollFormula ) {
+ let armeCombat, competence;
+ if ( c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
+ for (const competenceItem of c.actor.data.items) {
+ if ( competenceItem.data.iscombat) {
+ competence = duplicate(competenceItem);
+ }
}
- }
- rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(competence.data.carac_value / 2);
- } else {
- for (const item of c.actor.data.items) {
- if (item.type == "arme" && item.data.equipe) {
- armeCombat = duplicate(item);
+ rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(competence.data.carac_value / 2);
+ } else {
+ for (const item of c.actor.data.items) {
+ if (item.type == "arme" && item.data.equipe) {
+ armeCombat = duplicate(item);
+ }
}
+ 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);
}
- 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);
}
-
//console.log("Combatat", c);
const roll = this._getInitiativeRoll(c, rollFormula);
//console.log("Compute init for", armeCombat, competence, rollFormula, roll.total);
@@ -82,7 +83,7 @@ const _patch_initiative = () => {
alias: c.token.name,
sound: CONFIG.sounds.dice,
},
- flavor: `${c.token.name} a fait son jet d'Initiative (Compétence ${competence.name})`,
+ flavor: `${c.token.name} a fait son jet d'Initiative`,
},
messageOptions
);
diff --git a/module/rdd-utility.js b/module/rdd-utility.js
index 81685439..9ddad681 100644
--- a/module/rdd-utility.js
+++ b/module/rdd-utility.js
@@ -668,9 +668,32 @@ export class RdDUtility {
/* -------------------------------------------- */
static rollInitiativeCompetence( combatantId, arme ) {
const combatant = game.combat.getCombatant(combatantId);
+ const actor = combatant.actor;
+
+ let initOffset = 0;
+ let caracForInit = 0;
let competence = RdDUtility.findCompetence( combatant.actor.data.items, arme.data.competence);
- let rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(combatant.actor.data.data.carac[competence.data.defaut_carac].value/2);
- console.log("Roll !", combatantId, arme );
+
+ if ( actor.data.type == 'creature' || actor.data.type == 'entite') {
+ caracForInit = competence.data.carac_value;
+ } else {
+ if (arme.name == "Draconic") {
+ initOffset = 200;
+ competence = { name: "Draconic", data : { niveau: 0 } }; // Fake
+ } 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;
+ }
+ if (competence.data.categorie == "tir" ) { // Offset de principe pour les armes de jet
+ initOffset = 80;
+ }
+ }
+ }
+ // Cas des créatures et entités vs personnages
+ let rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(caracForInit/2) + "+" + initOffset;
+ game.combat.rollInitiative(combatantId, rollFormula );
+ console.log("Roll !", competence, arme, rollFormula );
}
/* -------------------------------------------- */
@@ -678,11 +701,26 @@ export class RdDUtility {
// Recupération du combatant et de l'acteur associé
const combatant = game.combat.getCombatant(combatantId);
const actor = combatant.actor;
- console.log("Combattant : ", combatant);
- // Recupération des items 'arme'
- let itemsByType = RdDUtility.buildItemsClassification( combatant.actor.data.items );
- let armesList = itemsByType['arme'];
- if ( armesList ) { // Do something...
+ //console.log("Combattant : ", combatant);
+
+ let armesList = [];
+ if ( actor.data.type == 'creature' || actor.data.type == 'entite') {
+ for (const competenceItem of actor.data.items) {
+ if ( competenceItem.data.iscombat) { // Siule un item de type arme
+ armesList.push( { name: competenceItem.name, data: { niveau: competenceItem.data.niveau, competence: competenceItem.name } } );
+ }
+ }
+ } else {
+ // Recupération des items 'arme'
+ let itemsByType = RdDUtility.buildItemsClassification( combatant.actor.data.items );
+ armesList = itemsByType['arme'];
+ // Force corps à corps et Draconic
+ let cc = RdDUtility.findCompetence( combatant.actor.data.items, "Corps à corps");
+ armesList.push( { name: "Corps à corps", data: { niveau: cc.data.niveau, description: "", force: 6, competence: "Corps à corps", dommages: combatant.actor.data.data.attributs.plusdom.value } } );
+ armesList.push( { name: "Draconic", data: { competence: "Draconic" } } );
+ }
+ // Build the relevant submenu
+ if ( armesList ) {
let menuItems = [];
for ( let arme of armesList ) {
menuItems.push( {
@@ -690,7 +728,7 @@ export class RdDUtility {
icon: "",
callback: target => { RdDUtility.rollInitiativeCompetence( combatantId, arme ) } } );
}
- new ContextMenu(html, "", menuItems, undefined, defaultMenuItem ).render();
+ new ContextMenu(html, ".directory-list", menuItems ).render();
}
}
@@ -703,8 +741,6 @@ export class RdDUtility {
icon: '',
callback: target => {
RdDUtility.displayInitiativeMenu( html, target.data('combatant-id') );
- //WFRP_Utility.displayStatus(target.attr("data-token-id"));
- //$(`#sidebar-tabs`).find(`.item[data-tab="chat"]`).click();
}
});
}
diff --git a/system.json b/system.json
index ddbcaeda..0ccf74f4 100644
--- a/system.json
+++ b/system.json
@@ -2,7 +2,7 @@
"name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon",
"description": "Rêve de Dragon RPG for FoundryVTT",
- "version": "0.9.82",
+ "version": "0.9.83",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.6",
"templateVersion": 48,