Пример #1
0
        public bool EquipItem(Items.Iitem item, Inventory inventory)
        {
            bool result = false;

            Items.Iweapon weaponItem = item as Items.Iweapon;
            if (weaponItem != null && weaponItem.IsWieldable)
            {
                //can't equip a wieldable weapon
            }
            else
            {
                if (!equipped.ContainsKey(item.WornOn))
                {
                    equipped.Add(item.WornOn, item);
                    if (inventory.inventory.Any(i => i.Id == item.Id))         //in case we are adding it from a load and not moving it from the inventory
                    {
                        inventory.inventory.RemoveWhere(i => i.Id == item.Id); //we moved the item over to equipped so we need it out of inventory
                    }
                    result = true;
                }
                else if (item.WornOn == Items.Wearable.WIELD_LEFT || item.WornOn == Items.Wearable.WIELD_RIGHT) //this item can go in the free hand
                {
                    Items.Wearable freeHand = Items.Wearable.WIELD_LEFT;                                        //we default to right hand for weapons
                    if (equipped.ContainsKey(freeHand))
                    {
                        freeHand = Items.Wearable.WIELD_RIGHT; //maybe this perosn is left handed
                    }
                    if (!equipped.ContainsKey(freeHand))       //ok let's equip this
                    {
                        item.WornOn = freeHand;
                        item.Save();
                        equipped.Add(freeHand, item);
                        if (inventory.inventory.Any(i => i.Id == item.Id))         //in case we are adding it from a load and not moving it from the inventory
                        {
                            inventory.inventory.RemoveWhere(i => i.Id == item.Id); //we moved the item over to equipped so we need it out of inventory
                        }
                        result = true;
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public static void Wield(User.User player, List <string> commands)
        {
            StringBuilder itemName     = new StringBuilder();
            int           itemPosition = 1;

            string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
            if (position.Count() > 1)
            {
                int.TryParse(position[position.Count() - 1], out itemPosition);
                itemName = itemName.Remove(itemName.Length - 2, 2);
            }

            string full = commands[0];

            commands.RemoveRange(0, 2);

            foreach (string word in commands)
            {
                itemName.Append(word + " ");
            }

            string msgPlayer = null;

            List <Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);

            Items.Iitem item = items[itemPosition - 1];

            Items.Iweapon weapon = (Items.Iweapon)item;

            if (weapon != null && weapon.IsWieldable && player.Player.Equipment.GetWieldedWeapons().Count < 2)
            {
                if (string.IsNullOrEmpty(player.Player.MainHand))                   //no mainhand assigned yet
                {
                    player.Player.MainHand = Items.Wearable.WIELD_RIGHT.ToString(); //we will default to the right hand
                }

                player.Player.Equipment.Wield(item, player.Player.Inventory);
                item.Save();
                //TODO: check weapon for any wield perks/curses

                string msgOthers = string.Format("{0} wields {1}", player.Player.FirstName, item.Name);
                Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID }));
                msgPlayer = string.Format("You wield {0}", item.Name);
            }
            else if (player.Player.Equipment.GetWieldedWeapons().Count == 2)
            {
                msgPlayer = "You are already wielding two weapons...and you don't seem to have a third hand.";
            }
            else if (item.IsWearable)
            {
                msgPlayer = "This item can only be wielded not worn.";
            }
            else if (!item.IsWearable)
            {
                msgPlayer = "That not something you can wear or would want to wear.";
            }
            else
            {
                msgPlayer = "You don't seem to have that in your inventory to be able to wear.";
            }

            player.MessageHandler(msgPlayer);
        }
Пример #3
0
        public static void Equip(User.User player, List <string> commands)
        {
            StringBuilder itemName     = new StringBuilder();
            int           itemPosition = 1;
            string        msgOthers    = null;
            string        msgPlayer    = null;

            //we need to make a list of items to wear from the players inventory and sort them based on stats
            if (commands.Count > 2 && string.Equals(commands[2].ToLower(), "all", StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (Items.Iitem item in player.Player.Inventory.GetAllItemsToWear())
                {
                    if (player.Player.Equipment.EquipItem(item, player.Player.Inventory))
                    {
                        msgPlayer += string.Format("You equip {0}.\n", item.Name);
                        msgOthers  = string.Format("{0} equips {1}.\n", player.Player.FirstName, item.Name);
                    }
                }
            }
            else
            {
                string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
                if (position.Count() > 1)
                {
                    int.TryParse(position[position.Count() - 1], out itemPosition);
                    itemName = itemName.Remove(itemName.Length - 2, 2);
                }

                string full = commands[0];
                commands.RemoveRange(0, 2);

                foreach (string word in commands)
                {
                    itemName.Append(word + " ");
                }

                List <Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
                msgPlayer = null;

                //players need to specify an indexer or we will just give them the first one we found that matched
                Items.Iitem item = items[itemPosition - 1];

                Items.Iweapon weapon = item as Items.Iweapon;

                if (item != null && item.IsWearable)
                {
                    player.Player.Equipment.EquipItem(item, player.Player.Inventory);
                    if (item.ItemType.ContainsKey(Items.ItemsType.CONTAINER))
                    {
                        Items.Icontainer container = item as Items.Icontainer;
                        container.Wear();
                    }
                    if (item.ItemType.ContainsKey(Items.ItemsType.CLOTHING))
                    {
                        Items.Iclothing clothing = item as Items.Iclothing;
                        clothing.Wear();
                    }

                    msgOthers = string.Format("{0} equips {1}.", player.Player.FirstName, item.Name);
                    msgPlayer = string.Format("You equip {0}.", item.Name);
                }
                else if (weapon.IsWieldable)
                {
                    msgPlayer = "This item can only be wielded not worn.";
                }
                else if (!item.IsWearable || !weapon.IsWieldable)
                {
                    msgPlayer = "That doesn't seem like something you can wear.";
                }
                else
                {
                    msgPlayer = "You don't seem to have that in your inventory to be able to wear.";
                }
            }

            player.MessageHandler(msgPlayer);
            Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID }));
        }