Fix initiative de masse
L'initiative de masse utilise la première compétence de combat trouvée
This commit is contained in:
parent
be1d109def
commit
5ff31d462f
@ -72,7 +72,7 @@ export class RdDCombatManager extends Combat {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async finDeRound(options = { terminer: false }) {
|
||||
this.combatants.map(it => RdDCombatManager.getActorCombatant(it))
|
||||
this.combatants.map(it => RdDCombatManager.getActorCombatant(it, { warning: false }))
|
||||
.filter(it => it != undefined)
|
||||
.forEach(async actor => {
|
||||
await actor.finDeRound(options)
|
||||
@ -80,13 +80,17 @@ export class RdDCombatManager extends Combat {
|
||||
})
|
||||
}
|
||||
|
||||
static getActorCombatant(combatant) {
|
||||
static getActorCombatant(combatant, options = { warning: true }) {
|
||||
if (!combatant.actor) {
|
||||
if (options.warning) {
|
||||
ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur!`)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
else if (!combatant.actor.isActorCombat()) {
|
||||
if (options.warning) {
|
||||
ui.notifications.warn(`${combatant.name} ne peut pas combattre!`)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
return combatant.actor
|
||||
@ -100,56 +104,27 @@ export class RdDCombatManager extends Combat {
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
|
||||
console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions);
|
||||
async rollInitiative(ids, messageOptions = {}) {
|
||||
console.log(`${game.system.title} | Combat.rollInitiative()`, ids, messageOptions)
|
||||
ids = typeof ids === "string" ? [ids] : ids
|
||||
ids.forEach(async id =>
|
||||
await this.rollInitRdD(id, undefined, messageOptions)
|
||||
)
|
||||
return this
|
||||
}
|
||||
|
||||
ids = typeof ids === "string" ? [ids] : ids;
|
||||
// calculate initiative
|
||||
for (let cId = 0; cId < ids.length; cId++) {
|
||||
const combatant = this.combatants.get(ids[cId]);
|
||||
const ajustement = RdDCombatManager.calculAjustementInit(combatant.actor, undefined);
|
||||
let rollFormula = formula ?? RdDCombatManager.formuleInitiative(2, 10, 0, ajustement);
|
||||
|
||||
if (!formula) {
|
||||
if (combatant.actor.type == 'creature' || combatant.actor.type == 'entite') {
|
||||
const competence = combatant.actor.items.find(it => RdDItemCompetenceCreature.isAttaque(it))
|
||||
if (competence) {
|
||||
rollFormula = RdDCombatManager.formuleInitiative(2, competence.system.carac_value, competence.system.niveau, etatGeneral);
|
||||
}
|
||||
} else {
|
||||
const armeCombat = combatant.actor.itemTypes['arme'].find(it => it.system.equipe)
|
||||
let compName = "Corps à corps"
|
||||
if (armeCombat) {
|
||||
if (armeCombat.system.competence != "") {
|
||||
compName = armeCombat.system.competence
|
||||
}
|
||||
if (armeCombat.system.lancer != "") {
|
||||
compName = armeCombat.system.lancer
|
||||
}
|
||||
if (armeCombat.system.tir != "") {
|
||||
compName = armeCombat.system.tir
|
||||
}
|
||||
}
|
||||
const competence = RdDItemCompetence.findCompetence(combatant.actor.items, compName);
|
||||
if (competence && competence.system.defaut_carac) {
|
||||
const carac = combatant.actor.system.carac[competence.system.defaut_carac].value;
|
||||
const niveau = competence.system.niveau;
|
||||
|
||||
const ajustement = RdDCombatManager.calculAjustementInit(combatant.actor, armeCombat)
|
||||
rollFormula = RdDCombatManager.formuleInitiative(2, carac, niveau, ajustement);
|
||||
} else {
|
||||
ui.notifications.warn(`Votre arme ${armeCombat.name} n'a pas de compétence renseignée`);
|
||||
}
|
||||
}
|
||||
}
|
||||
async rollInitRdD(id, formula, messageOptions = {}) {
|
||||
const combatant = this.combatants.get(id);
|
||||
const actor = RdDCombatManager.getActorCombatant(combatant)
|
||||
if (actor) {
|
||||
const rollFormula = formula ?? RdDCombatManager.getFirstInitRollFormula(actor)
|
||||
const roll = combatant.getInitiativeRoll(rollFormula);
|
||||
if (!roll.total) {
|
||||
await roll.evaluate();
|
||||
}
|
||||
const total = Math.max(roll.total, 0.00);
|
||||
console.log("Compute init for", rollFormula, roll, total, combatant);
|
||||
let id = combatant._id || combatant.id;
|
||||
await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: total }]);
|
||||
await this.updateEmbeddedDocuments("Combatant", [{ _id: combatant._id || combatant.id, initiative: total }]);
|
||||
|
||||
// Send a chat message
|
||||
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
|
||||
@ -161,7 +136,7 @@ export class RdDCombatManager extends Combat {
|
||||
alias: combatant.token.name,
|
||||
sound: CONFIG.sounds.dice,
|
||||
},
|
||||
flavor: `${combatant.token.name} a fait son jet d'Initiative (${messageOptions.info})<br>`,
|
||||
flavor: `${combatant.token.name} a fait son jet d'Initiative (${messageOptions.info})<br>`
|
||||
},
|
||||
messageOptions);
|
||||
roll.toMessage(messageData, { rollMode, create: true });
|
||||
@ -169,7 +144,20 @@ export class RdDCombatManager extends Combat {
|
||||
RdDCombatManager.processPremierRoundInit();
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
static getFirstInitRollFormula(actor) {
|
||||
const actions = actor.listActionsCombat()
|
||||
if (actions.length > 0) {
|
||||
const action = actions[0]
|
||||
const init = RdDCombatManager.getInitData(actor, action)
|
||||
const ajustement = RdDCombatManager.calculAjustementInit(actor, action)
|
||||
return RdDCombatManager.formuleInitiative(init.offset, init.carac, init.niveau, ajustement);
|
||||
}
|
||||
|
||||
let ajustement = RdDCombatManager.calculAjustementInit(actor, undefined);
|
||||
return RdDCombatManager.formuleInitiative(2, 10, 0, ajustement);
|
||||
}
|
||||
|
||||
static formuleInitiative(rang, carac, niveau, bonusMalus) {
|
||||
return `${rang} +( (${RdDCombatManager.calculInitiative(niveau, carac, bonusMalus)} )/100)`;
|
||||
@ -316,7 +304,7 @@ export class RdDCombatManager extends Combat {
|
||||
const ajustement = RdDCombatManager.calculAjustementInit(actor, action)
|
||||
const rollFormula = RdDCombatManager.formuleInitiative(init.offset, init.carac, init.niveau, ajustement);
|
||||
|
||||
game.combat.rollInitiative(combatantId, rollFormula, init);
|
||||
game.combat.rollInitRdD(combatantId, rollFormula, init);
|
||||
}
|
||||
|
||||
static getInitData(actor, action) {
|
||||
@ -352,7 +340,9 @@ export class RdDCombatManager extends Combat {
|
||||
/* -------------------------------------------- */
|
||||
static displayInitiativeMenu(html, combatantId) {
|
||||
const combatant = game.combat.combatants.get(combatantId)
|
||||
const actions = RdDCombatManager.listActionsCombatant(combatant);
|
||||
const actor = RdDCombatManager.getActorCombatant(combatant, { warning: false })
|
||||
if (actor) {
|
||||
const actions = RdDCombatManager.listActionsActorCombatant(actor)
|
||||
// Build the relevant submenu
|
||||
const menuItems = actions.map(action => {
|
||||
return {
|
||||
@ -365,11 +355,10 @@ export class RdDCombatManager extends Combat {
|
||||
new ContextMenu(html, ".directory-list", menuItems).render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static listActionsCombatant(combatant) {
|
||||
const actor = RdDCombatManager.getActorCombatant(combatant)
|
||||
if (actor) {
|
||||
static listActionsActorCombatant( actor) {
|
||||
const possessions = actor.listActionsPossessions()
|
||||
const actions = possessions.length > 0
|
||||
? possessions
|
||||
@ -380,8 +369,6 @@ export class RdDCombatManager extends Combat {
|
||||
}
|
||||
return actions
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,16 +28,15 @@ export class RdDTokenHud {
|
||||
await RdDTokenHud.addExtensionHudSoins(html, actor);
|
||||
|
||||
if (isCombat) {
|
||||
let combatant = game.combat.combatants.find(c => c.tokenId == tokenId);
|
||||
if (!(combatant?.actor)) {
|
||||
ui.notifications.warn(`Le combatant ${token.name} n'est pas associé à un acteur, impossible de déterminer ses actions de combat!`)
|
||||
return;
|
||||
}
|
||||
let actions = RdDCombatManager.listActionsCombatant(combatant);
|
||||
const combatant = game.combat.combatants.find(c => c.tokenId == tokenId)
|
||||
const actor = RdDCombatManager.getActorCombatant(combatant, { warning: false })
|
||||
if (actor) {
|
||||
let actions = RdDCombatManager.listActionsActorCombatant(actor)
|
||||
// initiative
|
||||
await RdDTokenHud.addExtensionHudInit(html, combatant, actions);
|
||||
await RdDTokenHud.addExtensionHudInit(html, combatant, actions)
|
||||
// combat
|
||||
await RdDTokenHud.addExtensionHudCombat(html, combatant, token, actions);
|
||||
await RdDTokenHud.addExtensionHudCombat(html, combatant, token, actions)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user