Fixes regarding shields usage and spells
This commit is contained in:
@@ -39,6 +39,7 @@ export default class LethalFantasySpell extends foundry.abstract.TypeDataModel {
|
||||
|
||||
schema.attackRoll = new fields.StringField({ required: true, initial: "" })
|
||||
schema.powerRoll = new fields.StringField({ required: true, initial: "" })
|
||||
schema.damageDice = new fields.StringField({ required: false, initial: "" })
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
@@ -235,6 +235,70 @@ export default class LethalFantasyUtils {
|
||||
|
||||
const isMonster = defender.type === "monster"
|
||||
|
||||
// Spell/miracle attacks use saving throws instead of weapon defense
|
||||
const isSpellAttack = attackRollType === "spell-attack" || attackRollType === "miracle-attack"
|
||||
if (isSpellAttack) {
|
||||
const savesConfig = isMonster ? SYSTEM.MONSTER_SAVES : SYSTEM.SAVES
|
||||
const combatSaves = ["will", "dodge", "toughness"]
|
||||
const savesHTML = Object.values(savesConfig)
|
||||
.filter(s => combatSaves.includes(s.id))
|
||||
.map(s => `<option value="${s.id}">${game.i18n.localize(s.label)}</option>`)
|
||||
.join("")
|
||||
|
||||
const content = `
|
||||
<div class="defense-request-dialog">
|
||||
<div class="attack-info">
|
||||
<p><strong>${attackerName}</strong> targets <strong>${defenderName}</strong> with <strong>${weaponName}</strong>!</p>
|
||||
<p>Attack roll: <strong>${attackRoll}</strong></p>
|
||||
</div>
|
||||
<div class="weapon-selection">
|
||||
<label for="save-type">Choose saving throw:</label>
|
||||
<select id="save-type" name="saveKey" style="width: 100%; margin-top: 8px;">
|
||||
${savesHTML}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
const result = await foundry.applications.api.DialogV2.wait({
|
||||
window: { title: "Saving Throw vs Spell" },
|
||||
classes: ["lethalfantasy"],
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
label: "Roll Save",
|
||||
icon: "fa-solid fa-person-running",
|
||||
callback: (event, button) => button.form.elements.saveKey.value,
|
||||
},
|
||||
],
|
||||
rejectClose: false
|
||||
})
|
||||
|
||||
if (result) {
|
||||
game.lethalFantasy = game.lethalFantasy || {}
|
||||
game.lethalFantasy.nextDefenseData = {
|
||||
attackerId,
|
||||
attackRoll,
|
||||
attackerName,
|
||||
defenderName,
|
||||
attackWeaponId,
|
||||
attackRollType,
|
||||
attackRollKey,
|
||||
attackD30result,
|
||||
attackD30message,
|
||||
attackRerollContext,
|
||||
defenderId: defender.id,
|
||||
defenderTokenId
|
||||
}
|
||||
if (isMonster) {
|
||||
defender.system.prepareMonsterRoll("save", result)
|
||||
} else {
|
||||
defender.prepareRoll("save", result)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Pour les monstres, récupérer les attaques activées
|
||||
if (isMonster) {
|
||||
const enabledAttacks = Object.entries(defender.system.attacks).filter(([key, attack]) => attack.enabled)
|
||||
@@ -440,11 +504,16 @@ export default class LethalFantasyUtils {
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
action: "roll",
|
||||
label: "Roll Bonus Die",
|
||||
icon: "fa-solid fa-dice",
|
||||
callback: (event, button, dialog) => button.form.elements.bonusDie.value
|
||||
callback: (event, button) => {
|
||||
const sel = button.form?.elements?.bonusDie ?? button.closest("form")?.elements?.bonusDie
|
||||
return sel?.value ?? choices[0]
|
||||
}
|
||||
},
|
||||
{
|
||||
action: "cancel",
|
||||
label: "Cancel",
|
||||
icon: "fa-solid fa-xmark",
|
||||
callback: () => null
|
||||
@@ -684,6 +753,24 @@ export default class LethalFantasyUtils {
|
||||
</button>
|
||||
</div>
|
||||
`
|
||||
} else if (data.attackRollType === "spell-attack" || data.attackRollType === "miracle-attack") {
|
||||
const attacker = game.actors.get(data.attackerId)
|
||||
const spell = attacker?.items.get(data.attackWeaponId)
|
||||
const damageDice = spell?.system?.damageDice
|
||||
if (damageDice) {
|
||||
damageButton = `
|
||||
<div class="attack-result-damage">
|
||||
<button class="roll-damage-btn"
|
||||
data-attacker-id="${data.attackerId}"
|
||||
data-defender-id="${data.defenderId}"
|
||||
data-defender-token-id="${data.defenderTokenId || ""}"
|
||||
data-damage-type="spell"
|
||||
data-damage-formula="${damageDice}">
|
||||
<i class="fa-solid fa-wand-magic-sparkles"></i> Spell Damage (${damageDice})
|
||||
</button>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,7 +796,7 @@ export default class LethalFantasyUtils {
|
||||
</div>
|
||||
<div class="combat-result-text">
|
||||
${outcome === "shielded-hit"
|
||||
? `<i class="fa-solid fa-shield"></i> <strong>${data.attackerName}</strong> still hits <strong>${data.defenderName}</strong>, but shield DR <strong>${data.shieldDamageReduction || 0}</strong> reduces the damage.`
|
||||
? `<i class="fa-solid fa-shield"></i> <strong>${data.attackerName}</strong> hits <strong>${data.defenderName}</strong>, but the shield blocked — apply armor DR + shield DR <strong>${data.shieldDamageReduction || 0}</strong>.`
|
||||
: isAttackWin
|
||||
? `<i class="fa-solid fa-circle-check"></i> <strong>${data.attackerName}</strong> hits <strong>${data.defenderName}</strong>!`
|
||||
: `<i class="fa-solid fa-shield-halved"></i> <strong>${data.defenderName}</strong> parries the attack!`
|
||||
|
||||
Reference in New Issue
Block a user