fvtt-hawkmoon-cyd/modules/hawkmoon-actor-sheet.js

217 lines
7.8 KiB
JavaScript
Raw Permalink Normal View History

2022-10-22 11:09:48 +02:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { HawkmoonUtility } from "./hawkmoon-utility.js";
2022-10-28 21:44:49 +02:00
import { HawkmoonAutomation } from "./hawkmoon-automation.js";
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
export class HawkmoonActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
2024-05-02 09:27:16 +02:00
return foundry.utils.mergeObject(super.defaultOptions, {
2022-10-23 09:55:02 +02:00
classes: ["fvtt-hawkmoon-cyd", "sheet", "actor"],
2022-10-22 11:09:48 +02:00
template: "systems/fvtt-hawkmoon-cyd/templates/actor-sheet.html",
width: 640,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: false
2022-11-13 23:01:41 +01:00
})
2022-10-22 11:09:48 +02:00
}
/* -------------------------------------------- */
async getData() {
2024-05-02 09:27:16 +02:00
const objectData = foundry.utils.duplicate(this.object)
2022-10-22 11:09:48 +02: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",
system: objectData.system,
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
limited: this.object.limited,
skills: this.actor.getSkills(),
2024-05-02 09:27:16 +02:00
armes: foundry.utils.duplicate(this.actor.getWeapons()),
monnaies: foundry.utils.duplicate(this.actor.getMonnaies()),
protections: foundry.utils.duplicate(this.actor.getArmors()),
historiques: foundry.utils.duplicate(this.actor.getHistoriques() || []),
talents: foundry.utils.duplicate(this.actor.getTalents() || []),
mutations: foundry.utils.duplicate(this.actor.getMutations() || []),
2022-11-10 23:43:51 +01:00
talentsCell: this.getCelluleTalents(),
2024-05-02 09:27:16 +02:00
profils: foundry.utils.duplicate(this.actor.getProfils() || []),
2022-10-22 11:09:48 +02:00
combat: this.actor.getCombatValues(),
2024-05-02 09:27:16 +02:00
equipements: foundry.utils.duplicate(this.actor.getEquipments()),
artefacts: foundry.utils.duplicate(this.actor.getArtefacts()),
2022-12-03 23:57:30 +01:00
richesse: this.actor.computeRichesse(),
2023-12-28 18:40:46 +01:00
coupDevastateur: this.actor.items.find(it => it.type =="talent" && it.name.toLowerCase() == "coup devastateur" && !it.system.used),
2022-12-03 23:57:30 +01:00
valeurEquipement: this.actor.computeValeurEquipement(),
2023-12-28 18:40:46 +01:00
nbCombativite: this.actor.system.sante.nbcombativite,
combativiteList: HawkmoonUtility.getCombativiteList(this.actor.system.sante.nbcombativite),
2022-12-03 23:13:08 +01:00
initiative: this.actor.getFlag("world", "last-initiative") || -1,
2022-10-22 11:09:48 +02:00
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
2022-11-13 23:01:41 +01:00
habitat: await TextEditor.enrichHTML(this.object.system.biodata.habitat, {async: true}),
2022-10-22 11:09:48 +02:00
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
2024-05-02 09:27:16 +02:00
isGM: game.user.isGM,
config: game.system.hawkmoon.config
2022-10-22 11:09:48 +02:00
}
this.formData = formData;
console.log("PC : ", formData, this.object);
return formData;
}
2022-11-10 23:43:51 +01:00
/* -------------------------------------------- */
getCelluleTalents( ) {
let talents = []
for(let cellule of game.actors) {
if (cellule.type == "cellule") {
let found = cellule.system.members.find( it => it.id == this.actor.id)
if (found) {
talents = talents.concat( cellule.getTalents() )
}
}
}
return talents
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// 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");
HawkmoonUtility.confirmDelete(this, li);
})
html.find('.edit-item-data').change(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
let itemType = li.data("item-type")
let itemField = $(ev.currentTarget).data("item-field")
let dataType = $(ev.currentTarget).data("dtype")
let value = ev.currentTarget.value
this.actor.editItemField(itemId, itemType, itemField, dataType, value)
})
2022-11-10 11:04:05 +01:00
html.find('.adversite-modify').click(event => {
const li = $(event.currentTarget).parents(".item")
let adv = li.data("adversite")
let value = Number($(event.currentTarget).data("adversite-value"))
this.actor.incDecAdversite(adv, value)
})
2022-12-03 23:57:30 +01:00
html.find('.quantity-modify').click(event => {
const li = $(event.currentTarget).parents(".item")
const value = Number($(event.currentTarget).data("quantite-value"))
this.actor.incDecQuantity( li.data("item-id"), value );
})
2022-10-22 11:09:48 +02:00
2022-11-10 23:43:51 +01:00
html.find('.roll-initiative').click((event) => {
this.actor.rollAttribut("adr", true)
2022-11-10 23:43:51 +01:00
})
2022-10-22 11:09:48 +02:00
html.find('.roll-attribut').click((event) => {
const li = $(event.currentTarget).parents(".item")
let attrKey = li.data("attr-key")
2022-11-13 23:01:41 +01:00
this.actor.rollAttribut(attrKey, false)
2022-10-22 11:09:48 +02:00
})
html.find('.roll-competence').click((event) => {
const li = $(event.currentTarget).parents(".item")
let attrKey = $(event.currentTarget).data("attr-key")
let compId = li.data("item-id")
this.actor.rollCompetence(attrKey, compId)
})
html.find('.roll-arme-offensif').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollArmeOffensif(armeId)
})
html.find('.roll-assomer').click((event) => {
this.actor.rollAssomer()
})
html.find('.roll-coup-bas').click((event) => {
this.actor.rollCoupBas()
})
html.find('.roll-immobiliser').click((event) => {
this.actor.rollImmobiliser()
})
html.find('.roll-repousser').click((event) => {
this.actor.rollRepousser()
})
html.find('.roll-desengager').click((event) => {
this.actor.rollDesengager()
})
2022-10-22 11:09:48 +02:00
html.find('.roll-arme-degats').click((event) => {
const li = $(event.currentTarget).parents(".item")
let armeId = li.data("item-id")
this.actor.rollArmeDegats(armeId)
})
2022-12-19 10:15:46 +01:00
html.find('.item-add').click((event) => {
const itemType = $(event.currentTarget).data("type")
this.actor.createEmbeddedDocuments('Item', [{ name: `Nouveau ${itemType}`, type: itemType }], { renderSheet: true })
})
2022-10-22 11:09:48 +02:00
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
});
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equipItem( li.data("item-id") );
this.render(true);
});
}
/* -------------------------------------------- */
/** @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-10-28 21:44:49 +02:00
async _onDropItem(event, dragData) {
let data = event.dataTransfer.getData('text/plain')
let dataItem = JSON.parse( data)
let item = fromUuidSync(dataItem.uuid)
if (item.pack) {
item = await HawkmoonUtility.searchItem(item)
}
let autoresult = HawkmoonAutomation.processAutomations("on-drop", item, this.actor)
if ( autoresult.isValid ) {
super._onDropItem(event, dragData)
2022-11-09 23:39:55 +01:00
} else {
ui.notifications.warn( autoresult.warningMessage)
2022-10-28 21:44:49 +02:00
}
}
2022-10-22 11:09:48 +02:00
}