garaelehouse.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. look(room, mobile, input) {
  27. switch(input[0]) {
  28. case "table":
  29. libs.Output.toMobile(mobile.id, "The small table has a few things on it but nothing of interest.");
  30. return true;
  31. }
  32. }
  33. leave(room, mobile, input) {
  34. if(this.homeIsLocked && !this.homeIsOpen) {
  35. libs.Output.toMobile(mobile.id, "The door out is closed and locked.");
  36. libs.Output.toRoom(room.id, mobile.name + " tries to open the door but fails.", mobile);
  37. return true;
  38. } else if(!this.homeIsLocked && !this.homeIsOpen) {
  39. libs.Output.toMobile(mobile.id, "The door is not open.");
  40. return true;
  41. } else if(!this.homeIsLocked && this.homeIsOpen) {
  42. world.mud_moveMobile(mobile.id, this.id, "PhandalinShrineLuck", "leaves", "leaves the house");
  43. return true;
  44. }
  45. }
  46. south(room, mobile, input) {
  47. return this.leave(room, mobile, input);
  48. }
  49. unlock(room, mobile, input) {
  50. if(["door", "south"].indexOf(input[0]) != -1) {
  51. var hasKey = false;
  52. for(var i = 0; i < mobile.items.length; i++) {
  53. if(session.items[mobile.items[i]].constructor.name == "UnassumingKey") {
  54. hasKey = true;
  55. }
  56. }
  57. if(this.homeIsLocked && !this.homeIsOpen && hasKey) {
  58. libs.Output.toMobile(mobile.id, "You unlock the door.");
  59. libs.Output.toRoom(room.id, mobile.name + " unlocks the door.", mobile);
  60. this.homeIsLocked = false;
  61. return true;
  62. } else if(!this.homeIsLocked) {
  63. libs.Output.toMobile(mobile.id, "The door is already unlocked.");
  64. return true;
  65. } else if(!hasKey) {
  66. libs.Output.toMobile(mobile.id, "You don't have a key that fits.");
  67. return true;
  68. }
  69. }
  70. }
  71. open(room, mobile, input) {
  72. if(["door", "south"].indexOf(input[0]) != -1) {
  73. if(!this.homeIsOpen && !this.homeIsLocked) {
  74. libs.Output.toMobile(mobile.id, "You open the door.");
  75. libs.Output.toRoom(room.id, mobile.name + " opens the door.", mobile);
  76. this.homeIsOpen = true;
  77. this.roomExits.push("leave");
  78. return true;
  79. } else if(!this.homeIsOpen && this.homeIsLocked) {
  80. libs.Output.toMobile(mobile.id, "The door is locked.");
  81. return true;
  82. } else if(this.homeIsOpen) {
  83. libs.Output.toMobile(mobile.id, "The door is already open.");
  84. return true;
  85. }
  86. }
  87. }
  88. lock(room, mobile, input) {
  89. if(["door", "south"].indexOf(input[0]) != -1) {
  90. var hasKey = false;
  91. for(var i = 0; i < mobile.items.length; i++) {
  92. if(session.items[mobile.items[i]].constructor.name == "UnassumingKey") {
  93. hasKey = true;
  94. }
  95. }
  96. if(!this.homeIsLocked && !this.homeIsOpen && hasKey) {
  97. libs.Output.toMobile(mobile.id, "You lock the door.");
  98. libs.Output.toRoom(room.id, mobile.name + " locks the door.", mobile);
  99. this.homeIsLocked = true;
  100. return true;
  101. } else if(!this.homeIsLocked && this.homeIsOpen && hasKey) {
  102. libs.Output.toMobile(mobile.id, "You close and lock the door.");
  103. libs.Output.toRoom(room.id, mobile.name + " closes and locks the door.", mobile);
  104. this.homeIsLocked = true;
  105. this.homeIsOpen = false;
  106. this.roomExits.splice(this.roomExits.indexOf("leave"), 1);
  107. return true;
  108. } else if(this.homeIsLocked && !this.homeIsOpen) {
  109. libs.Output.toMobile(mobile.id, "The door is already locked.");
  110. return true;
  111. } else if(!this.hasKey) {
  112. libs.Output.toMobile(mobile.id, "You don't have the key to this door.");
  113. return true;
  114. }
  115. }
  116. }
  117. close(room, mobile, input) {
  118. if(["door", "south"].indexOf(input[0]) != -1) {
  119. if(this.homeIsOpen) {
  120. libs.Output.toMobile(mobile.id, "You close the door.");
  121. libs.Output.toRoom(room.id, mobile.name + " closes the door.", mobile);
  122. this.homeIsOpen = false;
  123. this.roomExits.splice(this.roomExits.indexOf("leave"), 1);
  124. return true;
  125. } else if(!this.homeIsOpen) {
  126. libs.Output.toMobile(mobile.id, "The door is already closed.");
  127. return true;
  128. }
  129. }
  130. }
  131. };