garaelehouse.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. module.exports = class PhandalinGaraeleHouse {
  2. constructor() {
  3. this.id = this.constructor.name;
  4. this.name = "Sister Garaele's Home";
  5. this.description = "This small home is decorated with many trinkets of Tymora. There is a door to the south with a small {hint}table{/hint} next to it.";
  6. this.filename = "phandalin/garaelehouse.js";
  7. this.type = "room";
  8. this.items = [];
  9. this.mobiles = [];
  10. this.roomExits = [];
  11. this.roomExpires = 0;
  12. this.resetDelay = 12000000;
  13. this.roomExits = ["leave"];
  14. this.homeIsOpen = true;
  15. this.homeIsLocked = false;
  16. }
  17. mud_reset(time) {
  18. libs.Output.toRoom(this.id, "The house creaks.");
  19. this.roomExpires = time + this.resetDelay;
  20. }
  21. mud_tick(time) {
  22. if(time >= this.roomExpires) {
  23. this.mud_reset(time);
  24. }
  25. }
  26. mud_getName() {
  27. return this.name;
  28. }
  29. mud_getDescription() {
  30. return this.description;
  31. }
  32. look(room, mobile, input) {
  33. switch(input[0]) {
  34. case "table":
  35. libs.Output.toMobile(mobile.id, "The small table has a few things on it but nothing of interest.");
  36. return true;
  37. }
  38. }
  39. leave(room, mobile, input) {
  40. if(this.homeIsLocked && !this.homeIsOpen) {
  41. libs.Output.toMobile(mobile.id, "The door out is closed and locked.");
  42. libs.Output.toRoom(room.id, mobile.name + " tries to open the door but fails.", mobile);
  43. return true;
  44. } else if(!this.homeIsLocked && !this.homeIsOpen) {
  45. libs.Output.toMobile(mobile.id, "The door is not open.");
  46. return true;
  47. } else if(!this.homeIsLocked && this.homeIsOpen) {
  48. world.mud_moveMobile(mobile.id, this.id, "PhandalinShrineLuck", "leaves", "leaves the house");
  49. return true;
  50. }
  51. }
  52. south(room, mobile, input) {
  53. return this.leave(room, mobile, input);
  54. }
  55. unlock(room, mobile, input) {
  56. if(["door", "south"].indexOf(input[0]) != -1) {
  57. var hasKey = false;
  58. for(var i = 0; i < mobile.items.length; i++) {
  59. if(session.items[mobile.items[i]].constructor.name == "UnassumingKey") {
  60. hasKey = true;
  61. }
  62. }
  63. if(this.homeIsLocked && !this.homeIsOpen && hasKey) {
  64. libs.Output.toMobile(mobile.id, "You unlock the door.");
  65. libs.Output.toRoom(room.id, mobile.name + " unlocks the door.", mobile);
  66. this.homeIsLocked = false;
  67. return true;
  68. } else if(!this.homeIsLocked) {
  69. libs.Output.toMobile(mobile.id, "The door is already unlocked.");
  70. return true;
  71. } else if(!hasKey) {
  72. libs.Output.toMobile(mobile.id, "You don't have a key that fits.");
  73. return true;
  74. }
  75. }
  76. }
  77. open(room, mobile, input) {
  78. if(["door", "south"].indexOf(input[0]) != -1) {
  79. if(!this.homeIsOpen && !this.homeIsLocked) {
  80. libs.Output.toMobile(mobile.id, "You open the door.");
  81. libs.Output.toRoom(room.id, mobile.name + " opens the door.", mobile);
  82. this.homeIsOpen = true;
  83. this.roomExits.push("leave");
  84. return true;
  85. } else if(!this.homeIsOpen && this.homeIsLocked) {
  86. libs.Output.toMobile(mobile.id, "The door is locked.");
  87. return true;
  88. } else if(this.homeIsOpen) {
  89. libs.Output.toMobile(mobile.id, "The door is already open.");
  90. return true;
  91. }
  92. }
  93. }
  94. lock(room, mobile, input) {
  95. if(["door", "south"].indexOf(input[0]) != -1) {
  96. var hasKey = false;
  97. for(var i = 0; i < mobile.items.length; i++) {
  98. if(session.items[mobile.items[i]].constructor.name == "UnassumingKey") {
  99. hasKey = true;
  100. }
  101. }
  102. if(!this.homeIsLocked && !this.homeIsOpen && hasKey) {
  103. libs.Output.toMobile(mobile.id, "You lock the door.");
  104. libs.Output.toRoom(room.id, mobile.name + " locks the door.", mobile);
  105. this.homeIsLocked = true;
  106. return true;
  107. } else if(!this.homeIsLocked && this.homeIsOpen && hasKey) {
  108. libs.Output.toMobile(mobile.id, "You close and lock the door.");
  109. libs.Output.toRoom(room.id, mobile.name + " closes and locks the door.", mobile);
  110. this.homeIsLocked = true;
  111. this.homeIsOpen = false;
  112. this.roomExits.splice(this.roomExits.indexOf("leave"), 1);
  113. return true;
  114. } else if(this.homeIsLocked && !this.homeIsOpen) {
  115. libs.Output.toMobile(mobile.id, "The door is already locked.");
  116. return true;
  117. } else if(!this.hasKey) {
  118. libs.Output.toMobile(mobile.id, "You don't have the key to this door.");
  119. return true;
  120. }
  121. }
  122. }
  123. close(room, mobile, input) {
  124. if(["door", "south"].indexOf(input[0]) != -1) {
  125. if(this.homeIsOpen) {
  126. libs.Output.toMobile(mobile.id, "You close the door.");
  127. libs.Output.toRoom(room.id, mobile.name + " closes the door.", mobile);
  128. this.homeIsOpen = false;
  129. this.roomExits.splice(this.roomExits.indexOf("leave"), 1);
  130. return true;
  131. } else if(!this.homeIsOpen) {
  132. libs.Output.toMobile(mobile.id, "The door is already closed.");
  133. return true;
  134. }
  135. }
  136. }
  137. };