shop.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. module.exports = class ZebedeeShop {
  2. constructor() {
  3. this.id = this.constructor.name;
  4. this.name = "Zebedee Shop";
  5. 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.";
  6. this.filename = "zebedee/shop.js";
  7. this.type = "room";
  8. this.items = [];
  9. this.mobiles = [];
  10. this.roomExpires = 0;
  11. this.resetDelay = 6000000;
  12. this.roomExits = ["south"];
  13. this.shopInventory = [];
  14. this.shopAccount = 25000;
  15. this.shopMargin = 40;
  16. this.haggledItem = {};
  17. }
  18. mud_reset(time) {
  19. libs.Output.toRoom(this.id, "A register clacks and dings as it tallies some amount.");
  20. while(this.shopInventory.length > 24) {
  21. var consumedItemId = this.shopInventory.shift();
  22. var consumedItem = world.mud_getItem(consumedItemId);
  23. this.shopAccount += parseInt(consumedItem.value) || 0;
  24. world.mud_destroyItem(consumedItemId);
  25. }
  26. var pickaxe = builder.mud_spawnItem("Pickaxe");
  27. this.shopInventory.push(pickaxe.id);
  28. this.roomExpires = time + this.resetDelay;
  29. }
  30. mud_tick(time) {
  31. if(time >= this.roomExpires) {
  32. this.mud_reset(time);
  33. }
  34. }
  35. mud_getName() {
  36. return this.name;
  37. }
  38. mud_getDescription() {
  39. return this.description;
  40. }
  41. south(room, mobile, input) {
  42. world.mud_moveMobile(mobile.id, this.id, "ZebedeeCormallenRoad4", "leaves south");
  43. return true;
  44. }
  45. list(room, mobile, input) {
  46. var inventory = libs.ShopLogic.getListOfInventory(this, mobile);
  47. if(inventory.length <= 0) {
  48. libs.Output.toMobile(mobile.id, "The shop is out of things to sell.");
  49. return true;
  50. }
  51. for(var index in inventory) {
  52. var item = inventory[index];
  53. libs.Output.toMobile(mobile.id, item.name + " - $" + item.value);
  54. }
  55. return true;
  56. }
  57. sell(room, mobile, input) {
  58. if(input.join(" ") == null) {
  59. return false;
  60. }
  61. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  62. if(inventoryItem == null) {
  63. libs.Output.toMobile(mobile.id, "You don't seem to have '" + input.join(" ") + "'.");
  64. return true;
  65. }
  66. if(!libs.ShopLogic.canSell(this, mobile, inventoryItem)) {
  67. libs.Output.toMobile(mobile.id, "The shop can't buy that.");
  68. return true;
  69. }
  70. var salePrice = libs.ShopLogic.sellItemToShop(this, mobile, inventoryItem);
  71. libs.Output.toMobile(mobile.id, "You sell " + inventoryItem.mud_getName() + " for $" + salePrice + ".");
  72. libs.Output.toRoom(this.id, mobile.mud_getName() + " sells " + inventoryItem.mud_getName() + " to the shop.", mobile);
  73. return true;
  74. }
  75. value(room, mobile, input) {
  76. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  77. if(inventoryItem == null) {
  78. libs.Output.toMobile(mobile.id, "You don't seem to have '" + input.join(" ") + "'.");
  79. return true;
  80. }
  81. var itemValue = libs.ShopLogic.shopBuysFor(this, mobile, inventoryItem);
  82. libs.Output.toMobile(mobile.id, "You would get $" +itemValue + " for " + inventoryItem.mud_getName() + ".");
  83. return true;
  84. }
  85. info(room, mobile, input) {
  86. var shopItem = libs.Utilities.getSpecific(input.join(" "), this.shopInventory, session.items);
  87. if(shopItem == null) {
  88. libs.Output.toMobile(mobile.id, "The shop doesn't seem to have '" + input.join(" ") + "'.");
  89. return true;
  90. }
  91. libs.Output.toMobile(mobile.id, shopItem.mud_getDescription());
  92. return true;
  93. }
  94. buy(room, mobile, input) {
  95. if(input.join(" ") == null) {
  96. return false;
  97. }
  98. var shopItem = libs.Utilities.getSpecific(input.join(" "), this.shopInventory, session.items);
  99. if(shopItem == null) {
  100. libs.Output.toMobile(mobile.id, "The shop doesn't seem to have '" + input.join(" ") + "'.");
  101. return true;
  102. }
  103. if(!libs.ShopLogic.canBuy(this, mobile, shopItem)) {
  104. libs.Output.toMobile(mobile.id, "You can't afford that.");
  105. return true;
  106. }
  107. var purchasePrice = libs.ShopLogic.buyItemFromShop(this, mobile, shopItem);
  108. libs.Output.toMobile(mobile.id, "You buy " + shopItem.mud_getName() + " for $" + purchasePrice + ".");
  109. libs.Output.toRoom(this.id, mobile.mud_getName() + " buys "+shopItem.mud_getName()+" from the shop.", mobile);
  110. return true;
  111. }
  112. mud_addItemToInventory(itemId) {
  113. this.shopInventory.push(itemId);
  114. }
  115. mud_removeItemFromInventory(itemId) {
  116. this.shopInventory.splice(this.shopInventory.indexOf(itemId), 1);
  117. }
  118. mud_addCurrency(amount) {
  119. this.shopAccount += amount;
  120. }
  121. mud_removeCurrency(amount) {
  122. this.shopAccount -= amount;
  123. this.shopAccount = Math.max(0, this.shopAccount);
  124. }
  125. haggle(room, mobile, input) {
  126. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  127. if(inventoryItem != null) {
  128. libs.ShopLogic.trackHaggle(this, mobile, inventoryItem);
  129. libs.Output.toMobile(mobile.id, "You artfully negotiate with the shop clerk about the price of " + inventoryItem.mud_getName() + ".");
  130. libs.Output.toRoom(room.id, mobile.mud_getName() + " yells incoherently at the shop clerk until they agree to a better price.", mobile);
  131. return true;
  132. }
  133. var shopItem = libs.Utilities.getSpecific(input.join(" "), this.shopInventory, session.items);
  134. if(shopItem != null) {
  135. libs.ShopLogic.trackHaggle(this, mobile, shopItem);
  136. libs.Output.toMobile(mobile.id, "You artfully negotiate with the shop clerk about the price of " + shopItem.mud_getName() + ".");
  137. libs.Output.toRoom(room.id, mobile.mud_getName() + " yells incoherently at the shop clerk until they agree to a better price.", mobile);
  138. return true;
  139. }
  140. }
  141. };