Gestion assistée pour les actions
This commit is contained in:
@@ -12,7 +12,9 @@ export class TeDeumUtility {
|
||||
CONFIG.JournalEntry.compendiumBanner = "systems/fvtt-te-deum/images/ui/compendium_banner.webp"
|
||||
CONFIG.Macro.compendiumBanner = "systems/fvtt-te-deum/images/ui/compendium_banner.webp"
|
||||
CONFIG.Adventure.compendiumBanner = "systems/fvtt-te-deum/images/ui/compendium_banner.webp"
|
||||
}
|
||||
|
||||
static installHooks() {
|
||||
Hooks.on('renderChatLog', (log, html, data) => TeDeumUtility.chatListeners(html));
|
||||
|
||||
Hooks.on("renderActorDirectory", (app, html, data) => {
|
||||
@@ -28,7 +30,45 @@ export class TeDeumUtility {
|
||||
$(html).find('.header-actions').after(button)
|
||||
}
|
||||
})
|
||||
//Hooks.on("getChatLogEntryContext", (html, options) => TeDeumUtility.chatMenuManager(html, options));
|
||||
|
||||
Hooks.on("combatStart", async (combat, updateData, options) => {
|
||||
this.resetCombatActions(combat)
|
||||
});
|
||||
|
||||
Hooks.on("combatRound", (combat, updateData, updateOptions) => {
|
||||
// List all actors related to combatant
|
||||
if (game.user.isGM) {
|
||||
this.resetCombatActions(combat)
|
||||
}
|
||||
})
|
||||
|
||||
Hooks.on("getCombatTrackerContextOptions", (html, options) => {
|
||||
console.log("Get Combat Tracker Context", html, options)
|
||||
this.pushCombatOptions(html, options);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static pushCombatOptions(html, options) {
|
||||
options.push({ name: "Actions +1", condition: true, icon: '<i class="fas fa-plus"></i>', callback: target => { game.combat.modifyAction($(target).data('combatant-id'), 1); } })
|
||||
options.push({ name: "Actions -1", condition: true, icon: '<i class="fas fa-minus"></i>', callback: target => { game.combat.modifyAction($(target).data('combatant-id'), -1); } })
|
||||
options.push({ name: "Actions MG +1", condition: true, icon: '<i class="fas fa-plus"></i>', callback: target => { game.combat.modifyAction($(target).data('combatant-id'), 1, true); } })
|
||||
options.push({ name: "Actions MG -1", condition: true, icon: '<i class="fas fa-minus"></i>', callback: target => { game.combat.modifyAction($(target).data('combatant-id'), -1, true); } })
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async resetCombatActions(combat) {
|
||||
for (let c of combat.combatants) {
|
||||
let actor = game.actors.get(c.actorId)
|
||||
if (actor) {
|
||||
let nbActions = actor.getNbActions()?.value || 0
|
||||
let isMainGauche = (actor.getCompetenceScore("Main gauche") > 0)
|
||||
let nbActionsMainGauche = isMainGauche ? nbActions : 0
|
||||
await c.setFlag("world", "available-actions", { nbActions, nbActionsMainGauche })
|
||||
await c.update({ name: `${c.token.name} (${nbActions} / ${nbActionsMainGauche})` })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -201,7 +241,7 @@ export class TeDeumUtility {
|
||||
return actor
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */ /* -------------------------------------------- */
|
||||
/* -------------------------------------------- */
|
||||
static async manageOpposition(rollData) {
|
||||
if (!this.currentOpposition) {
|
||||
// Store rollData as current GM opposition
|
||||
@@ -210,12 +250,15 @@ export class TeDeumUtility {
|
||||
} else {
|
||||
// Perform the opposition
|
||||
let isAttackWinner = true
|
||||
let rWinner = this.currentOpposition
|
||||
let rLooser = rollData
|
||||
if (rWinner.total <= rLooser.total) {
|
||||
rWinner = rollData
|
||||
rLooser = this.currentOpposition
|
||||
let rWinner, rLooser
|
||||
if (this.currentOpposition.total <= rollData.total) {
|
||||
rWinner = foundry.utils.duplicate(rollData)
|
||||
rLooser = foundry.utils.duplicate(this.currentOpposition)
|
||||
isAttackWinner = false
|
||||
} else {
|
||||
rWinner = foundry.utils.duplicate(this.currentOpposition)
|
||||
rLooser = foundry.utils.duplicate(rollData)
|
||||
isAttackWinner = true
|
||||
}
|
||||
this.currentOpposition = undefined // Reset opposition
|
||||
let oppositionData = {
|
||||
@@ -247,7 +290,6 @@ export class TeDeumUtility {
|
||||
await this.appliquerDegats(rWinner)
|
||||
}
|
||||
|
||||
|
||||
console.log("Opposition result", rollData, isAttackWinner, oppositionData)
|
||||
}
|
||||
}
|
||||
@@ -576,6 +618,34 @@ export class TeDeumUtility {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async manageCombatActions(actor, rollData) {
|
||||
let combat = game.combats.active
|
||||
if (!combat) return;
|
||||
let combatant = combat.getCombatantByActor(actor)
|
||||
if (!combatant) return;
|
||||
let ca = combatant.getFlag("world", "available-actions")
|
||||
if (!ca) return;
|
||||
if (rollData.mode == "arme" && rollData.isMainGauche) {
|
||||
if (ca.nbActionsMainGauche > 0) {
|
||||
ca.nbActionsMainGauche -= 1
|
||||
ca.nbActions = Math.max(ca.nbActions - 1, 0)
|
||||
} else {
|
||||
ui.notifications.error(`${actor.name} n'a plus d'actions disponibles à la main gauche`)
|
||||
}
|
||||
}
|
||||
if (ca.nbActions > 0) {
|
||||
ca.nbActions -= 1
|
||||
} else {
|
||||
ui.notifications.error(`${actor.name} n'a plus d'actions disponibles`)
|
||||
}
|
||||
await combatant.setFlag("world", "available-actions", ca)
|
||||
await combatant.update({ name: `${combatant.token.name} (${ca.nbActions} / ${ca.nbActionsMainGauche})` })
|
||||
rollData.hasActions = true
|
||||
rollData.remainingActions = ca.nbActions
|
||||
rollData.remainingActionsMainGauche = ca.nbActionsMainGauche
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async rollTeDeum(rollData) {
|
||||
|
||||
@@ -585,8 +655,12 @@ export class TeDeumUtility {
|
||||
rollData.difficulty = "pardefaut"
|
||||
}
|
||||
rollData.difficulty = game.system.tedeum.config.difficulte[rollData.difficulty].value
|
||||
|
||||
// Compute the real competence score
|
||||
if (rollData.competence) {
|
||||
if (rollData.isMainGauche) {
|
||||
rollData.competence = actor.getMeilleureCompetenceMainGauche(rollData.competence)
|
||||
}
|
||||
if (rollData.competence.system.isBase) {
|
||||
rollData.compScore = actor.system.caracteristiques[rollData.competence.system.caracteristique].value
|
||||
} else {
|
||||
@@ -609,6 +683,8 @@ export class TeDeumUtility {
|
||||
|
||||
await this.processAttaqueDistance(rollData)
|
||||
|
||||
await this.manageCombatActions(actor, rollData)
|
||||
|
||||
let msg = await this.createChatWithRollMode(rollData.alias, {
|
||||
content: await foundry.applications.handlebars.renderTemplate(`systems/fvtt-te-deum/templates/chat/chat-generic-result.hbs`, rollData)
|
||||
})
|
||||
|
Reference in New Issue
Block a user