Market
Stock management
A shop only need a name to be created, the items are optional. To instanciate a
Shop
, use:
new gg.class.Shop({
name: 'Generic shop'
})
or instanciating with items:
May or may not be ShopItem instance
new gg.class.Shop({
name: 'Generic shop',
items: [
{
item: new gg.class.Vest({
name: 'Armet',
slotType: {name: 'helmet'},
type: gg.const.item.EQUIPABLE,
effects: [
new gg.class.Characteristic({name: gg.const.characteristic.DEFENSE, value: 1})
]
}),
price: new gg.class.Currency({
name: 'Gold',
symbol: 'G',
value: 100
})
}
]
})
stocking items
It’s possible to add more items in the shop after instanciation. Use addItem
:
const armet = new gg.class.Vest({
name: 'Armet',
slotType: {name: 'helmet'},
type: gg.const.item.EQUIPABLE,
effects: [
new gg.class.Characteristic({name: gg.const.characteristic.DEFENSE, value: 1})
]
})
const goldCurrency = new gg.class.Currency({
name: 'Gold',
symbol: 'G',
value: 100
})
shop.addItem({item: armet, price: goldCurrency})
and removing:
shop.removeItem(armet)
Once you remove all items, they vanish from shop istead having quantity equals zero
Trading
To make a character interact with shop, you can use buy
and sell
:
buying and selling
The character must have the items in inventory before selling; The character can’t sell the same instance more than twice.
hero.interact(shop).sell(someShopItemFromShop)
// <- Promise
The character must afford to buy the item; The character must be able to carry the item.
hero.interact(shop).buy(someShopItemFromShop)
// <- Promise