Init/progression dice

This commit is contained in:
2025-01-18 00:00:25 +01:00
parent e12476d64f
commit 4e673913a1
45 changed files with 660 additions and 504 deletions

View File

@ -2,6 +2,17 @@
/* -------------------------------------------- */
export class LethalFantasyCombatTracker extends CombatTracker {
async getData(options) {
let data = await super.getData(options);
for (let u of data.turns) {
let c = game.combat.combatants.get(u.id);
u.progressionCount = c.system.progressionCount
}
console.log("Combat Data", data);
return data;
}
/* -------------------------------------------- */
static get defaultOptions() {
let path = "systems/fvtt-lethal-fantasy/templates/combat-tracker.hbs";
@ -36,104 +47,25 @@ export class LethalFantasyCombat extends Combat {
async rollInitiative(ids, options) {
console.log("%%%%%%%%% Roll Initiative", ids, options);
await this.setFlag("acks", "lock-turns", true);
ids = typeof ids === "string" ? [ids] : ids;
let messages = [];
let rollMode = game.settings.get("core", "rollMode");
// Get current groups
let groups = this.getFlag('acks', 'groups') || [];
let maxInit = { value: -1, cId: "" }
let updates = [];
for (let cId of ids) {
const c = this.combatants.get(cId);
//console.log("Init for combattant", cId, c, ids)
let id = c._id || c.id
// get the associated token
let tokenId = c.token.id;
// Check if the current token ID is in a group
let groupData = groups.find((groupData) => groupData.tokens.includes(tokenId));
let initValue = -1;
let showMessage = true
let roll
if (groupData && groupData.initiative > 0) {
initValue = groupData.initiative;
showMessage = false
let user = game.users.find(u => u.active && u.character && u.character.id === c.actor.id);
if (user?.hasPlayerOwner) {
console.log("Rolling initiative for", c.actor.name);
game.socket.emit(`system.${SYSTEM.id}`, { type: "rollInitiative", actorId: c.actor.id, combatId: this.id, combatantId: c.id });
} else {
roll = c.getInitiativeRoll();
await roll.evaluate();
initValue = roll.total;
}
if (groupData) {
groupData.initiative = initValue
}
updates.push({ _id: id, initiative: initValue });
if (initValue > maxInit.value) {
maxInit.value = initValue;
maxInit.cId = id;
}
if (showMessage) {
// Determine the roll mode
if ((c.token.hidden || c.hidden)
&& (rollMode === "roll")) {
rollMode = "gmroll";
}
// Construct chat message data
const messageData = foundry.utils.mergeObject({
speaker: {
scene: canvas.scene._id,
actor: c.actor?.id || null,
token: c.token.id,
alias: c.token.name
},
flavor: game.i18n.format('ACKS.roll.individualInit', {
name: c.token.name,
}),
}, {});
const chatData = await roll.toMessage(messageData, {
rollMode,
create: false,
});
if (messages.length > 0) {
chatData.sound = null;
}
messages.push(chatData);
user = game.users.find(u => u.active && u.isGM);
c.actor.system.rollInitiative(this.id, c.id);
}
}
await CONFIG.ChatMessage.documentClass.create(messages);
this.pools = AcksCombat.getCombatantsPool();
await this.processOutNumbering();
await this.setFlag("acks", "lock-turns", false);
await this.updateEmbeddedDocuments("Combatant", updates);
setTimeout(function () {
const updateData = { turn: 0 };
game.combat.update(updateData);
}, 200);
return this;
}
async startCombat() {
console.log("Start Combat 1 !")
// Send chat message to all players to roll for initiative
ChatMessage.create({
user: game.user.id,
content: await renderTemplate(`systems/fvtt-lethal-fantasy/templates/chat-ask-initiative.hbs`, {
title: "Initiative roll requested",
text: text,
rollType: type,
}),
flags: { "fvtt-lethal-fantasy": { msg: "request-initiative-roll", content: {} } },
})
ChatMessage.create({ content: message, type: CONST.CHAT_MESSAGE_TYPES.GAME });
}
async nextTurn() {
@ -170,12 +102,25 @@ export class LethalFantasyCombat extends Combat {
this.turnsDone = false
let turn = this.turn === null ? null : 0; // Preserve the fact that it's no-one's turn currently.
console.log("ROUND", this.round, this.turns);
console.log("ROUND", this);
let advanceTime = Math.max(this.turns.length - this.turn, 0) * CONFIG.time.turnTime;
advanceTime += CONFIG.time.roundTime;
let nextRound = this.round + 1;
for (let c of this.combatants) {
if ( nextRound >= c.initiative) {
c.update({ 'system.progressionCount': c.system.progressionCount + 1 });
let user = game.users.find(u => u.active && u.character && u.character.id === c.actor.id);
if (user?.hasPlayerOwner) {
game.socket.emit(`system.${SYSTEM.id}`, { type: "rollProgressionDice", progressionCount: c.system.progressionCount+1, actorId: c.actor.id, combatId: this.id, combatantId: c.id });
} else {
user = game.users.find(u => u.active && u.isGM);
c.actor.system.rollProgressionDice(this.id, c.id, c.system.progressionCount+1);
}
}
}
// Update the document, passing data through a hook first
const updateData = { round: nextRound, turn };
const updateOptions = { advanceTime, direction: 1 };