observation.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. module.exports = class Observation {
  2. help(room, mobile, input) {
  3. var topic = input.join(" ").trim();
  4. switch(topic) {
  5. case "look":
  6. libs.Output.toMobile(mobile.id, "Look is the most important command in a MUD. It is the first thing you should do when trying to learn about something.");
  7. libs.Output.toMobile(mobile.id, "* look - shows you the name and description of the room you are in.");
  8. libs.Output.toMobile(mobile.id, "* look at [something] - can give you detailed descriptions of item in the room, other players or NPCs, and even descriptive elements around you.");
  9. libs.Output.toMobile(mobile.id, "In the case where there are multiple of the same item or NPC in the room, you can be specific.");
  10. libs.Output.toMobile(mobile.id, "* look at [number].[something] - for example, to look at the 3rd goblin in the room, you can type look 3.goblin");
  11. return true;
  12. case "inventory":
  13. libs.Output.toMobile(mobile.id, "As you collect items, you will need a way to check what you're carrying.");
  14. libs.Output.toMobile(mobile.id, "* inventory - Display a list of all the items you are currently holding.");
  15. libs.Output.toMobile(mobile.id, "aliases: i, inv");
  16. return true;
  17. case "who":
  18. libs.Output.toMobile(mobile.id, "To see a list of all the players currently logged in.");
  19. libs.Output.toMobile(mobile.id, "* who - Display a list of all the active players.");
  20. return true;
  21. }
  22. }
  23. look(room, mobile, input) {
  24. if (input[0] == "at") {
  25. input.shift();
  26. }
  27. if(this.mud_lookAt(room, mobile, input)) {
  28. return true;
  29. }
  30. if(input.length == 0) {
  31. return this.mud_lookRoom(room, mobile, input);
  32. }
  33. libs.Output.toMobile(mobile.id, "There isn't anything to see.");
  34. return true;
  35. }
  36. examine(room, mobile, input) {
  37. return this.look(room, mobile, input);
  38. }
  39. mud_lookRoom(room, mobile, input) {
  40. if(typeof room.mud_getName == "function") {
  41. libs.Output.toMobile(mobile.id, room.mud_getName());
  42. } else {
  43. libs.Output.toMobile(mobile.id, room.name);
  44. }
  45. if(typeof room.mud_getDescription == "function") {
  46. libs.Output.toMobile(mobile.id, room.mud_getDescription());
  47. } else {
  48. libs.Output.toMobile(mobile.id, room.description);
  49. }
  50. this.exits(room, mobile, input);
  51. room.mobiles.forEach(function(mobileId, index, array) {
  52. var otherMobile = session.mobiles[mobileId];
  53. if(mobile.id != otherMobile.id) {
  54. if(typeof otherMobile.mud_getName == "function") {
  55. libs.Output.toMobile(mobile.id, otherMobile.mud_getName());
  56. } else {
  57. libs.Output.toMobile(mobile.id, "{"+otherMobile.type+"}"+ otherMobile.name + "{/"+otherMobile.type+"} is standing here.");
  58. }
  59. }
  60. });
  61. room.items.forEach(function(itemId, index, array) {
  62. var otherItem = session.items[itemId];
  63. if(typeof otherItem.mud_getName == "function") {
  64. libs.Output.toMobile(mobile.id, otherItem.mud_getName());
  65. } else {
  66. libs.Output.toMobile(mobile.id, "{"+otherItem.type+"}" + otherItem.name + "{/"+otherItem.type+"}");
  67. }
  68. });
  69. return true;
  70. }
  71. mud_lookAt(room, mobile, input) {
  72. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  73. if(inventoryItem != null) {
  74. if(typeof inventoryItem.mud_getDescription == "function") {
  75. libs.Output.toMobile(mobile.id, inventoryItem.mud_getDescription());
  76. } else {
  77. libs.Output.toMobile(mobile.id, inventoryItem.description);
  78. }
  79. return true;
  80. }
  81. var roomMobile = libs.Utilities.getSpecific(input.join(" "), room.mobiles, session.mobiles);
  82. if(roomMobile != null) {
  83. if(typeof roomMobile.mud_getDescription == "function") {
  84. libs.Output.toMobile(mobile.id, roomMobile.mud_getDescription());
  85. } else {
  86. libs.Output.toMobile(mobile.id, roomMobile.description);
  87. }
  88. return true;
  89. }
  90. var roomItem = libs.Utilities.getSpecific(input.join(" "), room.items, session.items);
  91. if(roomItem != null) {
  92. if(typeof roomItem.mud_getDescription == "function") {
  93. libs.Output.toMobile(mobile.id, roomItem.mud_getDescription());
  94. } else {
  95. libs.Output.toMobile(mobile.id, roomItem.description);
  96. }
  97. return true;
  98. }
  99. }
  100. exits(room, mobile, input) {
  101. if(typeof room.exits == 'function') {
  102. return room.exits(room, mobile, input);
  103. }
  104. if(room.roomExits.length == 0) {
  105. libs.Output.toMobile(mobile.id, "There are no visible exits.");
  106. return true;
  107. }
  108. libs.Output.toMobile(mobile.id, "Visible exits are " + room.roomExits.join(", "));
  109. return true;
  110. }
  111. who(room, mobile, input) {
  112. var count = 0;
  113. for(var playerId in session.players) {
  114. count++;
  115. }
  116. var message = "There ";
  117. message += count > 1 ? "are" : "is";
  118. message += " " + count + " ";
  119. message += count > 1 ? "players" : "player";
  120. message += " currently online.";
  121. libs.Output.toMobile(mobile.id, message);
  122. for(var playerId in session.players) {
  123. var player = session.players[playerId];
  124. libs.Output.toMobile(mobile.id, "{"+player.type+"}"+ player.name + "{/"+player.type+"} " + player.title);
  125. }
  126. return true;
  127. }
  128. inventory(room, mobile, input) {
  129. if(mobile.items.length <= 0) {
  130. libs.Output.toMobile(mobile.id, "You are not carrying anything.");
  131. return true;
  132. }
  133. mobile.items.forEach(function(itemId, index, array) {
  134. var otherItem = session.items[itemId];
  135. if(typeof otherItem.mud_getName == "function") {
  136. libs.Output.toMobile(mobile.id, otherItem.mud_getName());
  137. } else {
  138. libs.Output.toMobile(mobile.id, "{item}"+otherItem.name+"{/item}");
  139. }
  140. });
  141. return true;
  142. }
  143. i(room, mobile, input) {
  144. return this.inventory(room, mobile, input);
  145. }
  146. mud_getErrorMessage() {
  147. return "You blink as things seem {error}fuzzy{/error} for a split-second.";
  148. }
  149. }