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

384 lines
13 KiB
JavaScript
Raw Normal View History

2021-12-02 07:38:59 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
2022-08-14 15:27:54 +02:00
import { PegasusUtility } from "./pegasus-utility.js"
import { PegasusRollDialog } from "./pegasus-roll-dialog.js"
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
export class PegasusActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-pegasus-rpg", "sheet", "actor"],
template: "systems/fvtt-pegasus-rpg/templates/actor-sheet.html",
2022-07-10 10:22:04 +02:00
width: 960,
2021-12-02 07:38:59 +01:00
height: 720,
2022-03-06 22:18:08 +01:00
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "combat" }],
2021-12-02 07:38:59 +01:00
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
2022-03-09 18:12:40 +01:00
editScore: true
2021-12-02 07:38:59 +01:00
});
}
/* -------------------------------------------- */
async getData() {
2022-09-04 09:58:51 +02:00
const objectData = this.object
let actorData = duplicate(this.object)
2021-12-02 07:38:59 +01:00
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",
2022-09-04 09:58:51 +02:00
data: actorData.system,
2022-07-10 10:22:04 +02:00
traumaState: this.actor.getTraumaState(),
2021-12-02 07:38:59 +01:00
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
limited: this.object.limited,
specs: this.actor.getSpecs( ),
2021-12-02 20:18:21 +01:00
optionsDiceList: PegasusUtility.getOptionsDiceList(),
optionsLevel: PegasusUtility.getOptionsLevel(),
2022-03-09 18:12:40 +01:00
weapons: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getWeapons()) ),
armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())),
shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields()) ),
equipments: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquipmentsOnly()) ),
2022-09-27 20:31:01 +02:00
perks: this.actor.getPerks(),
2022-01-06 18:22:05 +01:00
abilities: duplicate(this.actor.getAbilities()),
2021-12-03 18:31:43 +01:00
activePerks: duplicate(this.actor.getActivePerks()),
2021-12-02 07:38:59 +01:00
powers: duplicate(this.actor.getPowers()),
subActors: duplicate(this.actor.getSubActors()),
2022-01-08 18:28:01 +01:00
race: duplicate(this.actor.getRace()),
role: duplicate(this.actor.getRole()),
2022-01-12 16:25:55 +01:00
effects: duplicate(this.actor.getEffects()),
2022-01-22 21:49:34 +01:00
moneys: duplicate(this.actor.getMoneys()),
2022-07-19 00:18:46 +02:00
virtues: duplicate(this.actor.getVirtues()),
vices: duplicate(this.actor.getVices()),
2022-03-06 20:07:41 +01:00
encCapacity: this.actor.getEncumbranceCapacity(),
2022-07-13 22:47:07 +02:00
levelRemainingList: this.actor.getLevelRemainingList(),
2022-07-26 22:58:33 +02:00
maxLevelRemainingList: this.actor.getMaxLevelRemainingList(),
2022-03-06 20:07:41 +01:00
containersTree: this.actor.containersTree,
encCurrent: this.actor.encCurrent,
encHindrance: this.actor.encHindrance,
2021-12-02 07:38:59 +01:00
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
isGM: game.user.isGM
}
this.formData = formData;
console.log("PC : ", formData, this.object);
return formData;
}
2022-02-10 15:53:42 +01:00
/* -------------------------------------------- */
async openGenericRoll() {
2022-08-14 15:27:54 +02:00
let rollData = PegasusUtility.initGenericRoll()
2022-07-13 22:47:07 +02:00
rollData.traumaState = this.actor.getTraumaState()
2022-02-10 15:53:42 +01:00
let rollDialog = await PegasusRollDialog.create( this.actor, rollData);
rollDialog.render( true );
}
2022-03-09 18:12:40 +01:00
/* -------------------------------------------- */
2022-03-11 14:00:14 +01:00
async rollIDR( itemId, diceValue) {
2022-09-04 09:58:51 +02:00
let item = this.actor.items.get( itemId) ?? {name: "Unknown"}
2022-03-09 18:12:40 +01:00
let myRoll = new Roll(diceValue+"x").roll({ async: false })
2022-03-11 14:00:14 +01:00
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)
2022-03-09 18:12:40 +01:00
}
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
2022-02-10 15:53:42 +01:00
html.bind("keydown", function(e) { // Ignore Enter in actores sheet
if (e.keyCode === 13) return false;
});
2021-12-02 07:38:59 +01:00
// Update Inventory Item
html.find('.item-edit').click(ev => {
2022-03-15 20:57:51 +01:00
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
2021-12-02 07:38:59 +01:00
const item = this.actor.items.get( itemId );
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
2022-03-15 20:57:51 +01:00
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-02-10 21:58:19 +01:00
html.find('.spec-group-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.specPowerActivate( itemId)
});
html.find('.spec-group-deactivate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.specPowerDeactivate( itemId)
});
2022-02-16 17:43:51 +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)
});
2022-02-10 19:03:09 +01:00
html.find('.effect-used').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.perkEffectUsed( itemId)
});
2022-02-13 21:58:19 +01:00
2022-02-10 19:03:09 +01:00
html.find('.perk-status').change(ev => {
2022-01-12 16:25:55 +01:00
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
2022-02-10 19:03:09 +01:00
this.actor.updatePerkStatus( itemId, ev.currentTarget.value)
2022-08-16 21:21:37 +02:00
this.render()
2022-01-12 16:25:55 +01:00
});
2022-02-25 14:53:19 +01:00
2022-02-13 21:58:19 +01:00
html.find('.power-cost-spent').change(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.updatePowerSpentCost( itemId, ev.currentTarget.value)
});
2022-02-25 14:53:19 +01:00
html.find('.power-dmg-roll').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.powerDmgRoll( itemId )
})
2022-02-13 21:58:19 +01:00
html.find('.perk-used').change(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
let index = Number($(ev.currentTarget).data("use-index") )
this.actor.updatePerkUsed( itemId, index, ev.currentTarget.checked )
});
2021-12-02 07:38:59 +01:00
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);
});
2022-01-25 10:37:28 +01:00
html.find('.quantity-minus').click(event => {
2021-12-02 07:38:59 +01:00
const li = $(event.currentTarget).parents(".item");
2022-01-25 10:37:28 +01:00
this.actor.incDecQuantity( li.data("item-id"), -1 );
2022-07-26 22:38:04 +02:00
} )
2022-01-25 10:37:28 +01:00
html.find('.quantity-plus').click(event => {
2021-12-02 07:38:59 +01:00
const li = $(event.currentTarget).parents(".item");
2022-01-25 10:37:28 +01:00
this.actor.incDecQuantity( li.data("item-id"), +1 );
2022-07-26 22:38:04 +02:00
} )
html.find('.current-nrg-minus').click(event => {
this.actor.incDecNRG( -1 );
} )
html.find('.current-nrg-plus').click(event => {
this.actor.incDecNRG( 1 );
} )
2022-03-09 18:12:40 +01:00
html.find('.ammo-minus').click(event => {
2022-03-11 14:00:14 +01:00
const li = $(event.currentTarget).parents(".item")
2022-03-09 18:12:40 +01:00
this.actor.incDecAmmo( li.data("item-id"), -1 );
} );
html.find('.ammo-plus').click(event => {
2022-03-11 14:00:14 +01:00
const li = $(event.currentTarget).parents(".item")
this.actor.incDecAmmo( li.data("item-id"), +1 )
2022-03-09 18:12:40 +01:00
} );
2022-07-10 10:22:04 +02:00
html.find('.stun-minus').click(event => {
this.actor.modifyStun( -1 )
} )
html.find('.stun-plus').click(event => {
this.actor.modifyStun( 1 )
} )
2022-03-06 20:07:41 +01:00
html.find('.momentum-minus').click(event => {
this.actor.modifyMomentum( -1 )
} )
html.find('.momentum-plus').click(event => {
this.actor.modifyMomentum( 1 )
} )
2022-01-11 23:35:23 +01:00
html.find('.unarmed-attack').click((event) => {
this.actor.rollUnarmedAttack();
});
2022-02-10 15:53:42 +01:00
html.find('.generic-pool-roll').click((event) => {
this.openGenericRoll()
} );
2022-01-11 23:35:23 +01:00
html.find('.attack-melee').click((event) => {
2022-07-10 10:22:04 +02:00
this.actor.rollPool( 'com', false, "melee-atk");
2022-01-11 23:35:23 +01:00
});
html.find('.attack-ranged').click((event) => {
2022-07-10 10:22:04 +02:00
this.actor.rollPool( 'agi', false, "ranged-atk");
2022-01-11 23:35:23 +01:00
});
html.find('.defense-roll').click((event) => {
2022-09-25 09:26:12 +02:00
this.actor.rollPool( 'def', true, "defence");
2022-01-11 23:35:23 +01:00
});
html.find('.damage-melee').click((event) => {
2022-07-10 10:22:04 +02:00
this.actor.rollPool( 'str', false, "melee-dmg");
2022-01-11 23:35:23 +01:00
});
html.find('.damage-ranged').click((event) => {
2022-07-10 10:22:04 +02:00
this.actor.rollPool( 'per', false, "ranged-dmg");
2022-01-11 23:35:23 +01:00
});
html.find('.damage-resistance').click((event) => {
2022-07-10 10:22:04 +02:00
this.actor.rollPool( 'phy', false, "dmg-res");
2022-01-11 23:35:23 +01:00
});
2021-12-02 20:18:21 +01:00
html.find('.roll-stat').click((event) => {
const statId = $(event.currentTarget).data("stat-key");
this.actor.rollStat(statId);
});
2022-01-11 23:35:23 +01:00
html.find('.roll-mr').click((event) => {
this.actor.rollMR();
});
2022-03-09 18:12:40 +01:00
html.find('.roll-idr').click((event) => {
const diceValue = $(event.currentTarget).data("dice-value")
2022-03-11 14:00:14 +01:00
const li = $(event.currentTarget).parents(".item")
this.rollIDR( li.data("item-id"), diceValue)
2022-03-09 18:12:40 +01:00
})
2022-01-11 23:35:23 +01:00
2021-12-02 20:18:21 +01:00
html.find('.roll-spec').click((event) => {
2021-12-02 07:38:59 +01:00
const li = $(event.currentTarget).parents(".item");
2021-12-02 20:18:21 +01:00
const specId = li.data("item-id");
this.actor.rollSpec(specId);
2021-12-02 07:38:59 +01:00
});
2022-01-14 18:20:15 +01:00
html.find('.power-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const powerId = li.data("item-id");
this.actor.rollPower(powerId);
});
2021-12-02 07:38:59 +01:00
html.find('.weapon-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weaponId = li.data("item-id");
this.actor.rollWeapon(weaponId);
});
2022-01-14 18:20:15 +01:00
html.find('.armor-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const armorId = li.data("item-id");
this.actor.rollArmor(armorId);
});
2022-01-14 14:49:16 +01:00
html.find('.weapon-damage-roll').click((event) => {
2021-12-02 07:38:59 +01:00
const li = $(event.currentTarget).parents(".item");
2022-01-14 14:49:16 +01:00
const weaponId = li.data("item-id");
this.actor.rollWeapon(weaponId, true);
2021-12-02 07:38:59 +01:00
});
2022-01-14 14:49:16 +01:00
2021-12-02 07:38:59 +01:00
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") );
2021-12-08 13:53:22 +01:00
this.render(true);
2021-12-03 18:31:43 +01:00
});
2022-01-16 16:12:15 +01:00
html.find('.power-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.activatePower( li.data("item-id") );
this.render(true);
});
2022-07-19 00:18:46 +02:00
html.find('.vice-virtue-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
this.actor.activateViceOrVirtue( li.data("item-id") )
this.render(true);
})
2022-02-10 21:58:19 +01:00
html.find('.change-worstfear').change(ev => {
this.actor.manageWorstFear( ev.currentTarget.checked )
});
html.find('.change-desires').change(ev => {
this.actor.manageDesires( ev.currentTarget.checked )
});
2022-01-13 21:05:55 +01:00
html.find('.update-field').change(ev => {
const fieldName = $(ev.currentTarget).data("field-name");
2022-01-18 13:36:27 +01:00
let value = Number(ev.currentTarget.value);
2022-01-13 21:05:55 +01:00
this.actor.update( { [`${fieldName}`]: value } );
});
2021-12-03 18:31:43 +01:00
html.find('.perk-active').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.activatePerk( li.data("item-id") );
2022-01-13 21:05:55 +01:00
this.render(true);
2021-12-02 07:38:59 +01:00
});
}
2022-01-13 21:05:55 +01:00
2021-12-02 07:38:59 +01: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;
}
2022-01-30 09:44:37 +01:00
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
2022-01-30 09:44:37 +01:00
async _onDropItem(event, dragData) {
2022-09-04 09:58:51 +02:00
const item = fromUuidSync(dragData.uuid)
2022-03-06 20:07:41 +01:00
if (item == undefined) {
2022-09-04 09:58:51 +02:00
item = this.actor.items.get( dragData.uuid )
2022-03-06 20:07:41 +01:00
}
2022-09-25 09:26:12 +02:00
console.log("Dropped", item)
let itemFull = await PegasusUtility.searchItem( item )
let ret = await this.actor.preprocessItem( event, itemFull, true )
2022-07-19 20:51:48 +02:00
if ( ret ) {
super._onDropItem(event, dragData)
}
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
2022-07-28 18:45:04 +02:00
return this.object.update(formData)
2021-12-02 07:38:59 +01:00
}
}