module.exports = class Interaction { help(room, mobile, input) { var topic = input.join(" ").trim(); switch(topic) { case "get": libs.Output.toMobile(mobile.id, "Sometimes you will come across an item you can take for yourself."); libs.Output.toMobile(mobile.id, "* get [item] - if it's possible, you will take that item and store it in your inventory."); libs.Output.toMobile(mobile.id, "In the case where there are multiple of the same item in the room, you can be specific."); 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"); return true; case "drop": libs.Output.toMobile(mobile.id, "If you are holding an item that you no longer want, you can drop it in the room."); libs.Output.toMobile(mobile.id, "* drop [item] - drop the item in the current room"); libs.Output.toMobile(mobile.id, "In the case where there are multiple of the same item in your inventory, you can be specific."); 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"); return true; case "give": libs.Output.toMobile(mobile.id, "Sometimes you will come across an item you can take for yourself."); 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."); libs.Output.toMobile(mobile.id, "In the case where there are multiple of the same item or NPC, you can be specific."); 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"); return true; } } get(room, mobile, input) { var objIndex = 0; var objOffsetCounter = 0; if(input.join(" ").indexOf(".") != -1) { var counterString = input.join(" ").split(".") objIndex = parseInt(counterString[0]) - 1; input = counterString[1].split(" "); } objOffsetCounter = objIndex; var itemKey = input.join(" "); var roomItem = libs.Utilities.getSpecific(itemKey, room.items, session.items); if(roomItem != null) { world.mud_removeItemFromRoom(room.id, roomItem.id); world.mud_addItemToMobile(mobile.id, roomItem.id); libs.Output.toMobile(mobile.id, "You pick up " + roomItem.mud_getName() + "."); libs.Output.toRoom(room.id, mobile.mud_getName() + " picks up " + roomItem.mud_getName() + ".", mobile); return true; } libs.Output.toMobile(mobile.id, "That is not here."); return true; } drop(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem != null) { world.mud_removeItemFromMobile(mobile.id, inventoryItem.id); world.mud_addItemToRoom(room.id, inventoryItem.id); libs.Output.toMobile(mobile.id, "You drop " + inventoryItem.mud_getName() + "."); libs.Output.toRoom(room.id, mobile.mud_getName() + " drops " + inventoryItem.mud_getName() + ".", mobile); return true; } libs.Output.toMobile(mobile.id, "You don't have " + input.join(" ") + "."); return true; } give(room, mobile, input) { var giveString = input.join(" ").split(" to "); var itemKey = giveString[0].trim(); var mobKey = giveString[1].trim(); var itemToGive = null; var inventoryItem = libs.Utilities.getSpecific(itemKey, mobile.items, session.items); if(inventoryItem != null) { itemToGive = inventoryItem; } else { libs.Output.toMobile(mobile.id, "You don't seem to have '"+itemKey+"'."); return true; } var mobileToReceive = null; var roomMobile = libs.Utilities.getSpecific(mobKey, room.mobiles, session.mobiles); if(roomMobile != null) { mobileToReceive = roomMobile; } else { libs.Output.toMobile(mobile.id, "You cannot give that to '"+mobKey+"'."); return true; } world.mud_removeItemFromMobile(mobile.id, itemToGive.id); world.mud_addItemToMobile(mobileToReceive.id, itemToGive.id); libs.Output.toMobile(mobile.id, "You give " + itemToGive.mud_getName() + " to " + mobileToReceive.mud_getName() + "."); libs.Output.toMobile(mobileToReceive.id, mobile.mud_getName() + " gives you " +itemToGive.mud_getName() + "."); libs.Output.toRoom(room.id, mobile.mud_getName() + " gives " + itemToGive.mud_getName() + " to " + mobileToReceive.mud_getName() + ".", [mobile, mobileToReceive]); return true; } mud_isValidSlotToHold(itemSlot) { return [libs.ItemSlot.MainHand, libs.ItemSlot.OffHand].indexOf(itemSlot) != -1; } mud_isValidSlotToWear(itemSlot) { return [libs.ItemSlot.Head,libs.ItemSlot.Face,libs.ItemSlot.Neck,libs.ItemSlot.Shoulders, libs.ItemSlot.Back,libs.ItemSlot.Chest,libs.ItemSlot.Ring1,libs.ItemSlot.Ring2, libs.ItemSlot.Waist,libs.ItemSlot.Legs,libs.ItemSlot.Feet].indexOf(itemSlot) != -1; } hold(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem != null) { if(!this.mud_isValidSlotToHold(inventoryItem.itemSlot)) { libs.Output.toMobile(mobile.id, "You cannot hold "+inventoryItem.mud_getName()+"."); return true; } var itemId = mobile.mud_wearInSlot(inventoryItem.id, inventoryItem.itemSlot); if(itemId != null) { var otherItem = world.mud_getItem(itemId); libs.Output.toMobile(mobile.id, "You already hold "+otherItem.mud_getName()+"."); return true; } libs.Output.toMobile(mobile.id, "You hold "+inventoryItem.mud_getName()+"."); libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " holds " + inventoryItem.mud_getName() + ".", mobile); inventoryItem.isWorn = mobile.id; return true; } libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to hold."); return true; } wield(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem != null) { if(!this.mud_isValidSlotToHold(inventoryItem.itemSlot)) { libs.Output.toMobile(mobile.id, "You cannot wield "+inventoryItem.mud_getName()+"."); return true; } var itemId = mobile.mud_wearInSlot(inventoryItem.id, inventoryItem.itemSlot); if(itemId != null) { var otherItem = world.mud_getItem(itemId); libs.Output.toMobile(mobile.id, "You already wield "+otherItem.mud_getName()+"."); return true; } libs.Output.toMobile(mobile.id, "You wield "+inventoryItem.mud_getName()+"."); libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " wield " + inventoryItem.mud_getName() + ".", mobile); inventoryItem.isWorn = mobile.id; return true; } libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to wield."); return true; } wear(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem != null) { if(!this.mud_isValidSlotToWear(inventoryItem.itemSlot)) { libs.Output.toMobile(mobile.id, "You cannot wear "+inventoryItem.mud_getName()+"."); return true; } var itemId = mobile.mud_wearInSlot(inventoryItem.id, inventoryItem.itemSlot); if(itemId != null) { var otherItem = world.mud_getItem(itemId); libs.Output.toMobile(mobile.id, "You already wear "+otherItem.mud_getName()+"."); return true; } libs.Output.toMobile(mobile.id, "You wear "+inventoryItem.mud_getName()+"."); libs.Output.toRoom(mobile.roomId, mobile.mud_getName() + " wears " + inventoryItem.mud_getName() + ".", mobile); inventoryItem.isWorn = mobile.id; return true; } libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to wear."); return true; } unwield(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem != null) { var slotKey = Object.keys(mobile.itemSlots).find(key => mobile.itemSlots[key] === inventoryItem.id); if(slotKey == null) { libs.Output.toMobile(mobile.id, "You are not wielding "+input.join(" ")+"."); return true; } mobile.itemSlots[slotKey] = null; inventoryItem.isWorn = -1; libs.Output.toMobile(mobile.id, "You stop holding "+inventoryItem.mud_getName()+"."); libs.Output.toRoom(mobile.roomId, mobile.name + " stops holding " + inventoryItem.mud_getName() + ".", mobile); return true; } libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to unwield."); return true; } remove(room, mobile, input) { var inventoryItem = libs.Utilities.getSpecific(input.join(" "), mobile.items, session.items); if(inventoryItem != null) { var slotKey = Object.keys(mobile.itemSlots).find(key => mobile.itemSlots[key] === inventoryItem.id); if(slotKey == null) { libs.Output.toMobile(mobile.id, "You are not wearing "+input.join(" ")+"."); return true; } mobile.itemSlots[slotKey] = null; inventoryItem.isWorn = -1; libs.Output.toMobile(mobile.id, "You stop wearing "+inventoryItem.mud_getName()+"."); libs.Output.toRoom(mobile.roomId, mobile.name + " stops wearing " + inventoryItem.mud_getName() + ".", mobile); return true; } libs.Output.toMobile(mobile.id, "You have no "+input.join(" ")+" to remove."); return true; } pray(room, mobile, input) { var prayInput = input.join(" "); var god = null; if(prayInput != null) { prayInput = prayInput.trim().split("to"); if(prayInput[1] != null) { god = prayInput[1].trim(); } else { god = prayInput.join(" ").trim(); } } if(god != null && god != "") { var godName = "an unknown deity"; switch(god) { case "tymora": godName = "Tymora, the goddess of Luck"; break; } libs.Output.toMobile(mobile.id, "You say a quick prayer to "+godName+"."); libs.Output.toRoom(room.id, mobile.mud_getName() + " whispers a quiet prayer to "+godName+".", mobile); return true; } libs.Output.toMobile(mobile.id, "You say a quick prayer."); libs.Output.toRoom(room.id, mobile.mud_getName() + " whispers a quiet prayer.", mobile); return true; } mud_getErrorMessage() { return "Your fingers briefly {error}flicker{/error} out of existance."; } }