Files
fvtt-hamalron/module/models/personnage.mjs
T
uberwald 1749210322 feat: système de magie complet avec dialogue de lancement
- Modèle sortilege enrichi (type, niveau, portée, durée, conditions, effets)
- Personnage: champ rangMagie (ensorceleur/initié/thaumaturge)
- Constantes: SORTILEGE_MODIFICATEURS (table 3x3), RANG_MAGICIEN
- Dialogue de lancement: tirage MJ, sélection atouts + Coupe, total temps réel
- Calcul difficulté: carte MJ + modificateur selon type × niveau
- Table des échecs magiques (normal/critique selon rang)
- Pioche automatique après succès, défausse après échec
- Template chat avec résultat localisé

Corrections post-review:
- Boucle de défausse sur échec corrigée (itérait toujours sur [0])
- Clé de localisation HAMALRON.Roll.cast -> HAMALRON.Sortilege.cast
- Ajout de la clé manquante noCoupe
- Labels localisés dans le chat (categorieLabel, niveauLabel)
2026-07-10 19:07:05 +02:00

83 lines
3.2 KiB
JavaScript

import { SYSTEM } from "../config/system.mjs"
import HamalronTirageTarot from "../documents/tirage-tarot.mjs"
export default class HamalronPersonnage extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const requiredInteger = { required: true, nullable: false, integer: true }
const schema = {}
// Stats
const symboleCarte = (label) => {
const schema = {
label: new fields.StringField({ required: true, initial: label }),
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
max: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
}
return new fields.SchemaField(schema, { label })
}
schema.cartesSucces = new fields.SchemaField(
Object.values(SYSTEM.TAROT_SYMBOLES).reduce((obj, stat) => {
obj[stat.id] = symboleCarte(stat.label)
return obj
}, {}),
)
schema.resistances = new fields.SchemaField(
Object.values(SYSTEM.TAROT_SYMBOLES).reduce((obj, stat) => {
obj[stat.id] = symboleCarte(stat.label)
return obj
}, {}),
)
schema.historial = new fields.HTMLField({ required: true, textSearch: true })
schema.progression = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
schema.rangMagie = new fields.StringField({ required: true, initial: "initie", choices: Object.fromEntries(Object.entries(SYSTEM.RANG_MAGICIEN).map(([key, val]) => [key, val.label])) })
schema.biodata = new fields.SchemaField({
age: new fields.StringField({ required: true, nullable: false, initial: "" }),
gender: new fields.StringField({ required: true, nullable: false, initial: "" }),
height: new fields.StringField({ required: true, nullable: false, initial: "" }),
eyes: new fields.StringField({ required: true, nullable: false, initial: "" }),
birthplace: new fields.StringField({ required: true, nullable: false, initial: "" }),
hair: new fields.StringField({ required: true, nullable: false, initial: "" }),
home: new fields.StringField({ required: true, nullable: false, initial: "" }),
weight: new fields.StringField({ required: true, nullable: false, initial: "" }),
origineSociale: new fields.StringField({ required: true, nullable: false, initial: "" }),
})
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HAMALRON.Personnage"]
prepareDerivedData() {
super.prepareDerivedData();
}
/** */
/**
* Rolls a dice for a character.
* @param {("save"|"resource|damage")} rollType The type of the roll.
* @param {number} rollItem The target value for the roll. Which caracteristic or resource. If the roll is a damage roll, this is the id of the item.
* @returns {Promise<null>} - A promise that resolves to null if the roll is cancelled.
*/
async roll(rollType, rollItem) {
let roll = await HamalronTirageTarot.prompt({
rollType,
rollItem,
actorId: this.parent.id,
actorName: this.parent.name,
actorImage: this.parent.img,
hasTarget: false,
})
if (!roll) return null
await roll.toMessage({}, { rollMode: roll.options.rollMode })
}
}