Files
fvtt-oath-hammer/module/models/magic-item.mjs

50 lines
2.1 KiB
JavaScript

import { CLASS_RESTRICTION_CHOICES, SYSTEM } from "../config/system.mjs"
export default class OathHammerMagicItem extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const requiredInteger = { required: true, nullable: false, integer: true }
const schema = {}
// The magical effect / description of the item
schema.effect = new fields.HTMLField({ required: true, textSearch: true })
// Sub-type: Focus (arcane/divine instrument), Talisman (worn item), Trinket (misc object)
// Note: magic weapons and armor use the weapon/armor item types with isMagic=true instead.
schema.itemType = new fields.StringField({
required: true, initial: "talisman", choices: SYSTEM.MAGIC_ITEM_TYPE_CHOICES
})
// Quality: lesser / greater / legendary (determines power and how found, p.136)
schema.quality = new fields.StringField({
required: true, initial: "lesser", choices: SYSTEM.MAGIC_QUALITY_CHOICES
})
// Cursed items impose a bane that cannot be removed until the curse is broken
schema.isCursed = new fields.BooleanField({ initial: false })
// Legendary items bond to a single character (cannot be shared, p.136)
schema.isBonded = new fields.BooleanField({ initial: false })
// Class/lineage restriction printed in the item's type line, e.g. "Troubadour Only"
schema.classRestriction = new fields.StringField({ required: false, nullable: true, initial: null, choices: CLASS_RESTRICTION_CHOICES })
// Limited-use items (e.g. "once per day"); none = always active
schema.usagePeriod = new fields.StringField({
required: true, initial: "none", choices: SYSTEM.TRAIT_USAGE_PERIOD
})
schema.maxUses = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
schema.equipped = new fields.BooleanField({ initial: false })
// Attached runic spells — only for talisman subtype (max 2; snapshot of spell item)
schema.runes = new fields.ArrayField(new fields.ObjectField(), { required: true, initial: [] })
return schema
}
static LOCALIZATION_PREFIXES = ["OATHHAMMER.MagicItem"]
}