#20 Gestion des RollModes et gestion initiative plus fine
This commit is contained in:
parent
40e2d665df
commit
2cbd496517
@ -27,7 +27,7 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
|||||||
const _patch_initiative = () => {
|
const _patch_initiative = () => {
|
||||||
Combat.prototype.rollInitiative = async function (
|
Combat.prototype.rollInitiative = async function (
|
||||||
ids,
|
ids,
|
||||||
formula = null,
|
formula = undefined,
|
||||||
messageOptions = {}
|
messageOptions = {}
|
||||||
) {
|
) {
|
||||||
console.log(
|
console.log(
|
||||||
@ -39,31 +39,32 @@ const _patch_initiative = () => {
|
|||||||
// Structure input data
|
// Structure input data
|
||||||
ids = typeof ids === "string" ? [ids] : ids;
|
ids = typeof ids === "string" ? [ids] : ids;
|
||||||
const currentId = this.combatant._id;
|
const currentId = this.combatant._id;
|
||||||
|
|
||||||
// calculate initiative
|
// calculate initiative
|
||||||
for ( let cId = 0; cId < ids.length; cId++) {
|
for ( let cId = 0; cId < ids.length; cId++) {
|
||||||
const c = this.getCombatant( ids[cId] );
|
const c = this.getCombatant( ids[cId] );
|
||||||
//if (!c) return results;
|
//if (!c) return results;
|
||||||
|
|
||||||
let armeCombat, rollFormula, competence;
|
let rollFormula = formula; // Init per default
|
||||||
if ( c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
|
if ( !rollFormula ) {
|
||||||
for (const competenceItem of c.actor.data.items) {
|
let armeCombat, competence;
|
||||||
if ( competenceItem.data.iscombat) {
|
if ( c.actor.data.type == 'creature' || c.actor.data.type == 'entite') {
|
||||||
competence = duplicate(competenceItem);
|
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);
|
||||||
rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(competence.data.carac_value / 2);
|
} else {
|
||||||
} else {
|
for (const item of c.actor.data.items) {
|
||||||
for (const item of c.actor.data.items) {
|
if (item.type == "arme" && item.data.equipe) {
|
||||||
if (item.type == "arme" && item.data.equipe) {
|
armeCombat = duplicate(item);
|
||||||
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);
|
//console.log("Combatat", c);
|
||||||
const roll = this._getInitiativeRoll(c, rollFormula);
|
const roll = this._getInitiativeRoll(c, rollFormula);
|
||||||
//console.log("Compute init for", armeCombat, competence, rollFormula, roll.total);
|
//console.log("Compute init for", armeCombat, competence, rollFormula, roll.total);
|
||||||
@ -82,7 +83,7 @@ const _patch_initiative = () => {
|
|||||||
alias: c.token.name,
|
alias: c.token.name,
|
||||||
sound: CONFIG.sounds.dice,
|
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
|
messageOptions
|
||||||
);
|
);
|
||||||
|
@ -668,9 +668,32 @@ export class RdDUtility {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static rollInitiativeCompetence( combatantId, arme ) {
|
static rollInitiativeCompetence( combatantId, arme ) {
|
||||||
const combatant = game.combat.getCombatant(combatantId);
|
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 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é
|
// Recupération du combatant et de l'acteur associé
|
||||||
const combatant = game.combat.getCombatant(combatantId);
|
const combatant = game.combat.getCombatant(combatantId);
|
||||||
const actor = combatant.actor;
|
const actor = combatant.actor;
|
||||||
console.log("Combattant : ", combatant);
|
//console.log("Combattant : ", combatant);
|
||||||
// Recupération des items 'arme'
|
|
||||||
let itemsByType = RdDUtility.buildItemsClassification( combatant.actor.data.items );
|
let armesList = [];
|
||||||
let armesList = itemsByType['arme'];
|
if ( actor.data.type == 'creature' || actor.data.type == 'entite') {
|
||||||
if ( armesList ) { // Do something...
|
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 = [];
|
let menuItems = [];
|
||||||
for ( let arme of armesList ) {
|
for ( let arme of armesList ) {
|
||||||
menuItems.push( {
|
menuItems.push( {
|
||||||
@ -690,7 +728,7 @@ export class RdDUtility {
|
|||||||
icon: "<i class='fas fa-dice-d6'></i>",
|
icon: "<i class='fas fa-dice-d6'></i>",
|
||||||
callback: target => { RdDUtility.rollInitiativeCompetence( combatantId, arme ) } } );
|
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: '<i class="far fa-question-circle"></i>',
|
icon: '<i class="far fa-question-circle"></i>',
|
||||||
callback: target => {
|
callback: target => {
|
||||||
RdDUtility.displayInitiativeMenu( html, target.data('combatant-id') );
|
RdDUtility.displayInitiativeMenu( html, target.data('combatant-id') );
|
||||||
//WFRP_Utility.displayStatus(target.attr("data-token-id"));
|
|
||||||
//$(`#sidebar-tabs`).find(`.item[data-tab="chat"]`).click();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "foundryvtt-reve-de-dragon",
|
"name": "foundryvtt-reve-de-dragon",
|
||||||
"title": "Rêve de Dragon",
|
"title": "Rêve de Dragon",
|
||||||
"description": "Rêve de Dragon RPG for FoundryVTT",
|
"description": "Rêve de Dragon RPG for FoundryVTT",
|
||||||
"version": "0.9.82",
|
"version": "0.9.83",
|
||||||
"minimumCoreVersion": "0.7.5",
|
"minimumCoreVersion": "0.7.5",
|
||||||
"compatibleCoreVersion": "0.7.6",
|
"compatibleCoreVersion": "0.7.6",
|
||||||
"templateVersion": 48,
|
"templateVersion": 48,
|
||||||
|
Loading…
Reference in New Issue
Block a user