fvtt-pegasus-rpg/modules/pegasus-vehicle-sheet.js

329 lines
12 KiB
JavaScript
Raw Normal View History

2022-09-05 08:57:02 +02:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { PegasusUtility } from "./pegasus-utility.js"
import { PegasusRollDialog } from "./pegasus-roll-dialog.js"
/* -------------------------------------------- */
export class PegasusVehicleSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-pegasus-rpg", "sheet", "actor"],
template: "systems/fvtt-pegasus-rpg/templates/vehicle-sheet.html",
width: 960,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "combat" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: true
});
}
/* -------------------------------------------- */
async getData() {
const objectData = this.object
let actorData = duplicate(this.object)
let formData = {
title: this.title,
id: objectData.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: actorData.system,
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
limited: this.object.limited,
optionsDiceList: PegasusUtility.getOptionsDiceList(),
2022-09-18 17:30:15 +02:00
vmsAvailable: objectData.system.modules.totalvms - objectData.system.modules.vmsused,
2022-09-21 16:54:34 +02:00
crewList: this.actor.getCrewList(),
2022-09-18 17:30:15 +02:00
totalCost: this.actor.getTotalCost(),
2022-09-05 08:57:02 +02:00
optionsLevel: PegasusUtility.getOptionsLevel(),
subActors: duplicate(this.actor.getSubActors()),
effects: duplicate(this.actor.getEffects()),
2022-09-08 21:26:45 +02:00
combatModules: duplicate(this.actor.getCombatModules()),
powerCoreModules: duplicate(this.actor.getPowercoreModules()),
vehicleHull: duplicate(this.actor.getVehicleHull()),
mobilityModules: duplicate(this.actor.getMobilityModules()),
propulsionModules: duplicate(this.actor.getPropulsionModules()),
2022-10-06 17:47:56 +02:00
vehicleModules: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getVehicleModules())),
vehicleWeaponModules: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getVehicleWeaponModules())),
2022-09-26 18:42:13 +02:00
cargos: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getCargos()) ),
2022-09-25 15:48:11 +02:00
cargoCurrent: this.actor.getCurrentCargoCapacity(),
moneys: duplicate(this.actor.getMoneys()),
2022-09-05 08:57:02 +02:00
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
isGM: game.user.isGM
}
this.formData = formData;
console.log("VEHICLE : ", formData, this.object);
return formData;
}
/* -------------------------------------------- */
async openGenericRoll() {
let rollData = PegasusUtility.initGenericRoll()
rollData.traumaState = this.actor.getTraumaState()
let rollDialog = await PegasusRollDialog.create( this.actor, rollData);
rollDialog.render( true );
}
/* -------------------------------------------- */
async rollIDR( itemId, diceValue) {
let item = this.actor.items.get( itemId) ?? {name: "Unknown"}
let myRoll = new Roll(diceValue+"x").roll({ async: false })
await PegasusUtility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
content: `${this.actor.name} has roll IDR for ${item.name} : ${myRoll.total}`
}
ChatMessage.create(chatData)
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
html.bind("keydown", function(e) { // Ignore Enter in actores sheet
if (e.keyCode === 13) return false;
});
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
const item = this.actor.items.get( itemId );
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item")
PegasusUtility.confirmDelete(this, li)
})
html.find('.item-add').click(ev => {
let dataType = $(ev.currentTarget).data("type")
this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType }], { renderSheet: true })
})
2022-09-26 20:57:55 +02:00
html.find('.current-speed-change').change(ev => {
2022-09-09 08:33:28 +02:00
let speed = ev.currentTarget.value
this.actor.manageCurrentSpeed(speed)
2022-09-25 09:26:12 +02:00
})
2022-09-05 08:57:02 +02:00
2022-09-25 09:26:12 +02:00
html.find('.vehicle-module-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.activateVehicleModule( itemId)
});
html.find('.vehicle-weapon-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.activateVehicleModule( itemId)
});
2022-10-06 19:04:53 +02:00
html.find('.effect-used').click(ev => {
2022-09-05 08:57:02 +02:00
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.perkEffectUsed( itemId)
});
2022-09-21 16:58:02 +02:00
html.find('.member-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let actorId = li.data("actor-id")
this.actor.delCrew(actorId)
2022-09-05 08:57:02 +02:00
});
html.find('.quantity-minus').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.incDecQuantity( li.data("item-id"), -1 );
} )
html.find('.quantity-plus').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.incDecQuantity( li.data("item-id"), +1 );
} )
2022-09-16 17:36:58 +02:00
html.find('.vehicle-current-nrg-minus').click(event => {
2022-09-05 08:57:02 +02:00
this.actor.incDecNRG( -1 );
} )
2022-09-16 17:36:58 +02:00
html.find('.vehicle-current-nrg-plus').click(event => {
2022-09-05 08:57:02 +02:00
this.actor.incDecNRG( 1 );
} )
html.find('.ammo-minus').click(event => {
const li = $(event.currentTarget).parents(".item")
this.actor.incDecAmmo( li.data("item-id"), -1 );
} );
html.find('.ammo-plus').click(event => {
const li = $(event.currentTarget).parents(".item")
this.actor.incDecAmmo( li.data("item-id"), +1 )
} );
2022-09-09 08:33:28 +02:00
html.find('.vehicle-stun-minus').click(event => {
this.actor.modifyVehicleStun( -1 )
2022-09-05 08:57:02 +02:00
} )
2022-09-09 08:33:28 +02:00
html.find('.vehicle-stun-plus').click(event => {
this.actor.modifyVehicleStun( 1 )
2022-09-05 08:57:02 +02:00
} )
html.find('.momentum-minus').click(event => {
this.actor.modifyMomentum( -1 )
} )
html.find('.momentum-plus').click(event => {
this.actor.modifyMomentum( 1 )
} )
html.find('.unarmed-attack').click((event) => {
this.actor.rollUnarmedAttack();
});
html.find('.generic-pool-roll').click((event) => {
this.openGenericRoll()
} );
2022-09-21 16:54:34 +02:00
2022-09-05 08:57:02 +02:00
html.find('.attack-melee').click((event) => {
2022-09-21 16:54:34 +02:00
this.actor.rollPoolFromVehicle( 'com', false, "melee-atk")
2022-09-05 08:57:02 +02:00
});
html.find('.damage-melee').click((event) => {
2022-09-21 16:54:34 +02:00
this.actor.rollPoolFromVehicle( 'str', false, "melee-dmg")
});
html.find('.attack-ranged').click((event) => {
this.actor.rollPoolFromVehicle( 'agi', false, "ranged-atk")
2022-09-05 08:57:02 +02:00
});
html.find('.damage-ranged').click((event) => {
2022-09-21 16:54:34 +02:00
this.actor.rollPoolFromVehicle( 'per', false, "ranged-dmg");
});
html.find('.defense-roll').click((event) => {
2022-09-25 15:13:59 +02:00
this.actor.rollPoolFromVehicle( 'agi', true, "defence");
2022-09-05 08:57:02 +02:00
});
html.find('.damage-resistance').click((event) => {
2022-09-21 16:54:34 +02:00
this.actor.rollVehicleDamageResistance( );
2022-09-05 08:57:02 +02:00
});
2022-09-26 20:57:55 +02:00
html.find('.currentlevel-change').change((event) => {
const statKey = $(event.currentTarget).data("stat-key");
if ( statKey == "man") {
this.actor.setTurningArc(event.currentTarget.value)
}
2022-09-28 13:54:06 +02:00
if ( statKey == "pc") {
this.actor.updateMaxNrg(event.currentTarget.value)
}
2022-09-26 20:57:55 +02:00
})
2022-09-05 08:57:02 +02:00
html.find('.roll-stat').click((event) => {
const statId = $(event.currentTarget).data("stat-key");
this.actor.rollStat(statId);
});
html.find('.roll-mr').click((event) => {
this.actor.rollMR();
});
html.find('.roll-idr').click((event) => {
const diceValue = $(event.currentTarget).data("dice-value")
const li = $(event.currentTarget).parents(".item")
this.rollIDR( li.data("item-id"), diceValue)
})
html.find('.weapon-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weaponId = li.data("item-id");
this.actor.rollWeapon(weaponId);
});
html.find('.armor-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const armorId = li.data("item-id");
this.actor.rollArmor(armorId);
});
html.find('.weapon-damage-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weaponId = li.data("item-id");
this.actor.rollWeapon(weaponId, true);
});
html.find('.weapon-damage').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weapon = this.actor.getOwnedItem(li.data("item-id"));
this.actor.rollDamage(weapon, 'damage');
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
});
html.find('.item-link a').click((event) => {
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
});
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equipItem( li.data("item-id") );
this.render(true);
});
html.find('.update-field').change(ev => {
const fieldName = $(ev.currentTarget).data("field-name");
let value = Number(ev.currentTarget.value);
this.actor.update( { [`${fieldName}`]: value } );
2022-09-21 16:54:34 +02:00
})
html.find('.member-view').click((event) => {
const li = $(event.currentTarget).parents(".item")
let actorId = li.data("actor-id")
const actor = game.actors.get( actorId )
actor.sheet.render(true)
})
2022-09-05 08:57:02 +02:00
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
const item = fromUuidSync(dragData.uuid)
if (item == undefined) {
item = this.actor.items.get( dragData.uuid )
}
2022-09-26 17:35:44 +02:00
let itemFull = await PegasusUtility.searchItem( item )
let ret = await this.actor.preprocessItemVehicle( event, itemFull, true )
2022-09-05 08:57:02 +02:00
if ( ret ) {
super._onDropItem(event, dragData)
}
}
2022-09-21 16:54:34 +02:00
/* -------------------------------------------- */
async _onDropActor(event, dragData) {
const actor = fromUuidSync(dragData.uuid)
if (actor) {
this.actor.addCrew(actor.id)
}else {
ui.notifications.warn("This actor is not found and can't be added to the Vehicle's crew.")
}
super._onDropActor(event)
}
2022-09-05 08:57:02 +02:00
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData)
}
}