lionshieldcoster.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module.exports = class PhandalinLionshieldCoster {
  2. constructor() {
  3. this.id = this.constructor.name;
  4. this.name = "The Lionshield Coster";
  5. this.description = "A vast warehouse of armor, weapons and adventuring supplies. There are blue banners with white lionheads decorating the walls. A large wooden board above the counter displays a {hint}list{/hint} of the items for sale here.";
  6. this.filename = "phandalin/lionshieldcoster.js";
  7. this.type = "room";
  8. this.items = [];
  9. this.mobiles = [];
  10. this.roomExpires = 0;
  11. this.resetDelay = 12000000;
  12. this.roomExits = ["leave"];
  13. this.shopInventory = [];
  14. }
  15. mud_reset(time) {
  16. libs.Output.toRoom(this.id, "Sunlight from the windows glints off a shield on the wall.");
  17. this.roomExpires = time + this.resetDelay;
  18. }
  19. mud_tick(time) {
  20. if(time >= this.roomExpires) {
  21. this.mud_reset(time);
  22. }
  23. }
  24. mud_getName() {
  25. return this.name;
  26. }
  27. mud_getDescription() {
  28. return this.description;
  29. }
  30. leave(room, mobile, input) {
  31. world.mud_moveMobile(mobile.id, this.id, "PhandalinRoad5", "leaves", "leave the Coster");
  32. return true;
  33. }
  34. list(room, mobile, input) {
  35. for(var itemIndex in this.shopInventory) {
  36. var shopItem = world.mud_getItem(this.shopInventory[itemIndex]);
  37. if(typeof shopItem.mud_getName == "function") {
  38. libs.Output.toMobile(mobile.id, shopItem.mud_getName() + " - $" + shopItem.value);
  39. } else {
  40. libs.Output.toMobile(mobile.id, "{"+shopItem.type+"}" + shopItem.name + "{/"+shopItem.type+"} - $" + shopItem.value);
  41. }
  42. }
  43. return true;
  44. }
  45. sell(room, mobile, input) {
  46. if(input.join(" ") == null) {
  47. return false;
  48. }
  49. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  50. if(inventoryItem == null) {
  51. libs.Output.toMobile(mobile.id, "You don't seem to have '" + input.join(" ") + "'.");
  52. return true;
  53. }
  54. world.mud_removeItemFromMobile(mobile.id, inventoryItem.id);
  55. this.shopInventory.push(inventoryItem.id);
  56. //TODO: give money to mobile
  57. libs.Output.toMobile(mobile.id, "You sell " + inventoryItem.name + " for " + inventoryItem.value + ".");
  58. libs.Output.toRoom(room.id, mobile.name + " sells "+inventoryItem.name+" to the shop.", mobile);
  59. return true;
  60. }
  61. value(room, mobile, input) {
  62. libs.Output.toMobile(mobile.id, "value");
  63. //libs.Output.toRoom(room.id, mobile.name + " tries to open the door but fails.", mobile);
  64. return true;
  65. }
  66. info(room, mobile, input) {
  67. libs.Output.toMobile(mobile.id, "info of");
  68. //libs.Output.toRoom(room.id, mobile.name + " tries to open the door but fails.", mobile);
  69. return true;
  70. }
  71. buy(room, mobile, input) {
  72. if(input.join(" ") == null) {
  73. return false;
  74. }
  75. var shopItem = libs.Utilities.getSpecific(input.join(" "), this.shopInventory, session.items);
  76. if(shopItem == null) {
  77. libs.Output.toMobile(mobile.id, "The shop doesn't seem to have '" + input.join(" ") + "'.");
  78. return true;
  79. }
  80. world.mud_addItemToMobile(mobile.id, shopItem.id);
  81. this.shopInventory.splice(this.shopInventory.indexOf(shopItem.id), 1);
  82. //TODO: take money from mobile
  83. libs.Output.toMobile(mobile.id, "You buy " + shopItem.name + " for " + shopItem.value + ".");
  84. libs.Output.toRoom(room.id, mobile.name + " buys "+shopItem.name+" from the shop.", mobile);
  85. return true;
  86. }
  87. };