123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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);
- }
- };
|