Manage DR and damage roll

This commit is contained in:
2025-12-14 20:48:33 +01:00
parent 7d27562bb4
commit f6b35536de
37 changed files with 717 additions and 199 deletions

View File

@@ -65,7 +65,7 @@ export default class LethalFantasyActor extends Actor {
}
}
}
goodSkill.weaponSkillModifier = maxValue * multiplier
goodSkill.weaponSkillModifier = Math.ceil(maxValue * multiplier)
return goodSkill
}
@@ -119,6 +119,27 @@ export default class LethalFantasyActor extends Actor {
return defenseValue
}
/* *************************************************/
fuzzyNameSearchWeaponSkills(weaponName, weaponClass=null) {
// Get all weapon skills without the " skill" suffix
let skills = this.items.filter((i) => i.type === "skill" && i.system.weaponClass === weaponClass && i.system.category === "weapon")
// Remove parenthesis in the weapon name for better matching
weaponName = weaponName.replace(/\(.*?\)/g, "").trim()
// Now search if we find all the words of the weapon name in the skill name
skills = skills.filter((s) => {
let skillName = s.name.toLowerCase().replace(" skill", "").trim()
let wName = weaponName.toLowerCase().trim()
let wWords = wName.split(" ")
for (let w of wWords) {
if (!skillName.includes(w)) {
return false
}
}
return true
})
return skills
}
/* *************************************************/
async prepareRoll(rollType, rollKey, rollDice) {
console.log("Preparing roll", rollType, rollKey, rollDice)
@@ -179,19 +200,19 @@ export default class LethalFantasyActor extends Actor {
case "weapon-defense": {
let weapon = this.items.find((i) => i.type === "weapon" && i.id === rollKey)
let skill
let skills = this.items.filter((i) => i.type === "skill" && i.name.toLowerCase() === weapon.name.toLowerCase())
let skills = this.items.filter((i) => i.type === "skill" && i.system.category === "weapon" && i.name.toLowerCase() === weapon.name.toLowerCase())
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
} else {
skills = this.items.filter((i) => i.type === "skill" && i.name.toLowerCase().replace(" skill", "") === weapon.name.toLowerCase())
skills = this.fuzzyNameSearchWeaponSkills(weapon.name, weapon.system.weaponClass)
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
} else {
skills = this.items.filter((i) => i.type === "skill" && i.system.weaponClass === weapon.system.weaponClass)
skills = this.items.filter((i) => i.type === "skill" && i.system.category === "weapon" && i.system.weaponClass === weapon.system.weaponClass)
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 0.5)
} else {
skills = this.items.filter((i) => i.type === "skill" && i.system.weaponClass.includes(SYSTEM.WEAPON_CATEGORIES[weapon.system.weaponClass]))
skills = this.items.filter((i) => i.type === "skill" && i.system.category === "weapon" && i.system.weaponClass.includes(SYSTEM.WEAPON_CATEGORIES[weapon.system.weaponClass]))
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 0.25)
} else {

View File

@@ -260,14 +260,17 @@ export default class LethalFantasyRoll extends Roll {
} else if (options.rollType.includes("weapon-damage")) {
options.rollName = options.rollTarget.name
options.isDamage = true
hasModifier = true
hasChangeDice = false
let damageBonus = (options.rollTarget.weapon.system.applyStrengthDamageBonus) ? options.rollTarget.combat.damageModifier : 0
options.rollTarget.value = damageBonus + options.rollTarget.weaponSkillModifier + options.rollTarget.weapon.system.bonuses.damageBonus
options.rollTarget.charModifier = damageBonus
if (options.rollType.includes("small")) {
options.damageSmall = true
dice = options.rollTarget.weapon.system.damage.damageS
} else {
options.damageMedium = true
dice = options.rollTarget.weapon.system.damage.damageM
}
dice = dice.replace("E", "")
@@ -474,6 +477,9 @@ export default class LethalFantasyRoll extends Roll {
actorImage: options.actorImage,
rollMode: rollContext.visibility,
hasTarget: options.hasTarget,
isDamage: options.isDamage,
damageSmall: options.damageSmall,
damageMedium: options.damageMedium,
pointBlank,
beyondSkill,
letItFly,
@@ -1123,6 +1129,16 @@ export default class LethalFantasyRoll extends Roll {
* Generates the data required for rendering a roll chat card.
*/
async _getChatCardData(isPrivate) {
// Générer la liste des combatants de la scène
let combatants = []
if (game?.combat?.combatants && this.rollData?.isDamage) {
for (let c of game.combat.combatants) {
if (c.actorId !== this.actorId) {
combatants.push({ id: c.id, name: c.name })
}
}
}
const cardData = {
css: [SYSTEM.id, "dice-roll"],
data: this.data,
@@ -1146,7 +1162,8 @@ export default class LethalFantasyRoll extends Roll {
D30result: this.D30result,
badResult: this.badResult,
rollData: this.rollData,
isPrivate: isPrivate
isPrivate: isPrivate,
combatants: combatants
}
cardData.cssClass = cardData.css.join(" ")
cardData.tooltip = isPrivate ? "" : await this.getTooltip()

View File

@@ -22,43 +22,43 @@ export default class LethalFantasyUtils {
static setHookListeners() {
Hooks.on('renderTokenHUD', async (hud, html, token) => {
const lossHPButton = await foundry.applications.handlebars.renderTemplate('systems/fvtt-lethal-fantasy/templates/loss-hp-hud.hbs', {} )
const lossHPButton = await foundry.applications.handlebars.renderTemplate('systems/fvtt-lethal-fantasy/templates/loss-hp-hud.hbs', {})
$(html).find('div.left').append(lossHPButton);
$(html).find('img.lethal-hp-loss-hud').click((event) => {
event.preventDefault();
let hpMenu = $(html).find('.hp-loss-wrap')[0]
if (hpMenu.classList.contains("hp-loss-hud-disabled")) {
$(html).find('.hp-loss-wrap')[0].classList.add('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[0].classList.remove('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[1].classList.add('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[1].classList.remove('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[2].classList.add('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[2].classList.remove('hp-loss-hud-disabled');
} else {
$(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');
$(html).find('.hp-loss-wrap')[1].classList.add('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[2].classList.remove('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[2].classList.add('hp-loss-hud-disabled');
}
})
$(html).find('.loss-hp-hud-click').click((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 actor = tokenFull.actor;
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');
$(html).find('.hp-loss-wrap')[1].classList.add('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[2].classList.remove('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[2].classList.add('hp-loss-hud-disabled');
}
})
$(html).find('img.lethal-hp-loss-hud').click((event) => {
event.preventDefault();
let hpMenu = $(html).find('.hp-loss-wrap')[0]
if (hpMenu.classList.contains("hp-loss-hud-disabled")) {
$(html).find('.hp-loss-wrap')[0].classList.add('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[0].classList.remove('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[1].classList.add('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[1].classList.remove('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[2].classList.add('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[2].classList.remove('hp-loss-hud-disabled');
} else {
$(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');
$(html).find('.hp-loss-wrap')[1].classList.add('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[2].classList.remove('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[2].classList.add('hp-loss-hud-disabled');
}
})
$(html).find('.loss-hp-hud-click').click((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 actor = tokenFull.actor;
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');
$(html).find('.hp-loss-wrap')[1].classList.add('hp-loss-hud-disabled');
$(html).find('.hp-loss-wrap')[2].classList.remove('hp-loss-hud-active');
$(html).find('.hp-loss-wrap')[2].classList.add('hp-loss-hud-disabled');
}
})
})
}
@@ -246,4 +246,100 @@ export default class LethalFantasyUtils {
}
}
/* -------------------------------------------- */
static async applyDamage(message, event) {
// Récupérer les données du message
let combatantId = event.currentTarget.dataset.combatantId
if (!combatantId || !game.combat) {
ui.notifications.error("No combatant selected")
return
}
let combatant = game.combat.combatants.get(combatantId)
if (!combatant) {
ui.notifications.error("Combatant not found")
return
}
let targetActor = combatant.token?.actor || game.actors.get(combatant.actorId)
if (!targetActor) {
ui.notifications.error("Target actor not found")
return
}
// Récupérer les données de dégâts du message
let damageTotal = message.rolls[0]?.total || 0
let weaponName = message.rolls[0]?.options?.rollTarget?.weapon?.name || "Unknown Weapon"
// Calculer les DR
let armorDR = targetActor.computeDamageReduction() || 0
let shieldDR = targetActor.getShieldDR() || 0
let totalDR = armorDR + shieldDR
// Créer le dialogue
const content = await foundry.applications.handlebars.renderTemplate(
"systems/fvtt-lethal-fantasy/templates/apply-damage-dialog.hbs",
{
targetName: targetActor.name,
weaponName: weaponName,
damageTotal: damageTotal,
armorDR: armorDR,
shieldDR: shieldDR,
totalDR: totalDR,
damageNoDR: damageTotal,
damageWithArmor: Math.max(0, damageTotal - armorDR),
damageWithAll: Math.max(0, damageTotal - totalDR)
}
)
const result = await foundry.applications.api.DialogV2.wait({
window: { title: "Apply Damage" },
classes: ["lethalfantasy"],
position: { width: 280 },
content,
buttons: [
{
action: "noDR",
label: "No DR",
callback: () => ({ drType: "none", damage: damageTotal })
},
{
action: "armorDR",
label: "With Armor DR",
callback: () => ({ drType: "armor", damage: Math.max(0, damageTotal - armorDR) })
},
{
action: "allDR",
label: "With Armor + Shield DR",
callback: () => ({ drType: "all", damage: Math.max(0, damageTotal - totalDR) })
},
{
action: "cancel",
label: "Cancel",
callback: () => null
}
],
rejectClose: false
})
if (result && result.damage !== undefined) {
await targetActor.applyDamage(-result.damage)
// Message de confirmation
let drText = ""
if (result.drType === "armor") {
drText = ` (Armor DR: ${armorDR})`
} else if (result.drType === "all") {
drText = ` (Total DR: ${totalDR})`
}
ChatMessage.create({
user: game.user.id,
speaker: { alias: targetActor.name },
rollMode: "gmroll",
content: `${targetActor.name} takes ${result.damage} damage${drText} from ${weaponName}`
})
}
}
}