Add monsetr sheet
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
export { default as LethalFantasyCharacterSheet } from "./sheets/character-sheet.mjs";
|
||||
export { default as LethalFantasyOpponentSheet } from "./sheets/opponent-sheet.mjs"
|
||||
export { default as LethalFantasyMonsterSheet } from "./sheets/monster-sheet.mjs"
|
||||
export { default as LethalFantasyWeaponSheet } from "./sheets/weapon-sheet.mjs"
|
||||
export { default as LethalFantasySkillSheet } from "./sheets/skill-sheet.mjs"
|
||||
export { default as LethalFantasyGiftSheet } from "./sheets/gift-sheet.mjs"
|
||||
|
266
module/applications/sheets/monster-sheet.mjs
Normal file
266
module/applications/sheets/monster-sheet.mjs
Normal file
@ -0,0 +1,266 @@
|
||||
import LethalFantasyActorSheet from "./base-actor-sheet.mjs"
|
||||
import LethalFantasyRoll from "../../documents/roll.mjs"
|
||||
|
||||
export default class LethalFantasyMonsterSheet extends LethalFantasyActorSheet {
|
||||
/** @override */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["monster"],
|
||||
position: {
|
||||
width: 980,
|
||||
height: 780,
|
||||
},
|
||||
window: {
|
||||
contentClasses: ["monster-content"],
|
||||
},
|
||||
actions: {
|
||||
rangedAttackDefense: LethalFantasyMonsterSheet.#onRangedAttackDefense,
|
||||
rollInitiative: LethalFantasyMonsterSheet.#onRollInitiative,
|
||||
},
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
main: {
|
||||
template: "systems/fvtt-lethal-fantasy/templates/monster-main.hbs",
|
||||
},
|
||||
tabs: {
|
||||
template: "templates/generic/tab-navigation.hbs",
|
||||
},
|
||||
combat: {
|
||||
template: "systems/fvtt-lethal-fantasy/templates/monster-combat.hbs",
|
||||
},
|
||||
biography: {
|
||||
template: "systems/fvtt-lethal-fantasy/templates/monster-biography.hbs",
|
||||
},
|
||||
}
|
||||
|
||||
/** @override */
|
||||
tabGroups = {
|
||||
sheet: "combat",
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an array of form header tabs.
|
||||
* @returns {Record<string, Partial<ApplicationTab>>}
|
||||
*/
|
||||
#getTabs() {
|
||||
let tabs = {
|
||||
combat: { id: "combat", group: "sheet", icon: "fa-solid fa-swords", label: "LETHALFANTASY.Label.combat" },
|
||||
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "LETHALFANTASY.Label.biography" },
|
||||
}
|
||||
for (const v of Object.values(tabs)) {
|
||||
v.active = this.tabGroups[v.group] === v.id
|
||||
v.cssClass = v.active ? "active" : ""
|
||||
}
|
||||
return tabs
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext() {
|
||||
const context = await super._prepareContext()
|
||||
context.tabs = this.#getTabs()
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
_generateTooltip(type, target) {
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _preparePartContext(partId, context) {
|
||||
const doc = this.document
|
||||
switch (partId) {
|
||||
case "main":
|
||||
break
|
||||
case "combat":
|
||||
context.tab = context.tabs.combat
|
||||
context.weapons = doc.itemTypes.weapon
|
||||
break
|
||||
case "biography":
|
||||
context.tab = context.tabs.biography
|
||||
context.enrichedDescription = await TextEditor.enrichHTML(doc.system.description, { async: true })
|
||||
context.enrichedNotes = await TextEditor.enrichHTML(doc.system.notes, { async: true })
|
||||
break
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
// #region Drag-and-Drop Workflow
|
||||
|
||||
/**
|
||||
* Callback actions which occur when a dragged element is dropped on a target.
|
||||
* @param {DragEvent} event The originating DragEvent
|
||||
* @protected
|
||||
*/
|
||||
async _onDrop(event) {
|
||||
if (!this.isEditable || !this.isEditMode) return
|
||||
const data = TextEditor.getDragEventData(event)
|
||||
|
||||
// Handle different data types
|
||||
switch (data.type) {
|
||||
case "Item":
|
||||
const item = await fromUuid(data.uuid)
|
||||
return this._onDropItem(item)
|
||||
}
|
||||
}
|
||||
|
||||
static async #onRangedAttackDefense(event, target) {
|
||||
const hasTarget = false
|
||||
|
||||
let roll = await LethalFantasyRoll.promptRangedDefense({
|
||||
actorId: this.actor.id,
|
||||
actorName: this.actor.name,
|
||||
actorImage: this.actor.img,
|
||||
})
|
||||
if (!roll) return null
|
||||
|
||||
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
||||
}
|
||||
|
||||
static async #onRollInitiative(event, target) {
|
||||
const hasTarget = false
|
||||
let actorClass = this.actor.system.biodata.class;
|
||||
|
||||
let wisDef = SYSTEM.CHARACTERISTICS_TABLES.wis.find((c) => c.value === this.actor.system.characteristics.wis.value)
|
||||
let maxInit = Number(wisDef.init_cap) || 1000
|
||||
|
||||
let roll = await LethalFantasyRoll.promptInitiative({
|
||||
actorId: this.actor.id,
|
||||
actorName: this.actor.name,
|
||||
actorImage: this.actor.img,
|
||||
actorClass,
|
||||
maxInit,
|
||||
})
|
||||
if (!roll) return null
|
||||
|
||||
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
||||
}
|
||||
|
||||
static #onArmorHitPointsPlus(event, target) {
|
||||
let armorHP = this.actor.system.combat.armorHitPoints
|
||||
armorHP += 1
|
||||
this.actor.update({ "system.combat.armorHitPoints": armorHP })
|
||||
}
|
||||
|
||||
static #onArmorHitPointsMinus(event, target) {
|
||||
let armorHP = this.actor.system.combat.armorHitPoints
|
||||
armorHP -= 1
|
||||
this.actor.update({ "system.combat.armorHitPoints": Math.max(armorHP, 0) })
|
||||
}
|
||||
|
||||
static #onCreateEquipment(event, target) {
|
||||
}
|
||||
|
||||
getBestWeaponClassSkill(skills, rollType, multiplier = 1.0) {
|
||||
let maxValue = 0
|
||||
let goodSkill = skills[0]
|
||||
for (let s of skills) {
|
||||
if (rollType === "weapon-attack") {
|
||||
if (s.system.weaponBonus.attack > maxValue) {
|
||||
maxValue = Number(s.system.weaponBonus.attack)
|
||||
goodSkill = s
|
||||
}
|
||||
}
|
||||
if (rollType === "weapon-defense") {
|
||||
if (s.system.weaponBonus.defense > maxValue) {
|
||||
maxValue = Number(s.system.weaponBonus.defense)
|
||||
goodSkill = s
|
||||
}
|
||||
}
|
||||
if (rollType.includes("weapon-damage")) {
|
||||
if (s.system.weaponBonus.damage > maxValue) {
|
||||
maxValue = Number(s.system.weaponBonus.damage)
|
||||
goodSkill = s
|
||||
}
|
||||
}
|
||||
}
|
||||
goodSkill.weaponSkillModifier = maxValue * multiplier
|
||||
return goodSkill
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the roll action triggered by user interaction.
|
||||
*
|
||||
* @param {PointerEvent} event The event object representing the user interaction.
|
||||
* @param {HTMLElement} target The target element that triggered the roll.
|
||||
*
|
||||
* @returns {Promise<void>} A promise that resolves when the roll action is complete.
|
||||
*
|
||||
* @throws {Error} Throws an error if the roll type is not recognized.
|
||||
*
|
||||
* @description This method checks the current mode (edit or not) and determines the type of roll
|
||||
* (save, resource, or damage) based on the target element's data attributes. It retrieves the
|
||||
* corresponding value from the document's system and performs the roll.
|
||||
*/
|
||||
|
||||
async _onRoll(event, target) {
|
||||
if (this.isEditMode) return
|
||||
const rollType = event.target.dataset.rollType
|
||||
let rollTarget
|
||||
let rollKey = event.target.dataset.rollKey
|
||||
switch (rollType) {
|
||||
case "monster-attack":
|
||||
case "monster-defense":
|
||||
case "monster-damage":
|
||||
rollTarget = foundry.utils.duplicate(this.document.system.attacks[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
break
|
||||
case "resist":
|
||||
rollTarget = foundry.utils.duplicate(this.document.system.resists[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
break
|
||||
case "save":
|
||||
rollTarget = foundry.utils.duplicate(this.document.system.saves[rollKey])
|
||||
rollTarget.rollKey = rollKey
|
||||
rollTarget.rollDice = event.target.dataset?.rollDice
|
||||
break
|
||||
case "weapon-damage-small":
|
||||
case "weapon-damage-medium":
|
||||
case "weapon-attack":
|
||||
case "weapon-defense":
|
||||
let weapon = this.actor.items.find((i) => i.type === "weapon" && i.id === rollKey)
|
||||
let skill
|
||||
let skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase() === weapon.name.toLowerCase())
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase().replace(" skill", "") === weapon.name.toLowerCase())
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass === weapon.system.weaponClass)
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 0.5)
|
||||
} else {
|
||||
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass.includes(SYSTEM.WEAPON_CATEGORIES[weapon.system.weaponClass]))
|
||||
if (skills.length > 0) {
|
||||
skill = this.getBestWeaponClassSkill(skills, rollType, 0.25)
|
||||
} else {
|
||||
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!weapon || !skill) {
|
||||
console.error("Weapon or skill not found", weapon, skill)
|
||||
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
|
||||
return
|
||||
}
|
||||
rollTarget = skill
|
||||
rollTarget.weapon = weapon
|
||||
rollTarget.weaponSkillModifier = skill.weaponSkillModifier
|
||||
rollTarget.rollKey = rollKey
|
||||
rollTarget.combat = foundry.utils.duplicate(this.actor.system.combat)
|
||||
break
|
||||
default:
|
||||
ui.notifications.error(game.i18n.localize("LETHALFANTASY.Notifications.rollTypeNotFound") + String(rollType))
|
||||
break
|
||||
}
|
||||
|
||||
// In all cases
|
||||
console.log(rollTarget)
|
||||
await this.document.system.roll(rollType, rollTarget)
|
||||
}
|
||||
// #endregion
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
import LethalFantasyActorSheet from "./base-actor-sheet.mjs"
|
||||
|
||||
export default class LethalFantasyOpponentSheet extends LethalFantasyActorSheet {
|
||||
/** @override */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["opponent"],
|
||||
position: {
|
||||
width: 800,
|
||||
height: 700,
|
||||
},
|
||||
window: {
|
||||
contentClasses: ["opponent-content"],
|
||||
},
|
||||
actions: {
|
||||
createAttack: LethalFantasyOpponentSheet.#onCreateAttack,
|
||||
},
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
main: {
|
||||
template: "systems/fvtt-lethal-fantasy/templates/opponent.hbs",
|
||||
},
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext() {
|
||||
const context = await super._prepareContext()
|
||||
context.attacks = context.actor.itemTypes.attack
|
||||
context.spells = context.actor.itemTypes.spell
|
||||
context.hasSpells = context.spells.length > 0
|
||||
return context
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback actions which occur when a dragged element is dropped on a target.
|
||||
* @param {DragEvent} event The originating DragEvent
|
||||
* @protected
|
||||
*/
|
||||
async _onDrop(event) {
|
||||
if (!this.isEditable || !this.isEditMode) return
|
||||
const data = TextEditor.getDragEventData(event)
|
||||
|
||||
// Handle different data types
|
||||
switch (data.type) {
|
||||
case "Item":
|
||||
const item = await fromUuid(data.uuid)
|
||||
if (item.type === "attack") return this.#onDropAttackItem(item)
|
||||
if (item.type === "spell") return this._onDropItem(item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the drop event of an attack item.
|
||||
*
|
||||
* @param {Object} item The attack item being dropped.
|
||||
* @returns {Promise<void>} A promise that resolves when the attack item has been added to the document.
|
||||
* @private
|
||||
*/
|
||||
async #onDropAttackItem(item) {
|
||||
await this.document.addAttack(item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the creation of a new attack item.
|
||||
*
|
||||
* @param {Event} event The event that triggered the creation of the attack.
|
||||
* @param {Object} target The target object where the attack will be created.
|
||||
* @private
|
||||
* @static
|
||||
*/
|
||||
static #onCreateAttack(event, target) {
|
||||
const item = this.document.createEmbeddedDocuments("Item", [{ name: "Nouvelle attaque", type: "attack" }])
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll a damage roll.
|
||||
* @param {PointerEvent} event The originating click event
|
||||
* @param {HTMLElement} target the capturing HTML element which defined a [data-action]
|
||||
*/
|
||||
async _onRoll(event, target) {
|
||||
if (this.isEditMode) return
|
||||
const elt = event.currentTarget
|
||||
const rollValue = elt.dataset.rollValue
|
||||
const rollTarget = elt.dataset.itemName
|
||||
|
||||
await this.document.system.roll(rollValue, rollTarget)
|
||||
}
|
||||
}
|
48
module/config/monster.mjs
Normal file
48
module/config/monster.mjs
Normal file
@ -0,0 +1,48 @@
|
||||
export const MONSTER_CHARACTERISTICS = Object.freeze({
|
||||
int: {
|
||||
id: "int",
|
||||
label: "LETHALFANTASY.Character.int.label"
|
||||
},
|
||||
dex: {
|
||||
id: "dex",
|
||||
label: "LETHALFANTASY.Character.dex.label"
|
||||
},
|
||||
})
|
||||
|
||||
export const MONSTER_RESIST = Object.freeze({
|
||||
resistTorture: {
|
||||
id: "resistTorture",
|
||||
label: "LETHALFANTASY.Character.resistTorture.label"
|
||||
},
|
||||
resistPerformance: {
|
||||
id: "resistPerformance",
|
||||
label: "LETHALFANTASY.Character.resistPerformance.label"
|
||||
},
|
||||
resistIntimidation: {
|
||||
id: "resistIntimidation",
|
||||
label: "LETHALFANTASY.Character.resistIntimidation.label"
|
||||
}
|
||||
})
|
||||
|
||||
export const MONSTER_SAVES = Object.freeze({
|
||||
will: {
|
||||
id: "will",
|
||||
label: "LETHALFANTASY.Character.will.label"
|
||||
},
|
||||
dodge: {
|
||||
id: "dodge",
|
||||
label: "LETHALFANTASY.Character.dodge.label"
|
||||
},
|
||||
toughness: {
|
||||
id: "toughness",
|
||||
label: "LETHALFANTASY.Character.toughness.label"
|
||||
},
|
||||
contagion: {
|
||||
id: "contagion",
|
||||
label: "LETHALFANTASY.Character.contagion.label"
|
||||
},
|
||||
poison: {
|
||||
id: "poison",
|
||||
label: "LETHALFANTASY.Character.poison.label"
|
||||
}
|
||||
})
|
@ -5,6 +5,7 @@ import * as SPELL from "./spell.mjs"
|
||||
import * as SKILL from "./skill.mjs"
|
||||
import * as EQUIPMENT from "./equipment.mjs"
|
||||
import * as CHARACTERISTICS from "./characteristic-tables.mjs"
|
||||
import * as MONSTER from "./monster.mjs"
|
||||
|
||||
export const SYSTEM_ID = "fvtt-lethal-fantasy"
|
||||
export const DEV_MODE = false
|
||||
@ -230,6 +231,9 @@ export const SYSTEM = {
|
||||
CHARACTERISTICS: CHARACTER.CHARACTERISTICS,
|
||||
CHARACTERISTICS_TABLES: CHARACTERISTICS.TABLES,
|
||||
CHARACTERISTICS_MAJOR: CHARACTERISTICS.MAJOR,
|
||||
MONSTER_CHARACTERISTICS: MONSTER.MONSTER_CHARACTERISTICS,
|
||||
MONSTER_RESIST: MONSTER.MONSTER_RESIST,
|
||||
MONSTER_SAVES: MONSTER.MONSTER_SAVES,
|
||||
SAVES: CHARACTER.SAVES,
|
||||
CHALLENGES: CHARACTER.CHALLENGES,
|
||||
SKILL_CATEGORY: SKILL.CATEGORY,
|
||||
|
@ -135,8 +135,32 @@ export default class LethalFantasyRoll extends Roll {
|
||||
} else {
|
||||
dice = "1D20"
|
||||
maxValue = 20
|
||||
hasFavor = true
|
||||
}
|
||||
|
||||
|
||||
} else if (options.rollType === "monster-attack" || options.rollType === "monster-defense") {
|
||||
hasD30 = true
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D20"
|
||||
baseFormula = "D20"
|
||||
maxValue = 20
|
||||
hasModifier = true
|
||||
hasChangeDice = false
|
||||
hasFavor = true
|
||||
if (options.rollType === "monster-attack") {
|
||||
options.rollTarget.value = options.rollTarget.attackModifier
|
||||
options.rollTarget.charModifier = 0
|
||||
} else {
|
||||
options.rollTarget.value = options.rollTarget.defenseModifier
|
||||
options.rollTarget.charModifier = 0
|
||||
}
|
||||
|
||||
} else if (options.rollType === "resist") {
|
||||
dice = "1D20"
|
||||
maxValue = 20
|
||||
hasFavor = true
|
||||
options.rollName = options.rollTarget.rollKey
|
||||
|
||||
} else if (options.rollType === "skill") {
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D100"
|
||||
@ -200,8 +224,20 @@ export default class LethalFantasyRoll extends Roll {
|
||||
dice = dice.replace("E", "")
|
||||
baseFormula = dice
|
||||
maxValue = 20
|
||||
|
||||
} else if (options.rollType.includes("monster-damage")) {
|
||||
options.rollName = options.rollTarget.name
|
||||
hasModifier = true
|
||||
hasChangeDice = false
|
||||
options.rollTarget.value = 0
|
||||
options.rollTarget.charModifier = 0
|
||||
dice = options.rollTarget.damageDice
|
||||
dice = dice.replace("E", "")
|
||||
baseFormula = dice
|
||||
maxValue = 20
|
||||
}
|
||||
|
||||
|
||||
if (options.rollType === "save" && options.rollTarget.rollKey === "pain") {
|
||||
dice = options.rollTarget.rollDice
|
||||
baseFormula = options.rollTarget.rollDice
|
||||
@ -336,7 +372,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
|
||||
let rollBase = new this(baseFormula, options.data, rollData)
|
||||
const rollModifier = new Roll(modifierFormula, options.data, rollData)
|
||||
rollModifier.evaluate()
|
||||
await rollModifier.evaluate()
|
||||
await rollBase.evaluate()
|
||||
|
||||
let rollFavor
|
||||
@ -372,7 +408,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
if (hasD30) {
|
||||
let rollD30 = await new Roll("1D30").evaluate()
|
||||
if (game?.dice3d) {
|
||||
await game.dice3d.showForRoll(rollFavor, game.user, true)
|
||||
game.dice3d.showForRoll(rollD30, game.user, true)
|
||||
}
|
||||
options.D30result = rollD30.total
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
export { default as LethalFantasyCharacter } from "./character.mjs"
|
||||
export { default as LethalFantasyOpponent } from "./opponent.mjs"
|
||||
export { default as LethalFantasyMonster } from "./monster.mjs"
|
||||
export { default as LethalFantasyWeapon } from "./weapon.mjs"
|
||||
export { default as LethalFantasySpell } from "./spell.mjs"
|
||||
export { default as LethalFantasySkill } from "./skill.mjs"
|
||||
|
144
module/models/monster.mjs
Normal file
144
module/models/monster.mjs
Normal file
@ -0,0 +1,144 @@
|
||||
import { SYSTEM } from "../config/system.mjs"
|
||||
import LethalFantasyRoll from "../documents/roll.mjs"
|
||||
|
||||
export default class LethalFantasyMonster 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.MONSTER_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.MONSTER_SAVES).reduce((obj, save) => {
|
||||
obj[save.id] = saveField(save.label)
|
||||
return obj
|
||||
}, {}),
|
||||
)
|
||||
|
||||
// Resist
|
||||
const resistField = (label) => {
|
||||
const schema = {
|
||||
value: new fields.StringField({ initial: "0", required: true, nullable: false }),
|
||||
}
|
||||
return new fields.SchemaField(schema, { label })
|
||||
}
|
||||
schema.resists = new fields.SchemaField(
|
||||
Object.values(SYSTEM.MONSTER_RESIST).reduce((obj, save) => {
|
||||
obj[save.id] = resistField(save.label)
|
||||
return obj
|
||||
}, {}),
|
||||
)
|
||||
|
||||
schema.hp = new fields.SchemaField({
|
||||
value: new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 }),
|
||||
average: new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 }),
|
||||
max: new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 }),
|
||||
})
|
||||
|
||||
const attackField = (label) => {
|
||||
const schema = {
|
||||
key: new fields.StringField({ required: true, nullable: false, initial: `attack${label}` }),
|
||||
name: new fields.StringField({ required: true, nullable: false, initial: `Attack ${label}` }),
|
||||
attackScore: new fields.NumberField({ ...requiredInteger, initial: Number(label), min: 0 }),
|
||||
attackModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
defenseModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
damageDice: new fields.StringField({ required: true, nullable: false, initial: "1D6" }),
|
||||
}
|
||||
return new fields.SchemaField(schema, { label })
|
||||
}
|
||||
// Add 4 attackFields in an attack schema
|
||||
schema.attacks = new fields.SchemaField({
|
||||
attack1: attackField("1"),
|
||||
attack2: attackField("2"),
|
||||
attack3: attackField("3"),
|
||||
attack4: attackField("4"),
|
||||
})
|
||||
|
||||
schema.perception = new fields.SchemaField({
|
||||
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
bonus: 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.jump = new fields.SchemaField({
|
||||
broad: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
running: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
vertical: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
})
|
||||
schema.biodata = new fields.SchemaField({
|
||||
alignment: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
||||
vision: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
||||
height: new fields.NumberField({ ...requiredInteger, initial: 170, min: 50 }),
|
||||
length: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
||||
weight: new fields.NumberField({ ...requiredInteger, initial: 70, min: 0 })
|
||||
})
|
||||
schema.combat = new fields.SchemaField({
|
||||
attackModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
defenseModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
damageModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
armorHitPoints: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
})
|
||||
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static LOCALIZATION_PREFIXES = ["LETHALFANTASY.Monster"]
|
||||
|
||||
/**
|
||||
* 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 })
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
import LethalFantasyRoll from "../documents/roll.mjs"
|
||||
|
||||
export default class LethalFantasyOpponent extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields
|
||||
const requiredInteger = { required: true, nullable: false, integer: true }
|
||||
const schema = {}
|
||||
|
||||
schema.dv = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
||||
schema.pv = new fields.SchemaField({
|
||||
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
max: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
})
|
||||
schema.armure = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
||||
schema.malus = new fields.NumberField({ ...requiredInteger, initial: 0, max: 0 })
|
||||
schema.actions = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
||||
schema.description = new fields.HTMLField({ required: true, textSearch: true })
|
||||
// Attaques : embedded items of type Attack
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static LOCALIZATION_PREFIXES = ["LETHALFANTSY.Opponent"]
|
||||
|
||||
/**
|
||||
* Rolls a dice attack for an opponent.
|
||||
* @param {number} rollType Type of roll.
|
||||
* @param {number} rollTarget The name of the attack
|
||||
* @returns {Promise<null>} - A promise that resolves to null if the roll is cancelled.
|
||||
*/
|
||||
async roll(rollType, rollTarget) {
|
||||
let roll = await LethalFantasyRoll.prompt({
|
||||
rollType: rollType,
|
||||
rollValue,
|
||||
rollTarget,
|
||||
actorId: this.parent.id,
|
||||
actorName: this.parent.name,
|
||||
actorImage: this.parent.img,
|
||||
})
|
||||
if (!roll) return null
|
||||
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
||||
}
|
||||
|
||||
get toolTip() {
|
||||
return this.description || ""
|
||||
}
|
||||
}
|
@ -18,6 +18,9 @@ export default class LethalFantasyUtils {
|
||||
Handlebars.registerHelper('isNull', function (val) {
|
||||
return val == null;
|
||||
});
|
||||
Handlebars.registerHelper('match', function (val, search) {
|
||||
return val.match(search);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('exists', function (val) {
|
||||
return val != null && val !== undefined;
|
||||
@ -156,9 +159,6 @@ export default class LethalFantasyUtils {
|
||||
if (typeof text !== 'string') return text
|
||||
return text.charAt(0).toUpperCase()
|
||||
})
|
||||
Handlebars.registerHelper('isCreature', function (key) {
|
||||
return key === "creature" || key === "daemon";
|
||||
})
|
||||
|
||||
// Handle v12 removal of this helper
|
||||
Handlebars.registerHelper('select', function (selected, options) {
|
||||
|
Reference in New Issue
Block a user