261 lines
10 KiB
JavaScript
261 lines
10 KiB
JavaScript
import { RdDUtility } from "../rdd-utility.js";
|
|
import { Misc } from "../misc.js";
|
|
import { DialogSplitItem } from "../dialog-split-item.js";
|
|
import { RdDSheetUtility } from "../rdd-sheet-utility.js";
|
|
import { Monnaie } from "../item-monnaie.js";
|
|
import { RdDItem } from "../item.js";
|
|
|
|
/* -------------------------------------------- */
|
|
/**
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
* @extends {ActorSheet}
|
|
*/
|
|
export class RdDBaseActorSheet extends ActorSheet {
|
|
|
|
/** @override */
|
|
static get defaultOptions() {
|
|
RdDUtility.initAfficheContenu();
|
|
return mergeObject(super.defaultOptions, {
|
|
classes: ["rdd", "sheet", "actor"],
|
|
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
|
|
width: 550,
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }],
|
|
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: undefined }],
|
|
showCompNiveauBase: false,
|
|
vueDetaillee: false
|
|
});
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async getData() {
|
|
Monnaie.validerMonnaies(this.actor.itemTypes['monnaie']);
|
|
|
|
this.actor.recompute();
|
|
const userRightLevel = game.user.isGM ? CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER : this.actor.getUserLevel(game.user)
|
|
const options = duplicate(this.options);
|
|
mergeObject(options, {
|
|
isGM: game.user.isGM,
|
|
editable: this.isEditable,
|
|
cssClass: this.isEditable ? "editable" : "locked",
|
|
isLimited: userRightLevel >= CONST.DOCUMENT_OWNERSHIP_LEVELS.LIMITED,
|
|
isObserver: userRightLevel >= CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER,
|
|
isOwner: userRightLevel >= CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER,
|
|
owner: this.actor.isOwner,
|
|
});
|
|
|
|
let formData = {
|
|
title: this.title,
|
|
id: this.actor.id,
|
|
type: this.actor.type,
|
|
img: this.actor.img,
|
|
name: this.actor.name,
|
|
system: foundry.utils.deepClone(this.actor.system),
|
|
description: await TextEditor.enrichHTML(this.actor.system.description, { async: true }),
|
|
notesmj: await TextEditor.enrichHTML(this.actor.system.notesmj, { async: true }),
|
|
options: options,
|
|
}
|
|
RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
|
|
formData.calc = {
|
|
fortune: this.toSolsDeniers(this.actor.getFortune()),
|
|
prixTotalEquipement: this.actor.computePrixTotalEquipement(),
|
|
encTotal: await this.actor.computeEncTotal(),
|
|
}
|
|
|
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
|
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
|
|
|
|
|
|
return formData;
|
|
}
|
|
|
|
toSolsDeniers(fortune) {
|
|
return {
|
|
sols: Math.floor(fortune),
|
|
deniers: Math.round(100 * (fortune - Math.floor(fortune)))
|
|
};
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
static filterItemsPerTypeForSheet(formData, itemTypes) {
|
|
formData.recettescuisine = Misc.arrayOrEmpty(itemTypes['recettecuisine']);
|
|
formData.recettesAlchimiques = Misc.arrayOrEmpty(itemTypes['recettealchimique']);
|
|
formData.maladies = Misc.arrayOrEmpty(itemTypes['maladie']);
|
|
formData.poisons = Misc.arrayOrEmpty(itemTypes['poison']);
|
|
formData.possessions = Misc.arrayOrEmpty(itemTypes['possession']);
|
|
formData.maladiesPoisons = formData.maladies.concat(formData.poisons);
|
|
formData.competences = (itemTypes['competence'] ?? []).concat(itemTypes['competencecreature'] ?? []);
|
|
formData.sortsReserve = Misc.arrayOrEmpty(itemTypes['sortreserve']);
|
|
|
|
formData.sorts = Misc.arrayOrEmpty(itemTypes['sort']);
|
|
formData.rencontres = Misc.arrayOrEmpty(itemTypes['rencontre']);
|
|
formData.casestmr = Misc.arrayOrEmpty(itemTypes['casetmr']);
|
|
formData.signesdraconiques = Misc.arrayOrEmpty(itemTypes['signedraconique']);
|
|
formData.queues = Misc.arrayOrEmpty(itemTypes['queue']);
|
|
formData.souffles = Misc.arrayOrEmpty(itemTypes['souffle']);
|
|
formData.ombres = Misc.arrayOrEmpty(itemTypes['ombre']);
|
|
formData.tetes = Misc.arrayOrEmpty(itemTypes['tete']);
|
|
formData.taches = Misc.arrayOrEmpty(itemTypes['tache']);
|
|
formData.meditations = Misc.arrayOrEmpty(itemTypes['meditation']);
|
|
formData.chants = Misc.arrayOrEmpty(itemTypes['chant']);
|
|
formData.danses = Misc.arrayOrEmpty(itemTypes['danse']);
|
|
formData.musiques = Misc.arrayOrEmpty(itemTypes['musique']);
|
|
formData.oeuvres = Misc.arrayOrEmpty(itemTypes['oeuvre']);
|
|
formData.jeux = Misc.arrayOrEmpty(itemTypes['jeu']);
|
|
|
|
formData.services = Misc.arrayOrEmpty(itemTypes['service']);
|
|
formData.conteneurs = Misc.arrayOrEmpty(itemTypes['conteneur']);
|
|
formData.materiel = Misc.arrayOrEmpty(itemTypes['objet']);
|
|
formData.armes = Misc.arrayOrEmpty(itemTypes['arme']);
|
|
formData.armures = Misc.arrayOrEmpty(itemTypes['armure']);
|
|
formData.munitions = Misc.arrayOrEmpty(itemTypes['munition']);
|
|
formData.livres = Misc.arrayOrEmpty(itemTypes['livre']);
|
|
formData.potions = Misc.arrayOrEmpty(itemTypes['potion']);
|
|
formData.ingredients = Misc.arrayOrEmpty(itemTypes['ingredient']);
|
|
formData.faunes = Misc.arrayOrEmpty(itemTypes['faune']);
|
|
formData.herbes = Misc.arrayOrEmpty(itemTypes['herbe']);
|
|
formData.nourritureboissons = Misc.arrayOrEmpty(itemTypes['nourritureboisson']);
|
|
formData.gemmes = Misc.arrayOrEmpty(itemTypes['gemme']);
|
|
formData.monnaie = Misc.arrayOrEmpty(itemTypes['monnaie']).sort(Monnaie.triValeurEntiere());
|
|
|
|
formData.objets = RdDItem.getItemTypesInventaire('all')
|
|
.map(t => Misc.arrayOrEmpty(itemTypes[t]))
|
|
.reduce((a, b) => a.concat(b), [])
|
|
.sort(Misc.ascending(it => it.name));
|
|
}
|
|
|
|
/* -------------------------------------------- */ /** @override */
|
|
activateListeners(html) {
|
|
super.activateListeners(html);
|
|
this.html = html;
|
|
|
|
this.html.find('.conteneur-name a').click(async event => {
|
|
RdDUtility.toggleAfficheContenu(this.getItemId(event));
|
|
this.render(true);
|
|
});
|
|
this.html.find('.item-edit').click(async event => this.getItem(event)?.sheet.render(true))
|
|
this.html.find('.item-montrer').click(async event => this.getItem(event)?.postItemToChat());
|
|
this.html.find('.actor-montrer').click(async event => this.actor.postActorToChat());
|
|
|
|
// Everything below here is only needed if the sheet is editable
|
|
if (!this.options.editable) return;
|
|
|
|
this.html.find('.item-split').click(async event => {
|
|
const item = this.getItem(event);
|
|
RdDSheetUtility.splitItem(item, this.actor);
|
|
});
|
|
this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, this.getItem(event)));
|
|
this.html.find('.item-vendre').click(async event => this.vendre(this.getItem(event)));
|
|
|
|
this.html.find('.creer-un-objet').click(async event => {
|
|
this.selectObjetTypeToCreate();
|
|
});
|
|
this.html.find('.nettoyer-conteneurs').click(async event => {
|
|
this.actor.nettoyerConteneurs();
|
|
});
|
|
this.html.find('.monnaie-plus').click(async event => {
|
|
this.actor.monnaieIncDec(this.getItemId(event), 1);
|
|
});
|
|
this.html.find('.monnaie-moins').click(async event => {
|
|
this.actor.monnaieIncDec(this.getItemId(event), -1);
|
|
});
|
|
}
|
|
|
|
getItemId(event) {
|
|
return RdDSheetUtility.getItemId(event);
|
|
}
|
|
|
|
getItem(event) {
|
|
return RdDSheetUtility.getItem(event, this.actor);
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
_getHeaderButtons() {
|
|
let buttons = super._getHeaderButtons();
|
|
buttons.unshift({
|
|
class: "montrer",
|
|
icon: "fas fa-comment",
|
|
onclick: ev => this.actor.postActorToChat()
|
|
});
|
|
return buttons
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async _onDropItem(event, dragData) {
|
|
const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id')
|
|
const dropParams = await RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur)
|
|
if (dropParams) {
|
|
const callSuper = await this.actor.processDropItem(dropParams)
|
|
if (callSuper) {
|
|
await super._onDropItem(event, dragData)
|
|
}
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
async selectObjetTypeToCreate() {
|
|
let typeObjets = this.getTypesInventaire().sort(Misc.ascending(type => Misc.typeName('Item', type)));
|
|
let content = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
|
|
for (let typeName of typeObjets) {
|
|
content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
|
|
}
|
|
content += '</select>';
|
|
let d = new Dialog({
|
|
title: "Créer un équipement",
|
|
content: content,
|
|
buttons: {
|
|
create: {
|
|
icon: '<i class="fas fa-check"></i>',
|
|
label: "Créer l'objet",
|
|
callback: () => this.actor.createItem($(".item-type").val())
|
|
}
|
|
}
|
|
});
|
|
d.render(true);
|
|
}
|
|
|
|
getTypesInventaire() {
|
|
return RdDItem.getItemTypesInventaire();
|
|
}
|
|
|
|
/** @override */
|
|
setPosition(options = {}) {
|
|
const position = super.setPosition(options);
|
|
const sheetHeader = this.element.find(".sheet-header");
|
|
const sheetTabs = this.element.find(".sheet-tabs");
|
|
const sheetBody = this.element.find(".sheet-body");
|
|
let bodyHeight = position.height - sheetHeader[0].clientHeight;
|
|
if (sheetTabs.length > 0) {
|
|
bodyHeight -= sheetTabs[0].clientHeight;
|
|
}
|
|
sheetBody.css("height", bodyHeight);
|
|
return position;
|
|
}
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
/** @override */
|
|
_updateObject(event, formData) {
|
|
// Update the Actor
|
|
return this.actor.update(formData);
|
|
}
|
|
|
|
async splitItem(item) {
|
|
const dialog = await DialogSplitItem.create(item, (item, split) => this._onSplitItem(item, split));
|
|
dialog.render(true);
|
|
}
|
|
|
|
async _onSplitItem(item, split) {
|
|
if (split >= 1 && split < item.system.quantite) {
|
|
await item.diminuerQuantite(split);
|
|
const splitItem = duplicate(item);
|
|
splitItem.system.quantite = split;
|
|
await this.actor.createEmbeddedDocuments('Item', [splitItem])
|
|
}
|
|
}
|
|
|
|
vendre(item) {
|
|
item?.proposerVente(this.actor.getQuantiteDisponible(item));
|
|
}
|
|
|
|
}
|