interaction.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. world.mud_removeItemFromRoom(room.id, roomItem.id);
  38. world.mud_addItemToMobile(mobile.id, roomItem.id);
  39. libs.Output.toMobile(mobile.id, "You pick up " + roomItem.mud_getName() + ".");
  40. libs.Output.toRoom(room.id, mobile.mud_getName() + " picks up " + roomItem.mud_getName() + ".", mobile);
  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 inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  48. if(inventoryItem != null) {
  49. world.mud_removeItemFromMobile(mobile.id, inventoryItem.id);
  50. world.mud_addItemToRoom(room.id, inventoryItem.id);
  51. libs.Output.toMobile(mobile.id, "You drop " + inventoryItem.mud_getName() + ".");
  52. libs.Output.toRoom(room.id, mobile.mud_getName() + " drops " + inventoryItem.mud_getName() + ".", mobile);
  53. return true;
  54. }
  55. libs.Output.toMobile(mobile.id, "You don't have " + input.join(" ") + ".");
  56. return true;
  57. }
  58. give(room, mobile, input) {
  59. var giveString = input.join(" ").split(" to ");
  60. var itemKey = giveString[0].trim();
  61. var mobKey = giveString[1].trim();
  62. var itemToGive = null;
  63. var inventoryItem = libs.Utilities.getSpecific(itemKey, mobile.items, session.items);
  64. if(inventoryItem != null) {
  65. itemToGive = inventoryItem;
  66. } else {
  67. libs.Output.toMobile(mobile.id, "You don't seem to have '"+itemKey+"'.");
  68. return true;
  69. }
  70. var mobileToReceive = null;
  71. var roomMobile = libs.Utilities.getSpecific(mobKey, room.mobiles, session.mobiles);
  72. if(roomMobile != null) {
  73. mobileToReceive = roomMobile;
  74. } else {
  75. libs.Output.toMobile(mobile.id, "You cannot give that to '"+mobKey+"'.");
  76. return true;
  77. }
  78. world.mud_removeItemFromMobile(mobile.id, itemToGive.id);
  79. world.mud_addItemToMobile(mobileToReceive.id, itemToGive.id);
  80. libs.Output.toMobile(mobile.id, "You give " + itemToGive.mud_getName() + " to " + mobileToReceive.mud_getName() + ".");
  81. libs.Output.toMobile(mobileToReceive.id, mobile.mud_getName() + " gives you " +itemToGive.mud_getName() + ".");
  82. libs.Output.toRoom(room.id, mobile.mud_getName() + " gives " + itemToGive.mud_getName() + " to " + mobileToReceive.mud_getName() + ".", [mobile, mobileToReceive]);
  83. return true;
  84. }
  85. mud_isValidSlotToHold(itemSlot) {
  86. return [libs.ItemSlot.MainHand, libs.ItemSlot.OffHand].indexOf(itemSlot) != -1;
  87. }
  88. mud_isValidSlotToWear(itemSlot) {
  89. return [libs.ItemSlot.Head,libs.ItemSlot.Face,libs.ItemSlot.Neck,libs.ItemSlot.Shoulders,
  90. libs.ItemSlot.Back,libs.ItemSlot.Chest,libs.ItemSlot.Ring1,libs.ItemSlot.Ring2,
  91. libs.ItemSlot.Waist,libs.ItemSlot.Legs,libs.ItemSlot.Feet].indexOf(itemSlot) != -1;
  92. }
  93. hold(room, mobile, input) {
  94. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  95. if(inventoryItem != null) {
  96. if(!this.mud_isValidSlotToHold(inventoryItem.itemSlot)) {
  97. libs.Output.toMobile(mobile.id, "You cannot hold "+inventoryItem.mud_getName()+".");
  98. return true;
  99. }
  100. var itemId = mobile.mud_wearInSlot(inventoryItem.id, inventoryItem.itemSlot);
  101. if(itemId != null) {
  102. var otherItem = world.mud_getItem(itemId);
  103. libs.Output.toMobile(mobile.id, "You already hold "+otherItem.mud_getName()+".");
  104. return true;
  105. }
  106. libs.Output.toMobile(mobile.id, "You hold "+inventoryItem.mud_getName()+".");
  107. libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " holds " + inventoryItem.mud_getName() + ".", mobile);
  108. inventoryItem.isWorn = mobile.id;
  109. return true;
  110. }
  111. libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to hold.");
  112. return true;
  113. }
  114. wield(room, mobile, input) {
  115. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  116. if(inventoryItem != null) {
  117. if(!this.mud_isValidSlotToHold(inventoryItem.itemSlot)) {
  118. libs.Output.toMobile(mobile.id, "You cannot wield "+inventoryItem.mud_getName()+".");
  119. return true;
  120. }
  121. var itemId = mobile.mud_wearInSlot(inventoryItem.id, inventoryItem.itemSlot);
  122. if(itemId != null) {
  123. var otherItem = world.mud_getItem(itemId);
  124. libs.Output.toMobile(mobile.id, "You already wield "+otherItem.mud_getName()+".");
  125. return true;
  126. }
  127. libs.Output.toMobile(mobile.id, "You wield "+inventoryItem.mud_getName()+".");
  128. libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " wield " + inventoryItem.mud_getName() + ".", mobile);
  129. inventoryItem.isWorn = mobile.id;
  130. return true;
  131. }
  132. libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to wield.");
  133. return true;
  134. }
  135. wear(room, mobile, input) {
  136. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  137. if(inventoryItem != null) {
  138. if(!this.mud_isValidSlotToWear(inventoryItem.itemSlot)) {
  139. libs.Output.toMobile(mobile.id, "You cannot wear "+inventoryItem.mud_getName()+".");
  140. return true;
  141. }
  142. var itemId = mobile.mud_wearInSlot(inventoryItem.id, inventoryItem.itemSlot);
  143. if(itemId != null) {
  144. var otherItem = world.mud_getItem(itemId);
  145. libs.Output.toMobile(mobile.id, "You already wear "+otherItem.mud_getName()+".");
  146. return true;
  147. }
  148. libs.Output.toMobile(mobile.id, "You wear "+inventoryItem.mud_getName()+".");
  149. libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " wears " + inventoryItem.mud_getName() + ".", mobile);
  150. inventoryItem.isWorn = mobile.id;
  151. return true;
  152. }
  153. libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to wear.");
  154. return true;
  155. }
  156. unwield(room, mobile, input) {
  157. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  158. if(inventoryItem != null) {
  159. var slotKey = Object.keys(mobile.itemSlots).find(key => mobile.itemSlots[key] === inventoryItem.id);
  160. if(slotKey == null) {
  161. libs.Output.toMobile(mobile.id, "You are not wielding "+input.join(" ")+".");
  162. return true;
  163. }
  164. mobile.itemSlots[slotKey] = null;
  165. inventoryItem.isWorn = -1;
  166. libs.Output.toMobile(mobile.id, "You stop holding "+inventoryItem.mud_getName()+".");
  167. libs.Output.toRoom(mobile.roomId, mobile.name + " stops holding " + inventoryItem.mud_getName() + ".", mobile);
  168. return true;
  169. }
  170. libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to unwield.");
  171. return true;
  172. }
  173. remove(room, mobile, input) {
  174. var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items);
  175. if(inventoryItem != null) {
  176. var slotKey = Object.keys(mobile.itemSlots).find(key => mobile.itemSlots[key] === inventoryItem.id);
  177. if(slotKey == null) {
  178. libs.Output.toMobile(mobile.id, "You are not wearing "+input.join(" ")+".");
  179. return true;
  180. }
  181. mobile.itemSlots[slotKey] = null;
  182. inventoryItem.isWorn = -1;
  183. libs.Output.toMobile(mobile.id, "You stop wearing "+inventoryItem.mud_getName()+".");
  184. libs.Output.toRoom(mobile.roomId, mobile.name + " stops wearing " + inventoryItem.mud_getName() + ".", mobile);
  185. return true;
  186. }
  187. libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to remove.");
  188. return true;
  189. }
  190. pray(room, mobile, input) {
  191. var prayInput = input.join(" ");
  192. var god = null;
  193. if(prayInput != null) {
  194. prayInput = prayInput.trim().split("to");
  195. if(prayInput[1] != null) {
  196. god = prayInput[1].trim();
  197. } else {
  198. god = prayInput.join(" ").trim();
  199. }
  200. }
  201. if(god != null && god != "") {
  202. var godName = "an unknown deity";
  203. switch(god) {
  204. case "tymora":
  205. godName = "Tymora, the goddess of Luck";
  206. break;
  207. }
  208. libs.Output.toMobile(mobile.id, "You say a quick prayer to "+godName+".");
  209. libs.Output.toRoom(room.id, mobile.mud_getName() + " whispers a quiet prayer to "+godName+".", mobile);
  210. return true;
  211. }
  212. libs.Output.toMobile(mobile.id, "You say a quick prayer.");
  213. libs.Output.toRoom(room.id, mobile.mud_getName() + " whispers a quiet prayer.", mobile);
  214. return true;
  215. }
  216. mud_getErrorMessage() {
  217. return "Your fingers briefly {error}flicker{/error} out of existance.";
  218. }
  219. }