observation.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. libs.Output.toMobile(mobile.id, room.mud_getName());
  41. libs.Output.toMobile(mobile.id, room.mud_getDescription());
  42. this.exits(room, mobile, input);
  43. room.mobiles.forEach(function(mobileId, index, array) {
  44. var otherMobile = session.mobiles[mobileId];
  45. if(mobile.id != otherMobile.id) {
  46. libs.Output.toMobile(mobile.id, otherMobile.mud_getName());
  47. }
  48. });
  49. room.items.forEach(function(itemId, index, array) {
  50. var otherItem = session.items[itemId];
  51. libs.Output.toMobile(mobile.id, otherItem.mud_getName());
  52. });
  53. return true;
  54. }
  55. mud_lookAt(room, mobile, input) {
  56. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  57. if(inventoryItem != null) {
  58. libs.Output.toMobile(mobile.id, inventoryItem.mud_getDescription());
  59. return true;
  60. }
  61. var roomMobile = libs.Utilities.getSpecific(input.join(" "), room.mobiles, session.mobiles);
  62. if(roomMobile != null) {
  63. libs.Output.toMobile(mobile.id, roomMobile.mud_getDescription());
  64. if(roomMobile.itemSlots != null) {
  65. for(var index in roomMobile.itemSlots) {
  66. var item = world.mud_getItem(roomMobile.itemSlots[index]);
  67. if(item != null) {
  68. libs.Output.toMobile(mobile.id, item.mud_getName());
  69. }
  70. }
  71. }
  72. return true;
  73. }
  74. var roomItem = libs.Utilities.getSpecific(input.join(" "), room.items, session.items);
  75. if(roomItem != null) {
  76. libs.Output.toMobile(mobile.id, roomItem.mud_getDescription());
  77. return true;
  78. }
  79. }
  80. exits(room, mobile, input) {
  81. if(typeof room.exits == 'function') {
  82. return room.exits(room, mobile, input);
  83. }
  84. if(room.roomExits.length == 0) {
  85. libs.Output.toMobile(mobile.id, "There are no visible exits.");
  86. return true;
  87. }
  88. libs.Output.toMobile(mobile.id, "Visible exits are " + room.roomExits.join(", "));
  89. return true;
  90. }
  91. who(room, mobile, input) {
  92. var count = 0;
  93. for(var playerId in session.players) {
  94. count++;
  95. }
  96. var message = "There ";
  97. message += count > 1 ? "are" : "is";
  98. message += " " + count + " ";
  99. message += count > 1 ? "players" : "player";
  100. message += " currently online.";
  101. libs.Output.toMobile(mobile.id, message);
  102. for(var playerId in session.players) {
  103. var player = session.players[playerId];
  104. libs.Output.toMobile(mobile.id, "{"+player.type+"}"+ player.name + "{/"+player.type+"} " + player.title);
  105. }
  106. return true;
  107. }
  108. inventory(room, mobile, input) {
  109. if(mobile.account <= 0) {
  110. libs.Output.toMobile(mobile.id, "You don't have any money.");
  111. } else {
  112. libs.Output.toMobile(mobile.id, "You have "+mobile.account+" coins.");
  113. }
  114. if(mobile.items.length <= 0) {
  115. libs.Output.toMobile(mobile.id, "You are not carrying anything.");
  116. return true;
  117. }
  118. for(var index in mobile.items) {
  119. var otherItem = world.mud_getItem(mobile.items[index]);
  120. libs.Output.toMobile(mobile.id, otherItem.mud_getName());
  121. }
  122. return true;
  123. }
  124. i(room, mobile, input) {
  125. return this.inventory(room, mobile, input);
  126. }
  127. mud_getErrorMessage() {
  128. return "You blink as things seem {error}fuzzy{/error} for a split-second.";
  129. }
  130. }