public static void FollowThing(PlayerSetup.Player follower, Room.Room room, string thingToFollow) { string[] options = thingToFollow.Split(' '); int nth = -1; string getNth = string.Empty; string objectToFind = String.Empty; if (options.Length == 3) { objectToFind = options[2]; if (objectToFind.IndexOf('.') != -1) { getNth = objectToFind.Substring(0, objectToFind.IndexOf('.')); int.TryParse(getNth, out nth); } } var findPerson = FindItem.Player(room.players, nth, objectToFind); if (findPerson == null) { return; } if (findPerson.Followers == null) { findPerson.Followers = new List <PlayerSetup.Player>(); } //check if player already following player if (findPerson.Followers.Contains(follower)) { if (follower.HubGuid != null) { HubContext.SendToClient("You are already following them.", follower.HubGuid); } } else { HubContext.SendToClient($"{Helpers.ReturnName(follower, findPerson, String.Empty)} begins following you", findPerson.HubGuid); foreach (var character in room.players) { if (character != follower || character != findPerson) { HubContext.SendToClient($"{Helpers.ReturnName(follower, findPerson, String.Empty)} begins following {Helpers.ReturnName(findPerson, follower, String.Empty)}", character.HubGuid); } } findPerson.Followers.Add(follower); } }
public static object find(Room.Room room, PlayerSetup.Player player, int findNth, string itemToFind) { //search room items 1st var foundItem = FindItem.Item(room.items, findNth, itemToFind, Item.Item.ItemLocation.Room); if (foundItem != null) { return(foundItem); } //search player inventory foundItem = FindItem.Item(player.Inventory, findNth, itemToFind, Item.Item.ItemLocation.Inventory); if (foundItem != null) { return(foundItem); } //search mob var foundMob = FindItem.Player(room.mobs, findNth, itemToFind); if (foundMob != null) { return(foundMob); } //search players var foundPlayer = FindItem.Player(room.players, findNth, itemToFind); if (foundPlayer != null) { return(foundPlayer); } else { HubContext.Instance.SendToClient($"You don't see anything by that name here.", player.HubGuid); } return(null); }
public static object find(Room.Room room, PlayerSetup.Player player, int findNth, string itemToFind) { //search room items 1st var foundItem = FindItem.Item(room.items, findNth, itemToFind); if (foundItem != null) { return(foundItem); } //search player inventory foundItem = FindItem.Item(player.Inventory, findNth, itemToFind); if (foundItem != null) { return(foundItem); } //search mob var foundMob = FindItem.Player(room.mobs, findNth, itemToFind); if (foundMob != null) { return(foundMob); } //search players var foundPlayer = FindItem.Player(room.players, findNth, itemToFind); if (foundPlayer != null) { return(foundPlayer); } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't see anything by that name here", player.Name + " something something..."); } return(null); }
/// <summary> /// Finds Objects in room, inventory, containers or mobs and players /// </summary> /// <param name="room">the room the player is in</param> /// <param name="player">the player calling the method</param> /// <param name="command">command used</param> /// <param name="thingToFind">Object to find</param> /// <param name="objectTypeToFind">can only be item, inventory or all</param> /// <returns></returns> public static object FindObject(Room room, Player player, string command, string thingToFind, string objectTypeToFind = "") { string item = thingToFind; var itemContainer = string.Empty; //checks for spaces //get sword bag - text after the 1st space is the container item = FindFirstAndLast.FindFirstAndLastIndex(thingToFind).Key; itemContainer = FindFirstAndLast.FindFirstAndLastIndex(thingToFind).Value; //get Item var findObject = Events.FindNth.Findnth(item); int nth = findObject.Key; string itemToFind = findObject.Value; //get container var findContainer = new KeyValuePair <int, string>(); int nthContainer = 0; string comntainerToFind = string.Empty; if (!string.IsNullOrEmpty(itemContainer)) { findContainer = Events.FindNth.Findnth(itemContainer); nthContainer = findContainer.Key; comntainerToFind = findContainer.Value; } Item foundItem = null; Item foundContainer = null; Player foundMob = null; Player foundPlayer = null; List <Item> roomItems = room.items; List <Item> playerInv = player.Inventory; List <Player> mobList = room.mobs; List <Player> playerList = room.players; #region find Item searching Room and Player Inventory if (objectTypeToFind == lookItem && itemToFind != "all") { // if its not a container if (string.IsNullOrEmpty(itemContainer)) { //search room items 1st foundItem = FindItem.Item(room.items, nth, itemToFind); if (foundItem != null) { return(new KeyValuePair <Item, Item>(null, foundItem)); } string msgToPlayer = "You don't see " + AvsAnLib.AvsAn.Query(itemToFind) + " " + itemToFind + " here and you are not carrying " + AvsAnLib.AvsAn.Query(itemToFind) + " " + itemToFind; BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, msgToPlayer, player.Name + " rummages around for an item but finds nothing"); return(new KeyValuePair <Item, Item>(null, null)); } else { //look in room foundContainer = (nthContainer == -1) ? roomItems.Find(x => x.name.ToLower().Contains(comntainerToFind) && x.container == true) : roomItems.FindAll(x => x.name.ToLower().Contains(comntainerToFind) && x.container == true).Skip(nthContainer - 1).FirstOrDefault(); if (foundContainer != null) { foundItem = FindItem.Item(foundContainer.containerItems, nth, itemToFind); } //return item found in container if (foundItem != null || itemToFind.Equals("all", StringComparison.OrdinalIgnoreCase)) { return(new KeyValuePair <Item, Item>(foundContainer, foundItem)); } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't see that inside the container", player.Name + " searches around inside the container but finds nothing"); } } } else if (itemToFind == "all" && roomItems.Count == 0 && command == "get") { HubContext.SendToClient("There is nothing here to get", player.HubGuid); } else if (itemToFind == "all" && playerInv.Count == 0 && command == "drop" || itemToFind == "all" && playerInv.Count == 0 && command == "put") { HubContext.SendToClient("You have nothing to drop", player.HubGuid); } #endregion #region find item in player inventory for commands such as drop, equip, wield etc else if (objectTypeToFind == FindInventory) { if (string.IsNullOrEmpty(itemContainer)) { foundItem = FindItem.Item(player.Inventory, nth, itemToFind); if (foundItem != null || itemToFind.Equals("all", StringComparison.OrdinalIgnoreCase)) { return(new KeyValuePair <Item, Item>(foundContainer, foundItem)); } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "you are not carrying such an item", player.Name + " tries to get an item but can't find it."); } } else { //look in inv if (itemToFind != "all") { foundItem = FindItem.Item(player.Inventory, nth, itemToFind); } if (foundItem != null || itemContainer != null && itemToFind == "all") { //find container foundContainer = (nth == -1) ? roomItems.Find(x => x.name.ToLower().Contains(itemContainer)) : roomItems.FindAll(x => x.name.ToLower().Contains(itemContainer)) .Skip(nth - 1) .FirstOrDefault(); } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "you are not carrying such an item", player.Name + " tries to get an item but can't find it."); } //return item found in container if (foundItem != null || foundContainer != null) { return(new KeyValuePair <Item, Item>(foundContainer, foundItem)); } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't see that item inside the container", player.Name + " tries to get an item from a container but can't find it."); } } } #endregion #region find killable mob or player else if (objectTypeToFind == Findkillable) { //search mob foundMob = FindItem.Player(room.mobs, nth, itemToFind); if (foundMob != null) { return(foundMob); } //search player foundPlayer = FindItem.Player(room.players, nth, itemToFind); if (foundPlayer != null) { return(foundPlayer); } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "you don't see " + itemToFind + " here", player.Name + " tries to kill x but can't find them."); } } #endregion else if (objectTypeToFind == FindAll) { if (comntainerToFind == null) { FindWhere.find(room, player, nth, itemToFind); } else { //look in room foundContainer = (nthContainer == -1) ? roomItems.Find(x => x.name.ToLower().Contains(comntainerToFind) && x.container == true) : roomItems.FindAll(x => x.name.ToLower().Contains(comntainerToFind) && x .container == true).Skip(nthContainer - 1).FirstOrDefault(); if (foundContainer != null) { //inside found container if (foundContainer.containerItems != null) { var containerItemsCount = foundContainer.containerItems.Count; if (containerItemsCount == 0) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "The " + foundContainer.name + " is empty", player.Name + " looks in " + foundContainer.name + " but finds nothing"); return(new KeyValuePair <Item, Item>(foundContainer, foundItem)); } for (int i = containerItemsCount - 1; i >= 0; i--) { if (foundContainer.containerItems[i].type != Item.ItemType.Gold || foundContainer.containerItems[i].type != Item.ItemType.Silver || foundContainer.containerItems[i].type != Item.ItemType.Copper) { foundContainer.containerItems[i].location = Item.ItemLocation.Inventory; player.Inventory.Add(foundContainer.containerItems[i]); } else { if (foundContainer.containerItems[i].type == Item.ItemType.Gold) { player.Gold += foundContainer.containerItems[i].count; } if (foundContainer.containerItems[i].type == Item.ItemType.Silver) { player.Silver += foundContainer.containerItems[i].count; } if (foundContainer.containerItems[i].type == Item.ItemType.Copper) { player.Copper += foundContainer.containerItems[i].count; } } BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You pick up a " + foundContainer.containerItems[i].name, player.Name + " picks up a " + foundContainer.containerItems[i].name); foundContainer.containerItems.Remove(foundContainer.containerItems[i]); } } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't see that inside the container", player.Name + " searches around inside the container but finds nothing"); return(new KeyValuePair <Item, Item>(foundContainer, foundItem)); } } } } return(new KeyValuePair <Item, Item>(foundContainer, foundItem)); }
public static void FollowThing(PlayerSetup.Player follower, Room.Room room, string thingToFollow) { if (thingToFollow == "noFollow" && follower.CanFollow) { follower.CanFollow = false; HubContext.Instance.SendToClient("You can no longer be followed.", follower.HubGuid); if (follower.Following != null) { HubContext.Instance.SendToClient($"You stop following {follower.Following.Name}.", follower.HubGuid); follower.Following?.Followers.Remove(follower); follower.Following = null; } if (follower.Followers != null) { foreach (var follow in follower.Followers) { HubContext.Instance.SendToClient($"You stop following {follower.Name}.", follow.HubGuid); HubContext.Instance.SendToClient($"{follow.Name} stops following you.", follower.HubGuid); follow.Following = null; } } follower.Followers = null; return; } if (thingToFollow == "noFollow" && !follower.CanFollow) { follower.CanFollow = true; HubContext.Instance.SendToClient("You can now be followed.", follower.HubGuid); return; } follower.CanFollow = true; string[] options = thingToFollow.Split(' '); int nth = -1; string getNth = string.Empty; string objectToFind = String.Empty; if (options.Length == 3) { objectToFind = options[2]; if (objectToFind.IndexOf('.') != -1) { getNth = objectToFind.Substring(0, objectToFind.IndexOf('.')); int.TryParse(getNth, out nth); } } else if (options.Length >= 1) { objectToFind = options[0]; } var findPerson = FindItem.Player(room.players, nth, objectToFind); if (findPerson == null) { HubContext.Instance.SendToClient("No one here by that name to follow.", follower.HubGuid); return; } if (findPerson.Followers == null) { findPerson.Followers = new List <PlayerSetup.Player>(); } //check if player already following player if (findPerson.Followers.Contains(follower)) { if (follower.HubGuid != null) { HubContext.Instance.SendToClient("You are already following them.", follower.HubGuid); } } else { if (findPerson.Name == follower.Name) { if (follower.Following != null) { follower.Following.Followers.Remove(follower); HubContext.Instance.SendToClient($"You stop following {follower.Following.Name}.", findPerson.HubGuid); follower.Following = null; } else { HubContext.Instance.SendToClient($"You can't follow yourself.", findPerson.HubGuid); } return; } if (!findPerson.CanFollow) { HubContext.Instance.SendToClient($"{Helpers.ReturnName(findPerson, follower, String.Empty)} does not want to be followed", follower.HubGuid); return; } if (findPerson.Following?.Name == follower.Name) { HubContext.Instance.SendToClient($"You can't follow {Helpers.ReturnName(findPerson, follower, String.Empty)} as they are following you.", follower.HubGuid); return; } HubContext.Instance.SendToClient($"{Helpers.ReturnName(follower, findPerson, String.Empty)} begins following you", findPerson.HubGuid); HubContext.Instance.SendToClient($"You follow {Helpers.ReturnName(findPerson, follower, String.Empty)}", follower.HubGuid); foreach (var character in room.players) { if (character.Name != follower.Name && character != findPerson) { HubContext.Instance.SendToClient($"{Helpers.ReturnName(follower, findPerson, String.Empty)} begins following {Helpers.ReturnName(findPerson, follower, String.Empty)}", character.HubGuid); } } findPerson.Followers.Add(follower); follower.Following = findPerson; } }