import { Misc } from "./misc.js";
import { RdDUtility } from "./rdd-utility.js";
/* -------------------------------------------- */
export class RdDItem extends Item {
/* -------------------------------------------- */
async postItem() {
console.log(this);
const properties = this[`_${this.data.type}ChatData`]();
const itemData = Misc.data(this);
let chatData = duplicate(itemData);
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
if (chatData.hasPrice )
{
let sols = chatData.data.cout;
chatData.data.cout_deniers = Math.floor(sols * 100);
dialogResult = await new Promise( (resolve, reject) => {new Dialog({
content :
`
Modifier la quantité?
Modifier la prix?
`,
title : "Quantité & Prix",
buttons : {
post : {
label : "Soumettre",
callback: (dlg) => {
resolve( [ dlg.find('[name="quantity"]').val(), dlg.find('[name="price"]').val() ] )
}
},
}
}).render(true)
})
}
if (dialogResult[0] > 0)
{
if (this.isOwned)
{
if (itemData.data.quantite == 0)
dialogResult[0] = -1
else if (itemData.data.quantite < dialogResult[0])
{
dialogResult[0] = itemData.data.quantite;
ui.notifications.notify(`Impossible de poster plus que ce que vous avez. La quantité à été réduite à ${dialogResult[0]}.`)
this.update({"data.quantite" : 0})
}
else {
ui.notifications.notify(`Quantité réduite par ${dialogResult[0]}.`)
this.update({"data.quantite" : itemData.data.quantite - dialogResult[0]})
}
}
}
if ( chatData.hasPrice ) {
if (dialogResult[0] > 0)
chatData.postQuantity = Number(dialogResult[0]);
if (dialogResult[1] > 0) {
chatData.postPrice = dialogResult[1];
chatData.data.cout_deniers = Math.floor(dialogResult[1] * 100); // Mise à jour cout en deniers
}
chatData.finalPrice = Number(chatData.postPrice) * Number(chatData.postQuantity);
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);
}
// 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;
// JSON object for easy creation
chatData.jsondata = JSON.stringify(
{
compendium : "postedItem",
payload: itemData,
});
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-item.html', chatData).then(html => {
let chatOptions = RdDUtility.chatDataSetup(html);
ChatMessage.create(chatOptions)
});
}
/* -------------------------------------------- */
_objetChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Encombrement: ${rddData.encombrement}`
]
return properties;
}
/* -------------------------------------------- */
_armeChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Compétence: ${rddData.competence}`,
`Dommages: ${rddData.dommages}`,
`Force minimum: ${rddData.force}`,
`Resistance: ${rddData.resistance}`,
`Encombrement: ${rddData.encombrement}`
]
return properties;
}
/* -------------------------------------------- */
_conteneurChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Capacité: ${rddData.capacite} Enc.`,
`Encombrement: ${rddData.encombrement}`
]
return properties;
}
/* -------------------------------------------- */
_munitionChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Encombrement: ${rddData.encombrement}`
]
return properties;
}
/* -------------------------------------------- */
_armureChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Protection: ${rddData.protection}`,
`Détérioration: ${rddData.deterioration}`,
`Malus armure: ${rddData.malus}`,
`Encombrement: ${rddData.encombrement}`
]
return properties;
}
/* -------------------------------------------- */
_competenceChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Catégorie: ${rddData.categorie}`,
`Niveau: ${rddData.niveau}`,
`Caractéristique par défaut: ${rddData.carac_defaut}`,
`XP: ${rddData.xp}`
]
return properties;
}
/* -------------------------------------------- */
_competencecreatureChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Catégorie: ${rddData.categorie}`,
`Niveau: ${rddData.niveau}`,
`Caractéristique: ${rddData.carac_value}`,
`XP: ${rddData.xp}`
]
return properties;
}
/* -------------------------------------------- */
_sortChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Draconic: ${rddData.draconic}`,
`Difficulté: ${rddData.difficulte}`,
`Case TMR: ${rddData.caseTMR}`,
`Points de Rêve: ${rddData.ptreve}`
]
return properties;
}
/* -------------------------------------------- */
_herbeChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Milieu: ${rddData.milieu}`,
`Rareté: ${rddData.rarete}`,
`Catégorie: ${rddData.categorie}`,
]
return properties;
}
/* -------------------------------------------- */
_ingredientChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Milieu: ${rddData.milieu}`,
`Rareté: ${rddData.rarete}`,
`Catégorie: ${rddData.categorie}`,
]
return properties;
}
/* -------------------------------------------- */
_tacheChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Caractéristique: ${rddData.carac}`,
`Compétence: ${rddData.competence}`,
`Périodicité: ${rddData.periodicite}`,
`Fatigue: ${rddData.fatigue}`,
`Difficulté: ${rddData.difficulte}`,
`Points de Tâche: ${rddData.points_de_tache}`,
`Points de Tâche atteints: ${rddData.points_de_tache_courant}`
]
return properties;
}
/* -------------------------------------------- */
_livreChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Compétence: ${rddData.competence}`,
`Auteur: ${rddData.auteur}`,
`Difficulté: ${rddData.difficulte}`,
`Points de Tâche: ${rddData.points_de_tache}`,
`Encombrement: ${rddData.encombrement}`
]
return properties;
}
/* -------------------------------------------- */
_potionChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Rareté: ${rddData.rarete}`,
`Catégorie: ${rddData.categorie}`,
`Encombrement: ${rddData.encombrement}`,
]
return properties;
}
/* -------------------------------------------- */
_queueChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Refoulement: ${rddData.refoulement}`
]
return properties;
}
/* -------------------------------------------- */
_ombreChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Refoulement: ${rddData.refoulement}`
]
return properties;
}
/* -------------------------------------------- */
_souffleChatData() {
const rddData = Misc.data(this).data;
let properties = [];
return properties;
}
/* -------------------------------------------- */
_teteChatData() {
const rddData = Misc.data(this).data;
let properties = [];
return properties;
}
/* -------------------------------------------- */
_tarotChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Concept: ${rddData.concept}`,
`Aspect: ${rddData.aspect}`,
]
return properties;
}
/* -------------------------------------------- */
_nombreastralChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Valeur: ${rddData.value}`,
`Jour: ${rddData.jourlabel}`,
]
return properties;
}
/* -------------------------------------------- */
_monnaieChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Valeur en Deniers: ${rddData.valeur_deniers}`,
`Encombrement: ${rddData.encombrement}`
]
return properties;
}
/* -------------------------------------------- */
_meditationChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Thème: ${rddData.theme}`,
`Compétence: ${rddData.competence}`,
`Support: ${rddData.support}`,
`Heure: ${rddData.heure}`,
`Purification: ${rddData.purification}`,
`Vêture: ${rddData.veture}`,
`Comportement: ${rddData.comportement}`,
`Case TMR: ${rddData.tmr}`
]
return properties;
}
/* -------------------------------------------- */
_casetmrChatData() {
const rddData = Misc.data(this).data;
let properties = [
`Coordonnée: ${rddData.coord}`,
`Spécificité: ${rddData.specific}`
]
return properties;
}
}