Amélioration robustess et vérification sur import des modules

This commit is contained in:
2026-04-14 08:26:08 +02:00
parent b1e96af421
commit df1e0b9952
40 changed files with 212 additions and 140 deletions

View File

@@ -16,30 +16,27 @@ const _patch_eis = () => {
game.wfrp4e.config.symptomTreatment["swelling"] = "La plupart des traitements consistent à plonger la partie affectée, ou parfois tout le corps, dans un bain d'eau glacée pour réduire la chaleur qui accompagne les gonflements. Un <b> Test de Guérison Difficile (-20) étendu </b> nécessitant +3 DR réduit le renflement de <b> <a class ='chat-roll'> 2d10 </a> </b> heures. Chaque test dure une heure. Le patient se retrouve avec l'Etat Exténué +1 pour chaque test effectué au cours du processus. <br> <br> A la place, certains médecins saignent le patient avec une lame ou des sangsues. Un <b>Test de Guérison étendu </b> réussi nécessitant +4 SL et des Outils (médecin) réduit le renflement de (<a class ='chat-roll'> 1d10 </a> + Bonus d'Endurance du patient) heures. Chaque test a une difficulté de base <b> impossible (-50) </b> et dure une demi-heure.";
game.wfrp4e.config.loreEffects["tzeentch"] = {
label: "Domaine de Tzeentch",
icon: "modules/wfrp4e-core/icons/spells/tzeentch.png",
transfer: true,
flags: {
wfrp4e: {
"effectApplication": "apply",
"effectTrigger": "oneTime",
"lore": true,
"script": `
if (this.actor.isOwner)
args.actor.setupSkill("Résistance", {context : {failure: "1 Point de Corruption reçu", success : "1 Point de Chance gagné"}}).then(setupData => {
args.actor.basicTest(setupData).then(test =>
{
if (test.result.result == "success" && args.actor.type == "character")
{
args.actor.update({"system.status.fortune.value" : args.actor.system.status.fortune.value + 1})
}
else if (test.result.result == "failure" && args.actor.type == "character")
{
args.actor.update({"system.status.corruption.value" : args.actor.system.status.corruption.value + 1})
}
})
})`
}
name: "Domaine de Tzeentch",
img: "modules/wfrp4e-core/icons/spells/tzeentch.png",
system: {
transferData: {
type: "target"
},
scriptData: [{
trigger: "immediate",
label: "Test d'Endurance",
script: `
this.actor.setupSkill(game.i18n.localize("NAME.Endurance"), {appendTitle : " - " + this.effect.name, context : {failure: "1 Point de Corruption reçu", success : "1 Point de Chance gagné"}}).then(setupData => {
this.actor.basicTest(setupData).then(test => {
if (test.succeeded && this.actor.type == "character") {
this.actor.update({"system.status.fortune.value" : this.actor.system.status.fortune.value + 1})
} else if (test.failed && this.actor.type == "character") {
this.actor.update({"system.status.corruption.value" : this.actor.system.status.corruption.value + 1})
}
})
})
return false;`
}]
}
}
}
@@ -404,6 +401,40 @@ Hooks.on('ready', () => {
// Patch function for effects
game.wfrp4e.utility.findKey = warhammer.utility.findKey
// Patch SpellModel.computeSpellDamage to handle English characteristic bonus names.
// Babele instantiates actors TWICE: first with untranslated data (English formulas like
// "Willpower Bonus+4"), then with translated data. The first pass fails because
// characteristicsBonus values are already French ("Bonus de Force Mentale").
// This patch pre-replaces English bonus names with numeric values before the original
// formula evaluation runs, preventing SyntaxErrors and notification spam.
const __EN_BONUS_TO_CHAR = {
"weapon skill bonus": "ws", "ballistic skill bonus": "bs",
"strength bonus": "s", "toughness bonus": "t",
"initiative bonus": "i", "agility bonus": "ag",
"dexterity bonus": "dex", "intelligence bonus": "int",
"willpower bonus": "wp", "fellowship bonus": "fel"
};
const SpellModel = CONFIG.Item.dataModels?.["spell"];
if (SpellModel?.prototype?.computeSpellDamage) {
const _origComputeSpellDamage = SpellModel.prototype.computeSpellDamage;
SpellModel.prototype.computeSpellDamage = function(formula, options) {
if (typeof formula === "string") {
const actor = options?.actor || this.parent?.actor;
if (actor?.system?.characteristics) {
let f = formula.toLowerCase();
for (const [enName, ch] of Object.entries(__EN_BONUS_TO_CHAR)) {
if (f.includes(enName)) {
const bonus = actor.system.characteristics[ch]?.bonus ?? 0;
f = f.replace(enName, bonus);
}
}
formula = f;
}
}
return _origComputeSpellDamage.call(this, formula, options);
};
}
// Patch postSymptom to handle English symptom names in @Symptom[...] links.
// After i18nInit, config.symptoms values are French strings (e.g. "Fièvre"), so
// findKey("Fever", config.symptoms) fails. We normalize via game.i18n.localize first.