Ejemplo n.º 1
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void ReturnRoom(Player player, Room room, string commandOptions = "", string keyword = "")
        {
            var isBlind = player.Effects?.FirstOrDefault(
                x => x.Name.Equals("Blindness", StringComparison.CurrentCultureIgnoreCase)) != null;

            if (isBlind)
            {
                HubContext.Instance.SendToClient("You can't see a thing.", player.HubGuid);
                return;
            }


            if (string.IsNullOrEmpty(commandOptions) && keyword.StartsWith("examine"))
            {
                HubContext.Instance.SendToClient("Examine what?", player.HubGuid);
                return;
            }


            if (string.IsNullOrEmpty(commandOptions) && keyword.StartsWith("touch"))
            {
                HubContext.Instance.SendToClient("Touch what?", player.HubGuid);
                return;
            }

            if (string.IsNullOrEmpty(commandOptions) && keyword.StartsWith("smell"))
            {
                HubContext.Instance.SendToClient("Smell what?", player.HubGuid);
                return;
            }

            if (string.IsNullOrEmpty(commandOptions) && keyword.StartsWith("taste"))
            {
                HubContext.Instance.SendToClient("Taste what?", player.HubGuid);
                return;
            }



            CheckEvent.FindEvent(CheckEvent.EventType.Look, player, "look");

            Room roomData = room;

            if (string.IsNullOrEmpty(commandOptions) && keyword == "look")
            {
                var roomInfo = DisplayRoom(roomData, player.Name);
                HubContext.Instance.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 playerItemDescription = (n == -1)
                    ? player?.Inventory.Find(x => x.name.ToLower().Contains(commandOptions))
                    : player?.Inventory.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.Instance.SendToClient(descriptionText, player.HubGuid);

                        foreach (var players in room.players)
                        {
                            if (player.Name != players.Name)
                            {
                                HubContext.Instance.SendToClient(player.Name + broadcastAction, players.HubGuid);
                            }
                        }
                    }
                    else
                    {
                        HubContext.Instance.SendToClient("You see nothing special about the " + 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.Instance.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.Instance.SendToClient("You look into the " + itemDescription.name + " and see:", player.HubGuid);


                                foreach (var containerItem in itemDescription.containerItems.List(true))
                                {
                                    HubContext.Instance.SendToClient(containerItem, player.HubGuid);
                                }
                            }
                            else
                            {
                                HubContext.Instance.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.Instance.SendToClient(roomMessage, character.HubGuid);
                                }
                            }
                        }
                        else
                        {
                            HubContext.Instance.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.Instance.SendToClient(descriptionText, player.HubGuid);

                            foreach (var players in room.players)
                            {
                                if (player.Name != players.Name)
                                {
                                    HubContext.Instance.SendToClient(player.Name + broadcastAction,
                                                                     players.HubGuid);
                                }
                            }
                        }
                        else
                        {
                            var    result  = AvsAnLib.AvsAn.Query(itemDescription.name);
                            string article = result.Article;

                            HubContext.Instance.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.Instance.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.Instance.SendToClient(roomMessage, character.HubGuid);
                            }
                        }
                    }
                    else
                    {
                        HubContext.Instance.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.Instance.SendToClient(descriptionText, player.HubGuid);
                        Equipment.ShowEquipmentLook(playerDescription, player);
                        HubContext.Instance.SendToClient(player.Name + " looks at you", playerDescription.HubGuid);
                    }
                    else
                    {
                        HubContext.Instance.SendToClient("You can't do that to a " + playerDescription.Name, player.HubGuid);
                    }
                }
                else if (playerItemDescription != null && !string.IsNullOrWhiteSpace(commandOptions))
                {
                    string descriptionText = string.Empty;
                    string broadcastAction = string.Empty;

                    if (keyword.Equals("look in", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (playerItemDescription.open == false)
                        {
                            HubContext.Instance.SendToClient("You need to open the " + playerItemDescription.name + " before you can look inside", player.HubGuid);
                            return;
                        }

                        if (playerItemDescription.container == true)
                        {
                            if (playerItemDescription.containerItems.Count > 0)
                            {
                                HubContext.Instance.SendToClient("You look into the " + playerItemDescription.name + " and see:", player.HubGuid);

                                foreach (var containerItem in playerItemDescription.containerItems.List(true))
                                {
                                    HubContext.Instance.SendToClient(containerItem, player.HubGuid);
                                }
                            }
                            else
                            {
                                HubContext.Instance.SendToClient("You look into the " + playerItemDescription.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 {playerItemDescription.name}";

                                    HubContext.Instance.SendToClient(roomMessage, character.HubGuid);
                                }
                            }
                        }
                        else
                        {
                            HubContext.Instance.SendToClient(playerItemDescription.name + " is not a container", player.HubGuid);
                        }
                    }
                    else if (keyword.StartsWith("look"))
                    {
                        descriptionText = playerItemDescription.description.look;
                        broadcastAction = " looks at a " + playerItemDescription.name;
                    }
                    else if (keyword.StartsWith("examine"))
                    {
                        descriptionText = playerItemDescription.description.exam;
                        broadcastAction = " looks closely at a " + playerItemDescription.name;
                    }

                    if (!keyword.Equals("look in", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!string.IsNullOrEmpty(descriptionText))
                        {
                            HubContext.Instance.SendToClient(descriptionText, player.HubGuid);

                            foreach (var players in room.players)
                            {
                                if (player.Name != players.Name)
                                {
                                    HubContext.Instance.SendToClient(player.Name + broadcastAction,
                                                                     players.HubGuid);
                                }
                            }
                        }
                        else
                        {
                            var    result  = AvsAnLib.AvsAn.Query(playerItemDescription.name);
                            string article = result.Article;

                            HubContext.Instance.SendToClient("You see nothing special about " + article + " " + playerItemDescription.name, player.HubGuid);
                        }
                    }
                }
                else if (roomExitDescription != null)
                {
                    HubContext.Instance.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.Instance.SendToClient(showNextRoom, player.HubGuid);

                    player.AreaId = currentAreaId;

                    foreach (var players in room.players)
                    {
                        if (player.Name != players.Name)
                        {
                            HubContext.Instance.SendToClient(player.Name + " looks " + roomExitDescription.name, players.HubGuid);
                        }
                    }
                }
                else
                {
                    HubContext.Instance.SendToClient("You don't see that here.", player.HubGuid);
                }
            }
        }