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 = 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, }); 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), options: options, } this.filterItemsPerTypeForSheet(formData, this.actor.itemTypes); formData.calc = { fortune: this.toSolsDeniers(this.actor.getFortune()), prixTotalEquipement: this.actor.computePrixTotalEquipement(), encTotal: await this.actor.computeEncombrementTotalEtMalusArmure(), } 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))) }; } /* -------------------------------------------- */ filterItemsPerTypeForSheet(formData, itemTypes) { formData.services = Misc.arrayOrEmpty(itemTypes['service']); 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.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 = formData.conteneurs .concat(formData.materiel) .concat(formData.armes) .concat(formData.armures) .concat(formData.munitions) .concat(formData.livres) .concat(formData.potions) .concat(formData.ingredients) .concat(formData.herbes) .concat(formData.faunes) .concat(formData.monnaie) .concat(formData.nourritureboissons) .concat(formData.gemmes); } /* -------------------------------------------- */ /** @override */ activateListeners(html) { super.activateListeners(html); this.html = html; this.html.find('.conteneur-name a').click(async event => { RdDUtility.toggleAfficheContenu(RdDSheetUtility.getItemId(event)); this.render(true); }); this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true)) this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem()); // 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 = RdDSheetUtility.getItem(event, this.actor); RdDSheetUtility.splitItem(item, this.actor); }); this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, RdDSheetUtility.getItem(event, this.actor))); this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente()); 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(RdDSheetUtility.getItemId(event), 1); }); this.html.find('.monnaie-moins').click(async event => { this.actor.monnaieIncDec(RdDSheetUtility.getItemId(event), -1); }); } /* -------------------------------------------- */ async _onDropItem(event, dragData) { const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id') const dropParams = 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 = RdDItem.getItemTypesInventaire(); let content = `Selectionnez le type d'équipement'; let d = new Dialog({ title: "Créer un équipement", content: content, buttons: { create: { icon: '', label: "Créer l'objet", callback: () => this.actor.createItem($(".item-type").val()) } } }); d.render(true); } /** @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]) } } }