import { RdDUtility } from "./rdd-utility.js"; /* -------------------------------------------- */ export class RdDItem extends Item { /* -------------------------------------------- */ async postItem() { console.log(this); const properties = this[`_${this.data.type}ChatData`](); let chatData = duplicate(this.data); 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 prix?

`, title : "Quantité", 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 (this.data.data.quantite == 0) dialogResult[0] = -1 else if (this.data.data.quantite < dialogResult[0]) { dialogResult[0] = this.data.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" : this.data.data.quantite - dialogResult[0]}) } } } if (dialogResult[0] > 0) chatData.postQuantity = dialogResult[0]; if (dialogResult[1] > 0) { chatData.postPrice = dialogResult[1]; chatData.data.cout_deniers = Math.floor(dialogResult[1] * 100); // Mise à jour cout en deniers } // 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: this.data, }); renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-item.html', chatData).then(html => { let chatOptions = RdDUtility.chatDataSetup(html); ChatMessage.create(chatOptions) }); } /* -------------------------------------------- */ _objetChatData() { const data = duplicate(this.data.data); let properties = [ `Encombrement: ${data.encombrement}` ] return properties; } /* -------------------------------------------- */ _armeChatData() { const data = duplicate(this.data.data); let properties = [ `Compétence: ${data.competence}`, `Dommages: ${data.dommages}`, `Force minimum: ${data.force}`, `Resistance: ${data.resistance}`, `Encombrement: ${data.encombrement}` ] return properties; } /* -------------------------------------------- */ _conteneurChatData() { const data = duplicate(this.data.data); let properties = [ `Capacité: ${data.capacite} Enc.`, `Encombrement: ${data.encombrement}` ] return properties; } /* -------------------------------------------- */ _munitionChatData() { const data = duplicate(this.data.data); let properties = [ `Encombrement: ${data.encombrement}` ] return properties; } /* -------------------------------------------- */ _armureChatData() { const data = duplicate(this.data.data); let properties = [ `Protection: ${data.protection}`, `Détérioration: ${data.deterioration}`, `Malus armure: ${data.malus}`, `Encombrement: ${data.encombrement}` ] return properties; } /* -------------------------------------------- */ _competenceChatData() { const data = duplicate(this.data.data); let properties = [ `Catégorie: ${data.categorie}`, `Niveau: ${data.niveau}`, `Caractéristique par défaut: ${data.carac_defaut}`, `XP: ${data.xp}` ] return properties; } /* -------------------------------------------- */ _competencecreatureChatData() { const data = duplicate(this.data.data); let properties = [ `Catégorie: ${data.categorie}`, `Niveau: ${data.niveau}`, `Caractéristique: ${data.carac_value}`, `XP: ${data.xp}` ] return properties; } /* -------------------------------------------- */ _sortChatData() { const data = duplicate(this.data.data); let properties = [ `Draconic: ${data.draconic}`, `Difficulté: ${data.difficulte}`, `Case TMR: ${data.caseTMR}`, `Points de Rêve: ${data.ptreve}` ] return properties; } /* -------------------------------------------- */ _herbeChatData() { const data = duplicate(this.data.data); let properties = [ `Milieu: ${data.milieu}`, `Rareté: ${data.rarete}`, `Catégorie: ${data.categorie}`, ] return properties; } /* -------------------------------------------- */ _ingredientChatData() { const data = duplicate(this.data.data); let properties = [ `Milieu: ${data.milieu}`, `Rareté: ${data.rarete}`, `Catégorie: ${data.categorie}`, ] return properties; } /* -------------------------------------------- */ _tacheChatData() { const data = duplicate(this.data.data); let properties = [ `Caractéristique: ${data.carac}`, `Compétence: ${data.competence}`, `Périodicité: ${data.periodicite}`, `Fatigue: ${data.fatigue}`, `Difficulté: ${data.difficulte}`, `Points de Tâche: ${data.points_de_tache}`, `Points de Tâche atteints: ${data.points_de_tache_courant}` ] return properties; } /* -------------------------------------------- */ _livreChatData() { const data = duplicate(this.data.data); let properties = [ `Compétence: ${data.competence}`, `Auteur: ${data.auteur}`, `Difficulté: ${data.difficulte}`, `Points de Tâche: ${data.points_de_tache}`, `Encombrement: ${data.encombrement}` ] return properties; } /* -------------------------------------------- */ _potionChatData() { const data = duplicate(this.data.data); let properties = [ `Rareté: ${data.rarete}`, `Catégorie: ${data.categorie}`, `Encombrement: ${data.encombrement}`, ] return properties; } /* -------------------------------------------- */ _queueChatData() { const data = duplicate(this.data.data); let properties = [ `Refoulement: ${data.refoulement}` ] return properties; } /* -------------------------------------------- */ _ombreChatData() { const data = duplicate(this.data.data); let properties = [ `Refoulement: ${data.refoulement}` ] return properties; } /* -------------------------------------------- */ _souffleChatData() { const data = duplicate(this.data.data); let properties = []; return properties; } /* -------------------------------------------- */ _teteChatData() { const data = duplicate(this.data.data); let properties = []; return properties; } /* -------------------------------------------- */ _tarotChatData() { const data = duplicate(this.data.data); let properties = [ `Concept: ${data.concept}`, `Aspect: ${data.aspect}`, ] return properties; } /* -------------------------------------------- */ _nombreastralChatData() { const data = duplicate(this.data.data); let properties = [ `Valeur: ${data.value}`, `Jour: ${data.jourlabel}`, ] return properties; } /* -------------------------------------------- */ _monnaieChatData() { const data = duplicate(this.data.data); let properties = [ `Valeur en Deniers: ${data.valeur_deniers}`, `Encombrement: ${data.encombrement}` ] return properties; } /* -------------------------------------------- */ _meditationChatData() { const data = duplicate(this.data.data); let properties = [ `Thème: ${data.theme}`, `Compétence: ${data.competence}`, `Support: ${data.support}`, `Heure: ${data.heure}`, `Purification: ${data.purification}`, `Vêture: ${data.veture}`, `Comportement: ${data.comportement}`, `Case TMR: ${data.tmr}` ] return properties; } /* -------------------------------------------- */ _casetmrChatData() { const data = duplicate(this.data.data); let properties = [ `Coordonnée: ${data.coord}`, `Spécificité: ${data.specific}` ] return properties; } }