module.exports = class ZebedeeMiner1 { constructor() { this.id = 1; this.name = "a miner"; this.description = "A bearded dwarven man wearing incredibly filthy canvas coveralls. He has a large wiry beard that appears to have chips of rock embedded in it."; this.type = "mobile"; this.roomId = 1; this.idleDelay = 30000; this.filename = "zebedee/miner1.js"; this.lastIdle = 0; this.keywords = ["miner", "sir", "man", "dwarf"]; this.items = []; this.commandQueue = []; this.memory = {}; this.account = 125; this.itemSlots = {}; } mud_init(mobileName) { world.mud_addMobileToRoom("ZebedeeWestGate", this.id); world.mud_addItemToMobile(this.id, builder.mud_spawnItem("Pickaxe").id); this.mud_spawnThisMobile("ZebedeeEastGate"); } mud_spawnThisMobile(roomName) { var id = builder.mud_spawnMobile("ZebedeeMiner1").id; world.mud_addMobileToRoom(roomName, id); world.mud_addItemToMobile(id, builder.mud_spawnItem("Pickaxe").id); } mud_sendMessage(source, message) { message = message.replace(/\{.*?\}/g, ""); var cleanMessage = message.trim(); if(source == this) { return; } if(cleanMessage.indexOf("shout") != -1) { return; } if(libs.Conversation.basicDecency(source, cleanMessage, this)) { return; } if(cleanMessage.indexOf("don't find anything") != -1) { this.mud_addCommand(this, "emote grumbles."); var exits = libs.Conversation.getRoomExits(this); var exit = exits[parseInt(Math.random() * exits.length)]; this.mud_addCommand(this, exit); } /*if(libs.Conversation.followsOrders(source, cleanMessage, this)) { return; }*/ } mud_addMemory(section, newMemory) { if(!this.memory.hasOwnProperty(section)) { this.memory[section] = []; } if(!this.mud_checkMemory(section, newMemory)) { this.memory[section].push(newMemory); } } mud_checkMemory(section, memoryToCheck) { if(this.memory.hasOwnProperty(section)) { if(this.memory[section].indexOf(memoryToCheck) != -1) { return true; } } return false; } mud_addCommand(source, message) { this.commandQueue.push(message); } mud_reset(time) { if(this.mud_hasItem("pickaxe") && !this.mud_hasEquipped("pickaxe")) { this.mud_addCommand(this, "hold pickaxe"); } var idleMessages = ["emote wipes some sweat from his brow.", "emote grumbles to himself as he walks.", "emote strokes his beard and pulls out a chip of stone.", "emote adjusts his coveralls.", "mine" ]; idleMessages = idleMessages.concat(libs.Conversation.getRoomExits(this)); var randomIdle = idleMessages[parseInt(Math.random() * idleMessages.length)]; this.mud_addCommand(this, randomIdle); this.lastIdle = time + this.idleDelay; } mud_tick(time) { if(this.commandQueue.length <= 0 && this.roomId == "ZebedeeShop") { if(this.mud_hasItem("stone")) { this.mud_addCommand(this, "sell stone"); return; } if(this.mud_hasItem("coal")) { this.mud_addCommand(this, "sell coal"); return; } if(this.mud_hasItem("diamond")) { this.mud_addCommand(this, "haggle diamond"); this.mud_addCommand(this, "sell diamond"); return; } if(!this.mud_hasItem("pickaxe")) { this.mud_addCommand(this, "say I'd like to buy a pickaxe, shopkeep."); this.mud_addCommand(this, "haggle pickaxe"); this.mud_addCommand(this, "buy pickaxe"); this.mud_addCommand(this, "hold pickaxe"); return; } } if(this.commandQueue.length <= 0 && this.roomId == "Mine1") { this.mud_addCommand(this, "mine"); return; } if(time >= this.lastIdle) { this.mud_reset(time); } if(this.commandQueue.length > 0 ) { world.mud_handleInput(this.roomId, this.id, this.commandQueue.shift().split(" ")); this.lastIdle = time + this.idleDelay; } } mud_hasItem(itemName) { var inventoryItem = libs.Utilities.getSpecific(itemName, this.items, session.items); if(inventoryItem != null) { return true; } return false; } mud_getName() { return "{mobile}" + this.name + "{/mobile}"; } mud_getDescription() { return this.description; } mud_wearInSlot(itemId, slot) { if(this.itemSlots.hasOwnProperty(slot) && this.itemSlots[slot] != null) { return this.itemSlots[slot]; } this.itemSlots[slot] = itemId; } mud_removeSlot(slot) { if(!this.itemSlots.hasOwnProperty(slot) || this.itemSlots[slot] == null) { return false; } this.itemSlots[slot] = null; } mud_hasEquipped(itemName) { for(var index in this.itemSlots) { var slot = this.itemSlots[index]; if(slot != null) { if(world.mud_getItem(slot).constructor.name == itemName) { return true; } } } if(Object.keys(this.itemSlots).length > 0) { var inventoryItem = libs.Utilities.getSpecific(itemName, Object.values(this.itemSlots), session.items); if(inventoryItem != null) { return true; } } return false; } mud_addCurrency(amount) { this.account += amount; } mud_removeCurrency(amount) { this.account -= amount; this.account = Math.max(0, this.account); } };