This commit is contained in:
+35
-33
@@ -1,8 +1,9 @@
|
||||
import { SYSTEM } from "./config/system.mjs"
|
||||
|
||||
// Map temporaire pour stocker les données d'attaque en attente de défense
|
||||
if (!globalThis.pendingDefenses) {
|
||||
globalThis.pendingDefenses = new Map()
|
||||
export function log(...args) {
|
||||
if (game?.settings?.get(game.system.id, "debug")) {
|
||||
console.log(...args)
|
||||
}
|
||||
}
|
||||
|
||||
export default class LethalFantasyUtils {
|
||||
@@ -28,6 +29,7 @@ export default class LethalFantasyUtils {
|
||||
static setHookListeners() {
|
||||
|
||||
Hooks.on('renderTokenHUD', async (hud, html, token) => {
|
||||
if (html.querySelector(".lethal-hp-loss-hud")) return
|
||||
// HP Loss Button (existing)
|
||||
const lossHPButton = await foundry.applications.handlebars.renderTemplate('systems/fvtt-lethal-fantasy/templates/loss-hp-hud.hbs', {})
|
||||
$(html).find('div.left').append(lossHPButton);
|
||||
@@ -50,14 +52,14 @@ export default class LethalFantasyUtils {
|
||||
$(html).find('.hp-loss-wrap')[2].classList.add('hp-loss-hud-disabled');
|
||||
}
|
||||
})
|
||||
$(html).find('.loss-hp-hud-click').click((event) => {
|
||||
$(html).find('.loss-hp-hud-click').click(async (event) => {
|
||||
event.preventDefault();
|
||||
let hpLoss = event.currentTarget.dataset.hpValue;
|
||||
if (token) {
|
||||
let tokenFull = canvas.tokens.placeables.find(t => t.id === token._id);
|
||||
console.log(tokenFull, token)
|
||||
let tokenFull = canvas.tokens.placeables.find(t => t.id === token.id);
|
||||
log(tokenFull, token)
|
||||
let actor = tokenFull.actor;
|
||||
actor.applyDamage(Number(hpLoss));
|
||||
await actor.applyDamage(Number(hpLoss));
|
||||
$(html).find('.hp-loss-wrap')[0].classList.remove('hp-loss-hud-active');
|
||||
$(html).find('.hp-loss-wrap')[0].classList.add('hp-loss-hud-disabled');
|
||||
$(html).find('.hp-loss-wrap')[1].classList.remove('hp-loss-hud-active');
|
||||
@@ -89,14 +91,14 @@ export default class LethalFantasyUtils {
|
||||
$(html).find('.hp-gain-wrap')[2].classList.add('hp-gain-hud-disabled');
|
||||
}
|
||||
})
|
||||
$(html).find('.gain-hp-hud-click').click((event) => {
|
||||
$(html).find('.gain-hp-hud-click').click(async (event) => {
|
||||
event.preventDefault();
|
||||
let hpGain = event.currentTarget.dataset.hpValue;
|
||||
if (token) {
|
||||
let tokenFull = canvas.tokens.placeables.find(t => t.id === token._id);
|
||||
console.log(tokenFull, token)
|
||||
let tokenFull = canvas.tokens.placeables.find(t => t.id === token.id);
|
||||
log(tokenFull, token)
|
||||
let actor = tokenFull.actor;
|
||||
actor.applyDamage(Number(hpGain)); // Positive value to add HP
|
||||
await actor.applyDamage(Number(hpGain)); // Positive value to add HP
|
||||
$(html).find('.hp-gain-wrap')[0].classList.remove('hp-gain-hud-active');
|
||||
$(html).find('.hp-gain-wrap')[0].classList.add('hp-gain-hud-disabled');
|
||||
$(html).find('.hp-gain-wrap')[1].classList.remove('hp-gain-hud-active');
|
||||
@@ -120,16 +122,16 @@ export default class LethalFantasyUtils {
|
||||
wrap.classList.add('luck-grit-hud-disabled');
|
||||
}
|
||||
})
|
||||
$(html).find('.luck-grit-btn').click((event) => {
|
||||
$(html).find('.luck-grit-btn').click(async (event) => {
|
||||
event.preventDefault();
|
||||
if (token) {
|
||||
let tokenFull = canvas.tokens.placeables.find(t => t.id === token._id);
|
||||
let tokenFull = canvas.tokens.placeables.find(t => t.id === token.id);
|
||||
let actor = tokenFull.actor;
|
||||
const resource = event.currentTarget.dataset.resource;
|
||||
const amount = Number(event.currentTarget.dataset.amount);
|
||||
const current = Number(foundry.utils.getProperty(actor.system, `${resource}.current`)) || 0;
|
||||
const newValue = Math.max(0, current + amount);
|
||||
actor.update({ [`system.${resource}.current`]: newValue });
|
||||
await actor.update({ [`system.${resource}.current`]: newValue });
|
||||
$(html).find('.luck-grit-wrap')[0].classList.remove('luck-grit-hud-active');
|
||||
$(html).find('.luck-grit-wrap')[0].classList.add('luck-grit-hud-disabled');
|
||||
}
|
||||
@@ -138,8 +140,8 @@ export default class LethalFantasyUtils {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static handleSocketEvent(msg = {}) {
|
||||
console.log(`handleSocketEvent !`, msg)
|
||||
static async handleSocketEvent(msg = {}) {
|
||||
log(`handleSocketEvent !`, msg)
|
||||
let actor
|
||||
switch (msg.type) {
|
||||
case "applyDamage":
|
||||
@@ -149,18 +151,18 @@ export default class LethalFantasyUtils {
|
||||
? canvas.tokens?.placeables?.find(t => t.id === msg.tokenId)?.actor
|
||||
: (game.combat?.combatants?.find(c => c.actorId === msg.actorId)?.actor
|
||||
?? game.actors.get(msg.actorId))
|
||||
if (actor) actor.applyDamage(msg.damage)
|
||||
if (actor) await actor.applyDamage(msg.damage)
|
||||
}
|
||||
break
|
||||
case "rollInitiative":
|
||||
if (msg.userId && msg.userId !== game.user.id) break
|
||||
actor = game.actors.get(msg.actorId)
|
||||
actor.system.rollInitiative(msg.combatId, msg.combatantId)
|
||||
await actor.system.rollInitiative(msg.combatId, msg.combatantId)
|
||||
break
|
||||
case "rollProgressionDice":
|
||||
if (msg.userId && msg.userId !== game.user.id) break
|
||||
actor = game.actors.get(msg.actorId)
|
||||
actor.system.rollProgressionDice(msg.combatId, msg.combatantId, msg.rollProgressionCount)
|
||||
await actor.system.rollProgressionDice(msg.combatId, msg.combatantId, msg.rollProgressionCount)
|
||||
break
|
||||
case "requestDefense":
|
||||
// Vérifier si le message est destiné à cet utilisateur
|
||||
@@ -184,7 +186,7 @@ export default class LethalFantasyUtils {
|
||||
const slot = wounds.findIndex(w => !w.value && !w.duration)
|
||||
if (slot !== -1) {
|
||||
wounds[slot] = { value: msg.damage, duration: msg.damage, description: "Bleeding" }
|
||||
actor.update({ "system.hp.wounds": wounds })
|
||||
await actor.update({ "system.hp.wounds": wounds })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -497,7 +499,7 @@ export default class LethalFantasyUtils {
|
||||
|
||||
const isMonster = defender.type === "monster"
|
||||
|
||||
console.log(`[LF] showDefenseRequest | attackRollType=${attackRollType} isMonster=${isMonster} defender=${defender?.name}`)
|
||||
log(`[LF] showDefenseRequest | attackRollType=${attackRollType} isMonster=${isMonster} defender=${defender?.name}`)
|
||||
|
||||
// Spell/miracle attacks use saving throws instead of weapon defense
|
||||
const isSpellAttack = attackRollType === "spell-attack" || attackRollType === "miracle-attack"
|
||||
@@ -559,9 +561,9 @@ export default class LethalFantasyUtils {
|
||||
defenderTokenId
|
||||
}
|
||||
if (isMonster) {
|
||||
defender.system.prepareMonsterRoll("save", result)
|
||||
await defender.system.prepareMonsterRoll("save", result)
|
||||
} else {
|
||||
defender.prepareRoll("save", result)
|
||||
await defender.prepareRoll("save", result)
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -637,7 +639,7 @@ export default class LethalFantasyUtils {
|
||||
isRanged: msg.isRanged
|
||||
}
|
||||
|
||||
defender.system.prepareMonsterRoll("monster-defense", result)
|
||||
await defender.system.prepareMonsterRoll("monster-defense", result)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -744,9 +746,9 @@ export default class LethalFantasyUtils {
|
||||
isRanged: msg.isRanged
|
||||
}
|
||||
|
||||
console.log("Storing defense data for character:", defender.id)
|
||||
log("Storing defense data for character:", defender.id)
|
||||
|
||||
defender.prepareRoll("weapon-defense", result)
|
||||
await defender.prepareRoll("weapon-defense", result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1285,7 +1287,7 @@ export default class LethalFantasyUtils {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async compareAttackDefense(data) {
|
||||
console.log("compareAttackDefense called with:", data)
|
||||
log("compareAttackDefense called with:", data)
|
||||
|
||||
// Compute D30 effects from the attack D30 message directly.
|
||||
// This is more reliable than depending on the caller-provided values, which are
|
||||
@@ -1300,11 +1302,11 @@ export default class LethalFantasyUtils {
|
||||
|
||||
const outcome = data.outcome || (data.attackRoll > data.defenseRoll ? "hit" : "miss")
|
||||
const isAttackWin = outcome !== "miss"
|
||||
console.log("isAttackWin:", isAttackWin, "attackRoll:", data.attackRoll, "defenseRoll:", data.defenseRoll)
|
||||
log("isAttackWin:", isAttackWin, "attackRoll:", data.attackRoll, "defenseRoll:", data.defenseRoll)
|
||||
|
||||
let damageButton = ""
|
||||
if (isAttackWin && (data.attackWeaponId || data.attackRollKey)) {
|
||||
console.log("Creating damage button. defenderId:", data.defenderId)
|
||||
log("Creating damage button. defenderId:", data.defenderId)
|
||||
// Déterminer le type de dégâts à lancer
|
||||
if (data.attackRollType === "weapon-attack") {
|
||||
damageButton = `
|
||||
@@ -1385,12 +1387,12 @@ export default class LethalFantasyUtils {
|
||||
</div>
|
||||
`
|
||||
|
||||
console.log("Creating combat result message...")
|
||||
log("Creating combat result message...")
|
||||
await ChatMessage.create({
|
||||
content: resultMessage,
|
||||
speaker: { alias: "Combat System" }
|
||||
})
|
||||
console.log("Combat result message created!")
|
||||
log("Combat result message created!")
|
||||
}
|
||||
|
||||
static registerHandlebarsHelpers() {
|
||||
@@ -1527,7 +1529,7 @@ export default class LethalFantasyUtils {
|
||||
return eval(expr);
|
||||
})
|
||||
Handlebars.registerHelper('isOwnerOrGM', function (actor) {
|
||||
console.log("Testing actor", actor.isOwner, game.userId)
|
||||
log("Testing actor", actor.isOwner, game.userId)
|
||||
return actor.isOwner || game.isGM;
|
||||
})
|
||||
Handlebars.registerHelper('upperCase', function (text) {
|
||||
@@ -1665,7 +1667,7 @@ export default class LethalFantasyUtils {
|
||||
}
|
||||
)
|
||||
|
||||
ChatMessage.create({
|
||||
await ChatMessage.create({
|
||||
user: game.user.id,
|
||||
speaker: { alias: targetActor.name },
|
||||
mode: "gm",
|
||||
|
||||
Reference in New Issue
Block a user