interaction.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. module.exports = class Interaction {
  2. help(room, mobile, input) {
  3. var topic = input.join(" ").trim();
  4. switch(topic) {
  5. case "get":
  6. libs.Output.toMobile(mobile.id, "Sometimes you will come across an item you can take for yourself.");
  7. libs.Output.toMobile(mobile.id, "* get [item] - if it's possible, you will take that item and store it in your inventory.");
  8. libs.Output.toMobile(mobile.id, "In the case where there are multiple of the same item in the room, you can be specific.");
  9. libs.Output.toMobile(mobile.id, "* get [number].[item] - if there were 3 sticks in a room and you wanted the 3rd one, you could type get 3.stick");
  10. return true;
  11. case "drop":
  12. libs.Output.toMobile(mobile.id, "If you are holding an item that you no longer want, you can drop it in the room.");
  13. libs.Output.toMobile(mobile.id, "* drop [item] - drop the item in the current room");
  14. libs.Output.toMobile(mobile.id, "In the case where there are multiple of the same item in your inventory, you can be specific.");
  15. libs.Output.toMobile(mobile.id, "* drop [number].[item] - if there were 3 sticks in your inventory and you wanted drop drop the 3rd one, you could type drop 3.stick");
  16. return true;
  17. case "give":
  18. libs.Output.toMobile(mobile.id, "Sometimes you will come across an item you can take for yourself.");
  19. libs.Output.toMobile(mobile.id, "* give [item] to [npc/player] - if it's possible, you will take that item and store it in your inventory.");
  20. libs.Output.toMobile(mobile.id, "In the case where there are multiple of the same item or NPC, you can be specific.");
  21. libs.Output.toMobile(mobile.id, "* give [number].[item] to [number].[npc/player] - To give the second stick to the third goblin, type give 2.stick to 3.goblin");
  22. return true;
  23. }
  24. }
  25. get(room, mobile, input) {
  26. var objIndex = 0;
  27. var objOffsetCounter = 0;
  28. if(input.join(" ").indexOf(".") != -1) {
  29. var counterString = input.join(" ").split(".")
  30. objIndex = parseInt(counterString[0]) - 1;
  31. input = counterString[1].split(" ");
  32. }
  33. objOffsetCounter = objIndex;
  34. var itemKey = input.join(" ");
  35. var roomItem = libs.Utilities.getSpecific(itemKey, room.items, session.items);
  36. if(roomItem != null) {
  37. mobile.items.push(roomItem.id);
  38. libs.Output.toMobile(mobile.id, "You pick up " + roomItem.name + ".");
  39. libs.Output.toRoom(room.id, mobile.name + " picks up " + roomItem.name + ".", mobile);
  40. room.items.splice(room.items.indexOf(roomItem.id), 1);
  41. return true;
  42. }
  43. libs.Output.toMobile(mobile.id, "That is not here.");
  44. return true;
  45. }
  46. drop(room, mobile, input) {
  47. var itemKey = input.join(" ");
  48. var inventoryItem = libs.Utilities.getSpecific(itemKey, mobile.items, session.items);
  49. if(inventoryItem != null) {
  50. room.items.push(inventoryItem.id);
  51. libs.Output.toMobile(mobile.id, "You drop " + inventoryItem.name + ".");
  52. libs.Output.toRoom(room.id, mobile.name + " drops " + inventoryItem.name + ".", mobile);
  53. mobile.items.splice(mobile.items.indexOf(inventoryItem.id), 1);
  54. return true;
  55. }
  56. libs.Output.toMobile(mobile.id, "You don't have " + itemKey + ".");
  57. return true;
  58. }
  59. give(room, mobile, input) {
  60. var giveString = input.join(" ").split(" to ");
  61. var itemKey = giveString[0].trim();
  62. var mobKey = giveString[1].trim();
  63. var itemToGive = null;
  64. var inventoryItem = libs.Utilities.getSpecific(itemKey, mobile.items, session.items);
  65. if(inventoryItem != null) {
  66. itemToGive = inventoryItem;
  67. }
  68. if(itemToGive == null) {
  69. libs.Output.toMobile(mobile.id, "You don't seem to have '"+itemKey+"'.");
  70. return true;
  71. }
  72. var mobileIndex = 0;
  73. var mobileOffsetCounter = 0;
  74. if(mobKey.indexOf(".") != -1) {
  75. var counterString = mobKey.split(".")
  76. mobileIndex = parseInt(counterString[0]) - 1;
  77. mobKey = counterString[1];
  78. }
  79. mobileOffsetCounter = mobileIndex;
  80. var mobileToReceive = null;
  81. var roomMobile = libs.Utilities.getSpecific(mobKey, room.mobiles, session.mobiles);
  82. if(roomMobile != null) {
  83. mobileToReceive = roomMobile;
  84. }
  85. if(mobileToReceive == null) {
  86. libs.Output.toMobile(mobile.id, "You cannot give that to '"+mobKey+"'.");
  87. return true;
  88. }
  89. world.mud_removeItemFromMobile(mobile.id, itemToGive.id);
  90. world.mud_addItemToMobile(mobileToReceive.id, itemToGive.id);
  91. itemToGive.heldBy = mobileToReceive.id;
  92. libs.Output.toMobile(mobile.id, "You give " + itemToGive.name + " to " + mobileToReceive.name + ".");
  93. libs.Output.toMobile(mobileToReceive.id, mobile.name + " gives you " +itemToGive.name + ".");
  94. libs.Output.toRoom(room.id, mobile.name + " gives " + itemToGive.name + " to " + mobileToReceive.name + ".", [mobile, mobileToReceive]);
  95. return true;
  96. }
  97. pray(room, mobile, input) {
  98. var prayInput = input.join(" ");
  99. var god = null;
  100. if(prayInput != null) {
  101. prayInput = prayInput.trim().split("to");
  102. if(prayInput[1] != null) {
  103. god = prayInput[1].trim();
  104. } else {
  105. god = prayInput.join(" ").trim();
  106. }
  107. }
  108. if(god != null && god != "") {
  109. var godName = "an unknown deity";
  110. switch(god) {
  111. case "tymora":
  112. godName = "Tymora, the goddess of Luck";
  113. break;
  114. }
  115. libs.Output.toMobile(mobile.id, "You say a quick prayer to "+godName+".", mobile);
  116. libs.Output.toRoom(room.id, mobile.name + " whispers a quiet prayer to "+godName+".", mobile);
  117. return true;
  118. }
  119. libs.Output.toMobile(mobile.id, "You say a quick prayer.", mobile);
  120. libs.Output.toRoom(room.id, mobile.name + " whispers a quiet prayer.", mobile);
  121. return true;
  122. }
  123. mud_getErrorMessage() {
  124. return "Your fingers briefly {error}flicker{/error} out of existance.";
  125. }
  126. }