Gestion des signes draconiques #455

Closed
vincent.vandeme wants to merge 233 commits from v1.4-signes-draconiques into master
3 changed files with 167 additions and 135 deletions
Showing only changes of commit 6b31e81c72 - Show all commits

View File

@ -32,7 +32,7 @@ export class RdDItemSheet extends ItemSheet {
{ {
class: "post", class: "post",
icon: "fas fa-comment", icon: "fas fa-comment",
onclick: ev => new RdDItem(Misc.data(this.item)).postItem() onclick: ev => this.item.postItem()
}) })
return buttons return buttons
} }

View File

@ -16,15 +16,14 @@ export class RdDItem extends Item {
prepareDerivedData() { prepareDerivedData() {
super.prepareDerivedData(); super.prepareDerivedData();
const itemData = this.data; if (RdDItem.getTypeObjetsEquipement().includes(Misc.data(this).type)) {
if (RdDItem.getTypeObjetsEquipement().includes(itemData.type)) { this._calculsEquipement();
this._calculsEquipement(itemData);
} }
} }
_calculsEquipement(itemData) { _calculsEquipement() {
const tplData = itemData.data; const tplData = Misc.templateData(this);
const quantite = itemData.type == 'conteneur' ? 1 : (tplData.quantite ?? 0); const quantite = Misc.data(this).type == 'conteneur' ? 1 : (tplData.quantite ?? 0);
if (tplData.encombrement != undefined) { if (tplData.encombrement != undefined) {
tplData.encTotal = Math.max(tplData.encombrement, 0) * quantite; tplData.encTotal = Math.max(tplData.encombrement, 0) * quantite;
} }
@ -33,12 +32,25 @@ export class RdDItem extends Item {
} }
} }
async diminuerQuantite(nombre, options = { diminuerQuantite: true }) {
if (!options.diminuerQuantite) return;
const itemData = Misc.data(this);
const quantite = itemData.data.quantite;
if (quantite != undefined) {
const reste = Math.max(quantite - nombre, 0);
ui.notifications.notify(`Quantité de ${itemData.name} réduite de ${nombre}.${reste == 0
? "Il ne vous en reste plus, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer."
: ""}`);
await this.update({ "data.quantite": reste });
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async postItem() { async postItem() {
console.log(this); console.log(this);
const properties = this[`_${this.data.type}ChatData`](); let chatData = duplicate(Misc.data(this));
const itemData = Misc.data(this); const properties = this[`_${chatData.type}ChatData`]();
let chatData = duplicate(itemData);
chatData["properties"] = properties chatData["properties"] = properties
//Check if the posted item should have availability/pay buttons //Check if the posted item should have availability/pay buttons
@ -47,8 +59,7 @@ export class RdDItem extends Item {
let dialogResult = [-1, -1]; // dialogResult[0] = quantité, dialogResult[1] = prix let dialogResult = [-1, -1]; // dialogResult[0] = quantité, dialogResult[1] = prix
if (chatData.hasPrice) { if (chatData.hasPrice) {
let sols = chatData.data.cout; chatData.data.cout_deniers = Math.floor(chatData.data.cout * 100);
chatData.data.cout_deniers = Math.floor(sols * 100);
dialogResult = await new Promise((resolve, reject) => { dialogResult = await new Promise((resolve, reject) => {
new Dialog({ new Dialog({
content: content:
@ -68,7 +79,7 @@ export class RdDItem extends Item {
post: { post: {
label: "Soumettre", label: "Soumettre",
callback: (dlg) => { callback: (dlg) => {
resolve([dlg.find('[name="quantity"]').val(), dlg.find('[name="price"]').val()]) resolve([Number(dlg.find('[name="quantity"]').val()), Number(dlg.find('[name="price"]').val())])
} }
}, },
} }
@ -76,28 +87,29 @@ export class RdDItem extends Item {
}) })
} }
if (dialogResult[0] > 0) { let quantiteEnvoi = Math.min(dialogResult[0], chatData.data.quantite);
const prixTotal = dialogResult[1];
if (quantiteEnvoi > 0) {
if (this.isOwned) { if (this.isOwned) {
if (itemData.data.quantite == 0) if (chatData.data.quantite == 0) {
dialogResult[0] = -1 quantiteEnvoi = -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 { else if (quantiteEnvoi > chatData.data.quantite) {
ui.notifications.notify(`Quantité réduite par ${dialogResult[0]}.`) quantiteEnvoi = chatData.data.quantite;
this.update({ "data.quantite": itemData.data.quantite - dialogResult[0] }) ui.notifications.notify(`Impossible de poster plus que ce que vous avez. La quantité à été réduite à ${quantiteEnvoi}.`)
}
if (quantiteEnvoi > 0) {
this.diminuerQuantite(quantiteEnvoi);
} }
} }
} }
if (chatData.hasPrice) { if (chatData.hasPrice) {
if (dialogResult[0] > 0) if (quantiteEnvoi > 0)
chatData.postQuantity = Number(dialogResult[0]); chatData.postQuantity = Number(quantiteEnvoi);
if (dialogResult[1] > 0) { if (prixTotal > 0) {
chatData.postPrice = dialogResult[1]; chatData.postPrice = prixTotal;
chatData.data.cout_deniers = Math.floor(dialogResult[1] * 100); // Mise à jour cout en deniers chatData.data.cout_deniers = Math.floor(prixTotal * 100); // Mise à jour cout en deniers
} }
chatData.finalPrice = Number(chatData.postPrice) * Number(chatData.postQuantity); chatData.finalPrice = Number(chatData.postPrice) * Number(chatData.postQuantity);
chatData.data.cout_deniers_total = chatData.data.cout_deniers * Number(chatData.postQuantity); chatData.data.cout_deniers_total = chatData.data.cout_deniers * Number(chatData.postQuantity);
@ -112,7 +124,7 @@ export class RdDItem extends Item {
chatData.jsondata = JSON.stringify( chatData.jsondata = JSON.stringify(
{ {
compendium: "postedItem", compendium: "postedItem",
payload: itemData, payload: chatData,
}); });
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-item.html', chatData).then(html => { renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-item.html', chatData).then(html => {
@ -121,219 +133,237 @@ export class RdDItem extends Item {
}); });
} }
static propertyIfDefined(name, val, condition) {
return condition ? [`<b>${name}</b>: ${val}`] : [];
}
/* -------------------------------------------- */ /* -------------------------------------------- */
_objetChatData() { _objetChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Encombrement</b>: ${rddData.encombrement}` `<b>Encombrement</b>: ${tplData.encombrement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */
_nourritureboissonChatData() {
const tplData = Misc.templateData(this);
let properties = [].concat(
RdDItem.propertyIfDefined('Sustentation', tplData.sust, tplData.sust > 0),
RdDItem.propertyIfDefined('Désaltère', tplData.desaltere, tplData.boisson),
RdDItem.propertyIfDefined('Force alcool', tplData.force, tplData.boisson && tplData.alcoolise),
RdDItem.propertyIfDefined('Exotisme', tplData.qualite, tplData.qualite < 0),
RdDItem.propertyIfDefined('Qualité', tplData.qualite, tplData.qualite > 0),
[`<b>Encombrement</b>: ${tplData.encombrement}`],
);
return properties;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
_armeChatData() { _armeChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Compétence</b>: ${rddData.competence}`, `<b>Compétence</b>: ${tplData.competence}`,
`<b>Dommages</b>: ${rddData.dommages}`, `<b>Dommages</b>: ${tplData.dommages}`,
`<b>Force minimum</b>: ${rddData.force}`, `<b>Force minimum</b>: ${tplData.force}`,
`<b>Resistance</b>: ${rddData.resistance}`, `<b>Resistance</b>: ${tplData.resistance}`,
`<b>Encombrement</b>: ${rddData.encombrement}` `<b>Encombrement</b>: ${tplData.encombrement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_conteneurChatData() { _conteneurChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Capacité</b>: ${rddData.capacite} Enc.`, `<b>Capacité</b>: ${tplData.capacite} Enc.`,
`<b>Encombrement</b>: ${rddData.encombrement}` `<b>Encombrement</b>: ${tplData.encombrement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_munitionChatData() { _munitionChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Encombrement</b>: ${rddData.encombrement}` `<b>Encombrement</b>: ${tplData.encombrement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_armureChatData() { _armureChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Protection</b>: ${rddData.protection}`, `<b>Protection</b>: ${tplData.protection}`,
`<b>Détérioration</b>: ${rddData.deterioration}`, `<b>Détérioration</b>: ${tplData.deterioration}`,
`<b>Malus armure</b>: ${rddData.malus}`, `<b>Malus armure</b>: ${tplData.malus}`,
`<b>Encombrement</b>: ${rddData.encombrement}` `<b>Encombrement</b>: ${tplData.encombrement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_competenceChatData() { _competenceChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Catégorie</b>: ${rddData.categorie}`, `<b>Catégorie</b>: ${tplData.categorie}`,
`<b>Niveau</b>: ${rddData.niveau}`, `<b>Niveau</b>: ${tplData.niveau}`,
`<b>Caractéristique par défaut</b>: ${rddData.carac_defaut}`, `<b>Caractéristique par défaut</b>: ${tplData.carac_defaut}`,
`<b>XP</b>: ${rddData.xp}` `<b>XP</b>: ${tplData.xp}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_competencecreatureChatData() { _competencecreatureChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Catégorie</b>: ${rddData.categorie}`, `<b>Catégorie</b>: ${tplData.categorie}`,
`<b>Niveau</b>: ${rddData.niveau}`, `<b>Niveau</b>: ${tplData.niveau}`,
`<b>Caractéristique</b>: ${rddData.carac_value}`, `<b>Caractéristique</b>: ${tplData.carac_value}`,
`<b>XP</b>: ${rddData.xp}` `<b>XP</b>: ${tplData.xp}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_sortChatData() { _sortChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Draconic</b>: ${rddData.draconic}`, `<b>Draconic</b>: ${tplData.draconic}`,
`<b>Difficulté</b>: ${rddData.difficulte}`, `<b>Difficulté</b>: ${tplData.difficulte}`,
`<b>Case TMR</b>: ${rddData.caseTMR}`, `<b>Case TMR</b>: ${tplData.caseTMR}`,
`<b>Points de Rêve</b>: ${rddData.ptreve}` `<b>Points de Rêve</b>: ${tplData.ptreve}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_herbeChatData() { _herbeChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Milieu</b>: ${rddData.milieu}`, `<b>Milieu</b>: ${tplData.milieu}`,
`<b>Rareté</b>: ${rddData.rarete}`, `<b>Rareté</b>: ${tplData.rarete}`,
`<b>Catégorie</b>: ${rddData.categorie}`, `<b>Catégorie</b>: ${tplData.categorie}`,
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_ingredientChatData() { _ingredientChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Milieu</b>: ${rddData.milieu}`, `<b>Milieu</b>: ${tplData.milieu}`,
`<b>Rareté</b>: ${rddData.rarete}`, `<b>Rareté</b>: ${tplData.rarete}`,
`<b>Catégorie</b>: ${rddData.categorie}`, `<b>Catégorie</b>: ${tplData.categorie}`,
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_tacheChatData() { _tacheChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Caractéristique</b>: ${rddData.carac}`, `<b>Caractéristique</b>: ${tplData.carac}`,
`<b>Compétence</b>: ${rddData.competence}`, `<b>Compétence</b>: ${tplData.competence}`,
`<b>Périodicité</b>: ${rddData.periodicite}`, `<b>Périodicité</b>: ${tplData.periodicite}`,
`<b>Fatigue</b>: ${rddData.fatigue}`, `<b>Fatigue</b>: ${tplData.fatigue}`,
`<b>Difficulté</b>: ${rddData.difficulte}`, `<b>Difficulté</b>: ${tplData.difficulte}`,
`<b>Points de Tâche</b>: ${rddData.points_de_tache}`, `<b>Points de Tâche</b>: ${tplData.points_de_tache}`,
`<b>Points de Tâche atteints</b>: ${rddData.points_de_tache_courant}` `<b>Points de Tâche atteints</b>: ${tplData.points_de_tache_courant}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_livreChatData() { _livreChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Compétence</b>: ${rddData.competence}`, `<b>Compétence</b>: ${tplData.competence}`,
`<b>Auteur</b>: ${rddData.auteur}`, `<b>Auteur</b>: ${tplData.auteur}`,
`<b>Difficulté</b>: ${rddData.difficulte}`, `<b>Difficulté</b>: ${tplData.difficulte}`,
`<b>Points de Tâche</b>: ${rddData.points_de_tache}`, `<b>Points de Tâche</b>: ${tplData.points_de_tache}`,
`<b>Encombrement</b>: ${rddData.encombrement}` `<b>Encombrement</b>: ${tplData.encombrement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_potionChatData() { _potionChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Rareté</b>: ${rddData.rarete}`, `<b>Rareté</b>: ${tplData.rarete}`,
`<b>Catégorie</b>: ${rddData.categorie}`, `<b>Catégorie</b>: ${tplData.categorie}`,
`<b>Encombrement</b>: ${rddData.encombrement}`, `<b>Encombrement</b>: ${tplData.encombrement}`,
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_queueChatData() { _queueChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Refoulement</b>: ${rddData.refoulement}` `<b>Refoulement</b>: ${tplData.refoulement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_ombreChatData() { _ombreChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Refoulement</b>: ${rddData.refoulement}` `<b>Refoulement</b>: ${tplData.refoulement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_souffleChatData() { _souffleChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = []; let properties = [];
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_teteChatData() { _teteChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = []; let properties = [];
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_tarotChatData() { _tarotChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Concept</b>: ${rddData.concept}`, `<b>Concept</b>: ${tplData.concept}`,
`<b>Aspect</b>: ${rddData.aspect}`, `<b>Aspect</b>: ${tplData.aspect}`,
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_nombreastralChatData() { _nombreastralChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Valeur</b>: ${rddData.value}`, `<b>Valeur</b>: ${tplData.value}`,
`<b>Jour</b>: ${rddData.jourlabel}`, `<b>Jour</b>: ${tplData.jourlabel}`,
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_monnaieChatData() { _monnaieChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Valeur en Deniers</b>: ${rddData.valeur_deniers}`, `<b>Valeur en Deniers</b>: ${tplData.valeur_deniers}`,
`<b>Encombrement</b>: ${rddData.encombrement}` `<b>Encombrement</b>: ${tplData.encombrement}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_meditationChatData() { _meditationChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Thème</b>: ${rddData.theme}`, `<b>Thème</b>: ${tplData.theme}`,
`<b>Compétence</b>: ${rddData.competence}`, `<b>Compétence</b>: ${tplData.competence}`,
`<b>Support</b>: ${rddData.support}`, `<b>Support</b>: ${tplData.support}`,
`<b>Heure</b>: ${rddData.heure}`, `<b>Heure</b>: ${tplData.heure}`,
`<b>Purification</b>: ${rddData.purification}`, `<b>Purification</b>: ${tplData.purification}`,
`<b>Vêture</b>: ${rddData.veture}`, `<b>Vêture</b>: ${tplData.veture}`,
`<b>Comportement</b>: ${rddData.comportement}`, `<b>Comportement</b>: ${tplData.comportement}`,
`<b>Case TMR</b>: ${rddData.tmr}` `<b>Case TMR</b>: ${tplData.tmr}`
] ]
return properties; return properties;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_casetmrChatData() { _casetmrChatData() {
const rddData = Misc.data(this).data; const tplData = Misc.templateData(this);
let properties = [ let properties = [
`<b>Coordonnée</b>: ${rddData.coord}`, `<b>Coordonnée</b>: ${tplData.coord}`,
`<b>Spécificité</b>: ${rddData.specific}` `<b>Spécificité</b>: ${tplData.specific}`
] ]
return properties; return properties;
} }

View File

@ -3,26 +3,28 @@
{{#if img}} {{#if img}}
<img src="{{img}}" title="{{name}}" /> <img src="{{img}}" title="{{name}}" />
{{/if}} {{/if}}
<div class="card-content">{{{data.description}}}</div> <p class="card-content">{{{data.description}}}</p>
<p>
{{#each properties as |property p|}} {{#each properties as |property p|}}
<span>{{{property}}}</span><br> <span>{{{property}}}</span><br>
{{/each}} {{/each}}
<div> {{#if (or postQuantity postPrice)}}
{{#if postPrice}} <span>
<b>Prix: </b> <span class="postPrice">{{postPrice}} Sols</span> {{#if postQuantity}}
{{/if}}
{{#if postQuantity}}
<b>Quantité: </b> <span class="postQuantity">{{postQuantity}}</span> <b>Quantité: </b> <span class="postQuantity">{{postQuantity}}</span>
{{/if}} {{/if}}
</div> {{#if postPrice}}
<b>Prix: </b> <span class="postPrice">{{postPrice}} Sols</span><br>
{{#if finalPrice}} {{/if}}
<div> </span>
<b>Prix Total: </b> <span class="postPrice">{{finalPrice}} Sols</span> {{/if}}
</div> {{#if finalPrice}}
{{/if}} <span>
<b>Prix Total: </b> <span class="postPrice">{{finalPrice}} Sols</span><br>
</span>
{{/if}}
</p>
{{#if hasPrice}} {{#if hasPrice}}
<span class="chat-card-button-area"> <span class="chat-card-button-area">