public static void ReturnRoom(Player player, Room room, string commandOptions = "", string keyword = "") { Room roomData = room; if (string.IsNullOrEmpty(commandOptions) && keyword == "look") { var roomInfo = DisplayRoom(roomData, player.Name); HubContext.SendToClient(roomInfo, player.HubGuid); } else { int n = -1; string item = string.Empty; if (commandOptions.IndexOf('.') != -1) { n = Convert.ToInt32(commandOptions.Substring(0, commandOptions.IndexOf('.'))); item = commandOptions.Substring(commandOptions.LastIndexOf('.') + 1); } if (roomData.keywords == null) { roomData.keywords = new List <RoomObject>(); } var roomDescription = roomData.keywords.Find(x => x.name.ToLower().Contains(commandOptions)); if (roomData.items == null) { roomData.items = new List <Item.Item>(); } var itemDescription = (n == -1) ? roomData.items.Find(x => x.name.ToLower().Contains(commandOptions)) : roomData.items.FindAll(x => x.name.ToLower().Contains(item)) .Skip(n - 1) .FirstOrDefault(); if (roomData.mobs == null) { roomData.mobs = new List <Player>(); } var mobDescription = (n == -1) ? roomData.mobs.Find(x => x.Name.ToLower().Contains(commandOptions)) : roomData.mobs.FindAll(x => x.Name.ToLower().Contains(item)) .Skip(n - 1) .FirstOrDefault(); if (roomData.players == null) { roomData.players = new List <Player>(); } var playerDescription = (n == -1) ? roomData.players.Find(x => x.Name.ToLower().Contains(commandOptions)) : roomData.players.FindAll(x => x.Name.ToLower().Contains(item)) .Skip(n - 1) .FirstOrDefault(); var targetPlayerId = string.Empty; if (playerDescription != null) { var isPlayer = playerDescription.Type.Equals("Player"); if (isPlayer) { targetPlayerId = playerDescription.HubGuid; } } var roomExitDescription = roomData.exits.Find(x => x.name.ToLower().Contains(commandOptions)); //Returns descriptions for important objects in the room if (roomDescription != null && keyword != "look in" && !string.IsNullOrWhiteSpace(commandOptions)) { string descriptionText = string.Empty; string broadcastAction = string.Empty; if (keyword.Equals("look")) { descriptionText = roomDescription.look; broadcastAction = " looks at a " + roomDescription.name; } else if (keyword.StartsWith("examine")) { descriptionText = roomDescription.examine; broadcastAction = " looks closely at a " + roomDescription.name; } else if (keyword.StartsWith("touch")) { descriptionText = roomDescription.touch; broadcastAction = " touches closely a " + roomDescription.name; } else if (keyword.StartsWith("smell")) { descriptionText = roomDescription.smell; broadcastAction = " sniffs a " + roomDescription.name; } else if (keyword.StartsWith("taste")) { descriptionText = roomDescription.taste; broadcastAction = " licks a " + roomDescription.name; } if (!string.IsNullOrEmpty(descriptionText)) { HubContext.SendToClient(descriptionText, player.HubGuid); foreach (var players in room.players) { if (player.Name != players.Name) { HubContext.SendToClient(player.Name + broadcastAction, players.HubGuid); } } } else { HubContext.SendToClient("You can't do that to a " + roomDescription.name, player.HubGuid); } } else if (itemDescription != null && !string.IsNullOrWhiteSpace(commandOptions)) { string descriptionText = string.Empty; string broadcastAction = string.Empty; if (keyword.Equals("look in", StringComparison.InvariantCultureIgnoreCase)) { if (itemDescription.open == false) { HubContext.SendToClient("You need to open the " + itemDescription.name + " before you can look inside", player.HubGuid); return; } if (itemDescription.container == true) { if (itemDescription.containerItems.Count > 0) { HubContext.SendToClient("You look into the " + itemDescription.name + " and see:", player.HubGuid); foreach (var containerItem in itemDescription.containerItems) { HubContext.SendToClient(containerItem.name, player.HubGuid); } } else { HubContext.SendToClient("You look into the " + itemDescription.name + " but it is empty", player.HubGuid); } foreach (var character in room.players) { if (player != character) { var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} looks in a {itemDescription.name}"; HubContext.SendToClient(roomMessage, character.HubGuid); } } } else { HubContext.SendToClient(itemDescription.name + " is not a container", player.HubGuid); } } else if (keyword.StartsWith("look")) { descriptionText = itemDescription.description.look; broadcastAction = " looks at a " + itemDescription.name; } else if (keyword.StartsWith("examine")) { descriptionText = itemDescription.description.exam; broadcastAction = " looks closely at a " + itemDescription.name; } if (!keyword.Equals("look in", StringComparison.InvariantCultureIgnoreCase)) { if (!string.IsNullOrEmpty(descriptionText)) { HubContext.SendToClient(descriptionText, player.HubGuid); foreach (var players in room.players) { if (player.Name != players.Name) { HubContext.SendToClient(player.Name + broadcastAction, players.HubGuid); } } } else { var result = AvsAnLib.AvsAn.Query(itemDescription.name); string article = result.Article; HubContext.SendToClient("You see nothing special about " + article + " " + itemDescription.name, player.HubGuid); } } } else if (mobDescription != null && !string.IsNullOrWhiteSpace(commandOptions)) { string descriptionText = string.Empty; if (keyword.StartsWith("look") || keyword.StartsWith("examine")) { descriptionText = mobDescription.Description; } if (!string.IsNullOrEmpty(descriptionText)) { HubContext.SendToClient(descriptionText, player.HubGuid); Equipment.ShowEquipmentLook(mobDescription, player); foreach (var character in room.players) { if (player != character) { var roomMessage = $"{ Helpers.ReturnName(player, character, string.Empty)} looks at { Helpers.ReturnName(mobDescription, character, string.Empty)}"; HubContext.SendToClient(roomMessage, character.HubGuid); } } } else { HubContext.SendToClient("You can't do that to a " + mobDescription.Name, player.HubGuid); } } else if (playerDescription != null && !string.IsNullOrWhiteSpace(commandOptions)) { string descriptionText = string.Empty; if (keyword.StartsWith("look") || keyword.StartsWith("examine")) { descriptionText = playerDescription.Description; } if (!string.IsNullOrEmpty(descriptionText)) { HubContext.SendToClient(descriptionText, player.HubGuid); Equipment.ShowEquipmentLook(playerDescription, player); HubContext.SendToClient(player.Name + " looks at you", playerDescription.HubGuid); } else { HubContext.SendToClient("You can't do that to a " + playerDescription.Name, player.HubGuid); } } else if (roomExitDescription != null) { HubContext.SendToClient("You look " + roomExitDescription.name, player.HubGuid); var currentAreaId = player.AreaId; player.AreaId = roomExitDescription.areaId; var adjacentRoom = Cache.getRoom(player); if (adjacentRoom == null) { var newRoom = new LoadRoom(); newRoom.Area = roomExitDescription.area; newRoom.id = roomExitDescription.areaId; newRoom.Region = roomExitDescription.region; adjacentRoom = newRoom.LoadRoomFile(); //add to cache? } var showNextRoom = LoadRoom.DisplayRoom(adjacentRoom, player.Name); HubContext.SendToClient(showNextRoom, player.HubGuid); player.AreaId = currentAreaId; foreach (var players in room.players) { if (player.Name != players.Name) { HubContext.SendToClient(player.Name + " looks " + roomExitDescription.name, players.HubGuid); } } } else { HubContext.SendToClient("You don't see that here.", player.HubGuid); } } }
/// <summary> /// Displays room desc, players, mobs, items and exits /// </summary> /// <param name="room"></param> /// <param name="playerName"></param> /// <returns></returns> public static string DisplayRoom(Room room, string playerName) { string roomTitle = room.title; string roomDescription = room.description; var exitList = string.Empty; foreach (var exit in room.exits) { exitList += exit.name + " "; } var player = room.players.FirstOrDefault(x => x.Name.Equals(playerName)); var itemList = string.Empty; ////clean items //var conciseList = new List<Item.Item>(); //foreach (var item in room.items) //{ // if (conciseList.FirstOrDefault(x => x.name.Equals(item.name)) == null) // { // conciseList.Add(item); // } // else // { // var getItem = conciseList.FirstOrDefault(x => x.Equals(item)); // if (getItem != null) // { // getItem.count += 1; // } // } //} ////clean items foreach (var item in room.items) { if (item != null) { if (item.itemFlags?.Contains(Item.Item.ItemFlags.invis) == true && player.DetectInvis == false || item.itemFlags?.Contains(Item.Item.ItemFlags.hidden) == true && player.DetectHidden == false) { continue; } if (!item.isHiddenInRoom) { var result = AvsAnLib.AvsAn.Query(item.name); string article = result.Article; if (!string.IsNullOrEmpty(item.description?.room)) { if (item.count > 0) { itemList += $"<p class='roomItems'>({item.count}) {item.description.room}<p>"; } else { itemList += $"<p class='roomItems'>{item.description.room}<p>"; } } else { if (item.count > 0) { itemList += $"<p class='roomItems'>({item.count}) {item.name} are on the floor here.<p>"; } else { itemList += $"<p class='roomItems'>{article} {item.name} is on the floor here.<p>"; } } } } } var playerList = string.Empty; if (room.players != null) { foreach (var item in room.players) { if (item.invis == true && player.DetectInvis == false || item.hidden == true && player.DetectHidden == false) { continue; } if (item.nonDectect == true) { continue; } if (item.Name != playerName) { if (item.Status == Player.PlayerStatus.Standing) { playerList += LoadRoom.ShowObjectEffects(item) + " is here\r\n"; } else if (item.Status == Player.PlayerStatus.Fighting) { playerList += LoadRoom.ShowObjectEffects(item) + " is fighting " + item.Target.Name + "\r\n"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Resting) { playerList += LoadRoom.ShowObjectEffects(item) + " is resting."; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Sleeping) { playerList += LoadRoom.ShowObjectEffects(item) + " is sleeping."; } else { playerList += LoadRoom.ShowObjectEffects(item) + " is here\r\n"; } } } } var mobList = string.Empty; if (room.mobs != null) { foreach (var item in room.mobs) { if (item.invis == true && player.DetectInvis == false || item.hidden == true && player.DetectHidden == false) { continue; } if (item.nonDectect == true) { continue; } var result = AvsAnLib.AvsAn.Query(item.Name); string article = result.Article; if (item.KnownByName) { article = string.Empty; } if (item.Status == Player.PlayerStatus.Standing) { mobList += "<p class='roomItems'>" + article + " " + item.Name + " is here.<p>"; } else if (item.Status == Player.PlayerStatus.Fighting) { mobList += "<p class='roomItems'>" + article + " " + item.Name + " is fighting " + item.Target.Name + "</p>"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Resting) { mobList += "<p class='roomItems'>" + article + " " + item.Name + " is resting.<p>"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Sleeping) { mobList += "<p class='roomItems'>" + article + " " + item.Name + " is sleeping.<p>"; } else { mobList += "<p class='roomItems'>" + article + " " + item.Name + " is here.<p>"; } } } string displayRoom = "<p class='roomTitle'>" + roomTitle + "<p><p class='roomDescription'>" + roomDescription + "</p> <p class='RoomExits'>[ Exits: " + exitList.ToLower() + " ]</p>" + itemList + "\r\n" + playerList + "\r\n" + mobList; // Score.UpdateUiRoom(room.players.FirstOrDefault(x => x.Name.Equals(playerName)), displayRoom); return(displayRoom); }
public static void IsDead(Player attacker, Player defender, Room room) { if (defender.HitPoints <= 0) { CheckEvent.FindEvent(CheckEvent.EventType.Death, attacker, "death"); foreach (var player in room.players) { if (player != defender) { HubContext.SendToClient(defender.Name + " dies ", player.HubGuid); } else { HubContext.SendToClient("You die", defender.HubGuid); } } defender.Target = null; defender.ActiveFighting = false; defender.Status = Player.PlayerStatus.Ghost; //Turn corpse into room item var defenderCorpse = new Item { name = "The corpse of " + defender.Name, container = true, containerItems = new List <Item>(), description = new Description { look = "The slain corpse of " + defender.Name + " is here.", room = "The slain corpse of " + defender.Name } }; foreach (var invItem in defender.Inventory) { invItem.location = Item.ItemLocation.Room; defenderCorpse.containerItems.Add(invItem); } var oldRoom = room; room.items.Add(defenderCorpse); room.corpses.Add(defender); if (defender.Type == Player.PlayerTypes.Mob || string.IsNullOrEmpty(defender.HubGuid)) { room.mobs.Remove(defender); } else { //room.players.Remove(defender); //Add slain player to recall } defender.Target = null; if (attacker.Target.Name == defender.Name) { attacker.Target = null; attacker.Status = PlayerSetup.Player.PlayerStatus.Standing; attacker.ActiveFighting = false; } defender.Status = defender.Type == Player.PlayerTypes.Player ? PlayerSetup.Player.PlayerStatus.Ghost : PlayerSetup.Player.PlayerStatus.Dead; Cache.updateRoom(room, oldRoom); var xp = new Experience(); int xpGain = xp.GainXp(attacker, defender); attacker.Experience += xpGain; attacker.TotalExperience += xpGain; HubContext.SendToClient(xpGain + "XP", attacker.HubGuid); xp.GainLevel(attacker); //calc xp //create corpse foreach (var player in room.players) { var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); } if (attacker.HubGuid != null) { room.fighting.Remove(attacker.HubGuid); } if (defender.HubGuid != null) { room.fighting.Remove(defender.HubGuid); } //remove followers if (defender.Following != null) { if (defender.Followers.Count > 0) { foreach (var follower in defender.Followers) { if (follower.HubGuid != null) { HubContext.SendToClient("You stop following " + defender.Name, follower.HubGuid); } } } defender.Followers = null; defender.Following = null; } // check if defender is following? if (attacker.Followers?.FirstOrDefault(x => x.Equals(defender)) != null) { attacker.Followers.Remove(defender); if (attacker.HubGuid != null) { HubContext.SendToClient(defender.Name + " stops following you", attacker.HubGuid); } } } }
public static void IsDead(Player attacker, Player defender, Room room) { if (defender.HitPoints <= 0) { HubContext.SendToAllExcept(defender.Name + " dies ", room.fighting, room.players); HubContext.SendToClient("You die", defender.HubGuid); HubContext.SendToClient(defender.Name + " dies", attacker.HubGuid); defender.Target = null; //Turn corpse into room item var defenderCorpse = new Item { name = "The corpse of " + defender.Name, container = true, containerItems = new List <Item>(), description = new Description { look = "The slain corpse of " + defender.Name + " is here.", room = "The slain corpse of " + defender.Name } }; foreach (var invItem in defender.Inventory) { invItem.location = Item.ItemLocation.Room; defenderCorpse.containerItems.Add(invItem); } var oldRoom = room; room.items.Add(defenderCorpse); room.corpses.Add(defender); if (defender.Type == Player.PlayerTypes.Mob || string.IsNullOrEmpty(defender.HubGuid)) { room.mobs.Remove(defender); } else { //room.players.Remove(defender); //Add slain player to recall } defender.Target = null; attacker.Target = null; attacker.Status = PlayerSetup.Player.PlayerStatus.Standing; defender.Status = defender.Type == Player.PlayerTypes.Player ? PlayerSetup.Player.PlayerStatus.Ghost : PlayerSetup.Player.PlayerStatus.Dead; Cache.updateRoom(room, oldRoom); var xp = new Experience(); int xpGain = xp.GainXp(attacker, defender); attacker.Experience += xpGain; attacker.TotalExperience += xpGain; HubContext.SendToClient(xpGain + "XP", attacker.HubGuid); xp.GainLevel(attacker); //calc xp //create corpse foreach (var player in room.players) { var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); } } }
/// <summary> /// Drops item from player inventory /// </summary> /// <param name="room">room object</param> /// <param name="player">player object</param> /// <param name="userInput">text entered by user</param> /// <param name="commandKey">command entered</param> public static void GiveItem(Room room, Player player, string userInput, string commandKey, string type) { var currentRoom = room; var currentPlayer = player; string[] all = userInput.Split(); var itemToGive = all[0]; var thing = all.Last(); var item = itemToGive; var foundItem = player.Inventory.FirstOrDefault(x => item != null && x.name.StartsWith(item, StringComparison.CurrentCultureIgnoreCase)); var foundThing = room.players.FirstOrDefault(x => thing != null && x.Name.StartsWith(thing, StringComparison.CurrentCultureIgnoreCase)) ?? room.mobs.FirstOrDefault(x => thing != null && x.Name.StartsWith(thing, StringComparison.CurrentCultureIgnoreCase)); if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase)) { var playerInv = player.Inventory; var playerInvCount = player.Inventory.Count; for (int i = playerInvCount - 1; i >= 0; i--) { if (foundThing != null) { foundThing.Inventory.Add(playerInv[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You give a " + playerInv[i].name + " to " + foundThing.Name, player.Name + " gives a " + playerInv[i].name + " to " + foundThing.Name); player.Inventory.Remove(playerInv[i]); } } } else { if (foundThing == null) { HubContext.SendToClient("You don't see " + thing + " here.", player.HubGuid); return; } if (foundItem == null) { HubContext.SendToClient("You are not carrying a " + item, player.HubGuid); return; } player.Inventory.Remove(foundItem); foundThing.Inventory.Add(foundItem); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You give a " + foundItem.name + " to " + foundThing.Name, player.Name + " gives a " + foundItem.name + " to " + foundThing.Name); //check quest foreach (var quest in player.QuestLog) { if (!quest.Completed && quest.Type == Quest.QuestType.FindMob) { //Find quest requires player to give item to the mob. if (quest.QuestGiver == foundThing.Name && quest.QuestItem.name == foundItem.name) { // player completed quest var mobQuest = foundThing.Quest.FirstOrDefault(x => x.Id.Equals(quest.Id)); if (mobQuest != null) { HubContext.SendToClient( foundThing.Name + " says to you " + mobQuest.RewardDialog.Message.Replace("$playerName", player.Name), player.HubGuid, null, true); } //award player } } } } //save to cache Cache.updateRoom(room, currentRoom); Cache.updatePlayer(player, currentPlayer); Score.UpdateUiInventory(player); var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); }
/// <summary> /// Drops item from player inventory /// </summary> /// <param name="room">room object</param> /// <param name="player">player object</param> /// <param name="userInput">text entered by user</param> /// <param name="commandKey">command entered</param> public static void DropItem(Room room, Player player, string userInput, string commandKey) { var currentRoom = room; var currentPlayer = player; string[] all = userInput.Split(); var returnedItem = (KeyValuePair <Item, Item>)FindObject(room, player, commandKey, userInput, FindInventory); var container = returnedItem.Key; var item = returnedItem.Value; if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase)) { var playerInv = player.Inventory; var playerInvCount = player.Inventory.Count; for (int i = playerInvCount - 1; i >= 0; i--) { playerInv[i].location = Item.ItemLocation.Room; if (container == null) { playerInv[i].location = Item.ItemLocation.Room; playerInv[i].isHiddenInRoom = false; room.items.Add(playerInv[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You drop a " + playerInv[i].name, player.Name + " drops a " + playerInv[i].name); player.Inventory.Remove(playerInv[i]); } else { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } if (container.open == false) { HubContext.SendToClient("You have to open the " + container.name + " before you can put something inside", player.HubGuid); return; } container.containerItems.Add(playerInv[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You drop a " + playerInv[i].name + " into a " + container.name, player.Name + " drops a " + playerInv[i].name + " into a " + container.name); player.Inventory.Remove(playerInv[i]); } } } else { if (item == null) { return; } if (container == null) { player.Inventory.Remove(item); item.location = Item.ItemLocation.Room; room.items.Add(item); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You drop a " + item.name, player.Name + " drops a " + item.name); } else { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } if (container.open == false) { HubContext.SendToClient("You have to open the " + container.name + " before you can put something inside", player.HubGuid); return; } player.Inventory.Remove(item); item.location = Item.ItemLocation.Room; container.containerItems.Add(item); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You put a " + item.name + " inside the " + container.name, player.Name + " puts a " + item.name + " inside the " + container.name); } } //save to cache Cache.updateRoom(room, currentRoom); Cache.updatePlayer(player, currentPlayer); Score.UpdateUiInventory(player); var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); }
/// <summary> /// Adds item from room to player inventory /// </summary> /// <param name="room">Room Object</param> /// <param name="player">Player Object</param> /// <param name="userInput">Text user entered</param> public static void GetItem(Room room, Player player, string userInput, string commandKey, string type) { //TODO handle container var currentRoom = room; var currentPlayer = player; string[] all = userInput.Split(); if (all[0] == "all") { type = "all"; } var returnedItem = (KeyValuePair <Item, Item>)FindObject(room, player, commandKey, userInput, type); var container = returnedItem.Key; var item = returnedItem.Value; if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase) && all.Length == 1) { var roomItems = room.items; var roomItemsCount = roomItems.Count; for (int i = roomItemsCount - 1; i >= 0; i--) { if (!roomItems[i].stuck) { //Get all Items from the room if (roomItems[i].type != Item.ItemType.Gold) { roomItems[i].location = Item.ItemLocation.Inventory; player.Inventory.Add(roomItems[i]); BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You pick up a " + roomItems[i].name, player.Name + " picks up a " + roomItems[i].name); room.items.Remove(roomItems[i]); } else { player.Gold += roomItems[i].count; BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You pick up " + roomItems[i].count + " " + roomItems[i].name, player.Name + " picks up a " + roomItems[i].name); room.items.Remove(roomItems[i]); } } else { HubContext.SendToClient("You can't take that", player.HubGuid); } } } else if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase) && container != null) { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } //get all from container var containerItems = container.containerItems; var containerCount = containerItems.Count; for (int i = containerCount - 1; i >= 0; i--) { if (containerItems[i].type != Item.ItemType.Gold) { containerItems[i].location = Item.ItemLocation.Inventory; player.Inventory.Add(containerItems[i]); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You get a " + containerItems[i].name + " from a " + container.name, player.Name + " get a " + containerItems[i].name + " from a " + container.name); containerItems.Remove(containerItems[i]); } else { player.Gold += containerItems[i].count; BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You pick up " + item.count + " " + item.name + " from a " + container.name, player.Name + " picks up a " + item.name + containerItems[i].name + " from a " + container.name); containerItems.Remove(containerItems[i]); } } } else if (item != null) { //get single Item if (container == null) { if (!item.stuck) { if (item.type != Item.ItemType.Gold) { room.items.Remove(item); item.location = Item.ItemLocation.Inventory; player.Inventory.Add(item); BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You pick up a " + item.name, player.Name + " picks up a " + item.name); } else { room.items.Remove(item); player.Gold += item.count; BroadcastPlayerAction.BroadcastPlayerActions( player.HubGuid, player.Name, room.players, "You pick up " + item.count + " " + item.name, player.Name + " picks up a " + item.name); } } else { HubContext.SendToClient("You can't take that", player.HubGuid); } } else { if (container.locked == true) { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "Container is locked", player.Name + " container is locked"); return; } //Get item from container if (item.type != Item.ItemType.Gold) { container.containerItems.Remove(item); container.location = Item.ItemLocation.Inventory; player.Inventory.Add(item); BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You get a " + item.name + " from " + container.name, player.Name + " gets a " + item.name + " from " + container.name); } else { container.containerItems.Remove(item); player.Gold += item.count; BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You get " + item.count + " " + item.name + "coin from a " + container.name, player.Name + " gets a " + item.name + " from a " + container.name); } } } else { BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "There is nothing here to pick up", player.Name + " searches for something to pick up"); return; } //save to cache Cache.updateRoom(room, currentRoom); Cache.updatePlayer(player, currentPlayer); Score.UpdateUiInventory(player); var roomdata = LoadRoom.DisplayRoom(room, player.Name); Score.UpdateUiRoom(player, roomdata); }
/// <summary> /// Displays room desc, players, mobs, items and exits /// </summary> /// <param name="room"></param> /// <param name="playerName"></param> /// <returns></returns> public static string DisplayRoom(Room room, string playerName) { string roomTitle = room.title; string roomDescription = room.description; var exitList = string.Empty; foreach (var exit in room.exits) { exitList += exit.name + (exit.name == "East" || exit.name == "West" ? " - " : " - ") + Helpers.FirstLetterToUpper(Startup.ReturnRooms.FirstOrDefault(x => x.areaId == exit.areaId && x.area == exit.area && x.region == exit.region).title) + "\r\n"; } var player = room.players.FirstOrDefault(x => x.Name.Equals(playerName)); if (player != null && player.Status == Player.PlayerStatus.Sleeping) { return("You can't see anything while asleep."); } var itemList = string.Empty; foreach (var item in room.items) { if (item != null) { if (item.itemFlags?.Contains(Item.Item.ItemFlags.invis) == true && player.DetectInvis == false || item.itemFlags?.Contains(Item.Item.ItemFlags.hidden) == true && player.DetectHidden == false) { continue; } if (!item.isHiddenInRoom) { var result = AvsAnLib.AvsAn.Query(item.name); string article = result.Article; if (!string.IsNullOrEmpty(item.description?.room)) { if (item.count > 0) { itemList += $"<p class='roomItems'>({item.count}) {item.description.room}<p>"; } else { itemList += $"<p class='roomItems'>{item.description.room}<p>"; } } else { if (item.count > 0) { itemList += $"<p class='roomItems'>({item.count}) {article} {item.name}'s are on the floor here.<p>"; } else { itemList += $"<p class='roomItems'>{article} {item.name} is on the floor here.<p>"; } } } } } var playerList = string.Empty; if (room.players != null) { foreach (var item in room.players) { if (item.invis == true && player.DetectInvis == false || item.hidden == true && player.DetectHidden == false) { continue; } if (item.nonDectect == true) { continue; } if (item.Effects?.FirstOrDefault( x => x.Name.Equals("Hidden", StringComparison.CurrentCultureIgnoreCase)) != null) { continue; } if (item.Name != playerName) { if (item.Status == Player.PlayerStatus.Standing) { playerList += "<p>" + LoadRoom.ShowObjectEffects(item) + " is here.</p>"; } else if (item.Status == Player.PlayerStatus.Fighting) { if (item.Target.Name == player.Name) { playerList += "<p>You are fighting " + item.Target.Name + "</p>"; } else { playerList += "<p>" + LoadRoom.ShowObjectEffects(item) + " is fighting " + item.Target.Name + "</p>"; } } else if (item.Status == Player.PlayerStatus.Stunned) { playerList += "<p>" + LoadRoom.ShowObjectEffects(item) + " is stunned.</p>"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Resting) { playerList += "<p>" + LoadRoom.ShowObjectEffects(item) + " is resting here.</p>"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Sleeping) { playerList += "<p>" + LoadRoom.ShowObjectEffects(item) + " is sleeping here.</p>"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Mounted) { playerList += "<p>" + LoadRoom.ShowObjectEffects(item) + " is here riding " + Helpers.ReturnName(null, null, item.Mount.Name).ToLower() + ".</p>"; } else { playerList += "<p>" + LoadRoom.ShowObjectEffects(item) + " is here.</p>"; } } } } var mobList = string.Empty; if (room.mobs != null) { foreach (var item in room.mobs) { if (item.invis == true && player.DetectInvis == false || item.hidden == true && player.DetectHidden == false) { continue; } if (item.nonDectect == true) { continue; } var result = AvsAnLib.AvsAn.Query(item.Name); string article = result.Article; if (item.KnownByName) { article = string.Empty; } var npcName = !string.IsNullOrEmpty(item.NPCLongName) ? item.NPCLongName : $"{item.Name} is here"; if (item.Status == Player.PlayerStatus.Standing) { mobList += $"{Helpers.FirstLetterToUpper(article)} {npcName}.\r\n"; } else if (item.Status == Player.PlayerStatus.Fighting) { mobList += $"{article} {item.Name} is fighting {item.Target.Name}.\r\n"; } else if (item.Status == Player.PlayerStatus.Stunned) { mobList += article + " " + item.Name + " is stunned. \r\n"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Resting) { mobList += article + " " + item.Name + " is resting. \r\n"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Sleeping) { if (!string.IsNullOrEmpty(item.Pose)) { mobList += item.Pose + "\r\n"; } else { mobList += article + " " + item.Name + " is sleeping. \r\n"; } } else { mobList += article + " " + npcName + "\r\n"; } } } string displayRoom = $"<p class='roomTitle'>{roomTitle}<p><p class='roomDescription'>{roomDescription}</p> <pre class='RoomExits'>Exits: \r\n{exitList.ToLower()}</pre> {itemList} {playerList} <pre class='roomMob'>{mobList}</pre>"; return(displayRoom); }
/// <summary> /// Displays room desc, players, mobs, items and exits /// </summary> /// <param name="room"></param> /// <param name="playerName"></param> /// <returns></returns> public static string DisplayRoom(Room room, string playerName) { string roomTitle = room.title; string roomDescription = room.description; var exitList = string.Empty; foreach (var exit in room.exits) { exitList += exit.name + " "; } var player = room.players.FirstOrDefault(x => x.Name.Equals(playerName)); if (player != null && player.Status == Player.PlayerStatus.Sleeping) { return("You can't see anything while asleep."); } var itemList = string.Empty; foreach (var item in room.items) { if (item != null) { if (item.itemFlags?.Contains(Item.Item.ItemFlags.invis) == true && player.DetectInvis == false || item.itemFlags?.Contains(Item.Item.ItemFlags.hidden) == true && player.DetectHidden == false) { continue; } if (!item.isHiddenInRoom) { var result = AvsAnLib.AvsAn.Query(item.name); string article = result.Article; if (!string.IsNullOrEmpty(item.description?.room)) { if (item.count > 0) { itemList += $"<p class='roomItems'>({item.count}) {item.description.room}<p>"; } else { itemList += $"<p class='roomItems'>{item.description.room}<p>"; } } else { if (item.count > 0) { itemList += $"<p class='roomItems'>({item.count}) {item.name} are on the floor here.<p>"; } else { itemList += $"<p class='roomItems'>{article} {item.name} is on the floor here.<p>"; } } } } } var playerList = string.Empty; if (room.players != null) { foreach (var item in room.players) { if (item.invis == true && player.DetectInvis == false || item.hidden == true && player.DetectHidden == false) { continue; } if (item.nonDectect == true) { continue; } if (item.Name != playerName) { if (item.Status == Player.PlayerStatus.Standing) { playerList += LoadRoom.ShowObjectEffects(item) + " is here\r\n"; } else if (item.Status == Player.PlayerStatus.Fighting) { if (item.Target.Name == player.Name) { playerList += "You are fighting " + item.Target.Name + "\r\n"; } else { playerList += LoadRoom.ShowObjectEffects(item) + " is fighting " + item.Target.Name + "\r\n"; } } else if (item.Status == PlayerSetup.Player.PlayerStatus.Resting) { playerList += LoadRoom.ShowObjectEffects(item) + " is resting."; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Sleeping) { playerList += LoadRoom.ShowObjectEffects(item) + " is sleeping."; } else { playerList += LoadRoom.ShowObjectEffects(item) + " is here\r\n"; } } } } var mobList = string.Empty; if (room.mobs != null) { foreach (var item in room.mobs) { if (item.invis == true && player.DetectInvis == false || item.hidden == true && player.DetectHidden == false) { continue; } if (item.nonDectect == true) { continue; } var result = AvsAnLib.AvsAn.Query(item.Name); string article = result.Article; if (item.KnownByName) { article = string.Empty; } var npcName = !string.IsNullOrEmpty(item.NPCLongName) ?item.NPCLongName : $"{item.Name} is here"; if (item.Status == Player.PlayerStatus.Standing) { mobList += "<p class='roomMob'>" + article + " " + npcName + ".<p>"; } else if (item.Status == Player.PlayerStatus.Fighting) { mobList += "<p class='roomMob'>" + article + " " + item.Name + " is fighting " + item.Target.Name + ".</p>"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Resting) { mobList += "<p class='roomMob'>" + article + " " + item.Name + " is resting.<p>"; } else if (item.Status == PlayerSetup.Player.PlayerStatus.Sleeping) { if (!string.IsNullOrEmpty(item.Pose)) { mobList += "<p class='roomMob'>" + item.Pose + "<p>"; } else { mobList += "<p class='roomMob'>" + article + " " + item.Name + " is sleeping.<p>"; } } else { mobList += "<p class='roomMob'>" + article + " " + npcName + "<p>"; } } } string displayRoom = "<p class='roomTitle'>" + roomTitle + "<p><p class='roomDescription'>" + roomDescription + "</p> <p class='RoomExits'>[ Exits: " + exitList.ToLower() + " ]</p>" + itemList + "\r\n" + playerList + "\r\n" + mobList; return(displayRoom); }