New robot stuff
All checks were successful
Release Creation / build (release) Successful in 1m15s

This commit is contained in:
2025-10-15 15:27:58 +02:00
parent 941db9436f
commit e65f0a1670
43 changed files with 2125 additions and 265 deletions

View File

@@ -11,4 +11,4 @@ export { default as FTLNomadImplantSheet } from "./sheets/implant-sheet.mjs"
export { default as FTLNomadStarshipSheet } from "./sheets/starship-sheet.mjs"
export { default as FTLNomadCreatureTraitSheet } from "./sheets/creature-trait-sheet.mjs"
export { default as FTLNomadCreatureAbilitySheet } from "./sheets/creature-ability-sheet.mjs"
export { default as FTLNomadRobotSheet } from "./sheets/robot-sheet.mjs"

View File

@@ -0,0 +1,174 @@
import FTLNomadActorSheet from "./base-actor-sheet.mjs"
export default class FTLNomadRobotSheet extends FTLNomadActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["robot"],
position: {
width: 860,
height: 620,
},
window: {
contentClasses: ["robot-content"],
},
actions: {
createEquipment: FTLNomadRobotSheet.#onCreateEquipment,
createArmor: FTLNomadRobotSheet.#onCreateArmor,
createWeapon: FTLNomadRobotSheet.#onCreateWeapon,
createTalent: FTLNomadRobotSheet.#onCreateTalent,
createImplant: FTLNomadRobotSheet.#onCreateImplant,
createPsionic: FTLNomadRobotSheet.#onCreatePsionic,
createLanguage: FTLNomadRobotSheet.#onCreateLanguage
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-ftl-nomad/templates/robot-main.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
equipment: {
template: "systems/fvtt-ftl-nomad/templates/robot-equipment.hbs",
},
description: {
template: "systems/fvtt-ftl-nomad/templates/robot-description.hbs",
},
}
/** @override */
tabGroups = {
sheet: "equipment",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "FTLNOMAD.Label.equipment" },
description: {
id: "description", group: "sheet", icon: "fa-solid fa-book", label: "FTLNOMAD.Label.description"
}
}
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()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.notes, { async: true })
return context
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
case "equipment":
context.tab = context.tabs.equipment
context.weapons = doc.itemTypes.weapon
context.weapons.sort((a, b) => a.name.localeCompare(b.name))
context.armors = doc.itemTypes.armor
context.armors.sort((a, b) => a.name.localeCompare(b.name))
context.equipments = doc.itemTypes.equipment
context.equipments.sort((a, b) => a.name.localeCompare(b.name))
break
case "description":
context.tab = context.tabs.description
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.description, { async: true })
context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.notes, { async: true })
break
}
return context
}
static #onCreateEquipment(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newEquipment"), type: "equipment" }])
}
static #onCreateWeapon(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newWeapon"), type: "weapon" }])
}
static #onCreateArmor(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newArmor"), type: "armor" }])
}
static #onCreateTalent(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newTalent"), type: "talent" }])
}
static #onCreateImplant(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newImplant"), type: "implant" }])
}
static #onCreatePsionic(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newPsionic"), type: "psionic" }])
}
static #onCreateLanguage(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("FTLNOMAD.Label.newLanguage"), type: "language" }])
}
/**
* 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) {
const rollType = $(event.currentTarget).data("roll-type")
let item
let li
switch (rollType) {
case "skill":
let skillId = $(event.currentTarget).data("skill-id");
item = this.actor.system.skills[skillId];
break
case "weapon":
case "damage":
li = $(event.currentTarget).parents(".item");
item = this.actor.items.get(li.data("item-id"));
break
default:
throw new Error(`Unknown roll type ${rollType}`)
}
await this.document.system.roll(rollType, item)
}
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 super._onDropItem(item)
}
}
}

View File

@@ -41,6 +41,13 @@ export const TECH_AGES = {
"cosmic": { id: "cosmic", label: "FTLNOMAD.TechAge.Cosmic", level: 13 }
}
export const ROBOT_SIZES = {
"tiny": { id: "tiny", label: "FTLNOMAD.Robot.Size.Tiny" },
"small": { id: "small", label: "FTLNOMAD.Robot.Size.Small" },
"medium": { id: "medium", label: "FTLNOMAD.Robot.Size.Medium" },
"large": { id: "large", label: "FTLNOMAD.Robot.Size.Large" },
"giant": { id: "giant", label: "FTLNOMAD.Robot.Size.Giant" }
}
export const WEAPON_TYPES = {
"melee": { id: "melee", label: "FTLNOMAD.Weapon.Types.Melee" },
@@ -72,6 +79,16 @@ export const ATTACK_MODIFIERS = {
"aware": -1
}
export const DAMAGE_MODIFIER_CHOICES = [
{ id: "-3", label: "-3", value: "-3" },
{ id: "-2", label: "-2", value: "-2" },
{ id: "-1", label: "-1", value: "-1" },
{ id: "0", label: "0", value: "0" },
{ id: "1", label: "+1", value: "1" },
{ id: "2", label: "+2", value: "2" },
{ id: "3", label: "+3", value: "3" }
]
export const TRIAGE_RESULTS = {
"none": { id: "none", dice: 0, label: "FTLNOMAD.TriageResults.None" },
"death": { id: "death", dice: 3, label: "FTLNOMAD.TriageResults.Death" },
@@ -156,5 +173,7 @@ export const SYSTEM = {
CREATURE_NICHES,
STARSHIP_HULL,
SKILLS,
ROBOT_SIZES,
DAMAGE_MODIFIER_CHOICES,
ASCII
}

View File

@@ -63,7 +63,7 @@ export default class FTLNomadRoll extends Roll {
static updateFullFormula(options) {
let fullFormula
if (options.rollType === "damage") {
fullFormula = `${options.formula} + ${options.skillModifier}D6 `
fullFormula = `${options.formula} + ${options.damageModifier}D6 `
} else {
let mod = options.rollItem?.value || 0
fullFormula = `${options.formula} + ${options.skillModifier}D + ${mod} + ${options.rangeModifier}D + ${options.numericModifier}D`
@@ -125,11 +125,14 @@ export default class FTLNomadRoll extends Roll {
choiceRangeModifier[key] = { label: `${key} (${value}D)`, value: value }
}
}
const choiceDamageModifier = SYSTEM.DAMAGE_MODIFIER_CHOICES
let damageModifier = "0"
let modifier = "0"
options.skillModifier = 0
options.numericModifier = 0
options.rangeModifier = rangeModifier
options.damageModifier = damageModifier
let fullFormula = `${formula} + ${options.rollItem.value}`
if (options.isEncumbered) {
fullFormula += ` - 1D`
@@ -150,7 +153,9 @@ export default class FTLNomadRoll extends Roll {
fieldRollMode,
choiceModifier,
choiceRangeModifier,
choiceDamageModifier,
rangeModifier,
damageModifier,
formula,
hasTarget: options.hasTarget,
modifier,
@@ -184,6 +189,10 @@ export default class FTLNomadRoll extends Roll {
options.skillModifier = Number(event.target.value)
FTLNomadRoll.updateFullFormula(options)
})
$(".roll-damage-modifier").change(event => {
options.damageModifier = Number(event.target.value)
FTLNomadRoll.updateFullFormula(options)
})
$(".roll-skill-range-modifier").change(event => {
options.rangeModifier = Number(event.target.value)
FTLNomadRoll.updateFullFormula(options)
@@ -230,9 +239,13 @@ export default class FTLNomadRoll extends Roll {
// Replace the D6 by the correct number of D6
damageFormula = damageFormula.replace(/(\d*)d6/gi, (match, p1) => {
let numDice = Number(p1) || 1
numDice += Number(options.skillModifier)
//numDice += options?.finalModifier || 0
return `${numDice}d6 + ${mod}`
let damageModifier = Number(options.damageModifier)
let postArg = ""
if (damageModifier && damageModifier !== 0) {
postArg = (damageModifier > 0) ? `kh${numDice}` : `kl${numDice}`
numDice += Math.abs(damageModifier)
}
return `${numDice}d6${postArg} + ${mod}`
})
diceFormula = damageFormula
} else {

View File

@@ -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
View 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 })
}
}