2020-12-04 20:52:04 +01:00
|
|
|
import { RdDItemSort } from "./item-sort.js";
|
2020-12-15 21:28:55 +01:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
2021-01-07 20:04:10 +01:00
|
|
|
import { RdDAlchimie } from "./rdd-alchimie.js";
|
2021-01-08 22:23:50 +01:00
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
2021-04-04 18:37:16 +02:00
|
|
|
import { RdDHerbes } from "./rdd-herbes.js";
|
2021-10-29 09:53:35 +02:00
|
|
|
import { RdDGemme } from "./rdd-gemme.js";
|
2021-03-22 20:10:37 +01:00
|
|
|
import { Misc } from "./misc.js";
|
2021-05-06 19:42:29 +02:00
|
|
|
import { HtmlUtility } from "./html-utility.js";
|
|
|
|
import { ReglesOptionelles } from "./regles-optionelles.js";
|
2021-11-11 02:43:38 +01:00
|
|
|
import { SYSTEM_RDD } from "./constants.js";
|
2021-12-05 01:50:09 +01:00
|
|
|
import { RdDSheetUtility } from "./rdd-sheet-utility.js";
|
2020-12-04 20:52:04 +01:00
|
|
|
|
2020-05-21 21:48:20 +02:00
|
|
|
/**
|
|
|
|
* Extend the basic ItemSheet with some very simple modifications
|
|
|
|
* @extends {ItemSheet}
|
|
|
|
*/
|
2020-05-22 00:48:43 +02:00
|
|
|
export class RdDItemSheet extends ItemSheet {
|
2020-05-21 21:48:20 +02:00
|
|
|
|
|
|
|
/** @override */
|
2021-05-07 17:27:02 +02:00
|
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
2021-11-11 02:43:38 +01:00
|
|
|
classes: [SYSTEM_RDD, "sheet", "item"],
|
2021-05-07 17:27:02 +02:00
|
|
|
template: "systems/foundryvtt-reve-de-dragon/templates/item-sheet.html",
|
|
|
|
width: 550,
|
|
|
|
height: 550
|
|
|
|
});
|
2020-05-21 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2021-12-05 16:48:18 +01:00
|
|
|
|
2020-05-21 21:48:20 +02:00
|
|
|
/* -------------------------------------------- */
|
2021-01-01 21:11:56 +01:00
|
|
|
_getHeaderButtons() {
|
|
|
|
let buttons = super._getHeaderButtons();
|
|
|
|
// Add "Post to chat" button
|
|
|
|
// We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry!
|
2022-09-07 18:47:56 +02:00
|
|
|
if ("cout" in this.item.system && this.item.isVideOuNonConteneur()) {
|
2021-05-07 17:27:02 +02:00
|
|
|
buttons.unshift({
|
2021-12-10 01:21:01 +01:00
|
|
|
class: "vendre",
|
2021-05-07 17:27:02 +02:00
|
|
|
icon: "fas fa-comments-dollar",
|
|
|
|
onclick: ev => this.item.proposerVente()
|
|
|
|
});
|
|
|
|
}
|
2021-12-10 01:21:01 +01:00
|
|
|
buttons.unshift({
|
|
|
|
class: "montrer",
|
|
|
|
icon: "fas fa-comment",
|
|
|
|
onclick: ev => this.item.postItem()
|
|
|
|
});
|
2021-01-01 21:11:56 +01:00
|
|
|
return buttons
|
|
|
|
}
|
2020-05-21 21:48:20 +02:00
|
|
|
|
2021-01-01 21:11:56 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-05-21 21:48:20 +02:00
|
|
|
/** @override */
|
2021-05-07 17:27:02 +02:00
|
|
|
setPosition(options = {}) {
|
2020-05-21 21:48:20 +02:00
|
|
|
const position = super.setPosition(options);
|
2021-05-10 19:14:05 +02:00
|
|
|
const sheetHeader = this.element.find(".sheet-header");
|
2020-05-21 21:48:20 +02:00
|
|
|
const sheetBody = this.element.find(".sheet-body");
|
2021-05-10 19:14:05 +02:00
|
|
|
const bodyHeight = position.height - sheetHeader[0].clientHeight;
|
2020-05-21 21:48:20 +02:00
|
|
|
sheetBody.css("height", bodyHeight);
|
|
|
|
return position;
|
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-15 21:28:55 +01:00
|
|
|
async getData() {
|
2021-05-07 17:27:02 +02:00
|
|
|
let formData = {
|
2022-09-07 18:47:56 +02:00
|
|
|
id: this.item.id,
|
|
|
|
title: this.item.name,
|
|
|
|
type: this.item.type,
|
|
|
|
img: this.item.img,
|
|
|
|
name: this.item.name,
|
|
|
|
system: this.item.system,
|
|
|
|
// TODO: v10 remove
|
|
|
|
data: this.item.system,
|
2021-03-29 18:08:18 +02:00
|
|
|
isGM: game.user.isGM,
|
2021-12-05 01:50:09 +01:00
|
|
|
actorId: this.actor?.id,
|
2022-09-07 18:47:56 +02:00
|
|
|
owner: this.item.isOwner,
|
2021-03-29 18:08:18 +02:00
|
|
|
editable: this.isEditable,
|
|
|
|
cssClass: this.isEditable ? "editable" : "locked",
|
2021-05-06 21:36:40 +02:00
|
|
|
isSoins: false
|
2021-03-25 09:28:36 +01:00
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
if (this.actor) {
|
2021-04-10 21:07:53 +02:00
|
|
|
formData.isOwned = true;
|
2022-09-07 18:47:56 +02:00
|
|
|
if (this.item.type == 'conteneur') {
|
2021-12-05 01:50:09 +01:00
|
|
|
this.prepareConteneurData(formData);
|
|
|
|
}
|
2021-04-10 21:07:53 +02:00
|
|
|
}
|
|
|
|
|
2022-04-30 23:42:55 +02:00
|
|
|
formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences()
|
2021-05-07 17:27:02 +02:00
|
|
|
if (formData.type == 'tache' || formData.type == 'livre' || formData.type == 'meditation' || formData.type == 'oeuvre') {
|
2022-04-30 23:42:55 +02:00
|
|
|
formData.caracList = duplicate(game.system.model.Actor.personnage.carac)
|
2022-06-12 08:17:59 +02:00
|
|
|
formData.caracList["reve-actuel"] = duplicate(game.system.model.Actor.personnage.reve.reve)
|
|
|
|
formData.competences = await RdDUtility.loadCompendium('foundryvtt-reve-de-dragon.competences')
|
2021-01-08 22:23:50 +01:00
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
if (formData.type == 'arme') {
|
|
|
|
formData.competences = await RdDUtility.loadCompendium('foundryvtt-reve-de-dragon.competences', it => RdDItemCompetence.isCompetenceArme(it));
|
2022-04-30 23:42:55 +02:00
|
|
|
console.log(formData.competences)
|
2020-12-15 21:28:55 +01:00
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
if (formData.type == 'recettealchimique') {
|
2022-09-07 18:47:56 +02:00
|
|
|
RdDAlchimie.processManipulation(this.item, this.actor && this.actor.id);
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|
2021-10-29 09:53:35 +02:00
|
|
|
if (formData.type == 'gemme') {
|
|
|
|
formData.gemmeTypeList = RdDGemme.getGemmeTypeOptionList();
|
2022-09-07 18:47:56 +02:00
|
|
|
RdDGemme.calculDataDerivees(this.item);
|
2021-10-29 09:53:35 +02:00
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
if (formData.type == 'potion') {
|
2021-04-04 18:37:16 +02:00
|
|
|
if (this.dateUpdated) {
|
2022-09-07 18:47:56 +02:00
|
|
|
formData.system.prdate = this.dateUpdated;
|
2021-04-04 18:37:16 +02:00
|
|
|
this.dateUpdated = undefined;
|
|
|
|
}
|
|
|
|
RdDHerbes.updatePotionData(formData);
|
2021-05-07 17:27:02 +02:00
|
|
|
}
|
2022-09-07 00:09:17 +02:00
|
|
|
if (formData.isOwned && formData.type == 'herbe' && (formData.system.categorie == 'Soin' || formData.system.categorie == 'Repos')) {
|
2021-05-07 17:27:02 +02:00
|
|
|
formData.isIngredientPotionBase = true;
|
2020-12-15 08:37:52 +01:00
|
|
|
}
|
2021-03-16 22:56:57 +01:00
|
|
|
formData.bonusCaseList = RdDItemSort.getBonusCaseList(formData, true);
|
2020-12-04 20:52:04 +01:00
|
|
|
|
2021-03-16 22:56:57 +01:00
|
|
|
return formData;
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
|
2022-06-12 08:17:59 +02:00
|
|
|
/* -------------------------------------------- */
|
2021-12-05 01:50:09 +01:00
|
|
|
prepareConteneurData(formData) {
|
2022-06-12 09:46:58 +02:00
|
|
|
formData.itemsByType = Misc.classify(this.actor.items.map(i => foundry.utils.deepClone(i)))
|
|
|
|
RdDUtility.filterEquipementParType(formData)
|
2021-12-05 01:50:09 +01:00
|
|
|
|
|
|
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
2022-09-07 18:47:56 +02:00
|
|
|
formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems;
|
2021-12-05 01:50:09 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-21 21:48:20 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
2021-05-07 17:27:02 +02:00
|
|
|
activateListeners(html) {
|
2020-05-21 21:48:20 +02:00
|
|
|
super.activateListeners(html);
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
if (this.item.type == 'conteneur') {
|
2021-12-05 16:48:18 +01:00
|
|
|
this.form.ondragstart = (event) => this._onDragStart(event);
|
|
|
|
this.form.ondrop = (event) => this._onDrop(event);
|
|
|
|
}
|
|
|
|
|
2021-12-05 01:50:09 +01:00
|
|
|
let itemSheetDialog = this;
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
HtmlUtility._showControlWhen($(".item-cout"), ReglesOptionelles.isUsing('afficher-prix-joueurs') || game.user.isGM || !this.item.isOwned);
|
|
|
|
HtmlUtility._showControlWhen($(".item-magique"), this.item.isMagique());
|
2021-12-05 01:50:09 +01:00
|
|
|
|
2020-05-21 21:48:20 +02:00
|
|
|
// Everything below here is only needed if the sheet is editable
|
|
|
|
if (!this.options.editable) return;
|
2021-05-06 21:34:07 +02:00
|
|
|
|
2020-05-22 19:28:01 +02:00
|
|
|
// Select competence categorie
|
2021-05-06 21:34:07 +02:00
|
|
|
html.find(".categorie").change(event => this._onSelectCategorie(event));
|
2020-12-15 21:28:55 +01:00
|
|
|
|
2021-03-29 18:08:18 +02:00
|
|
|
html.find('.sheet-competence-xp').change((event) => {
|
2022-09-07 18:47:56 +02:00
|
|
|
if (this.item.type == 'competence') {
|
|
|
|
RdDUtility.checkThanatosXP(this.item.name);
|
2021-02-06 23:51:04 +01:00
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
});
|
2021-02-06 23:51:04 +01:00
|
|
|
|
2021-04-04 18:37:16 +02:00
|
|
|
html.find('.enchanteDate').change((event) => {
|
|
|
|
let jour = Number($('#jourMois').val());
|
|
|
|
let mois = $('#nomMois').val();
|
|
|
|
this.dateUpdated = game.system.rdd.calendrier.getIndexFromDate(jour, mois);
|
|
|
|
});
|
|
|
|
|
2021-03-29 18:08:18 +02:00
|
|
|
html.find('.creer-tache-livre').click((event) => {
|
2020-12-15 21:28:55 +01:00
|
|
|
let actorId = event.currentTarget.attributes['data-actor-id'].value;
|
2021-05-07 17:27:02 +02:00
|
|
|
let actor = game.actors.get(actorId);
|
|
|
|
actor.creerTacheDepuisLivre(this.item);
|
2020-12-15 21:28:55 +01:00
|
|
|
});
|
2021-04-04 18:37:16 +02:00
|
|
|
html.find('.consommer-potion').click((event) => {
|
|
|
|
let actorId = event.currentTarget.attributes['data-actor-id'].value;
|
2021-05-07 17:27:02 +02:00
|
|
|
let actor = game.actors.get(actorId);
|
|
|
|
actor.consommerPotion(this.item);
|
2021-04-04 18:37:16 +02:00
|
|
|
});
|
2021-04-10 21:07:53 +02:00
|
|
|
html.find('.creer-potion-base').click((event) => {
|
|
|
|
let actorId = event.currentTarget.attributes['data-actor-id'].value;
|
2021-05-07 17:27:02 +02:00
|
|
|
let actor = game.actors.get(actorId);
|
|
|
|
actor.dialogFabriquerPotion(this.item);
|
2021-04-10 21:07:53 +02:00
|
|
|
});
|
2021-05-07 17:27:02 +02:00
|
|
|
|
2021-01-07 20:04:10 +01:00
|
|
|
html.find('.alchimie-tache a').click((event) => {
|
|
|
|
let actorId = event.currentTarget.attributes['data-actor-id'].value;
|
|
|
|
let recetteId = event.currentTarget.attributes['data-recette-id'].value;
|
|
|
|
let tacheName = event.currentTarget.attributes['data-alchimie-tache'].value;
|
|
|
|
let tacheData = event.currentTarget.attributes['data-alchimie-data'].value;
|
2021-05-07 17:27:02 +02:00
|
|
|
let actor = game.actors.get(actorId);
|
|
|
|
if (actor) {
|
2021-01-07 20:04:10 +01:00
|
|
|
actor.effectuerTacheAlchimie(recetteId, tacheName, tacheData);
|
|
|
|
} else {
|
2022-06-12 13:58:55 +02:00
|
|
|
ui.notifications.info("Impossible trouver un acteur pour réaliser cette tache Alchimique.");
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|
|
|
|
});
|
2021-05-07 17:27:02 +02:00
|
|
|
|
2021-12-05 01:50:09 +01:00
|
|
|
html.find('.item-split').click(async event => {
|
|
|
|
const item = RdDSheetUtility.getItem(event, this.actor);
|
|
|
|
await RdDSheetUtility.splitItem(item, this.actor, async () => itemSheetDialog.render(true));
|
|
|
|
});
|
|
|
|
html.find('.item-edit').click(async event => {
|
|
|
|
const item = RdDSheetUtility.getItem(event, this.actor);
|
|
|
|
item.sheet.render(true);
|
|
|
|
});
|
|
|
|
html.find('.item-delete').click(async event => {
|
|
|
|
const li = RdDSheetUtility.getEventElement(event);
|
2022-09-17 01:53:13 +02:00
|
|
|
const item = this.actor.getObjet(li.data("item-id"));
|
|
|
|
RdDUtility.confirmerSuppressionItem(this, item, li);
|
2021-12-05 01:50:09 +01:00
|
|
|
});
|
|
|
|
html.find('.item-vendre').click(async event => {
|
|
|
|
const item = RdDSheetUtility.getItem(event, this.actor);
|
|
|
|
item?.proposerVente();
|
|
|
|
});
|
2021-12-10 01:21:01 +01:00
|
|
|
html.find('.item-montrer').click(async event => {
|
|
|
|
const item = RdDSheetUtility.getItem(event, this.actor);
|
|
|
|
item?.postItem();
|
|
|
|
});
|
2021-12-05 01:50:09 +01:00
|
|
|
html.find('.item-action').click(async event => {
|
|
|
|
const item = RdDSheetUtility.getItem(event, this.actor);
|
|
|
|
this.actor.actionItem(item, async () => itemSheetDialog.render(true));
|
|
|
|
});
|
|
|
|
html.find('.conteneur-name a').click(async event => {
|
|
|
|
RdDUtility.toggleAfficheContenu(RdDSheetUtility.getItemId(event));
|
|
|
|
this.render(true);
|
|
|
|
});
|
2020-05-21 21:48:20 +02:00
|
|
|
}
|
2021-05-07 17:27:02 +02:00
|
|
|
|
2020-05-21 21:48:20 +02:00
|
|
|
/* -------------------------------------------- */
|
2021-05-06 21:34:07 +02:00
|
|
|
async _onSelectCategorie(event) {
|
2020-05-21 21:48:20 +02:00
|
|
|
event.preventDefault();
|
2021-05-06 21:34:07 +02:00
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
if (this.item.isCompetence()) {
|
2021-05-06 21:34:07 +02:00
|
|
|
let level = RdDItemCompetence.getNiveauBase(event.currentTarget.value);
|
2022-09-07 18:47:56 +02:00
|
|
|
this.item.system.base = level;
|
2021-05-06 21:34:07 +02:00
|
|
|
$("#base").val(level);
|
|
|
|
}
|
2020-05-22 19:28:01 +02:00
|
|
|
}
|
2020-05-21 21:48:20 +02:00
|
|
|
|
2020-05-22 19:28:01 +02:00
|
|
|
/* -------------------------------------------- */
|
2021-05-07 17:27:02 +02:00
|
|
|
get template() {
|
2022-09-07 18:47:56 +02:00
|
|
|
let type = this.item.type
|
2022-06-12 08:17:59 +02:00
|
|
|
return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`;
|
2020-05-21 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
2021-03-25 09:28:36 +01:00
|
|
|
_updateObject(event, formData) { // Deprecated en v0.8 à clarifier
|
2020-12-04 20:52:04 +01:00
|
|
|
// Données de bonus de cases ?
|
2021-05-07 17:27:02 +02:00
|
|
|
formData = RdDItemSort.buildBonusCaseStringFromFormData(formData);
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
return this.item.update(formData);
|
2020-05-21 21:48:20 +02:00
|
|
|
}
|
2021-12-05 01:50:09 +01:00
|
|
|
|
2021-12-05 16:48:18 +01:00
|
|
|
async _onDragStart(event) {
|
|
|
|
console.log("_onDragStart", event);
|
2022-01-01 14:01:41 +01:00
|
|
|
if (event.target.classList.contains("entity-link")) return;
|
2021-12-05 16:48:18 +01:00
|
|
|
|
|
|
|
const itemId = event.srcElement?.attributes["data-item-id"].value;
|
|
|
|
const item = this.actor.items.get(itemId);
|
|
|
|
// Create drag data
|
|
|
|
const dragData = {
|
|
|
|
actorId: this.actor.id,
|
|
|
|
type: "Item",
|
2022-09-07 18:47:56 +02:00
|
|
|
data: item.system
|
2021-12-05 16:48:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onDrop(event) {
|
2022-09-07 18:47:56 +02:00
|
|
|
// Try to extract the dragData
|
|
|
|
let dragData;
|
2021-12-05 16:48:18 +01:00
|
|
|
try {
|
2022-09-07 18:47:56 +02:00
|
|
|
dragData = JSON.parse(event.dataTransfer.getData('text/plain'));
|
2021-12-05 16:48:18 +01:00
|
|
|
} catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
const allowed = Hooks.call("dropActorSheetData", this.actor, this, dragData);
|
2022-01-01 14:01:41 +01:00
|
|
|
if (allowed === false) return;
|
2021-12-05 16:48:18 +01:00
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
// Handle different dragData types
|
|
|
|
switch (dragData.type) {
|
2021-12-05 16:48:18 +01:00
|
|
|
case "Item":
|
2022-09-07 18:47:56 +02:00
|
|
|
return this._onDropItem(event, dragData);
|
2021-12-05 16:48:18 +01:00
|
|
|
}
|
|
|
|
return super._onDrop(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onDropItem(event, dragData) {
|
|
|
|
if (this.actor) {
|
2022-09-07 18:47:56 +02:00
|
|
|
const dropParams = RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor.id, dragData, this.objetVersConteneur);
|
2021-12-05 16:48:18 +01:00
|
|
|
await this.actor.processDropItem(dropParams);
|
|
|
|
await this.render(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 01:50:09 +01:00
|
|
|
|
2020-05-21 21:48:20 +02:00
|
|
|
}
|