best stock prices guaranteed.

pull/64/head
macniel 2025-11-02 21:00:50 +01:00
parent 8258f53a3a
commit 4be53924d8
3 changed files with 42 additions and 24 deletions

View File

@ -21,6 +21,7 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
}, },
actions: { actions: {
buy: MerchantSheet.#buyWare, buy: MerchantSheet.#buyWare,
editItem: MerchantSheet.#openEmbeddedDocument,
editImage: DocumentSheetV2.DEFAULT_OPTIONS.actions.editImage, editImage: DocumentSheetV2.DEFAULT_OPTIONS.actions.editImage,
editServiceImage: MerchantSheet.#editServiceImage, editServiceImage: MerchantSheet.#editServiceImage,
editNewServiceImage: MerchantSheet.#editNewServiceImage, editNewServiceImage: MerchantSheet.#editNewServiceImage,
@ -88,7 +89,7 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
const item = this.document.items.get(itemId) const item = this.document.items.get(itemId)
let selections = '' let selections = ''
game.actors.filter(p => p.isOwner).forEach(actor => { game.actors.filter(p => p.isOwner && p.type === "character").forEach(actor => {
selections += `<option value=${actor.id}>${actor.name}</option>` selections += `<option value=${actor.id}>${actor.name}</option>`
}) })
@ -101,31 +102,47 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
} }
}); });
const actor = game.actors.get(actorId) if (actorId) { // ignore the following when dialog was cancelled
const canBuy = await actor.reduceWealth(item.system.price) const actor = game.actors.get(actorId)
if (canBuy) { // returns false when the wealth cant be reduced sufficiently const canBuy = await actor.reduceWealth(item.system.price)
actor.createEmbeddedDocuments('Item', [item]).then(documents => { if (canBuy) { // returns false when the wealth cant be reduced sufficiently
documents[0].update({'system.quantity': 1}) 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) { if (item.system.quantity != -1) { // -1 means infinite
item.update({'system.quantity': item.system.quantity - 1}) if (item.system.quantity > 1) {
} else { item.update({'system.quantity': item.system.quantity - 1})
this.document.deleteEmbeddedDocuments('Item', [item._id]) // delete when the quantity is equal to 0 } 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) { static async #removeService(event, target) {
@ -251,6 +268,7 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
context.description = this.document.system.description context.description = this.document.system.description
context.goods = this.document.itemTypes["Equipment"] ?? [] context.goods = this.document.itemTypes["Equipment"] ?? []
context.services = this.document.system.services context.services = this.document.system.services
context.isOwner = this.document.isOwner
return context return context
} }

View File

@ -2,7 +2,7 @@
"id": "DSA_4-1", "id": "DSA_4-1",
"title": "Das Schwarze Auge 4.1", "title": "Das Schwarze Auge 4.1",
"description": "Noch ein Spielsystem für 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": { "compatibility": {
"minimum": 12, "minimum": 12,
"verified": 13 "verified": 13
@ -348,5 +348,5 @@
"primaryTokenAttribute": "lep.aktuell", "primaryTokenAttribute": "lep.aktuell",
"url": "https://git.macniel.online/macniel/foundry-dsa41-game", "url": "https://git.macniel.online/macniel/foundry-dsa41-game",
"manifest": "https://git.macniel.online/macniel/foundry-dsa41-game/raw/branch/main/src/system.json", "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"
} }

View File

@ -4,7 +4,7 @@
<div class="merchant-goods"> <div class="merchant-goods">
{{#each goods}} {{#each goods}}
<div class="merchant-good"> <div class="merchant-good" {{#if isOwner}}data-action="editItem"{{/if}} data-item-id="{{this._id}}">
<img src="{{this.img}}" style="width: 32px; height: 32px;"/> <img src="{{this.img}}" style="width: 32px; height: 32px;"/>
<span class="name">{{this.name}}</span> <span class="name">{{this.name}}</span>
<span class="price">{{currency this.system.price}}</span> <span class="price">{{currency this.system.price}}</span>