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 };

View File

@ -6,7 +6,7 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
static DEFAULT_OPTIONS = {
classes: ["character"],
position: {
width: 1080,
width: 972,
height: 780,
},
window: {
@ -18,6 +18,10 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
rollInitiative: LethalFantasyCharacterSheet.#onRollInitiative,
armorHitPointsPlus: LethalFantasyCharacterSheet.#onArmorHitPointsPlus,
armorHitPointsMinus: LethalFantasyCharacterSheet.#onArmorHitPointsMinus,
divinityPointsPlus: LethalFantasyCharacterSheet.#onDivinityPointsPlus,
divinityPointsMinus: LethalFantasyCharacterSheet.#onDivinityPointsMinus,
aetherPointsPlus: LethalFantasyCharacterSheet.#onAetherPointsPlus,
aetherPointsMinus: LethalFantasyCharacterSheet.#onAetherPointsMinus,
},
}
@ -162,22 +166,7 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
}
static async #onRollInitiative(event, target) {
const hasTarget = false
let actorClass = this.actor.system.biodata.class;
let wisDef = SYSTEM.CHARACTERISTICS_TABLES.wis.find((c) => c.value === this.actor.system.characteristics.wis.value)
let maxInit = Number(wisDef.init_cap) || 1000
let roll = await LethalFantasyRoll.promptInitiative({
actorId: this.actor.id,
actorName: this.actor.name,
actorImage: this.actor.img,
actorClass,
maxInit,
})
if (!roll) return null
await roll.toMessage({}, { rollMode: roll.options.rollMode })
await this.document.system.rollInitiative()
}
static #onArmorHitPointsPlus(event, target) {
@ -192,6 +181,34 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
this.actor.update({ "system.combat.armorHitPoints": Math.max(armorHP, 0) })
}
static #onDivinityPointsPlus(event, target) {
let points = this.actor.system.divinityPoints.value
points += 1
points = Math.min(points, this.actor.system.divinityPoints.max)
this.actor.update({ "system.divinityPoints.value": points })
}
static #onDivinityPointsMinus(event, target) {
let points = this.actor.system.divinityPoints.value
points -= 1
points = Math.max(points, 0)
this.actor.update({ "system.divinityPoints.value": points })
}
static #onAetherPointsPlus(event, target) {
let points = this.actor.system.aetherPoints.value
points += 1
points = Math.min(points, this.actor.system.aetherPoints.max)
this.actor.update({ "system.aetherPoints.value": points })
}
static #onAetherPointsMinus(event, target) {
let points = this.actor.system.aetherPoints.value
points -= 1
points = Math.max(points, 0)
this.actor.update({ "system.aetherPoints.value": points })
}
static #onCreateEquipment(event, target) {
}

View File

@ -6,7 +6,7 @@ export default class LethalFantasyMonsterSheet extends LethalFantasyActorSheet {
static DEFAULT_OPTIONS = {
classes: ["monster"],
position: {
width: 980,
width: 1060,
height: 780,
},
window: {
@ -118,37 +118,7 @@ export default class LethalFantasyMonsterSheet extends LethalFantasyActorSheet {
}
static async #onRollInitiative(event, target) {
const hasTarget = false
let actorClass = this.actor.system.biodata.class;
let wisDef = SYSTEM.CHARACTERISTICS_TABLES.wis.find((c) => c.value === this.actor.system.characteristics.wis.value)
let maxInit = Number(wisDef.init_cap) || 1000
let roll = await LethalFantasyRoll.promptInitiative({
actorId: this.actor.id,
actorName: this.actor.name,
actorImage: this.actor.img,
actorClass,
maxInit,
})
if (!roll) return null
await roll.toMessage({}, { rollMode: roll.options.rollMode })
}
static #onArmorHitPointsPlus(event, target) {
let armorHP = this.actor.system.combat.armorHitPoints
armorHP += 1
this.actor.update({ "system.combat.armorHitPoints": armorHP })
}
static #onArmorHitPointsMinus(event, target) {
let armorHP = this.actor.system.combat.armorHitPoints
armorHP -= 1
this.actor.update({ "system.combat.armorHitPoints": Math.max(armorHP, 0) })
}
static #onCreateEquipment(event, target) {
await this.document.system.rollInitiative(event, target)
}
getBestWeaponClassSkill(skills, rollType, multiplier = 1.0) {