Add crew member option with pilot rolls integrated
All checks were successful
Release Creation / build (release) Successful in 48s

This commit is contained in:
2025-11-09 22:12:00 +01:00
parent c180365a61
commit 27b09d4546
30 changed files with 687 additions and 85 deletions

View File

@@ -14,9 +14,100 @@ export default class FTLNomadStarshipSheet extends FTLNomadActorSheet {
actions: {
createEquipment: FTLNomadStarshipSheet.#onCreateEquipment,
createWeapon: FTLNomadStarshipSheet.#onCreateWeapon,
removeCrew: FTLNomadStarshipSheet.#onRemoveCrew,
viewCrew: FTLNomadStarshipSheet.#onViewCrew,
pilotCrew: FTLNomadStarshipSheet.#onPilotCrew,
},
}
/**
* Remove a crew member from the starship
* @param {Event} event The initiating click event
* @param {HTMLElement} target The current target of the event listener
*/
static async #onRemoveCrew(event, target) {
const crewUuid = target.dataset.crewUuid
const actor = await fromUuid(crewUuid)
// Show confirmation dialog
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { title: game.i18n.localize("FTLNOMAD.RemoveCrewTitle") },
content: game.i18n.format("FTLNOMAD.RemoveCrewContent", { name: actor?.name || "Unknown" }),
rejectClose: false,
modal: true
})
if (!confirmed) return
const currentCrew = this.document.system.crewList || []
const updatedCrew = currentCrew.filter(uuid => uuid !== crewUuid)
await this.document.update({ "system.crewList": updatedCrew })
}
/**
* Open the actor sheet of a crew member
* @param {Event} event The initiating click event
* @param {HTMLElement} target The current target of the event listener
*/
static async #onViewCrew(event, target) {
const actorUuid = target.closest('.crew-member').dataset.actorUuid
const actor = await fromUuid(actorUuid)
if (actor) {
actor.sheet.render(true)
}
}
/**
* Roll a piloting check for a crew member with starship agility bonus
* @param {Event} event The initiating click event
* @param {HTMLElement} target The current target of the event listener
*/
static async #onPilotCrew(event, target) {
const actorUuid = target.closest('.crew-member').dataset.actorUuid
const actor = await fromUuid(actorUuid)
console.log("Pilot crew - Actor:", actor, "Type:", actor?.type)
if (!actor) {
ui.notifications.warn("Actor not found")
return
}
if (actor.type !== "character") {
ui.notifications.warn(`This actor is of type "${actor.type}", not "character"`)
return
}
// Get starship agility bonus
const starshipAgility = this.document.system.agility || 0
// Get the vehicles skill from the actor
const vehiclesSkill = actor.system.skills?.vehicles
if (!vehiclesSkill) {
ui.notifications.warn(game.i18n.localize("FTLNOMAD.Warning.noVehiclesSkill"))
return
}
// Import the Roll class
const FTLNomadRoll = (await import("../../documents/roll.mjs")).default
// Call the roll prompt with the starship agility as a vehicle bonus
let roll = await FTLNomadRoll.prompt({
rollType: "skill",
rollItem: vehiclesSkill,
actorId: actor.id,
actorName: actor.name,
actorImage: actor.img,
talents: actor.items.filter(i => i.type === "talent" && i.system.isAdvantage),
isEncumbered: actor.system.isEncumbered(),
hasTarget: false,
vehicleBonus: starshipAgility
})
if (!roll) return null
await roll.toMessage({}, { rollMode: roll.options.rollMode })
}
/** @override */
static PARTS = {
main: {
@@ -63,9 +154,35 @@ export default class FTLNomadStarshipSheet extends FTLNomadActorSheet {
context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.notes, { async: true })
context.enrichedModifications = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.modifications, { async: true })
// Prepare crew members data
context.crewMembers = await this.#prepareCrewMembers()
return context
}
/**
* Prepare crew members data from stored UUIDs
* @returns {Promise<Array>}
*/
async #prepareCrewMembers() {
const crewUuids = this.document.system.crewList || []
const crewMembers = []
for (const uuid of crewUuids) {
const actor = await fromUuid(uuid)
if (actor) {
crewMembers.push({
uuid: uuid,
id: actor.id,
name: actor.name,
img: actor.img
})
}
}
return crewMembers
}
_generateTooltip(type, target) {
}
@@ -128,7 +245,41 @@ export default class FTLNomadStarshipSheet extends FTLNomadActorSheet {
case "Item":
const item = await fromUuid(data.uuid)
return super._onDropItem(item)
case "Actor":
const actor = await fromUuid(data.uuid)
return this.#onDropActor(actor)
}
}
/**
* Handle dropping an actor onto the starship sheet to add them to the crew
* @param {Actor} actor The actor being dropped
*/
async #onDropActor(actor) {
if (!actor) return
// Check if actor is of type "character"
if (actor.type !== "character") {
ui.notifications.info(game.i18n.localize("FTLNOMAD.Warning.onlyCharactersAllowed"))
return
}
// Check if the actor has a linked prototype
if (!actor.prototypeToken?.actorLink) {
ui.notifications.info(game.i18n.localize("FTLNOMAD.Warning.noLinkedPrototype"))
return
}
const currentCrew = this.document.system.crewList || []
// Check if actor is already in crew
if (currentCrew.includes(actor.uuid)) {
ui.notifications.warn(game.i18n.localize("FTLNOMAD.Warning.alreadyInCrew"))
return
}
// Add actor UUID to crew array
const updatedCrew = [...currentCrew, actor.uuid]
await this.document.update({ "system.crewList": updatedCrew })
}
}