2021-03-22 20:10:37 +01:00
|
|
|
import { Misc } from "./misc.js";
|
2021-01-01 21:11:56 +01:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
|
|
|
|
2021-04-08 20:37:11 +02:00
|
|
|
const typesObjetsEquipement = ["objet", "arme", "armure", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "nourritureboisson", "monnaie"];
|
2021-04-06 23:36:35 +02:00
|
|
|
const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"];
|
2021-01-01 21:11:56 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class RdDItem extends Item {
|
|
|
|
|
2021-04-06 23:36:35 +02:00
|
|
|
static getTypeObjetsEquipement() {
|
|
|
|
return typesObjetsEquipement;
|
|
|
|
}
|
|
|
|
static getTypesOeuvres() {
|
|
|
|
return typesObjetsOeuvres;
|
|
|
|
}
|
|
|
|
prepareDerivedData() {
|
|
|
|
super.prepareDerivedData();
|
|
|
|
const itemData = this.data;
|
|
|
|
if (RdDItem.getTypeObjetsEquipement().includes(itemData.type)) {
|
2021-04-08 20:37:11 +02:00
|
|
|
this._calculsEquipement(itemData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_calculsEquipement(itemData) {
|
|
|
|
const tplData = itemData.data;
|
|
|
|
const quantite = itemData.type == 'conteneur' ? 1 : (tplData.quantite ?? 0);
|
|
|
|
if (tplData.encombrement != undefined) {
|
|
|
|
tplData.encTotal = Math.max(tplData.encombrement, 0) * quantite;
|
|
|
|
}
|
|
|
|
if (tplData.cout != undefined) {
|
|
|
|
tplData.prixTotal = Math.max(tplData.cout, 0) * quantite;
|
2021-04-06 23:36:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-01 21:11:56 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async postItem() {
|
|
|
|
console.log(this);
|
|
|
|
const properties = this[`_${this.data.type}ChatData`]();
|
2021-03-22 20:10:37 +01:00
|
|
|
const itemData = Misc.data(this);
|
|
|
|
let chatData = duplicate(itemData);
|
2021-01-01 21:11:56 +01:00
|
|
|
chatData["properties"] = properties
|
|
|
|
|
|
|
|
//Check if the posted item should have availability/pay buttons
|
|
|
|
chatData.hasPrice = "cout" in chatData.data;
|
|
|
|
chatData.data.cout_deniers = 0;
|
|
|
|
|
|
|
|
let dialogResult = [-1, -1]; // dialogResult[0] = quantité, dialogResult[1] = prix
|
2021-04-06 23:36:35 +02:00
|
|
|
if (chatData.hasPrice) {
|
2021-01-01 21:11:56 +01:00
|
|
|
let sols = chatData.data.cout;
|
|
|
|
chatData.data.cout_deniers = Math.floor(sols * 100);
|
2021-04-06 23:36:35 +02:00
|
|
|
dialogResult = await new Promise((resolve, reject) => {
|
|
|
|
new Dialog({
|
|
|
|
content:
|
|
|
|
`<p>Modifier la quantité?</p>
|
2021-01-11 18:04:26 +01:00
|
|
|
<div class="form-group">
|
2021-01-01 21:11:56 +01:00
|
|
|
<label> Quantité</label>
|
2021-01-29 21:03:32 +01:00
|
|
|
<input name="quantity" type="text" value="1"/>
|
2021-01-01 21:11:56 +01:00
|
|
|
</div>
|
|
|
|
<p>Modifier la prix?</p>
|
|
|
|
<div class="form-group">
|
|
|
|
<label> Prix en Sols</label>
|
|
|
|
<input name="price" type="text" value="${chatData.data.cout}"/>
|
|
|
|
</div>
|
|
|
|
`,
|
2021-04-06 23:36:35 +02:00
|
|
|
title: "Quantité & Prix",
|
|
|
|
buttons: {
|
|
|
|
post: {
|
|
|
|
label: "Soumettre",
|
2021-01-01 21:11:56 +01:00
|
|
|
callback: (dlg) => {
|
2021-04-06 23:36:35 +02:00
|
|
|
resolve([dlg.find('[name="quantity"]').val(), dlg.find('[name="price"]').val()])
|
2021-01-01 21:11:56 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}).render(true)
|
|
|
|
})
|
2021-04-06 23:36:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dialogResult[0] > 0) {
|
|
|
|
if (this.isOwned) {
|
2021-03-22 20:10:37 +01:00
|
|
|
if (itemData.data.quantite == 0)
|
2021-01-01 21:11:56 +01:00
|
|
|
dialogResult[0] = -1
|
2021-04-06 23:36:35 +02:00
|
|
|
else if (itemData.data.quantite < dialogResult[0]) {
|
2021-03-22 20:10:37 +01:00
|
|
|
dialogResult[0] = itemData.data.quantite;
|
2021-04-06 23:36:35 +02:00
|
|
|
ui.notifications.notify(`Impossible de poster plus que ce que vous avez. La quantité à été réduite à ${dialogResult[0]}.`)
|
|
|
|
this.update({ "data.quantite": 0 })
|
2021-01-01 21:11:56 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-04-06 23:36:35 +02:00
|
|
|
ui.notifications.notify(`Quantité réduite par ${dialogResult[0]}.`)
|
|
|
|
this.update({ "data.quantite": itemData.data.quantite - dialogResult[0] })
|
2021-01-01 21:11:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-06 23:36:35 +02:00
|
|
|
|
|
|
|
if (chatData.hasPrice) {
|
2021-01-11 18:04:26 +01:00
|
|
|
if (dialogResult[0] > 0)
|
|
|
|
chatData.postQuantity = Number(dialogResult[0]);
|
|
|
|
if (dialogResult[1] > 0) {
|
2021-04-06 23:36:35 +02:00
|
|
|
chatData.postPrice = dialogResult[1];
|
2021-01-11 18:04:26 +01:00
|
|
|
chatData.data.cout_deniers = Math.floor(dialogResult[1] * 100); // Mise à jour cout en deniers
|
|
|
|
}
|
|
|
|
chatData.finalPrice = Number(chatData.postPrice) * Number(chatData.postQuantity);
|
2021-01-22 10:05:30 +01:00
|
|
|
chatData.data.cout_deniers_total = chatData.data.cout_deniers * Number(chatData.postQuantity);
|
|
|
|
chatData.data.quantite = chatData.postQuantity;
|
|
|
|
console.log("POST : ", chatData.finalPrice, chatData.data.cout_deniers_total, chatData.postQuantity);
|
2021-01-01 21:11:56 +01:00
|
|
|
}
|
|
|
|
// Don't post any image for the item (which would leave a large gap) if the default image is used
|
|
|
|
if (chatData.img.includes("/blank.png"))
|
|
|
|
chatData.img = null;
|
2021-04-06 23:36:35 +02:00
|
|
|
|
2021-01-01 21:11:56 +01:00
|
|
|
// JSON object for easy creation
|
|
|
|
chatData.jsondata = JSON.stringify(
|
2021-04-06 23:36:35 +02:00
|
|
|
{
|
|
|
|
compendium: "postedItem",
|
|
|
|
payload: itemData,
|
|
|
|
});
|
|
|
|
|
2021-01-01 21:11:56 +01:00
|
|
|
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-item.html', chatData).then(html => {
|
|
|
|
let chatOptions = RdDUtility.chatDataSetup(html);
|
|
|
|
ChatMessage.create(chatOptions)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_objetChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_armeChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Compétence</b>: ${rddData.competence}`,
|
|
|
|
`<b>Dommages</b>: ${rddData.dommages}`,
|
|
|
|
`<b>Force minimum</b>: ${rddData.force}`,
|
|
|
|
`<b>Resistance</b>: ${rddData.resistance}`,
|
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_conteneurChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Capacité</b>: ${rddData.capacite} Enc.`,
|
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_munitionChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_armureChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Protection</b>: ${rddData.protection}`,
|
|
|
|
`<b>Détérioration</b>: ${rddData.deterioration}`,
|
|
|
|
`<b>Malus armure</b>: ${rddData.malus}`,
|
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_competenceChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Catégorie</b>: ${rddData.categorie}`,
|
|
|
|
`<b>Niveau</b>: ${rddData.niveau}`,
|
|
|
|
`<b>Caractéristique par défaut</b>: ${rddData.carac_defaut}`,
|
|
|
|
`<b>XP</b>: ${rddData.xp}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_competencecreatureChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Catégorie</b>: ${rddData.categorie}`,
|
|
|
|
`<b>Niveau</b>: ${rddData.niveau}`,
|
|
|
|
`<b>Caractéristique</b>: ${rddData.carac_value}`,
|
|
|
|
`<b>XP</b>: ${rddData.xp}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_sortChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Draconic</b>: ${rddData.draconic}`,
|
|
|
|
`<b>Difficulté</b>: ${rddData.difficulte}`,
|
|
|
|
`<b>Case TMR</b>: ${rddData.caseTMR}`,
|
|
|
|
`<b>Points de Rêve</b>: ${rddData.ptreve}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_herbeChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Milieu</b>: ${rddData.milieu}`,
|
|
|
|
`<b>Rareté</b>: ${rddData.rarete}`,
|
|
|
|
`<b>Catégorie</b>: ${rddData.categorie}`,
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_ingredientChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Milieu</b>: ${rddData.milieu}`,
|
|
|
|
`<b>Rareté</b>: ${rddData.rarete}`,
|
|
|
|
`<b>Catégorie</b>: ${rddData.categorie}`,
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_tacheChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Caractéristique</b>: ${rddData.carac}`,
|
|
|
|
`<b>Compétence</b>: ${rddData.competence}`,
|
|
|
|
`<b>Périodicité</b>: ${rddData.periodicite}`,
|
|
|
|
`<b>Fatigue</b>: ${rddData.fatigue}`,
|
|
|
|
`<b>Difficulté</b>: ${rddData.difficulte}`,
|
|
|
|
`<b>Points de Tâche</b>: ${rddData.points_de_tache}`,
|
|
|
|
`<b>Points de Tâche atteints</b>: ${rddData.points_de_tache_courant}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_livreChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Compétence</b>: ${rddData.competence}`,
|
|
|
|
`<b>Auteur</b>: ${rddData.auteur}`,
|
|
|
|
`<b>Difficulté</b>: ${rddData.difficulte}`,
|
|
|
|
`<b>Points de Tâche</b>: ${rddData.points_de_tache}`,
|
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_potionChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Rareté</b>: ${rddData.rarete}`,
|
|
|
|
`<b>Catégorie</b>: ${rddData.categorie}`,
|
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`,
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_queueChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Refoulement</b>: ${rddData.refoulement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_ombreChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Refoulement</b>: ${rddData.refoulement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_souffleChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [];
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_teteChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [];
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_tarotChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Concept</b>: ${rddData.concept}`,
|
|
|
|
`<b>Aspect</b>: ${rddData.aspect}`,
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_nombreastralChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Valeur</b>: ${rddData.value}`,
|
|
|
|
`<b>Jour</b>: ${rddData.jourlabel}`,
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_monnaieChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Valeur en Deniers</b>: ${rddData.valeur_deniers}`,
|
|
|
|
`<b>Encombrement</b>: ${rddData.encombrement}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_meditationChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Thème</b>: ${rddData.theme}`,
|
|
|
|
`<b>Compétence</b>: ${rddData.competence}`,
|
|
|
|
`<b>Support</b>: ${rddData.support}`,
|
|
|
|
`<b>Heure</b>: ${rddData.heure}`,
|
|
|
|
`<b>Purification</b>: ${rddData.purification}`,
|
|
|
|
`<b>Vêture</b>: ${rddData.veture}`,
|
|
|
|
`<b>Comportement</b>: ${rddData.comportement}`,
|
|
|
|
`<b>Case TMR</b>: ${rddData.tmr}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_casetmrChatData() {
|
2021-03-22 20:10:37 +01:00
|
|
|
const rddData = Misc.data(this).data;
|
2021-01-01 21:11:56 +01:00
|
|
|
let properties = [
|
2021-03-22 20:10:37 +01:00
|
|
|
`<b>Coordonnée</b>: ${rddData.coord}`,
|
|
|
|
`<b>Spécificité</b>: ${rddData.specific}`
|
2021-01-01 21:11:56 +01:00
|
|
|
]
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|