diff --git a/module/actor-creature-sheet.js b/module/actor-creature-sheet.js index 218ba08f..215731aa 100644 --- a/module/actor-creature-sheet.js +++ b/module/actor-creature-sheet.js @@ -56,15 +56,15 @@ export class RdDActorCreatureSheet extends RdDActorSheet { if (!this.options.editable) return; // On competence change - html.find('.creature-carac').change((event) => { + html.find('.creature-carac').change(async event => { let compName = event.currentTarget.attributes.compname.value; this.actor.updateCreatureCompetence(compName, "carac_value", parseInt(event.target.value)); }); - html.find('.creature-niveau').change((event) => { + html.find('.creature-niveau').change(async event => { let compName = event.currentTarget.attributes.compname.value; this.actor.updateCreatureCompetence(compName, "niveau", parseInt(event.target.value)); }); - html.find('.creature-dommages').change((event) => { + html.find('.creature-dommages').change(async event => { let compName = event.currentTarget.attributes.compname.value; this.actor.updateCreatureCompetence(compName, "dommages", parseInt(event.target.value)); }); diff --git a/module/actor-entite-sheet.js b/module/actor-entite-sheet.js index aa836cbf..eabaf828 100644 --- a/module/actor-entite-sheet.js +++ b/module/actor-entite-sheet.js @@ -69,59 +69,59 @@ export class RdDActorEntiteSheet extends ActorSheet { if (!this.options.editable) return; // Update Inventory Item - html.find('.item-edit').click(ev => { - const li = $(ev.currentTarget).parents(".item"); + html.find('.item-edit').click(event => { + const li = $(event.currentTarget).parents(".item"); const item = this.actor.getEmbeddedDocument('Item', li.data("itemId")); item.sheet.render(true); }); // Delete Inventory Item - html.find('.item-delete').click(ev => { - const li = $(ev.currentTarget).parents(".item"); + html.find('.item-delete').click(event => { + const li = $(event.currentTarget).parents(".item"); this.actor.deleteEmbeddedDocuments('Item', [li.data("itemId")]); li.slideUp(200, () => this.render(false)); }); // Roll Carac - html.find('.carac-label a').click((event) => { + html.find('.carac-label a').click(async event => { let caracName = event.currentTarget.attributes.name.value; this.actor.rollCarac( caracName.toLowerCase() ); }); // On competence change - html.find('.creature-carac').change((event) => { + html.find('.creature-carac').change(async event => { let compName = event.currentTarget.attributes.compname.value; this.actor.updateCreatureCompetence( compName, "carac_value", parseInt(event.target.value) ); } ); - html.find('.creature-niveau').change((event) => { + html.find('.creature-niveau').change(async event => { let compName = event.currentTarget.attributes.compname.value; this.actor.updateCreatureCompetence( compName, "niveau", parseInt(event.target.value) ); } ); - html.find('.creature-dommages').change((event) => { + html.find('.creature-dommages').change(async event => { let compName = event.currentTarget.attributes.compname.value; this.actor.updateCreatureCompetence( compName, "dommages", parseInt(event.target.value) ); } ); // Roll Skill - html.find('.competence-label a').click((event) => { + html.find('.competence-label a').click(async event => { let compName = event.currentTarget.text; this.actor.rollCompetence( compName ); }); - html.find('.endurance-plus').click((event) => { + html.find('.endurance-plus').click(event => { this.actor.santeIncDec("endurance", 1); this.render(true); }); - html.find('.endurance-moins').click((event) => { + html.find('.endurance-moins').click(event => { this.actor.santeIncDec("endurance", -1); this.render(true); }); - html.find('.encaisser-direct').click(ev => { + html.find('.encaisser-direct').click(event => { this.actor.encaisser(); }); - html.find('.remise-a-neuf').click(ev => { + html.find('.remise-a-neuf').click(event => { if (game.user.isGM) { this.actor.remiseANeuf(); } diff --git a/module/actor-sheet.js b/module/actor-sheet.js index e5ac0586..808b1c70 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -188,6 +188,11 @@ export class RdDActorSheet extends ActorSheet { const item = RdDSheetUtility.getItem(event, this.actor); item?.proposerVente(); }); + html.find('.item-montrer').click(async event => { + const item = RdDSheetUtility.getItem(event, this.actor); + item?.postItem(); + }); + html.find('.item-action').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor); this.actor.actionItem(item); diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js index 8b2f6096..4ae2356c 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor-vehicule-sheet.js @@ -103,12 +103,12 @@ export class RdDActorVehiculeSheet extends ActorSheet { if (!this.options.editable) return; // Update Inventory Item - html.find('.item-edit').click(ev => { + html.find('.item-edit').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor); item.sheet.render(true); }); // Delete Inventory Item - html.find('.item-delete').click(ev => { + html.find('.item-delete').click(async event => { const li = RdDSheetUtility.getEventElement(event); RdDUtility.confirmerSuppression(this, li); }); diff --git a/module/actor.js b/module/actor.js index 1aaebd46..e786e985 100644 --- a/module/actor.js +++ b/module/actor.js @@ -936,15 +936,15 @@ export class RdDActor extends Actor { return; } const xpUtilise = Math.min(stressTransforme, xpRequis); - const stressTransformeRestant = Math.max(0, stressTransforme - xpUtilise); const gainNiveau = xpUtilise >= xpRequis ? 1 : 0; - - await this.update({ "data.compteurs.experience.value": stressTransformeRestant }); const nouveauNiveau = niveau + gainNiveau; + const nouveauXp = gainNiveau > 0 ? Math.max(compData.data.xp - xpRequis, 0) : (compData.data.xp + xpUtilise); await competence.update({ - "data.xp": Math.max(compData.data.xp - xpRequis, 0), + "data.xp": nouveauXp, "data.niveau": nouveauNiveau, }); + const stressTransformeRestant = Math.max(0, stressTransforme - xpUtilise); + await this.update({ "data.compteurs.experience.value": stressTransformeRestant }); this.updateExperienceLog('Dépense stress', xpUtilise, `Stress en ${competence.name} ${gainNiveau ? "pour passer à " + nouveauNiveau : ""}`); } @@ -3711,7 +3711,7 @@ export class RdDActor extends Actor { } const itemVendu = Misc.data(vendeur?.getObjet(itemId)); if (itemVendu) { - if (isItemEmpilable ? itemVendu.data.quantite < achat.quantiteTotal : achat.choix.nombreLots != 1) { + if (isItemEmpilable ? (itemVendu.data.quantite < achat.quantiteTotal) : (achat.choix.nombreLots != 1)) { await acheteur?.ajouterDeniers(coutDeniers); ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a plus assez de ${vente.item.name} !`); return; diff --git a/module/dialog-item-vente.js b/module/dialog-item-vente.js index a0a5dcf4..b0802171 100644 --- a/module/dialog-item-vente.js +++ b/module/dialog-item-vente.js @@ -5,6 +5,7 @@ export class DialogItemVente extends Dialog { static async create(item, callback) { const itemData = Misc.data(item); + const quantite = item.isConteneur() ? 1 : itemData.data.quantite; const venteData = { item: itemData, alias: item.actor?.name ?? game.user.name, @@ -13,9 +14,9 @@ export class DialogItemVente extends Dialog { prixUnitaire: itemData.data.cout, prixLot: itemData.data.cout, tailleLot: 1, - quantiteNbLots: itemData.data.quantite, - quantiteMaxLots: itemData.data.quantite, - quantiteMax: itemData.data.quantite, + quantiteNbLots: quantite, + quantiteMaxLots: quantite, + quantiteMax: quantite , quantiteIllimite: !item.isOwned, isOwned: item.isOwned, }; diff --git a/module/item-sheet.js b/module/item-sheet.js index 2863e30c..204fa00b 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -30,23 +30,20 @@ export class RdDItemSheet extends ItemSheet { /* -------------------------------------------- */ _getHeaderButtons() { let buttons = super._getHeaderButtons(); - const videSiConteneur = this.object.isConteneur() ? this.object.isVide() : true; // 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! - if ("cout" in Misc.templateData(this.object) && videSiConteneur) { + if ("cout" in Misc.templateData(this.object) && this.object.isVideOuNonConteneur()) { buttons.unshift({ - class: "post", + class: "vendre", icon: "fas fa-comments-dollar", onclick: ev => this.item.proposerVente() }); } - else { - buttons.unshift({ - class: "post", - icon: "fas fa-comment", - onclick: ev => this.item.postItem() - }); - } + buttons.unshift({ + class: "montrer", + icon: "fas fa-comment", + onclick: ev => this.item.postItem() + }); return buttons } @@ -203,6 +200,10 @@ export class RdDItemSheet extends ItemSheet { const item = RdDSheetUtility.getItem(event, this.actor); item?.proposerVente(); }); + html.find('.item-montrer').click(async event => { + const item = RdDSheetUtility.getItem(event, this.actor); + item?.postItem(); + }); html.find('.item-action').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor); this.actor.actionItem(item, async () => itemSheetDialog.render(true)); diff --git a/module/item.js b/module/item.js index 679f21b6..23bfb441 100644 --- a/module/item.js +++ b/module/item.js @@ -63,8 +63,16 @@ export class RdDItem extends Item { return Misc.data(this).type == 'conteneur'; } - isVide() { - return this.isConteneur() && (Misc.templateData(this).contenu ?? []).length == 0; + isConteneurNonVide() { + return this.isConteneur() && (Misc.templateData(this).contenu?.length ?? 0) > 0; + } + + isConteneurVide() { + return this.isConteneur() && (Misc.templateData(this).contenu?.length ?? 0) == 0; + } + + isVideOuNonConteneur() { + return !this.isConteneur() || (Misc.templateData(this).contenu?.length ?? 0) == 0; } isAlcool() { @@ -143,7 +151,7 @@ export class RdDItem extends Item { getActionPrincipale(options = { warnIfNot: true }) { const itemData = Misc.data(this); - if (itemData.type != 'conteneur' && (itemData.data.quantite ?? 0) <= 0) { + if (!this.isConteneur() && (itemData.data.quantite ?? 0) <= 0) { if (options.warnIfNot) { ui.notifications.warn(`Vous n'avez plus de ${itemData.name}.`); } @@ -217,6 +225,10 @@ export class RdDItem extends Item { async proposerVente() { console.log(this); + if (this.isConteneurNonVide()) { + ui.notifications.warn(`Votre ${this.name} n'est pas vide, pas possible de le donner ou le vendre`); + return; + } const dialog = await DialogItemVente.create(this, (vente) => this._onProposerVente(vente)) dialog.render(true); } @@ -250,70 +262,6 @@ export class RdDItem extends Item { if (this.actor) { chatData.actor = { id: this.actor.id }; } - //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) { - chatData.data.cout_deniers = Math.floor(chatData.data.cout * 100); - dialogResult = await new Promise((resolve, reject) => { - new Dialog({ - content: - `
Modifier la quantité?
-Modifier la prix?
-