enables selling of goods
parent
95712704b5
commit
1d714a3773
117
src/main.mjs
117
src/main.mjs
|
|
@ -54,6 +54,63 @@ async function preloadHandlebarsTemplates() {
|
||||||
|
|
||||||
Hooks.once("init", () => {
|
Hooks.once("init", () => {
|
||||||
|
|
||||||
|
const displayCurrency = (data) => {
|
||||||
|
|
||||||
|
|
||||||
|
// schema for Mittelreich: 1 Ducat = 10 Silver = 100 Kreutzer = 1000 Heller
|
||||||
|
// internally the price is always given in Silver
|
||||||
|
// so we need to inflate the value of price by 100 to be able to divide beginning from Heller
|
||||||
|
|
||||||
|
const baseValue = data * 100
|
||||||
|
|
||||||
|
// then we can regex over it
|
||||||
|
|
||||||
|
const currencyRegexp = /(.*)(.)(.)(.)/g
|
||||||
|
const withDucats = currencyRegexp.exec(baseValue)
|
||||||
|
let _ = undefined
|
||||||
|
let ducats = 0
|
||||||
|
let silver = 0
|
||||||
|
let kreutzer = 0
|
||||||
|
let heller = 0
|
||||||
|
|
||||||
|
if (withDucats) {
|
||||||
|
[_, ducats, silver, kreutzer, heller] = withDucats
|
||||||
|
} else {
|
||||||
|
const currencyRegexp = /(.)(.)(.)/g
|
||||||
|
const withSilver = currencyRegexp.exec(baseValue)
|
||||||
|
if (withSilver) {
|
||||||
|
[_, silver, kreutzer, heller] = withSilver
|
||||||
|
} else {
|
||||||
|
const currencyRegexp = /(.)(.)/g
|
||||||
|
const withKreutzer = currencyRegexp.exec(baseValue)
|
||||||
|
|
||||||
|
if (withKreutzer) {
|
||||||
|
[_, kreutzer, heller] = withKreutzer
|
||||||
|
|
||||||
|
} else {
|
||||||
|
heller = baseValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let str = `<span class='coins' data-tooltip="${ducats > 0 ? ducats + ' Dukaten ' : ''}${silver > 0 ? silver + ' Silbertaler ' : ''}${kreutzer > 0 ? kreutzer + ' Kreuzer ' : ''}${heller > 0 ? heller + ' Heller' : ''}">`
|
||||||
|
if (ducats > 0) {
|
||||||
|
str += ducats + "<i class='symbol ducat'></i>"
|
||||||
|
}
|
||||||
|
if (silver > 0) {
|
||||||
|
str += silver + "<i class='symbol silver'></i>"
|
||||||
|
}
|
||||||
|
if (kreutzer > 0) {
|
||||||
|
str += kreutzer + "<i class='symbol kreutzer'></i>"
|
||||||
|
}
|
||||||
|
if (heller > 0) {
|
||||||
|
str += heller + "<i class='symbol heller'></i>"
|
||||||
|
}
|
||||||
|
str = str + "</span>"
|
||||||
|
|
||||||
|
return new Handlebars.SafeString(str)
|
||||||
|
}
|
||||||
|
|
||||||
game.DSA41 = {
|
game.DSA41 = {
|
||||||
rollItemMacro,
|
rollItemMacro,
|
||||||
Zonenruestung,
|
Zonenruestung,
|
||||||
|
|
@ -62,7 +119,8 @@ Hooks.once("init", () => {
|
||||||
Wunde,
|
Wunde,
|
||||||
RestingDialog,
|
RestingDialog,
|
||||||
BattleDialog,
|
BattleDialog,
|
||||||
Talent
|
Talent,
|
||||||
|
displayCurrency
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure custom Document implementations.
|
// Configure custom Document implementations.
|
||||||
|
|
@ -331,62 +389,7 @@ Hooks.once("init", () => {
|
||||||
return new Handlebars.SafeString(tooltip)
|
return new Handlebars.SafeString(tooltip)
|
||||||
})
|
})
|
||||||
|
|
||||||
Handlebars.registerHelper("currency", (data) => {
|
Handlebars.registerHelper("currency", game.DSA41.displayCurrency)
|
||||||
|
|
||||||
|
|
||||||
// schema for Mittelreich: 1 Ducat = 10 Silver = 100 Kreutzer = 1000 Heller
|
|
||||||
// internally the price is always given in Silver
|
|
||||||
// so we need to inflate the value of price by 100 to be able to divide beginning from Heller
|
|
||||||
|
|
||||||
const baseValue = data * 100
|
|
||||||
|
|
||||||
// then we can regex over it
|
|
||||||
|
|
||||||
const currencyRegexp = /(.*)(.)(.)(.)/g
|
|
||||||
const withDucats = currencyRegexp.exec(baseValue)
|
|
||||||
let _ = undefined
|
|
||||||
let ducats = 0
|
|
||||||
let silver = 0
|
|
||||||
let kreutzer = 0
|
|
||||||
let heller = 0
|
|
||||||
|
|
||||||
if (withDucats) {
|
|
||||||
[_, ducats, silver, kreutzer, heller] = withDucats
|
|
||||||
} else {
|
|
||||||
const currencyRegexp = /(.)(.)(.)/g
|
|
||||||
const withSilver = currencyRegexp.exec(baseValue)
|
|
||||||
if (withSilver) {
|
|
||||||
[_, silver, kreutzer, heller] = withSilver
|
|
||||||
} else {
|
|
||||||
const currencyRegexp = /(.)(.)/g
|
|
||||||
const withKreutzer = currencyRegexp.exec(baseValue)
|
|
||||||
|
|
||||||
if (withKreutzer) {
|
|
||||||
[_, kreutzer, heller] = withKreutzer
|
|
||||||
|
|
||||||
} else {
|
|
||||||
heller = baseValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let str = `<span class='coins' data-tooltip="${ducats > 0 ? ducats + ' Dukaten ' : ''}${silver > 0 ? silver + ' Silbertaler ' : ''}${kreutzer > 0 ? kreutzer + ' Kreuzer ' : ''}${heller > 0 ? heller + ' Heller' : ''}">`
|
|
||||||
if (ducats > 0) {
|
|
||||||
str += ducats + "<i class='symbol ducat'></i>"
|
|
||||||
}
|
|
||||||
if (silver > 0) {
|
|
||||||
str += silver + "<i class='symbol silver'></i>"
|
|
||||||
}
|
|
||||||
if (kreutzer > 0) {
|
|
||||||
str += kreutzer + "<i class='symbol kreutzer'></i>"
|
|
||||||
}
|
|
||||||
if (heller > 0) {
|
|
||||||
str += heller + "<i class='symbol heller'></i>"
|
|
||||||
}
|
|
||||||
str = str + "</span>"
|
|
||||||
|
|
||||||
return new Handlebars.SafeString(str)
|
|
||||||
})
|
|
||||||
|
|
||||||
return preloadHandlebarsTemplates();
|
return preloadHandlebarsTemplates();
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -310,6 +310,11 @@ export class Character extends Actor {
|
||||||
return updateObject;
|
return updateObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reduceWealth(by) {
|
||||||
|
console.log('Reichtum reduziert um ', by)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
isWorn(itemId) {
|
isWorn(itemId) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
resizable: true,
|
resizable: true,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
buy: MerchantSheet.#buyWare,
|
||||||
editImage: DocumentSheetV2.DEFAULT_OPTIONS.actions.editImage,
|
editImage: DocumentSheetV2.DEFAULT_OPTIONS.actions.editImage,
|
||||||
editServiceImage: MerchantSheet.#editServiceImage,
|
editServiceImage: MerchantSheet.#editServiceImage,
|
||||||
editNewServiceImage: MerchantSheet.#editNewServiceImage,
|
editNewServiceImage: MerchantSheet.#editNewServiceImage,
|
||||||
|
|
@ -81,6 +82,50 @@ export class MerchantSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
await this.document.update(formData.object) // Note: formData.object
|
await this.document.update(formData.object) // Note: formData.object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async #buyWare(event, target) {
|
||||||
|
|
||||||
|
const {itemId} = target.dataset
|
||||||
|
const item = this.document.items.get(itemId)
|
||||||
|
|
||||||
|
let selections = ''
|
||||||
|
game.actors.filter(p => p.isOwner).forEach(actor => {
|
||||||
|
selections += `<option value=${actor.id}>${actor.name}</option>`
|
||||||
|
})
|
||||||
|
|
||||||
|
const actorId = await foundry.applications.api.DialogV2.prompt({
|
||||||
|
window: {title: `${item.name} kaufen mit wem?`},
|
||||||
|
content: `<select name="actor">${selections}</select>`,
|
||||||
|
ok: {
|
||||||
|
label: `Kaufen`,
|
||||||
|
callback: (event, button, dialog) => button.form.elements.actor.value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const actor = game.actors.get(actorId)
|
||||||
|
|
||||||
|
|
||||||
|
let wealth = 0
|
||||||
|
|
||||||
|
actor.itemTypes["Equipment"].forEach(coin => {
|
||||||
|
if (coin.system.category.indexOf("Währung") !== -1) {
|
||||||
|
wealth += (coin.system.quantity * coin.system.currencyDenominator)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (wealth >= item.system.price) {
|
||||||
|
|
||||||
|
actor.reduceWealth(item.system.price)
|
||||||
|
actor.createEmbeddedDocuments('Item', [item])
|
||||||
|
this.document.deleteEmbeddedDocuments('Item', [item._id])
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ui.notifications.error(item.name + " ist zu teuer für " + actor.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(actorId)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static async #removeService(event, target) {
|
static async #removeService(event, target) {
|
||||||
const {rowId} = target.dataset;
|
const {rowId} = target.dataset;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<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>
|
||||||
<button><i class="fa-solid fa-coins"></i></button>
|
<button data-action="buy" data-item-id="{{this._id}}"><i class="fa-solid fa-coins"></i></button>
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue