Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Close
        /// </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 Close(Room room, Player player, string userInput, string commandKey)
        {
            var currentRoom = room;

            var findObject = Events.FindNth.Findnth(userInput);
            int nth        = findObject.Key;

            Item foundItem = null;
            Exit foundExit = null;

            foundItem = FindItem.Item(room.items, nth, userInput);


            if (foundItem == null)
            {
                foundExit = FindItem.Exit(room.exits, nth, userInput);

                if (foundExit.canOpen == false)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't close that", player.Name + " tries to close the " + foundExit.name);
                    return;
                }
            }

            if (foundItem != null)
            {
                if (foundItem.canOpen == false)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't close that", player.Name + " tries to close the " + foundItem.name);
                    return;
                }

                if (foundItem.open == false)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "It's already closed", player.Name + " tries to close the " + foundItem.name + " which is already closed");
                    return;
                }

                if (foundItem.locked)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You need to unlock that before you can close it", player.Name + " tries to close the " + foundItem.name + "without a key");
                    return;
                }


                if (foundItem.open)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(
                        player.HubGuid,
                        player.Name,
                        room.players,
                        "You close the chest",
                        player.Name + " close the " + foundItem.name);
                    foundItem.open = false;
                }
                else
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(
                        player.HubGuid,
                        player.Name,
                        room.players,
                        "the " + foundItem.name + " is already close  " + foundItem.name,
                        player.Name + " tries to close the already close chest" + foundItem.name);

                    return;
                }
            }
            else if (foundExit != null)
            {
                if (foundExit.open != true)
                {
                    if (foundExit.locked)
                    {
                        BroadcastPlayerAction.BroadcastPlayerActions(
                            player.HubGuid,
                            player.Name,
                            room.players,
                            "You need to unlock that before you can close it",
                            player.Name + " tries to close the " + foundExit.name + "without a key");
                        return;
                    }

                    BroadcastPlayerAction.BroadcastPlayerActions(
                        player.HubGuid,
                        player.Name,
                        room.players,
                        "You close " + foundExit.name,
                        player.Name + " closes the " + foundExit.name);
                    foundExit.open = false;
                }
                else
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(
                        player.HubGuid,
                        player.Name,
                        room.players,
                        "the " + foundExit.name + " is already closed  " + foundExit.name,
                        player.Name + " tries to close the already closed chest" + foundExit.name);
                    return;
                }
            }
            //save to cache
            Cache.updateRoom(room, currentRoom);
        }
Exemplo n.º 4
0
        /// <summary>
        /// lock Item
        /// </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 LockItem(Room room, Player player, string userInput, string commandKey)
        {
            var currentRoom   = room;
            var currentPlayer = player;

            string[] all = userInput.Split();
            // var lockedItem = (KeyValuePair<Item, Item>)FindObject(room, player, commandKey, userInput, FindInventory);
            // var container = lockedItem.Key;
            //  var item = lockedItem.Value;

            var findObject = Events.FindNth.Findnth(userInput);
            int nth        = findObject.Key;

            Item foundItem = null;
            Exit foundExit = null;

            foundItem = FindItem.Item(room.items, nth, userInput);



            if (foundItem == null)
            {
                foundExit = FindItem.Exit(room.exits, nth, userInput);

                if (foundExit.canLock == false)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't lock that", player.Name + " tries to lock the " + foundItem.name);
                    return;
                }
            }

            if (foundItem != null)
            {
                if (foundItem.canLock == false)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You can't lock that", player.Name + " tries to lock the " + foundItem.name);
                    return;
                }

                // find key matching chest lock id
                var hasKey = false;

                foreach (var key in player.Inventory)
                {
                    if (key.keyValue != null)
                    {
                        if (key.keyValue == foundItem.keyId)
                        {
                            hasKey = true;
                        }
                    }
                }

                if (hasKey == false)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't have a key for that", player.Name + " tries to lock the " + foundItem.name + " without the key");
                    return;
                }

                if (foundItem.locked != true)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You lock the chest", player.Name + " locks the " + foundItem.name);
                    foundItem.locked = true;
                }
                else
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "the chest is already locked  " + foundItem.name, player.Name + " tries to locked the already locked chest" + foundItem.name);

                    return;
                }
            }
            else
            {
                // find key matching chest lock id
                var hasKey = false;

                foreach (var key in player.Inventory.Where(key => key.keyValue != null).Where(key => key.keyValue == foundExit.keyId))
                {
                    hasKey = true;
                }

                if (hasKey == false)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You don't have a key for that", player.Name + " tries to lock the " + foundExit.name + " without the key");
                    return;
                }

                if (foundExit.locked != true)
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "You lock the chest", player.Name + " locks the " + foundExit.name);
                    foundExit.locked = true;
                }
                else
                {
                    BroadcastPlayerAction.BroadcastPlayerActions(player.HubGuid, player.Name, room.players, "the chest is already locked  " + foundExit.name, player.Name + " tries to locked the already locked chest" + foundExit.name);

                    return;
                }
            }



            //save to cache
            Cache.updateRoom(room, currentRoom);
        }
Exemplo n.º 5
0
        /// <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));
        }
Exemplo n.º 6
0
        public static void RepairItem(PlayerSetup.Player player, Room.Room room, string commandOptions)
        {
            var hasSkill = player.Skills.FirstOrDefault(x => x.Name.Equals("Repair"));

            if (hasSkill == null)
            {
                HubContext.Instance.SendToClient("You don't know how to do that.", player.HubGuid);
                return;
            }


            if (string.IsNullOrEmpty(commandOptions))
            {
                return;
            }

            var item         = FindNth.Findnth(commandOptions);
            var foundItem    = FindItem.Item(player.Inventory, item.Key, item.Value, Item.Item.ItemLocation.Inventory);
            var repairHammer =
                player.Inventory.FirstOrDefault(x => x.name.ToLower().Contains(player.Equipment.Held.ToLower()));

            if (foundItem == null)
            {
                HubContext.Instance.SendToClient("You don't have " + Helpers.ReturnName(null, null, item.Value), player.HubGuid);
                return;
            }

            if (foundItem.Condition >= 75)
            {
                HubContext.Instance.SendToClient("You can't improve " + Helpers.ReturnName(null, null, foundItem.name) + " any further.", player.HubGuid);
                return;
            }

            if (repairHammer != null && repairHammer.type == Item.Item.ItemType.Repair)
            {
                var chance = Helpers.Rand(1, 100);

                if (hasSkill.Proficiency >= chance)
                {
                    foundItem.Condition += Helpers.Rand(10, 25);

                    HubContext.Instance.SendToClient(Helpers.ReturnName(null, null, item.Value) + " looks to be in a better condition.", player.HubGuid);

                    if (foundItem.Condition > 0)
                    {
                        var iname = Helpers.FirstLetterToUpper(foundItem.name.ToLower().Replace("broken", String.Empty)
                                                               .Trim());
                        foundItem.name = iname;
                    }

                    if (foundItem.Condition >= 75)
                    {
                        var removeBrokenFromName = foundItem.name.ToLower().Replace("broken ", String.Empty).Trim();
                        foundItem.name      = Helpers.FirstLetterToUpper(removeBrokenFromName);
                        foundItem.Condition = 75;
                        HubContext.Instance.SendToClient(Helpers.ReturnName(null, null, item.Value) + " has been fully repaired.", player.HubGuid);

                        Score.UpdateUiInventory(player);
                        return;
                    }

                    repairHammer.Uses -= 1;
                }
                else
                {
                    HubContext.Instance.SendToClient("You fail to improve the condition of " + Helpers.ReturnName(null, null, item.Value), player.HubGuid);
                    PlayerSetup.Player.LearnFromMistake(player, hasSkill, 100);
                }



                if (repairHammer.Uses <= 0)
                {
                    HubContext.Instance.SendToClient("The repair hammer falls to pieces in your hand.", player.HubGuid);
                    player.Inventory.Remove(repairHammer);
                    player.Equipment.Held = "Nothing";
                }

                Score.UpdateUiInventory(player);
                Score.ReturnScoreUI(player);
            }
            else
            {
                HubContext.Instance.SendToClient("You need to equip a repair hammer", player.HubGuid);
                return;
            }
        }