module.exports = class ZebedeeShop { constructor() { this.id = this.constructor.name; this.name = "Zebedee Shop"; this.description = "Various display cases line the walls to the east and west, full of assorted adventurer trinkets and equipment. A line of registers sit on counters to the north, and above them is an enchanted board showing the {hint}list{/hint} of items for sale."; this.filename = "zebedee/shop.js"; this.type = "room"; this.items = []; this.mobiles = []; this.roomExpires = 0; this.resetDelay = 6000000; this.roomExits = ["south"]; this.shopInventory = []; this.shopAccount = 25000; this.shopMargin = 40; this.haggledItem = {}; } mud_reset(time) { libs.Output.toRoom(this.id, "A register clacks and dings as it tallies some amount."); while(this.shopInventory.length > 24) { var consumedItemId = this.shopInventory.shift(); var consumedItem = world.mud_getItem(consumedItemId); this.shopAccount += parseInt(consumedItem.value) || 0; world.mud_destroyItem(consumedItemId); } var pickaxe = builder.mud_spawnItem("Pickaxe"); this.shopInventory.push(pickaxe.id); this.roomExpires = time + this.resetDelay; } mud_tick(time) { if(time >= this.roomExpires) { this.mud_reset(time); } } mud_getName() { return this.name; } mud_getDescription() { return this.description; } south(room, mobile, input) { world.mud_moveMobile(mobile.id, this.id, "ZebedeeCormallenRoad4", "leaves south"); return true; } list(room, mobile, input) { var inventory = libs.ShopLogic.getListOfInventory(this, mobile); if(inventory.length <= 0) { libs.Output.toMobile(mobile.id, "The shop is out of things to sell."); return true; } for(var index in inventory) { var item = inventory[index]; libs.Output.toMobile(mobile.id, item.name + " - $" + item.value); } return true; } sell(room, mobile, input) { if(input.join(" ") == null) { return false; } var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem == null) { libs.Output.toMobile(mobile.id, "You don't seem to have '" + input.join(" ") + "'."); return true; } if(!libs.ShopLogic.canSell(this, mobile, inventoryItem)) { libs.Output.toMobile(mobile.id, "The shop can't buy that."); return true; } var salePrice = libs.ShopLogic.sellItemToShop(this, mobile, inventoryItem); libs.Output.toMobile(mobile.id, "You sell " + inventoryItem.mud_getName() + " for $" + salePrice + "."); libs.Output.toRoom(this.id, mobile.mud_getName() + " sells " + inventoryItem.mud_getName() + " to the shop.", mobile); return true; } value(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem == null) { libs.Output.toMobile(mobile.id, "You don't seem to have '" + input.join(" ") + "'."); return true; } var itemValue = libs.ShopLogic.shopBuysFor(this, mobile, inventoryItem); libs.Output.toMobile(mobile.id, "You would get $" +itemValue + " for " + inventoryItem.mud_getName() + "."); return true; } info(room, mobile, input) { var shopItem = libs.Utilities.getSpecific(input.join(" "), this.shopInventory, session.items); if(shopItem == null) { libs.Output.toMobile(mobile.id, "The shop doesn't seem to have '" + input.join(" ") + "'."); return true; } libs.Output.toMobile(mobile.id, shopItem.mud_getDescription()); return true; } buy(room, mobile, input) { if(input.join(" ") == null) { return false; } var shopItem = libs.Utilities.getSpecific(input.join(" "), this.shopInventory, session.items); if(shopItem == null) { libs.Output.toMobile(mobile.id, "The shop doesn't seem to have '" + input.join(" ") + "'."); return true; } if(!libs.ShopLogic.canBuy(this, mobile, shopItem)) { libs.Output.toMobile(mobile.id, "You can't afford that."); return true; } var purchasePrice = libs.ShopLogic.buyItemFromShop(this, mobile, shopItem); libs.Output.toMobile(mobile.id, "You buy " + shopItem.mud_getName() + " for $" + purchasePrice + "."); libs.Output.toRoom(this.id, mobile.mud_getName() + " buys "+shopItem.mud_getName()+" from the shop.", mobile); return true; } mud_addItemToInventory(itemId) { this.shopInventory.push(itemId); } mud_removeItemFromInventory(itemId) { this.shopInventory.splice(this.shopInventory.indexOf(itemId), 1); } mud_addCurrency(amount) { this.shopAccount += amount; } mud_removeCurrency(amount) { this.shopAccount -= amount; this.shopAccount = Math.max(0, this.shopAccount); } haggle(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem != null) { libs.ShopLogic.trackHaggle(this, mobile, inventoryItem); libs.Output.toMobile(mobile.id, "You artfully negotiate with the shop clerk about the price of " + inventoryItem.mud_getName() + "."); libs.Output.toRoom(room.id, mobile.mud_getName() + " yells incoherently at the shop clerk until they agree to a better price.", mobile); return true; } var shopItem = libs.Utilities.getSpecific(input.join(" "), this.shopInventory, session.items); if(shopItem != null) { libs.ShopLogic.trackHaggle(this, mobile, shopItem); libs.Output.toMobile(mobile.id, "You artfully negotiate with the shop clerk about the price of " + shopItem.mud_getName() + "."); libs.Output.toRoom(room.id, mobile.mud_getName() + " yells incoherently at the shop clerk until they agree to a better price.", mobile); return true; } } };