175 lines
7.2 KiB
JavaScript
175 lines
7.2 KiB
JavaScript
import { ROLL_TYPE, SYSTEM } from "../config/system.mjs"
|
|
import LethalFantasyRoll from "../documents/roll.mjs"
|
|
import LethalFantasyUtils from "../utils.mjs"
|
|
|
|
export default class LethalFantasyCharacter extends foundry.abstract.TypeDataModel {
|
|
static defineSchema() {
|
|
const fields = foundry.data.fields
|
|
const requiredInteger = { required: true, nullable: false, integer: true }
|
|
const schema = {}
|
|
|
|
schema.description = new fields.HTMLField({ required: true, textSearch: true })
|
|
schema.notes = new fields.HTMLField({ required: true, textSearch: true })
|
|
|
|
// Carac
|
|
const characteristicField = (label) => {
|
|
const schema = {
|
|
value: new fields.NumberField({ ...requiredInteger, initial: 3, min: 0 }),
|
|
percent: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 100 }),
|
|
attackMod: new fields.NumberField({ ...requiredInteger, initial: 0 }),
|
|
defenseMod: new fields.NumberField({ ...requiredInteger, initial: 0 })
|
|
}
|
|
return new fields.SchemaField(schema, { label })
|
|
}
|
|
|
|
schema.characteristics = new fields.SchemaField(
|
|
Object.values(SYSTEM.CHARACTERISTICS).reduce((obj, characteristic) => {
|
|
obj[characteristic.id] = characteristicField(characteristic.label)
|
|
return obj
|
|
}, {}),
|
|
)
|
|
|
|
// Save
|
|
const saveField = (label) => {
|
|
const schema = {
|
|
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
|
}
|
|
return new fields.SchemaField(schema, { label })
|
|
}
|
|
schema.saves = new fields.SchemaField(
|
|
Object.values(SYSTEM.SAVES).reduce((obj, save) => {
|
|
obj[save.id] = saveField(save.label)
|
|
return obj
|
|
}, {}),
|
|
)
|
|
|
|
// Challenges
|
|
const challengeField = (label) => {
|
|
const schema = {
|
|
value: new fields.StringField({ initial: "0", required: true, nullable: false }),
|
|
}
|
|
return new fields.SchemaField(schema, { label })
|
|
}
|
|
schema.challenges = new fields.SchemaField(
|
|
Object.values(SYSTEM.CHALLENGES).reduce((obj, save) => {
|
|
obj[save.id] = challengeField(save.label)
|
|
return obj
|
|
}, {}),
|
|
)
|
|
|
|
schema.hp = new fields.SchemaField({
|
|
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
max: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
})
|
|
|
|
schema.perception = new fields.SchemaField({
|
|
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
bonus: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
|
})
|
|
schema.grit = new fields.SchemaField({
|
|
starting: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
earned: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
current: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
|
})
|
|
schema.luck = new fields.SchemaField({
|
|
earned: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
current: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
|
})
|
|
schema.movement = new fields.SchemaField({
|
|
walk: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
jog: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
sprint: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
run: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
armorAdjust: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
})
|
|
schema.biodata = new fields.SchemaField({
|
|
class: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
|
level: new fields.NumberField({ ...requiredInteger, initial: 1, min: 1 }),
|
|
mortal: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
|
alignment: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
|
age: new fields.NumberField({ ...requiredInteger, initial: 15, min: 6 }),
|
|
height: new fields.NumberField({ ...requiredInteger, initial: 170, min: 50 }),
|
|
eyes: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
|
hair: new fields.StringField({ required: true, nullable: false, initial: "" })
|
|
})
|
|
schema.developmentPoints = new fields.SchemaField({
|
|
total: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
remaining: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
|
})
|
|
schema.spellMiraclePoints = new fields.SchemaField({
|
|
total: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
|
used: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
|
})
|
|
|
|
const moneyField = (label) => {
|
|
const schema = {
|
|
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
|
}
|
|
return new fields.SchemaField(schema, { label })
|
|
}
|
|
schema.moneys = new fields.SchemaField(
|
|
Object.values(SYSTEM.MONEY).reduce((obj, save) => {
|
|
obj[save.id] = moneyField(save.label)
|
|
return obj
|
|
}, {}),
|
|
)
|
|
|
|
return schema
|
|
}
|
|
|
|
/** @override */
|
|
static LOCALIZATION_PREFIXES = ["LETHALFANTASY.Character"]
|
|
|
|
prepareDerivedData() {
|
|
super.prepareDerivedData();
|
|
let grit = 0
|
|
for (let c in this.characteristics) {
|
|
if (SYSTEM.CHARACTERISTICS_MAJOR[c.id]) {
|
|
grit += this.characteristics[c].value
|
|
}
|
|
}
|
|
this.grit.starting = Math.round(grit / 6)
|
|
|
|
let strDef = SYSTEM.CHARACTERISTICS_TABLES.str.find(s => s.value === this.characteristics.str.value)
|
|
this.challenges.str.value = strDef.challenge
|
|
|
|
let dexDef = SYSTEM.CHARACTERISTICS_TABLES.dex.find(s => s.value === this.characteristics.dex.value)
|
|
this.challenges.agility.value = dexDef.challenge
|
|
this.saves.dodge.value = dexDef.dodge
|
|
|
|
let wisDef = SYSTEM.CHARACTERISTICS_TABLES.wis.find(s => s.value === this.characteristics.wis.value)
|
|
this.saves.will.value = wisDef.willpower_save
|
|
|
|
let conDef = SYSTEM.CHARACTERISTICS_TABLES.con.find(s => s.value === this.characteristics.con.value)
|
|
this.saves.pain.value = conDef.pain_save
|
|
this.saves.toughness.value = conDef.toughness_save
|
|
this.challenges.dying.value = conDef.stabilization_dice
|
|
|
|
this.saves.contagion.value = this.characteristics.con.value
|
|
this.saves.poison.value = this.characteristics.con.value
|
|
}
|
|
|
|
/**
|
|
* Rolls a dice for a character.
|
|
* @param {("save"|"resource|damage")} rollType The type of the roll.
|
|
* @param {number} rollTarget The target value for the roll. Which caracteristic or resource. If the roll is a damage roll, this is the id of the item.
|
|
* @param {"="|"+"|"++"|"-"|"--"} rollAdvantage If there is an avantage (+), a disadvantage (-), a double advantage (++), a double disadvantage (--) or a normal roll (=).
|
|
* @returns {Promise<null>} - A promise that resolves to null if the roll is cancelled.
|
|
*/
|
|
async roll(rollType, rollTarget) {
|
|
const hasTarget = false
|
|
let roll = await LethalFantasyRoll.prompt({
|
|
rollType,
|
|
rollTarget,
|
|
actorId: this.parent.id,
|
|
actorName: this.parent.name,
|
|
actorImage: this.parent.img,
|
|
hasTarget,
|
|
target: false
|
|
})
|
|
if (!roll) return null
|
|
|
|
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
|
}
|
|
}
|