This commit is contained in:
@@ -11,4 +11,4 @@ export { default as FTLNomadImplant } from "./implant.mjs"
|
||||
export { default as FTLNomadStarship } from "./starship.mjs"
|
||||
export { default as FTLNomadCreatureTrait } from "./creature-trait.mjs"
|
||||
export { default as FTLNomadCreatureAbility } from "./creature-ability.mjs"
|
||||
|
||||
export { default as FTLNomadRobot } from "./robot.mjs"
|
||||
|
||||
84
module/models/robot.mjs
Normal file
84
module/models/robot.mjs
Normal file
@@ -0,0 +1,84 @@
|
||||
import { SYSTEM } from "../config/system.mjs"
|
||||
import FTLNomadRoll from "../documents/roll.mjs"
|
||||
|
||||
export default class FTLNomadRobot 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 })
|
||||
schema.name = new fields.StringField({ required: true, nullable: false, initial: "" })
|
||||
|
||||
schema.techAge = new fields.StringField({ required: true, choices: SYSTEM.TECH_AGES, initial: "lateatomic" })
|
||||
schema.robotSize = new fields.StringField({ required: true, choices: SYSTEM.ROBOT_SIZES, initial: "medium" })
|
||||
schema.durability = new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 })
|
||||
schema.protection = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
||||
schema.brain = new fields.StringField({ required: true, nullable: false, initial: "" })
|
||||
schema.speed = new fields.StringField({ required: true, nullable: false, initial: "" })
|
||||
|
||||
// Carac
|
||||
const skillField = (label) => {
|
||||
const schema = {
|
||||
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 }),
|
||||
label: new fields.StringField({ required: true, nullable: false, initial: label })
|
||||
}
|
||||
return new fields.SchemaField(schema, { label })
|
||||
}
|
||||
|
||||
schema.skills = new fields.SchemaField(
|
||||
Object.values(SYSTEM.SKILLS).reduce((obj, characteristic) => {
|
||||
obj[characteristic.id] = skillField(characteristic.label)
|
||||
return obj
|
||||
}, {}),
|
||||
)
|
||||
|
||||
schema.enc = new fields.SchemaField({
|
||||
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
max: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
|
||||
})
|
||||
|
||||
schema.cost = new fields.StringField({ required: true, initial: "0" })
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static LOCALIZATION_PREFIXES = ["FTLNOMAD.Robot"]
|
||||
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData();
|
||||
|
||||
}
|
||||
|
||||
isEncumbered() {
|
||||
return this.enc.value > this.enc.max
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
* 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 opponentTarget
|
||||
const hasTarget = opponentTarget !== undefined
|
||||
|
||||
let roll = await FTLNomadRoll.prompt({
|
||||
rollType,
|
||||
rollItem,
|
||||
actorId: this.parent.id,
|
||||
actorName: this.parent.name,
|
||||
actorImage: this.parent.img,
|
||||
isEncumbered: this.isEncumbered(),
|
||||
hasTarget,
|
||||
target: opponentTarget
|
||||
})
|
||||
if (!roll) return null
|
||||
|
||||
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user