miner1.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. module.exports = class ZebedeeMiner1 {
  2. constructor() {
  3. this.id = 1;
  4. this.name = "a miner";
  5. 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.";
  6. this.type = "mobile";
  7. this.roomId = 1;
  8. this.idleDelay = 30000;
  9. this.filename = "zebedee/miner1.js";
  10. this.lastIdle = 0;
  11. this.keywords = ["miner", "sir", "man", "dwarf"];
  12. this.items = [];
  13. this.commandQueue = [];
  14. this.memory = {};
  15. this.account = 125;
  16. this.itemSlots = {};
  17. }
  18. mud_init(mobileName) {
  19. world.mud_addMobileToRoom("ZebedeeWestGate", this.id);
  20. world.mud_addItemToMobile(this.id, builder.mud_spawnItem("Pickaxe").id);
  21. this.mud_spawnThisMobile("ZebedeeEastGate");
  22. }
  23. mud_spawnThisMobile(roomName) {
  24. var id = builder.mud_spawnMobile("ZebedeeMiner1").id;
  25. world.mud_addMobileToRoom(roomName, id);
  26. world.mud_addItemToMobile(id, builder.mud_spawnItem("Pickaxe").id);
  27. }
  28. mud_sendMessage(source, message) {
  29. message = message.replace(/\{.*?\}/g, "");
  30. var cleanMessage = message.trim();
  31. if(source == this) {
  32. return;
  33. }
  34. if(cleanMessage.indexOf("shout") != -1) {
  35. return;
  36. }
  37. if(libs.Conversation.basicDecency(source, cleanMessage, this)) {
  38. return;
  39. }
  40. if(cleanMessage.indexOf("don't find anything") != -1) {
  41. this.mud_addCommand(this, "emote grumbles.");
  42. var exits = libs.Conversation.getRoomExits(this);
  43. var exit = exits[parseInt(Math.random() * exits.length)];
  44. this.mud_addCommand(this, exit);
  45. }
  46. /*if(libs.Conversation.followsOrders(source, cleanMessage, this)) {
  47. return;
  48. }*/
  49. }
  50. mud_addMemory(section, newMemory) {
  51. if(!this.memory.hasOwnProperty(section)) {
  52. this.memory[section] = [];
  53. }
  54. if(!this.mud_checkMemory(section, newMemory)) {
  55. this.memory[section].push(newMemory);
  56. }
  57. }
  58. mud_checkMemory(section, memoryToCheck) {
  59. if(this.memory.hasOwnProperty(section)) {
  60. if(this.memory[section].indexOf(memoryToCheck) != -1) {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. mud_addCommand(source, message) {
  67. this.commandQueue.push(message);
  68. }
  69. mud_reset(time) {
  70. if(this.mud_hasItem("pickaxe") && !this.mud_hasEquipped("pickaxe")) {
  71. this.mud_addCommand(this, "hold pickaxe");
  72. }
  73. var idleMessages = ["emote wipes some sweat from his brow.",
  74. "emote grumbles to himself as he walks.",
  75. "emote strokes his beard and pulls out a chip of stone.",
  76. "emote adjusts his coveralls.",
  77. "mine"
  78. ];
  79. idleMessages = idleMessages.concat(libs.Conversation.getRoomExits(this));
  80. var randomIdle = idleMessages[parseInt(Math.random() * idleMessages.length)];
  81. this.mud_addCommand(this, randomIdle);
  82. this.lastIdle = time + this.idleDelay;
  83. }
  84. mud_tick(time) {
  85. if(this.commandQueue.length <= 0 && this.roomId == "ZebedeeShop") {
  86. if(this.mud_hasItem("stone")) {
  87. this.mud_addCommand(this, "sell stone");
  88. return;
  89. }
  90. if(this.mud_hasItem("coal")) {
  91. this.mud_addCommand(this, "sell coal");
  92. return;
  93. }
  94. if(this.mud_hasItem("diamond")) {
  95. this.mud_addCommand(this, "haggle diamond");
  96. this.mud_addCommand(this, "sell diamond");
  97. return;
  98. }
  99. if(!this.mud_hasItem("pickaxe")) {
  100. this.mud_addCommand(this, "say I'd like to buy a pickaxe, shopkeep.");
  101. this.mud_addCommand(this, "haggle pickaxe");
  102. this.mud_addCommand(this, "buy pickaxe");
  103. this.mud_addCommand(this, "hold pickaxe");
  104. return;
  105. }
  106. }
  107. if(this.commandQueue.length <= 0 && this.roomId == "Mine1") {
  108. this.mud_addCommand(this, "mine");
  109. return;
  110. }
  111. if(time >= this.lastIdle) {
  112. this.mud_reset(time);
  113. }
  114. if(this.commandQueue.length > 0 ) {
  115. world.mud_handleInput(this.roomId, this.id, this.commandQueue.shift().split(" "));
  116. this.lastIdle = time + this.idleDelay;
  117. }
  118. }
  119. mud_hasItem(itemName) {
  120. var inventoryItem = libs.Utilities.getSpecific(itemName, this.items, session.items);
  121. if(inventoryItem != null) {
  122. return true;
  123. }
  124. return false;
  125. }
  126. mud_getName() {
  127. return "{mobile}" + this.name + "{/mobile}";
  128. }
  129. mud_getDescription() {
  130. return this.description;
  131. }
  132. mud_wearInSlot(itemId, slot) {
  133. if(this.itemSlots.hasOwnProperty(slot) && this.itemSlots[slot] != null) {
  134. return this.itemSlots[slot];
  135. }
  136. this.itemSlots[slot] = itemId;
  137. }
  138. mud_removeSlot(slot) {
  139. if(!this.itemSlots.hasOwnProperty(slot) || this.itemSlots[slot] == null) {
  140. return false;
  141. }
  142. this.itemSlots[slot] = null;
  143. }
  144. mud_hasEquipped(itemName) {
  145. for(var index in this.itemSlots) {
  146. var slot = this.itemSlots[index];
  147. if(slot != null) {
  148. if(world.mud_getItem(slot).constructor.name == itemName) {
  149. return true;
  150. }
  151. }
  152. }
  153. if(Object.keys(this.itemSlots).length > 0) {
  154. var inventoryItem = libs.Utilities.getSpecific(itemName, Object.values(this.itemSlots), session.items);
  155. if(inventoryItem != null) {
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161. mud_addCurrency(amount) {
  162. this.account += amount;
  163. }
  164. mud_removeCurrency(amount) {
  165. this.account -= amount;
  166. this.account = Math.max(0, this.account);
  167. }
  168. };