From 4be53924d83dbf353647eb6778a8c9e39ab5014d Mon Sep 17 00:00:00 2001 From: macniel Date: Sun, 2 Nov 2025 21:00:50 +0100 Subject: [PATCH] best stock prices guaranteed. --- src/module/sheets/merchantSheet.mjs | 60 ++++++++++++++-------- src/system.json | 4 +- src/templates/actor/merchant/tab-goods.hbs | 2 +- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/module/sheets/merchantSheet.mjs b/src/module/sheets/merchantSheet.mjs index 15066116..49f96b84 100644 --- a/src/module/sheets/merchantSheet.mjs +++ b/src/module/sheets/merchantSheet.mjs @@ -21,6 +21,7 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) { }, actions: { buy: MerchantSheet.#buyWare, + editItem: MerchantSheet.#openEmbeddedDocument, editImage: DocumentSheetV2.DEFAULT_OPTIONS.actions.editImage, editServiceImage: MerchantSheet.#editServiceImage, editNewServiceImage: MerchantSheet.#editNewServiceImage, @@ -88,7 +89,7 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) { const item = this.document.items.get(itemId) let selections = '' - game.actors.filter(p => p.isOwner).forEach(actor => { + game.actors.filter(p => p.isOwner && p.type === "character").forEach(actor => { selections += `` }) @@ -101,31 +102,47 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) { } }); - const actor = game.actors.get(actorId) - const canBuy = await actor.reduceWealth(item.system.price) - if (canBuy) { // returns false when the wealth cant be reduced sufficiently - actor.createEmbeddedDocuments('Item', [item]).then(documents => { - documents[0].update({'system.quantity': 1}) - }) - if (item.system.quantity != -1) { // -1 means infinite - if (item.system.quantity > 1) { - item.update({'system.quantity': item.system.quantity - 1}) - } else { - this.document.deleteEmbeddedDocuments('Item', [item._id]) // delete when the quantity is equal to 0 + if (actorId) { // ignore the following when dialog was cancelled + const actor = game.actors.get(actorId) + const canBuy = await actor.reduceWealth(item.system.price) + if (canBuy) { // returns false when the wealth cant be reduced sufficiently + actor.createEmbeddedDocuments('Item', [item]).then(documents => { + documents[0].update({'system.quantity': 1}) + }) + if (item.system.quantity != -1) { // -1 means infinite + if (item.system.quantity > 1) { + item.update({'system.quantity': item.system.quantity - 1}) + } else { + this.document.deleteEmbeddedDocuments('Item', [item._id]) // delete when the quantity is equal to 0 + } } + ChatMessage.create({ + user: game.user._id, + speaker: {actor}, + content: `hat ${item.name} für ${game.DSA41.displayCurrency(item.system.price)} gekauft`, + type: CONST.CHAT_MESSAGE_TYPES.IC + }) + } else { + ui.notifications.error(item.name + " ist zu teuer für " + actor.name) } - ChatMessage.create({ - user: game.user._id, - speaker: {actor}, - content: `hat ${item.name} für ${game.DSA41.displayCurrency(item.system.price)} gekauft`, - type: CONST.CHAT_MESSAGE_TYPES.IC - }) - } else { - ui.notifications.error(item.name + " ist zu teuer für " + actor.name) } - console.log(actorId) + } + /** + * + * @param {MouseEvent} event + */ + static #openEmbeddedDocument(event) { + let dataset = event.target.dataset + if (!dataset.itemId && !dataset.id) { + dataset = event.target.parentElement.dataset + } + const id = dataset.itemId ?? dataset.id + + if (this.document.isOwner) { // only shop owner can change stock and price + this.document.items.get(id).sheet.render(true) + } } static async #removeService(event, target) { @@ -251,6 +268,7 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) { context.description = this.document.system.description context.goods = this.document.itemTypes["Equipment"] ?? [] context.services = this.document.system.services + context.isOwner = this.document.isOwner return context } diff --git a/src/system.json b/src/system.json index 1bf03dbb..325b58e2 100644 --- a/src/system.json +++ b/src/system.json @@ -2,7 +2,7 @@ "id": "DSA_4-1", "title": "Das Schwarze Auge 4.1", "description": "Noch ein Spielsystem für Das Schwarze Auge 4.1", - "version": "0.4.0-rc4", + "version": "0.0.1", "compatibility": { "minimum": 12, "verified": 13 @@ -348,5 +348,5 @@ "primaryTokenAttribute": "lep.aktuell", "url": "https://git.macniel.online/macniel/foundry-dsa41-game", "manifest": "https://git.macniel.online/macniel/foundry-dsa41-game/raw/branch/main/src/system.json", - "download": "https://git.macniel.online/macniel/foundry-dsa41-game/releases/download/0.4.0-rc4/release.zip" + "download": "https://git.macniel.online/macniel/foundry-dsa41-game/releases/download/0.0.1/release.zip" } diff --git a/src/templates/actor/merchant/tab-goods.hbs b/src/templates/actor/merchant/tab-goods.hbs index 445bd6a2..ab61828f 100644 --- a/src/templates/actor/merchant/tab-goods.hbs +++ b/src/templates/actor/merchant/tab-goods.hbs @@ -4,7 +4,7 @@
{{#each goods}} -
+
{{this.name}} {{currency this.system.price}}