Add crew member option with pilot rolls integrated
All checks were successful
Release Creation / build (release) Successful in 48s
All checks were successful
Release Creation / build (release) Successful in 48s
This commit is contained in:
@@ -14,9 +14,100 @@ export default class FTLNomadVehicleSheet extends FTLNomadActorSheet {
|
||||
actions: {
|
||||
createEquipment: FTLNomadVehicleSheet.#onCreateEquipment,
|
||||
createWeapon: FTLNomadVehicleSheet.#onCreateWeapon,
|
||||
removeCrew: FTLNomadVehicleSheet.#onRemoveCrew,
|
||||
viewCrew: FTLNomadVehicleSheet.#onViewCrew,
|
||||
pilotCrew: FTLNomadVehicleSheet.#onPilotCrew,
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a crew member from the vehicle
|
||||
* @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 vehicle 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 vehicle agility bonus
|
||||
const vehicleAgility = 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 vehicle 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: vehicleAgility
|
||||
})
|
||||
if (!roll) return null
|
||||
|
||||
await roll.toMessage({}, { rollMode: roll.options.rollMode })
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
main: {
|
||||
@@ -62,9 +153,35 @@ export default class FTLNomadVehicleSheet extends FTLNomadActorSheet {
|
||||
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 })
|
||||
|
||||
// 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,36 @@ export default class FTLNomadVehicleSheet 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 vehicle 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
|
||||
}
|
||||
|
||||
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 })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user