2023-01-04 21:24:56 +01:00
|
|
|
/**
|
|
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
|
|
* @extends {ActorSheet}
|
|
|
|
*/
|
|
|
|
|
2023-01-04 22:09:09 +01:00
|
|
|
import { WarheroUtility } from "./warhero-utility.js";
|
2023-01-04 21:24:56 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2023-01-04 22:09:09 +01:00
|
|
|
export class WarheroActorSheet extends ActorSheet {
|
2023-01-04 21:24:56 +01:00
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static get defaultOptions() {
|
2023-02-08 21:19:53 +01:00
|
|
|
|
2023-01-04 21:24:56 +01:00
|
|
|
return mergeObject(super.defaultOptions, {
|
2023-01-04 22:09:09 +01:00
|
|
|
classes: ["fvtt-warhero", "sheet", "actor"],
|
|
|
|
template: "systems/fvtt-warhero/templates/actor-sheet.html",
|
2023-01-29 16:56:09 +01:00
|
|
|
width: 720,
|
2023-01-04 21:24:56 +01:00
|
|
|
height: 720,
|
|
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "skills" }],
|
|
|
|
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
|
|
|
editScore: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async getData() {
|
2023-02-06 07:37:39 +01:00
|
|
|
|
|
|
|
this.actor.setLevel()
|
|
|
|
this.actor.computeDRTotal()
|
|
|
|
this.actor.computeParryBonusTotal()
|
|
|
|
this.actor.computeBonusLanguages()
|
2023-01-29 16:56:09 +01:00
|
|
|
const objectData = duplicate(this.object.system)
|
2023-02-06 07:37:39 +01:00
|
|
|
let race = this.actor.getRace()
|
2023-01-04 21:24:56 +01:00
|
|
|
|
|
|
|
let formData = {
|
|
|
|
title: this.title,
|
|
|
|
id: this.actor.id,
|
|
|
|
type: this.actor.type,
|
|
|
|
img: this.actor.img,
|
|
|
|
name: this.actor.name,
|
|
|
|
editable: this.isEditable,
|
|
|
|
cssClass: this.isEditable ? "editable" : "locked",
|
2023-01-29 16:56:09 +01:00
|
|
|
system: objectData,
|
2023-01-04 21:24:56 +01:00
|
|
|
limited: this.object.limited,
|
2023-02-27 22:04:03 +01:00
|
|
|
compentencyItems:this.actor.getCompetencyItems( ),
|
2023-02-06 07:37:39 +01:00
|
|
|
skills: this.actor.getNormalSkills( ),
|
2023-02-27 22:04:03 +01:00
|
|
|
raceSkills: this.actor.getRaceSkills( ),
|
2023-02-06 07:37:39 +01:00
|
|
|
classSkills: this.actor.getClassSkills( ),
|
|
|
|
languages: this.actor.getLanguages( ),
|
2023-01-04 21:24:56 +01:00
|
|
|
weapons: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getWeapons()) ),
|
2023-02-07 15:18:00 +01:00
|
|
|
conditions: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getConditions()) ),
|
2023-01-04 21:24:56 +01:00
|
|
|
armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())),
|
|
|
|
shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields())),
|
2023-02-08 21:19:53 +01:00
|
|
|
powers: this.actor.sortPowers(),
|
2023-01-04 21:24:56 +01:00
|
|
|
equipments: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquipmentsOnly()) ),
|
2023-01-29 16:56:09 +01:00
|
|
|
slotEquipments: this.actor.buildEquipmentsSlot(),
|
2023-01-04 21:24:56 +01:00
|
|
|
subActors: duplicate(this.actor.getSubActors()),
|
2023-02-07 15:18:00 +01:00
|
|
|
competency: this.actor.getCompetency(),
|
2023-02-06 07:37:39 +01:00
|
|
|
race: duplicate(race),
|
2023-01-29 16:56:09 +01:00
|
|
|
class: duplicate(this.actor.getClass()),
|
2023-02-21 17:53:00 +01:00
|
|
|
totalMoney: this.actor.computeTotalMoney(),
|
2023-02-10 20:31:18 +01:00
|
|
|
//moneys: duplicate(this.actor.getMoneys()),
|
2023-01-04 21:24:56 +01:00
|
|
|
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
|
|
|
|
notes: await TextEditor.enrichHTML(this.object.system.biodata.notes, {async: true}),
|
|
|
|
options: this.options,
|
|
|
|
owner: this.document.isOwner,
|
|
|
|
editScore: this.options.editScore,
|
|
|
|
isGM: game.user.isGM
|
|
|
|
}
|
2023-02-27 22:04:03 +01:00
|
|
|
// Dynamic patch
|
|
|
|
formData.system.secondary.counterspell.hasmax = false
|
|
|
|
// Race mngt
|
2023-02-06 07:37:39 +01:00
|
|
|
if ( race && race.name) {
|
|
|
|
formData.hpprogression = game.system.warhero.config.progressionList[race.system.hpprogresion]
|
|
|
|
}
|
|
|
|
this.formData = formData
|
2023-01-04 21:24:56 +01:00
|
|
|
console.log("PC : ", formData, this.object);
|
|
|
|
return formData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @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")
|
2023-01-04 22:09:09 +01:00
|
|
|
WarheroUtility.confirmDelete(this, li)
|
2023-01-04 21:24:56 +01:00
|
|
|
})
|
|
|
|
html.find('.item-add').click(ev => {
|
|
|
|
let dataType = $(ev.currentTarget).data("type")
|
2023-02-18 23:19:10 +01:00
|
|
|
let slotKey = $(ev.currentTarget).data("slot")
|
|
|
|
this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType, system: { slotlocation: slotKey} }], { renderSheet: true })
|
2023-01-04 21:24:56 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
html.find('.equip-activate').click(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item")
|
|
|
|
let itemId = li.data("item-id")
|
|
|
|
this.actor.equipActivate( itemId)
|
|
|
|
});
|
|
|
|
html.find('.equip-deactivate').click(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item")
|
|
|
|
let itemId = li.data("item-id")
|
|
|
|
this.actor.equipDeactivate( itemId)
|
|
|
|
});
|
|
|
|
|
|
|
|
html.find('.subactor-edit').click(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
|
|
let actorId = li.data("actor-id");
|
|
|
|
let actor = game.actors.get( actorId );
|
|
|
|
actor.sheet.render(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
html.find('.subactor-delete').click(ev => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
|
|
let actorId = li.data("actor-id");
|
|
|
|
this.actor.delSubActor(actorId);
|
|
|
|
});
|
|
|
|
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 );
|
|
|
|
} );
|
2023-02-20 10:16:17 +01:00
|
|
|
html.find('.skill-use-minus').click(event => {
|
|
|
|
const li = $(event.currentTarget).parents(".item");
|
|
|
|
this.actor.incDecSkillUse( li.data("item-id"), -1 );
|
|
|
|
} );
|
|
|
|
html.find('.skill-use-plus').click(event => {
|
|
|
|
const li = $(event.currentTarget).parents(".item");
|
|
|
|
this.actor.incDecSkillUse( li.data("item-id"), +1 );
|
|
|
|
} );
|
|
|
|
|
2023-01-04 21:24:56 +01:00
|
|
|
|
|
|
|
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 )
|
|
|
|
} );
|
|
|
|
|
2023-01-29 16:56:09 +01:00
|
|
|
html.find('.roll-this').click((event) => {
|
|
|
|
const rollType = $(event.currentTarget).data("type")
|
|
|
|
const statKey = $(event.currentTarget).data("key")
|
|
|
|
this.actor.rollFromType(rollType, statKey)
|
2023-01-04 21:24:56 +01:00
|
|
|
});
|
2023-02-06 07:37:39 +01:00
|
|
|
html.find('.roll-save').click((event) => {
|
|
|
|
const rollType = $(event.currentTarget).data("type")
|
|
|
|
const statKey = $(event.currentTarget).data("key")
|
|
|
|
this.actor.rollSaveFromType(rollType, statKey)
|
|
|
|
});
|
2023-01-04 21:24:56 +01:00
|
|
|
html.find('.roll-weapon').click((event) => {
|
2023-01-29 18:32:30 +01:00
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
const weaponId = li.data("item-id")
|
|
|
|
this.actor.rollWeapon(weaponId)
|
2023-01-04 21:24:56 +01:00
|
|
|
});
|
2023-01-29 18:32:30 +01:00
|
|
|
html.find('.power-roll').click((event) => {
|
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
const powerId = li.data("item-id")
|
|
|
|
this.actor.rollPower(powerId)
|
|
|
|
});
|
|
|
|
html.find('.roll-damage').click((event) => {
|
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
const weaponId = li.data("item-id")
|
|
|
|
this.actor.rollDamage(weaponId)
|
|
|
|
});
|
2023-02-08 21:19:53 +01:00
|
|
|
html.find('.roll-damage-2hands').click((event) => {
|
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
const weaponId = li.data("item-id")
|
|
|
|
this.actor.rollDamage(weaponId, true)
|
|
|
|
});
|
2023-01-04 21:24:56 +01:00
|
|
|
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 } );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @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) {
|
|
|
|
console.log(">>>>>> DROPPED!!!!")
|
|
|
|
const item = fromUuidSync(dragData.uuid)
|
|
|
|
if (item == undefined) {
|
|
|
|
item = this.actor.items.get( item.id )
|
|
|
|
}
|
|
|
|
let ret = await this.actor.preprocessItem( event, item, true )
|
|
|
|
if ( ret ) {
|
|
|
|
super._onDropItem(event, dragData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
_updateObject(event, formData) {
|
|
|
|
// Update the Actor
|
|
|
|
return this.object.update(formData);
|
|
|
|
}
|
|
|
|
}
|