12.0.19 - La témérité d'Astrobazzarh #720

Merged
uberwald merged 4 commits from VincentVk/foundryvtt-reve-de-dragon:v11 into v11 2024-11-08 07:10:13 +01:00
2 changed files with 67 additions and 81 deletions
Showing only changes of commit 5ff31d462f - Show all commits

View File

@ -72,7 +72,7 @@ export class RdDCombatManager extends Combat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async finDeRound(options = { terminer: false }) { 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) .filter(it => it != undefined)
.forEach(async actor => { .forEach(async actor => {
await actor.finDeRound(options) 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 (!combatant.actor) {
ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur!`) if (options.warning) {
ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur!`)
}
return undefined return undefined
} }
else if (!combatant.actor.isActorCombat()) { else if (!combatant.actor.isActorCombat()) {
ui.notifications.warn(`${combatant.name} ne peut pas combattre!`) if (options.warning) {
ui.notifications.warn(`${combatant.name} ne peut pas combattre!`)
}
return undefined return undefined
} }
return combatant.actor return combatant.actor
@ -100,56 +104,27 @@ export class RdDCombatManager extends Combat {
} }
/************************************************************************************/ /************************************************************************************/
async rollInitiative(ids, formula = undefined, messageOptions = {}) { async rollInitiative(ids, messageOptions = {}) {
console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, 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; async rollInitRdD(id, formula, messageOptions = {}) {
// calculate initiative const combatant = this.combatants.get(id);
for (let cId = 0; cId < ids.length; cId++) { const actor = RdDCombatManager.getActorCombatant(combatant)
const combatant = this.combatants.get(ids[cId]); if (actor) {
const ajustement = RdDCombatManager.calculAjustementInit(combatant.actor, undefined); const rollFormula = formula ?? RdDCombatManager.getFirstInitRollFormula(actor)
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`);
}
}
}
const roll = combatant.getInitiativeRoll(rollFormula); const roll = combatant.getInitiativeRoll(rollFormula);
if (!roll.total) { if (!roll.total) {
await roll.evaluate(); await roll.evaluate();
} }
const total = Math.max(roll.total, 0.00); const total = Math.max(roll.total, 0.00);
console.log("Compute init for", rollFormula, roll, total, combatant); console.log("Compute init for", rollFormula, roll, total, combatant);
let id = combatant._id || combatant.id; await this.updateEmbeddedDocuments("Combatant", [{ _id: combatant._id || combatant.id, initiative: total }]);
await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: total }]);
// Send a chat message // Send a chat message
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode"); let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
@ -161,7 +136,7 @@ export class RdDCombatManager extends Combat {
alias: combatant.token.name, alias: combatant.token.name,
sound: CONFIG.sounds.dice, 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); messageOptions);
roll.toMessage(messageData, { rollMode, create: true }); roll.toMessage(messageData, { rollMode, create: true });
@ -169,7 +144,20 @@ export class RdDCombatManager extends Combat {
RdDCombatManager.processPremierRoundInit(); RdDCombatManager.processPremierRoundInit();
} }
return this; 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) { static formuleInitiative(rang, carac, niveau, bonusMalus) {
return `${rang} +( (${RdDCombatManager.calculInitiative(niveau, carac, bonusMalus)} )/100)`; return `${rang} +( (${RdDCombatManager.calculInitiative(niveau, carac, bonusMalus)} )/100)`;
@ -316,7 +304,7 @@ export class RdDCombatManager extends Combat {
const ajustement = RdDCombatManager.calculAjustementInit(actor, action) const ajustement = RdDCombatManager.calculAjustementInit(actor, action)
const rollFormula = RdDCombatManager.formuleInitiative(init.offset, init.carac, init.niveau, ajustement); 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) { static getInitData(actor, action) {
@ -352,35 +340,34 @@ export class RdDCombatManager extends Combat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static displayInitiativeMenu(html, combatantId) { static displayInitiativeMenu(html, combatantId) {
const combatant = game.combat.combatants.get(combatantId) const combatant = game.combat.combatants.get(combatantId)
const actions = RdDCombatManager.listActionsCombatant(combatant); const actor = RdDCombatManager.getActorCombatant(combatant, { warning: false })
// Build the relevant submenu if (actor) {
const menuItems = actions.map(action => { const actions = RdDCombatManager.listActionsActorCombatant(actor)
return { // Build the relevant submenu
name: action.system.competence, const menuItems = actions.map(action => {
icon: "<i class='fas fa-dice-d6'></i>", return {
callback: target => { RdDCombatManager.rollInitiativeAction(combatantId, action) } name: action.system.competence,
icon: "<i class='fas fa-dice-d6'></i>",
callback: target => { RdDCombatManager.rollInitiativeAction(combatantId, action) }
}
})
if (menuItems.length > 0) {
new ContextMenu(html, ".directory-list", menuItems).render();
} }
})
if (menuItems.length > 0) {
new ContextMenu(html, ".directory-list", menuItems).render();
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static listActionsCombatant(combatant) { static listActionsActorCombatant( actor) {
const actor = RdDCombatManager.getActorCombatant(combatant) const possessions = actor.listActionsPossessions()
if (actor) { const actions = possessions.length > 0
const possessions = actor.listActionsPossessions() ? possessions
const actions = possessions.length > 0 : actor.listActionsCombat()
? possessions
: actor.listActionsCombat()
for (let index = 0; index < actions.length; index++) { for (let index = 0; index < actions.length; index++) {
actions[index].index = index actions[index].index = index
}
return actions
} }
return [] return actions
} }

View File

@ -28,16 +28,15 @@ export class RdDTokenHud {
await RdDTokenHud.addExtensionHudSoins(html, actor); await RdDTokenHud.addExtensionHudSoins(html, actor);
if (isCombat) { if (isCombat) {
let combatant = game.combat.combatants.find(c => c.tokenId == tokenId); const combatant = game.combat.combatants.find(c => c.tokenId == tokenId)
if (!(combatant?.actor)) { const actor = RdDCombatManager.getActorCombatant(combatant, { warning: false })
ui.notifications.warn(`Le combatant ${token.name} n'est pas associé à un acteur, impossible de déterminer ses actions de combat!`) if (actor) {
return; let actions = RdDCombatManager.listActionsActorCombatant(actor)
// initiative
await RdDTokenHud.addExtensionHudInit(html, combatant, actions)
// combat
await RdDTokenHud.addExtensionHudCombat(html, combatant, token, actions)
} }
let actions = RdDCombatManager.listActionsCombatant(combatant);
// initiative
await RdDTokenHud.addExtensionHudInit(html, combatant, actions);
// combat
await RdDTokenHud.addExtensionHudCombat(html, combatant, token, actions);
} }