Combat initiativ

This commit is contained in:
2025-01-18 19:26:14 +01:00
parent 4e673913a1
commit 4198bf82be
28 changed files with 102 additions and 82 deletions

View File

@ -7,6 +7,7 @@ export class LethalFantasyCombatTracker extends CombatTracker {
for (let u of data.turns) {
let c = game.combat.combatants.get(u.id);
u.progressionCount = c.system.progressionCount
u.isMonster = c.actor.type === "monster"
}
console.log("Combat Data", data);
return data;
@ -107,7 +108,19 @@ export class LethalFantasyCombat extends Combat {
let advanceTime = Math.max(this.turns.length - this.turn, 0) * CONFIG.time.turnTime;
advanceTime += CONFIG.time.roundTime;
let nextRound = this.round + 1;
let initOK = true;
for (let c of this.combatants) {
if (c.initiative === null) {
initOK = false;
break;
}
}
if (!initOK) {
ui.notifications.error("All combatants must have initiative rolled before the round can advance.");
return this;
}
for (let c of this.combatants) {
if ( nextRound >= c.initiative) {
c.update({ 'system.progressionCount': c.system.progressionCount + 1 });

View File

@ -565,8 +565,10 @@ export default class LethalFantasyRoll extends Roll {
},
{
action: "cancel",
label: "Other action, no weapon progression dice",
callback: (event, button, dialog) => { return null; }
label: "Other action, no progression dice",
callback: (event, button, dialog) => {
return null;
}
}
],
rejectClose: false // Click on Close button will not launch an error
@ -574,12 +576,16 @@ export default class LethalFantasyRoll extends Roll {
console.log("RollContext", rollContext)
if (rollContext === null || !rollContext?.progressionDiceId) {
let combat = game.combats.get(options.combatId)
let combatant = combat.combatants.get(options.combatantId)
combatant.update({ 'system.progressionCount': 1 })
return
}
// Get the weapons from the actor items
let actor = game.actors.get(options.actorId)
let weapon = actor.items.find(i => i.type === "weapon" && i.id === rollContext.progressionDiceId)
let isMonster = actor.type === "monster"
// Get the dice and roll it
let formula = weapon.system.combatProgressionDice
let roll = new Roll(formula)
@ -592,7 +598,7 @@ export default class LethalFantasyRoll extends Roll {
if (roll.total <= max ) {
// Notify that the player can act now with a chat message
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionOK", { name: actor.name, weapon: weapon.name, roll: roll.total })
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionOK", { isMonster, name: actor.name, weapon: weapon.name, roll: roll.total })
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: actor }) })
// Update the combatant progression count
let combat = game.combats.get(options.combatId)
@ -600,7 +606,7 @@ export default class LethalFantasyRoll extends Roll {
combatant.update({ 'system.progressionCount': 0 })
} else {
// Notify that the player cannot act now with a chat message
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionKO", { name: actor.name, weapon: weapon.name, roll: roll.total })
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionKO", { isMonster, name: actor.name, weapon: weapon.name, roll: roll.total })
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: actor }) })
}
}

View File

@ -173,7 +173,7 @@ export default class LethalFantasyMonster extends foundry.abstract.TypeDataModel
let roll = new Roll("1D8")
await roll.evaluate()
let max = rollProgressionCount
let msg = await roll.toMessage({ flavor: `Progression Roll for ${this.parent.name}, progression count : ${rollProgressionCount}/${max}` } )
let msg = await roll.toMessage({ flavor: `Progression Roll for ${this.parent.name}` } )
await game.dice3d.waitFor3DAnimationByMessageID(msg.id)
let hasAttack = false
@ -181,16 +181,12 @@ export default class LethalFantasyMonster extends foundry.abstract.TypeDataModel
let attack = this.attacks[key]
if (attack.attackScore > 0 && attack.attackScore === roll.total) {
hasAttack = true
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionOK", { name: this.parent.name, weapon: attack.name, roll: roll.total })
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionOKMonster", { isMonster: true, name: this.parent.name, weapon: attack.name, roll: roll.total })
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: this.parent }) })
// Update the combatant progression count
let combat = game.combats.get(combatId)
let combatant = combat.combatants.get(combatantId)
combatant.update({ 'system.progressionCount': 0 })
}
}
if (!hasAttack) {
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionKO", { name: this.parent.name, roll: roll.total })
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionKOMonster", { isMonster: true, name: this.parent.name, roll: roll.total })
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: this.parent }) })
}