Ejemplo n.º 1
0
        private static Items.Iitem KeepOpening(string itemName, Items.Iitem item, int itemPosition = 1, int itemIndex = 1)
        {
            Items.Icontainer container = item as Items.Icontainer;

            if (item.ItemType.ContainsKey(Items.ItemsType.CONTAINER) && container.Contents.Count > 0)
            {
                foreach (string innerID in container.GetContents())
                {
                    Items.Iitem innerItem = Items.Items.GetByID(innerID);
                    if (innerItem != null && KeepOpening(itemName, innerItem, itemPosition, itemIndex).Name.Contains(itemName))
                    {
                        if (itemIndex == itemPosition)
                        {
                            return(innerItem);
                        }
                        else
                        {
                            itemIndex++;
                        }
                    }
                }
            }

            return(item);
        }
Ejemplo n.º 2
0
        public static void Drop(User.User player, List <string> commands)
        {
            //1.get the item name from the command, may have to join all the words after dropping the command
            StringBuilder itemName = new StringBuilder();
            Room          room     = Room.GetRoom(player.Player.Location);

            string full = commands[0];

            commands.RemoveAt(0);
            commands.RemoveAt(0);

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

            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);
            }

            //2.get the item from the DB
            List <Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);

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

            //3.have player drop item
            string msgPlayer = null;

            if (item != null)
            {
                player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);
                item.Location = player.Player.Location;
                item.Owner    = item.Location.ToString();
                item.Save();

                //4.Inform room and player of action
                string msgOthers = string.Format("{0} drops {1}", player.Player.FirstName, item.Name);
                room.InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID }));
                msgPlayer = string.Format("You drop {0}", item.Name);
            }
            else
            {
                msgPlayer = "You are not carrying anything of the sorts.";
            }

            player.MessageHandler(msgPlayer);
        }
Ejemplo n.º 3
0
        //TODO: had a bug where I removed item form a container, shut down the game and then both container and player still had the same item (the player even had it duped)
        //needless to say this is bad and fail.
        public static void Get(User.User player, List <string> commands)
        {
            int    itemPosition      = 1;
            int    containerPosition = 1;
            string itemName          = "";
            string containerName     = "";

            List <string> commandAltered = ParseItemPositions(commands, "from", out itemPosition, out itemName);

            ParseContainerPosition(commandAltered, commands[3], out containerPosition, out containerName);

            string location = player.Player.Location;

            Items.Iitem retrievedItem = null;
            Items.Iitem containerItem = null;

            //using a recursive method we will dig down into each sub container and look for the appropriate item/container
            TraverseItems(player, containerName.ToString().Trim(), itemName.ToString().Trim(), containerPosition, itemPosition, out retrievedItem, out containerItem);

            string msg       = null;
            string msgOthers = null;

            if (retrievedItem != null)
            {
                Items.Icontainer container = containerItem as Items.Icontainer;
                if (containerItem != null)
                {
                    retrievedItem = container.RetrieveItem(retrievedItem.Id.ToString());
                    msg           = "You take " + retrievedItem.Name.ToLower() + " out of " + containerItem.Name.ToLower() + ".";

                    msgOthers = string.Format("{0} takes {1} out of {2}", player.Player.FirstName, retrievedItem.Name.ToLower(), containerItem.Name.ToLower());
                }
                else
                {
                    msg       = "You get " + retrievedItem.Name.ToLower();
                    msgOthers = string.Format("{0} grabs {1}.", player.Player.FirstName, retrievedItem.Name.ToLower());
                }

                retrievedItem.Location = null;
                retrievedItem.Owner    = player.UserID;
                retrievedItem.Save();
                player.Player.Inventory.AddItemToInventory(retrievedItem);
            }
            else
            {
                msg = "You can't seem to find " + itemName.ToString().Trim().ToLower() + " to grab it.";
            }

            Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID }));
            player.MessageHandler(msg);
        }
Ejemplo n.º 4
0
        public void UpdateInventoryFromDatabase()
        {
            MongoCollection col  = MongoUtils.MongoData.GetCollection("World", "Items");
            var             docs = col.FindAs <BsonDocument>(Query.EQ("Owner", playerID));

            foreach (BsonDocument dbItem in docs)
            {
                ObjectId    itemID = dbItem["_id"].AsObjectId;
                Items.Iitem temp   = inventory.Where(i => i.Id == itemID).SingleOrDefault();
                if (temp == null)
                {
                    inventory.Add(Items.Items.GetByID(dbItem["_id"].AsObjectId.ToString()));
                }
            }
        }
Ejemplo n.º 5
0
        private static string FindAnItem(List <string> commands, User.User player, Room room, out bool foundIt)
        {
            foundIt = false;
            string message = null;

            List <string> itemsInRoom = room.GetObjectsInRoom(Room.RoomObjects.Items);

            foreach (string id in itemsInRoom)
            {
                Items.Iitem item = Items.ItemFactory.CreateItem(ObjectId.Parse(id));
                if (commands[2].ToLower().Contains(item.Name.ToLower()))
                {
                    message = item.Examine();
                    foundIt = true;
                    break;
                }
            }

            if (!foundIt)   //not in room check inventory
            {
                List <Items.Iitem> inventory = player.Player.Inventory.GetInventoryAsItemList();
                foreach (Items.Iitem item in inventory)
                {
                    if (commands[2].ToLower().Contains(item.Name.ToLower()))
                    {
                        message = item.Examine();
                        foundIt = true;
                        break;
                    }
                }
            }

            if (!foundIt)   //check equipment
            {
                Dictionary <Items.Wearable, Items.Iitem> equipment = player.Player.Equipment.GetEquipment();
                foreach (Items.Iitem item in equipment.Values)
                {
                    if (commands[2].ToLower().Contains(item.Name.ToLower()))
                    {
                        message = item.Examine();
                        foundIt = true;
                        break;
                    }
                }
            }

            return(message);
        }
Ejemplo n.º 6
0
 public static void Drink(User.User player, List <string> commands)
 {
     Items.Iitem item = GetItem(commands, player.Player.Location.ToString());
     if (item == null)
     {
         player.MessageHandler("You don't seem to be carrying that to drink it.");
         return;
     }
     if (item.ItemType.ContainsKey(Items.ItemsType.DRINKABLE))
     {
         Consume(player, commands, "drink", item);
     }
     else
     {
         player.MessageHandler("You can't drink that!");
     }
 }
Ejemplo n.º 7
0
        private void GetItemsInRoom()
        {
            MongoDatabase   playersDB        = MongoUtils.MongoData.GetDatabase("World");
            MongoCollection playerCollection = playersDB.GetCollection("Items");
            IMongoQuery     query            = Query.EQ("Location", Id);
            MongoCursor     itemsInRoom      = playerCollection.FindAs <BsonDocument>(query);

            items = new List <string>();

            foreach (BsonDocument doc in itemsInRoom)
            {
                Items.Iitem item = Items.Items.GetByID(doc["_id"].AsObjectId.ToString());
                if (item != null)
                {
                    items.Add(item.Id.ToString());
                }
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 private void UpdateEquipmentFromDatabase(Dictionary <Items.Wearable, Items.Iitem> equipped)
 {
     if (playerID != null)
     {
         MongoCollection col  = MongoUtils.MongoData.GetCollection("World", "Items");
         var             docs = col.FindAs <BsonDocument>(Query.EQ("Owner", playerID));
         foreach (BsonDocument dbItem in docs)
         {
             ObjectId itemID = dbItem["_id"].AsObjectId;
             //do they have this item equipped?
             Items.Iitem temp = equipped.Where(i => i.Value.Id == itemID).SingleOrDefault().Value;
             if (temp == null)
             {
                 //let's equip it then
                 temp = Items.Items.GetByID(dbItem["_id"].AsObjectId.ToString());
                 equipped[temp.WornOn] = temp;
             }
         }
     }
 }
Ejemplo n.º 10
0
        public Items.Iitem RemoveInventoryItem(Items.Iitem item, Equipment equipment)
        {
            Items.Iitem result = null;

            result = inventory.Where(i => i.Id == item.Id).SingleOrDefault();
            inventory.RemoveWhere(i => i.Id == item.Id);

            if (result == null)   //so if it wasn't in the inventory we need to check what is equipped
            {
                foreach (KeyValuePair <Items.Wearable, Items.Iitem> slot in equipment.equipped)
                {
                    if (slot.Value == item)
                    {
                        result = (Items.Iitem)slot.Value;
                        equipment.equipped.Remove(slot.Key);
                        break;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 11
0
        public bool UnequipItem(Items.Iitem item, Iactor player)
        {
            bool result = false;

            if (equipped.ContainsKey(item.WornOn))
            {
                player.Inventory.inventory.Add(item); //unequipped stuff goes to inventory
                equipped.Remove(item.WornOn);

                //if their main hand is now empty, we will make the other hand the main hand
                if (!string.IsNullOrEmpty(player.MainHand) && string.Equals(item.WornOn.ToString(), player.MainHand, StringComparison.InvariantCultureIgnoreCase))
                {
                    player.MainHand = Items.Wearable.WIELD_RIGHT.ToString();
                    if (item.WornOn == Items.Wearable.WIELD_RIGHT)
                    {
                        player.MainHand = Items.Wearable.WIELD_LEFT.ToString();
                    }
                }
                result = true;
            }
            return(result);
        }
Ejemplo n.º 12
0
        public bool WieldItem(Items.Iitem item, Inventory inventory)
        {
            bool wielded = false;

            if (!equipped.ContainsKey(Items.Wearable.WIELD_RIGHT))
            {
                item.WornOn = Items.Wearable.WIELD_RIGHT;
                wielded     = true;
            }
            else if (!equipped.ContainsKey(Items.Wearable.WIELD_LEFT))
            {
                item.WornOn = Items.Wearable.WIELD_LEFT;
                wielded     = true;
            }

            if (wielded)
            {
                equipped.Add(item.WornOn, item);
                inventory.inventory.RemoveWhere(i => i.Id == item.Id);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 13
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 }));
        }
Ejemplo n.º 14
0
        private bool LightSourcePresent()
        {
            //foreach player/npc/item in room check to see if it is lightsource and on
            bool lightSource = false;

            //check th eplayers and see if anyones equipment is a lightsource
            foreach (string id in players)
            {
                User.User temp = MySockets.Server.GetAUser(id);
                Dictionary <Items.Wearable, Items.Iitem> equipped = temp.Player.Equipment.GetEquipment();
                foreach (Items.Iitem item in equipped.Values)
                {
                    Items.Iiluminate light = item as Items.Iiluminate;
                    if (light != null && light.isLit)
                    {
                        lightSource = true;
                        break;
                    }
                }
                if (lightSource)
                {
                    break;
                }
            }

            //check the NPCS and do the same as we did with the players
            if (!lightSource)
            {
                foreach (string id in npcs)
                {
                    Character.Iactor actor = Character.NPCUtils.GetAnNPCByID(id);
                    Dictionary <Items.Wearable, Items.Iitem> equipped = actor.Equipment.GetEquipment();
                    foreach (Items.Iitem item in equipped.Values)
                    {
                        Items.Iiluminate light = item as Items.Iiluminate;
                        if (light != null && light.isLit)
                        {
                            lightSource = true;
                            break;
                        }
                    }
                    if (lightSource)
                    {
                        break;
                    }
                }
            }

            //finally check for items in the room (just ones laying in the room, if a container is open check in container)
            if (!lightSource)
            {
                foreach (string id in items)
                {
                    Items.Iitem      item      = Items.Items.GetByID(id);
                    Items.Icontainer container = item as Items.Icontainer;
                    Items.Iiluminate light     = item as Items.Iiluminate; //even if container check this first. Container may have light enchanment.
                    if (light != null && light.isLit)
                    {
                        lightSource = true;
                        break;
                    }
                    if (container != null && (container.Contents != null && container.Contents.Count > 0) && container.Opened)  //let's look in the container only if it's open
                    {
                        foreach (string innerId in container.Contents)
                        {
                            Items.Iitem innerItem = Items.Items.GetByID(id);
                            light = innerItem as Items.Iiluminate;
                            if (light != null && light.isLit)
                            {
                                lightSource = true;
                                break;
                            }
                        }
                    }

                    if (lightSource)
                    {
                        break;
                    }
                }
            }
            return(lightSource);
        }
Ejemplo n.º 15
0
        private static void LookIn(User.User player, List <string> commands)
        {
            commands.RemoveAt(2); //remove "in"
            string itemNameToGet = Items.Items.ParseItemName(commands);
            bool   itemFound     = false;
            Room   room          = Room.GetRoom(player.Player.Location);

            string location;

            if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase))
            {
                location = null;
                commands.RemoveAt(commands.Count - 1); //get rid of "inventory" se we can parse an index specifier if there is one
            }
            else
            {
                location = player.Player.Location;
            }

            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);
                itemNameToGet = itemNameToGet.Remove(itemNameToGet.Length - 2, 2);
            }

            int index = 1;

            if (!string.IsNullOrEmpty(location))  //player didn't specify it was in his inventory check room first
            {
                foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items))
                {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);
                    inventoryItem = KeepOpening(itemNameToGet, inventoryItem, itemPosition, index);

                    if (inventoryItem.Name.Contains(itemNameToGet))
                    {
                        Items.Icontainer container = inventoryItem as Items.Icontainer;
                        player.MessageHandler(container.LookIn());
                        itemFound = true;
                        break;
                    }
                }
            }


            if (!itemFound)   //so we didn't find one in the room that matches
            {
                var playerInventory = player.Player.Inventory.GetInventoryAsItemList();
                foreach (Items.Iitem inventoryItem in playerInventory)
                {
                    if (inventoryItem.Name.Contains(itemNameToGet))
                    {
                        //if player didn't specify an index number loop through all items until we find the first one we want otherwise we will
                        // keep going through each item that matches until we hit the index number
                        if (index == itemPosition)
                        {
                            Items.Icontainer container = inventoryItem as Items.Icontainer;
                            player.MessageHandler(container.LookIn());
                            itemFound = true;
                            break;
                        }
                        else
                        {
                            index++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        private static string DisplayItemsInRoom(Room room)
        {
            StringBuilder sb = new StringBuilder();

            List <string> itemsInRoom = room.GetObjectsInRoom(Room.RoomObjects.Items);

            Dictionary <string, int> itemGroups = new Dictionary <string, int>();

            if (!room.IsDark)
            {
                foreach (string id in itemsInRoom)
                {
                    Items.Iitem item = Items.Items.GetByID(id);
                    if (item != null)
                    {
                        // Items.Icontainer containerItem = item as Items.Icontainer;
                        // Items.Iedible edible = item as Items.Iedible;

                        if (item.ItemType.ContainsKey(Items.ItemsType.CONTAINER))
                        {
                            Items.Icontainer containerItem = item as Items.Icontainer;
                            if (!itemGroups.ContainsKey(item.Name + "$" + (containerItem.IsOpenable == true ? (containerItem.Opened ? "[Opened]" : "[Closed]") : "[container]")))
                            {
                                itemGroups.Add(item.Name + "$" + (containerItem.IsOpenable == true ? (containerItem.Opened ? "[Opened]" : "[Closed]") : "[container]"), 1);
                            }
                            else
                            {
                                itemGroups[item.Name + "$" + (containerItem.IsOpenable == true ? (containerItem.Opened ? "[Opened]" : "[Closed]") : "[container]")] += 1;
                            }
                        }
                        else if (item.ItemType.ContainsKey(Items.ItemsType.DRINKABLE) || item.ItemType.ContainsKey(Items.ItemsType.EDIBLE))
                        {
                            if (!itemGroups.ContainsKey(item.Name))
                            {
                                itemGroups.Add(item.Name, 1);
                            }
                            else
                            {
                                itemGroups[item.Name] += 1;
                            }
                        }
                        else
                        {
                            if (!itemGroups.ContainsKey(item.Name + "$" + item.CurrentCondition))
                            {
                                itemGroups.Add(item.Name + "$" + item.CurrentCondition, 1);
                            }
                            else
                            {
                                itemGroups[item.Name + "$" + item.CurrentCondition] += 1;
                            }
                        }
                    }
                }

                foreach (KeyValuePair <string, int> pair in itemGroups)
                {
                    string[] temp = pair.Key.Split('$');
                    sb.Append(temp[0] + " is laying here");
                    if (temp.Count() > 1 && !string.Equals(temp[1], "NONE", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (temp[1].Contains("[Opened]") || temp[1].Contains("[Closed]") || temp[1].Contains("[container]"))
                        {
                            sb.AppendLine(". " + (temp[1] == "[container]" ? "" : temp[1]) + (pair.Value > 1 ? (" [x" + pair.Value + "]") : ""));
                        }
                        else
                        {
                            sb.AppendLine(" in " + temp[1].Replace("_", " ").ToLower() + " condition." + (pair.Value > 1 ? ("[x" + pair.Value + "]") : ""));
                        }
                    }
                    else
                    {
                        sb.AppendLine(".");
                    }
                }
            }
            else
            {
                int count = 0;
                foreach (string id in itemsInRoom)
                {
                    Items.Iitem item = Items.Items.GetByID(id);
                    if (item != null)
                    {
                        count++;
                    }
                }

                if (count == 1)
                {
                    sb.AppendLine("Something is laying here.");
                }
                else if (count > 1)
                {
                    sb.AppendLine("Somethings are laying here.");
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 18
0
        private static Items.Iiluminate FindLightInEquipment(List <string> commands, User.User player, Rooms.Room room)
        {
            Items.Iitem lightItem = null;
            if (commands.Count > 0)
            {
                string itemName = GetItemName(commands, "").ToString();
                //let's see if player has a lightsource equipped
                foreach (Items.Iitem item in player.Player.Equipment.GetEquipment().Values)
                {
                    if (item.WornOn == Items.Wearable.WIELD_LEFT || item.WornOn == Items.Wearable.WIELD_RIGHT)
                    {
                        Items.Iiluminate temp = item as Items.Iiluminate;
                        if (temp != null && temp.isLightable)
                        {
                            lightItem = item;
                            break;
                        }
                    }
                }
            }
            else   //let's be smart and figure out what lightSource he wants activated, first come first serve otherwise
            {
                foreach (Items.Iitem item in player.Player.Equipment.GetEquipment().Values)
                {
                    Items.Iiluminate lightsource = item as Items.Iiluminate;
                    if (lightsource != null && lightsource.isLightable)
                    {
                        lightItem = item;
                        break;
                    }
                }
                if (lightItem == null)   //not in players equipment let's check the room
                {
                    foreach (string itemId in room.GetObjectsInRoom(Room.RoomObjects.Items))
                    {
                        lightItem = Items.Items.GetByID(itemId);
                        Items.Iiluminate lightsource = lightItem as Items.Iiluminate;
                        if (lightsource != null && lightsource.isLightable)
                        {
                            break;
                        }
                        //if it's a container and it's open see if it has a lightsource inside
                        if (lightItem.ItemType.ContainsKey(Items.ItemsType.CONTAINER))
                        {
                            Items.Icontainer containerItem = lightItem as Items.Icontainer;
                            if (containerItem.Opened)
                            {
                                foreach (string id in containerItem.GetContents())
                                {
                                    lightItem   = Items.Items.GetByID(itemId);
                                    lightsource = lightItem as Items.Iiluminate;
                                    if (lightsource != null && lightsource.isLightable)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(lightItem as Items.Iiluminate);
        }
Ejemplo n.º 19
0
 public void AddItemToInventory(Items.Iitem item)
 {
     item.Owner = playerID;
     item.Save();
     inventory.Add(item);
 }
Ejemplo n.º 20
0
        //container commands
        public static void Put(User.User player, List <string> commands)
        {
            //this command is used only for putting an Item in the root inventory of a player into a bag.
            //If an item needs to go from a bag to the root inventory level player should use the GET command instead.

            int    itemPosition      = 1;
            int    containerPosition = 1;
            string itemName          = "";
            string containerName     = "";

            //this allows players to use either IN or INTO
            int commandIndex = 0;

            foreach (string word in commands)
            {
                if (string.Equals(word, "in", StringComparison.InvariantCultureIgnoreCase))
                {
                    commands[commandIndex] = "into";
                    break;
                }
                commandIndex++;
            }

            string location;

            if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase))
            {
                location = null;
                commands.RemoveAt(commands.Count - 1); //get rid of "inventory" se we can parse an index specifier if there is one
            }
            else
            {
                location = player.Player.Location;
            }

            List <string> commandAltered = ParseItemPositions(commands, "into", out itemPosition, out itemName);

            ParseContainerPosition(commandAltered, "", out containerPosition, out containerName);

            Items.Iitem retrievedItem = null;
            Items.Iitem containerItem = null;

            //using a recursive method we will dig down into each sub container looking for the appropriate container
            if (!string.IsNullOrEmpty(location))
            {
                TraverseItems(player, containerName.ToString().Trim(), itemName.ToString().Trim(), containerPosition, itemPosition, out retrievedItem, out containerItem);

                //player is an idiot and probably wanted to put it in his inventory but didn't specify it so let's check there as well
                if (containerItem == null)
                {
                    foreach (Items.Iitem tempContainer in player.Player.Inventory.GetInventoryAsItemList())
                    {
                        //Items.Iitem tempContainer = Items.Items.GetByID(id);
                        containerItem = KeepOpening(containerName.CamelCaseString(), tempContainer, containerPosition);
                        if (string.Equals(containerItem.Name, containerName.CamelCaseString(), StringComparison.InvariantCultureIgnoreCase))
                        {
                            break;
                        }
                    }
                }
            }
            else  //player specified it is in his inventory
            {
                foreach (string id in player.Player.Inventory.GetInventoryList())
                {
                    Items.Iitem tempContainer = Items.Items.GetByID(id);
                    containerItem = KeepOpening(containerName.CamelCaseString(), tempContainer, containerPosition);
                    if (string.Equals(containerItem.Name, containerName.CamelCaseString(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        break;
                    }
                }
            }

            bool stored = false;

            retrievedItem = player.Player.Inventory.GetInventoryAsItemList().Where(i => i.Name == itemName).SingleOrDefault();

            if (containerItem != null && retrievedItem != null)
            {
                retrievedItem.Location = containerItem.Location;
                retrievedItem.Owner    = containerItem.Id.ToString();
                retrievedItem.Save();
                Items.Icontainer container = containerItem as Items.Icontainer;
                stored = container.StoreItem(retrievedItem.Id.ToString());
            }


            string msg = null;

            if (!stored)
            {
                msg = "Could not put " + itemName.ToString().Trim().ToLower() + " inside the " + containerName.ToString().Trim().ToLower() + ".";
            }
            else
            {
                msg = "You place " + itemName.ToString().Trim().ToLower() + " inside the " + containerName.ToString().Trim().ToLower() + ".";
            }

            player.MessageHandler(msg);
        }
Ejemplo n.º 21
0
        private static void OpenContainer(User.User player, List <string> commands)
        {
            //this is a quick work around for knowing which container to open without implementing the dot operator
            //I need to come back and make it work like with NPCS once I've tested everything works correctly
            string location;

            if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase))
            {
                location = null;
                commands.RemoveAt(commands.Count - 1); //get rid of "inventory" se we can parse an index specifier if there is one
            }
            else
            {
                location = player.Player.Location;
            }

            string itemNameToGet = Items.Items.ParseItemName(commands);
            bool   itemFound     = false;

            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);
            }

            int  index = 1;
            Room room  = Room.GetRoom(location);

            if (!string.IsNullOrEmpty(location))  //player didn't specify it was in his inventory check room first
            {
                foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items))
                {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);
                    inventoryItem = KeepOpening(itemNameToGet, inventoryItem, itemPosition);

                    if (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (index == itemPosition)
                        {
                            Items.Icontainer container = inventoryItem as Items.Icontainer;
                            player.MessageHandler(container.Open());
                            itemFound = true;
                            break;
                        }
                        else
                        {
                            index++;
                        }
                    }
                }
            }


            if (!itemFound)   //so we didn't find one in the room that matches
            {
                var playerInventory = player.Player.Inventory.GetInventoryAsItemList();
                foreach (Items.Iitem inventoryItem in playerInventory)
                {
                    if (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //if player didn't specify an index number loop through all items until we find the want we want otherwise we will
                        // keep going through each item that matches until we hit the index number
                        if (index == itemPosition)
                        {
                            Items.Icontainer container = inventoryItem as Items.Icontainer;
                            player.MessageHandler(container.Open());
                            room.InformPlayersInRoom(player.Player.FirstName + " opens " + inventoryItem.Name.ToLower(), new List <string>(new string[] { player.UserID }));
                            itemFound = true;
                            break;
                        }
                        else
                        {
                            index++;
                        }
                    }
                }
            }

            if (!itemFound)
            {
                player.MessageHandler("Open what?");
            }
        }
Ejemplo n.º 22
0
        public void Load(string id)
        {
            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase   characterDB         = MongoUtils.MongoData.GetDatabase("Characters");
            MongoCollection characterCollection = characterDB.GetCollection <BsonDocument>("PlayerCharacter");
            IMongoQuery     query = Query.EQ("_id", ObjectId.Parse(id));
            BsonDocument    found = characterCollection.FindOneAs <BsonDocument>(query);

            ID                  = found["_id"].AsObjectId.ToString();
            FirstName           = found["FirstName"].AsString.CamelCaseWord();
            LastName            = found["LastName"].AsString.CamelCaseWord();
            _class              = (CharacterClass)Enum.Parse(typeof(CharacterClass), found["Class"].AsString.CamelCaseWord());
            _race               = (CharacterRace)Enum.Parse(typeof(CharacterRace), found["Race"].AsString.CamelCaseWord());
            _gender             = (Genders)Enum.Parse(typeof(Genders), found["Gender"].AsString.CamelCaseWord());
            _skinType           = (SkinType)Enum.Parse(typeof(SkinType), found["SkinType"].AsString.CamelCaseWord());
            _skinColor          = (SkinColors)Enum.Parse(typeof(SkinColors), found["SkinColor"].AsString.CamelCaseWord());
            _skinType           = (SkinType)Enum.Parse(typeof(SkinType), found["SkinType"].AsString.CamelCaseWord());
            _hairColor          = (HairColors)Enum.Parse(typeof(HairColors), found["HairColor"].AsString.CamelCaseWord());
            _eyeColor           = (EyeColors)Enum.Parse(typeof(EyeColors), found["EyeColor"].AsString.CamelCaseWord());
            Height              = found["Height"].AsDouble;
            Weight              = found["Weight"].AsDouble;
            _stanceState        = (CharacterStanceState)Enum.Parse(typeof(CharacterStanceState), found["StanceState"].AsString.CamelCaseWord());
            _actionState        = (CharacterActionState)Enum.Parse(typeof(CharacterActionState), found["ActionState"].AsString.CamelCaseWord());
            Description         = found["Description"].AsString;
            Location            = found["Location"].AsString;
            Password            = found["Password"].AsString;
            IsNPC               = found["IsNPC"].AsBoolean;
            Experience          = found["Experience"].AsInt64;
            NextLevelExperience = found["NextLevelExperience"].AsInt64;
            Level               = found["Level"].AsInt32;
            Leveled             = found["Leveled"].AsBoolean;
            PointsToSpend       = found["PointsToSpend"].AsInt32;
            MainHand            = found["MainHand"].AsString != "" ? found["MainHand"].AsString : null;
            Title               = found.Contains("Title") ? found["Title"].AsString : "";
            KillerID            = found.Contains("KillerID") ? found["KillerID"].AsString : "";

            BsonArray playerAttributes = found["Attributes"].AsBsonArray;
            BsonArray inventoryList    = found["Inventory"].AsBsonArray;
            BsonArray equipmentList    = found["Equipment"].AsBsonArray;
            BsonArray bonusesList      = found["Bonuses"].AsBsonArray;

            if (playerAttributes != null)
            {
                foreach (BsonDocument attrib in playerAttributes)
                {
                    if (!this.Attributes.ContainsKey(attrib["Name"].ToString()))
                    {
                        Attribute tempAttrib = new Attribute();
                        tempAttrib.Name      = attrib["Name"].ToString();
                        tempAttrib.Value     = attrib["Value"].AsDouble;
                        tempAttrib.Max       = attrib["Max"].AsDouble;
                        tempAttrib.RegenRate = attrib["RegenRate"].AsDouble;
                        tempAttrib.Rank      = attrib["Rank"].AsInt32;

                        this.Attributes.Add(tempAttrib.Name, tempAttrib);
                    }
                    else
                    {
                        this.Attributes[attrib["Name"].ToString()].Max       = attrib["Max"].AsDouble;
                        this.Attributes[attrib["Name"].ToString()].Value     = attrib["Value"].AsDouble;
                        this.Attributes[attrib["Name"].ToString()].RegenRate = attrib["RegenRate"].AsDouble;
                        this.Attributes[attrib["Name"].ToString()].Rank      = attrib["Rank"].AsInt32;
                    }
                }
            }

            if (inventoryList.Count > 0)
            {
                foreach (BsonDocument item in inventoryList)
                {
                    Items.Iitem fullItem = Items.Items.GetByID(item["_id"].AsObjectId.ToString());
                    if (!Inventory.inventory.Contains(fullItem))
                    {
                        Inventory.AddItemToInventory(fullItem);
                    }
                }
            }

            if (equipmentList.Count > 0)
            {
                foreach (BsonDocument item in equipmentList)
                {
                    Items.Iitem fullItem = Items.Items.GetByID(item["_id"].AsObjectId.ToString());
                    if (!Equipment.equipped.ContainsKey(fullItem.WornOn))
                    {
                        Equipment.EquipItem(fullItem, this.Inventory);
                    }
                }
            }

            if (bonusesList.Count > 0)
            {
                Bonuses.LoadFromBson(bonusesList);
            }
        }
Ejemplo n.º 23
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (ConnectedToDB)
            {
                BsonDocument item = new BsonDocument();
                if (!string.IsNullOrEmpty(idValue.Text))
                {
                    item["_id"] = ObjectId.Parse(idValue.Text);
                }

                //general stuff
                if (!IsEmpty(nameValue.Text))
                {
                    item["Name"] = nameValue.Text;
                }
                if (!IsEmpty(descriptionValue.Text))
                {
                    item["Description"] = descriptionValue.Text;
                }
                if (!IsEmpty(ownerValue.Text))
                {
                    item["Owner"] = ownerValue.Text;
                }
                if (!IsEmpty(minLevelValue.Text))
                {
                    item["MinimumLevel"] = int.Parse(minLevelValue.Text);
                }
                if (!IsEmpty(conditionValue.Text))
                {
                    item["CurrentCondition"] = (Items.ItemCondition)Enum.Parse(typeof(Items.ItemCondition), conditionValue.Text);
                }
                if (!IsEmpty(maxConditionValue.Text))
                {
                    item["MaxCondition"] = (Items.ItemCondition)Enum.Parse(typeof(Items.ItemCondition), maxConditionValue.Text);
                }
                if (!IsEmpty(weightValue.Text))
                {
                    item["Weight"] = double.Parse(weightValue.Text);
                }


                //attributes
                item["IsMovable"]    = isMovable.Checked;
                item["IsWearable"]   = isWearable.Checked;
                item["IsOpenable"]   = isOpenable.Checked;
                item["Opened"]       = isOpened.Checked;
                item["IsWieldable"]  = isWieldable.Checked;
                item["isLit"]        = isLit.Checked;
                item["isChargeable"] = isChargeable.Checked;
                item["isLightable"]  = isLightable.Checked;

                //key
                item["SkeletonKey"] = isSkeletonKey.Checked;
                if (!IsEmpty(doorIdValue.Text))
                {
                    item["DoorID"] = doorIdValue.Text;
                }

                //container stuff
                if (!IsEmpty(reduceWeightValue.Text))
                {
                    item["ReduceCarryWeightBy"] = double.Parse(reduceWeightValue.Text);
                }
                if (!IsEmpty(weightLimitValue.Text))
                {
                    item["WeightLimit"] = double.Parse(weightLimitValue.Text);
                }

                BsonArray contentsArray = new BsonArray();
                foreach (string value in itemContentsValue.Items)
                {
                    contentsArray.Add(value);
                }
                if (contentsArray.Count > 0)
                {
                    item["Contents"] = contentsArray;
                }
                //weapon stuff
                if (!IsEmpty(attackSpeedValue.Text))
                {
                    item["AttackSpeed"] = double.Parse(attackSpeedValue.Text);
                }
                if (!IsEmpty(maxDamageValue.Text))
                {
                    item["MaxDamage"] = double.Parse(maxDamageValue.Text);
                }
                if (!IsEmpty(minDamageValue.Text))
                {
                    item["MinDamage"] = double.Parse(minDamageValue.Text);
                }

                //clothing
                if (!IsEmpty(maxDefenseValue.Text))
                {
                    item["MaxDefense"] = double.Parse(maxDefenseValue.Text);
                }
                if (!IsEmpty(defenseValue.Text))
                {
                    item["CurrentDefense"] = double.Parse(defenseValue.Text);
                }

                //light source
                if (!IsEmpty(decayRateValue.Text))
                {
                    item["chargeDecayRate"] = double.Parse(decayRateValue.Text);
                }
                if (!IsEmpty(lowWarningValue.Text))
                {
                    item["chargeLowWarning"] = double.Parse(lowWarningValue.Text);
                }
                if (!IsEmpty(chargeValue.Text))
                {
                    item["currentCharge"] = double.Parse(chargeValue.Text);
                }
                if (!IsEmpty(maxChargeValue.Text))
                {
                    item["maxCharge"] = double.Parse(maxChargeValue.Text);
                }
                if (!IsEmpty(lightTypeValue.Text))
                {
                    item["lightType"] = (Items.LightType)Enum.Parse(typeof(Items.LightType), lightTypeValue.Text);
                }
                if (!IsEmpty(fuelSourceValue.Text))
                {
                    item["fuelSource"] = (Items.FuelSource)Enum.Parse(typeof(Items.FuelSource), fuelSourceValue.Text);
                }

                //item Type
                BsonArray itemTypeArray = new BsonArray();
                foreach (CheckBox cb in itemTypeGroup.Controls)
                {
                    BsonDocument itemTypeBson = new BsonDocument {
                        { "k", "" },
                        { "v", "" }
                    };
                    if (cb.Checked)
                    {
                        itemTypeBson["k"] = (Items.ItemsType)Enum.Parse(typeof(Items.ItemsType), cb.Text.ToUpper());
                        itemTypeBson["v"] = 0;

                        itemTypeArray.Add(itemTypeBson);
                    }
                }

                item["ItemType"] = itemTypeArray;

                if (_itemTriggers.Count > 0)
                {
                    item["Triggers"] = _itemTriggers;
                }


                Items.Iitem result = null;
                result = BsonSerializer.Deserialize <Items.Items>(item);
                result.Save();
                GetItemsFromDB();
            }
        }
Ejemplo n.º 24
0
 public void Wield(Items.Iitem item, Inventory inventory)
 {
     WieldItem(item, inventory);
 }
Ejemplo n.º 25
0
        private static void Consume(User.User player, List <string> commands, string action, Items.Iitem item)
        {
            string        upDown          = "gain";
            StringBuilder msgPlayer       = new StringBuilder();
            string        msgOtherPlayers = null;

            Dictionary <string, double> affectAttributes = null;

            Items.Iedible food = item as Items.Iedible;
            affectAttributes = food.Consume();

            foreach (KeyValuePair <string, double> attribute in affectAttributes)
            {
                player.Player.ApplyEffectOnAttribute(attribute.Key.CamelCaseWord(), attribute.Value);
                if (attribute.Value < 0)
                {
                    upDown = "lost";
                }

                msgPlayer.AppendLine(string.Format("You {0} {1} and {2} {3:F1} points of {4}.", action, item.Name, upDown, Math.Abs(attribute.Value), attribute.Key));
                msgOtherPlayers = string.Format("{0} {1}s {2}", player.Player.FirstName.CamelCaseWord(), action, item.Name);
            }

            //now remove it from the players inventory
            player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);

            //item has been consumed so get rid of it from the DB
            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase   db  = MongoUtils.MongoData.GetDatabase("World");
            MongoCollection col = db.GetCollection("Items");

            col.Remove(Query.EQ("_id", item.Id));

            Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOtherPlayers, new List <string>(new string[] { player.UserID }));
            player.MessageHandler(msgPlayer.ToString());
        }
Ejemplo n.º 26
0
        private static void TraverseItems(User.User player, string containerName, string itemName, int containerPosition, int itemPosition, out Items.Iitem retrievedItem, out Items.Iitem retrievedContainer)
        {
            int containerIndex = 1;
            int itemIndex      = 1;

            retrievedItem      = null;
            retrievedContainer = null;
            Room room = Room.GetRoom(player.Player.Location);

            if (!string.IsNullOrEmpty(containerName.CamelCaseString()))
            {
                foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items))
                {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);

                    inventoryItem = KeepOpening(containerName.CamelCaseString(), inventoryItem, containerPosition, containerIndex);

                    if (inventoryItem.Name.Contains(containerName.CamelCaseString()))
                    {
                        retrievedContainer = inventoryItem;
                        break;
                    }
                }
            }

            //if we retrieved a specific indexed container search within it for the item
            if (retrievedContainer != null)
            {
                Items.Icontainer container = null;
                container = retrievedContainer as Items.Icontainer;
                foreach (string itemID in container.GetContents())
                {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);

                    inventoryItem = KeepOpening(itemName.CamelCaseString(), inventoryItem, itemPosition, itemIndex);

                    if (inventoryItem.Name.Contains(itemName.CamelCaseString()))
                    {
                        retrievedItem = inventoryItem;
                        break;
                    }
                }
            }
            else if (string.IsNullOrEmpty(containerName))  //we are grabbing a container or an item without a specific index
            {
                foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items))
                {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);

                    inventoryItem = KeepOpening(itemName.CamelCaseString(), inventoryItem, itemPosition, itemIndex);

                    if (inventoryItem.Name.Contains(itemName.CamelCaseString()))
                    {
                        retrievedItem = inventoryItem;
                        break;
                    }
                }
            }
            else
            {
                foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items))
                {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);

                    if (inventoryItem.Name.Contains(itemName.CamelCaseString()))
                    {
                        retrievedItem = inventoryItem;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 27
0
        private static void CloseContainer(User.User player, List <string> commands)
        {
            string location;

            if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase))
            {
                location = null;
                commands.RemoveAt(commands.Count - 1); //get rid of "inventory" se we can parse an index specifier if there is one
            }
            else
            {
                location = player.Player.Location;
            }

            string itemNameToGet = Items.Items.ParseItemName(commands);
            bool   itemFound     = false;

            Room room = Room.GetRoom(player.Player.Location);

            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);
            }
            int index = 1;

            //Here is the real problem, how do I differentiate between a container in the room and one in the players inventory?
            //if a backpack is laying on the ground th eplayer should be able to put stuff in it or take from it, same as if it were
            //in his inventory.  I should probably check room containers first then player inventory otherwise the player can
            //specify "inventory" to just do it in their inventory container.

            if (!string.IsNullOrEmpty(location))  //player didn't specify it was in his inventory check room first
            {
                foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items))
                {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);
                    if (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (index == itemPosition)
                        {
                            Items.Icontainer container = inventoryItem as Items.Icontainer;
                            player.MessageHandler(container.Close());
                            room.InformPlayersInRoom(player.Player.FirstName + " closes " + inventoryItem.Name.ToLower(), new List <string>(new string[] { player.UserID }));
                            itemFound = true;
                            break;
                        }
                    }
                }
            }


            if (!itemFound)   //so we didn't find one in the room that matches
            {
                var playerInventory = player.Player.Inventory.GetInventoryAsItemList();
                foreach (Items.Iitem inventoryItem in playerInventory)
                {
                    if (string.Equals(inventoryItem.Name, itemNameToGet, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //if player didn't specify an index number loop through all items until we find the want we want otherwise we will
                        // keep going through each item that matches until we hit the index number
                        if (index == itemPosition)
                        {
                            Items.Icontainer container = inventoryItem as Items.Icontainer;
                            player.MessageHandler(container.Close());
                            itemFound = true;
                            break;
                        }
                        else
                        {
                            index++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
        public static void Unequip(User.User player, List <string> commands)
        {
            StringBuilder itemName     = new StringBuilder();
            int           itemPosition = 1;
            string        msgPlayer    = null;
            string        msgOthers    = null;

            //they said 'all' so we are going to remove everything
            if (commands.Count > 2 && string.Equals(commands[2].ToLower(), "all", StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (KeyValuePair <Items.Wearable, Items.Iitem> item in player.Player.Equipment.GetEquipment())
                {
                    if (player.Player.Equipment.UnequipItem(item.Value, player.Player))
                    {
                    }
                }

                msgOthers = string.Format("{0} removes all his equipment.", player.Player.FirstName);
            }
            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.RemoveAt(0);
                commands.RemoveAt(0);

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

                List <Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
                Items.Iitem        item  = items[itemPosition - 1];

                if (item != null)
                {
                    player.Player.Equipment.UnequipItem(item, player.Player);
                    msgOthers = string.Format("{0} unequips {1}", player.Player.FirstName, item.Name);
                    msgPlayer = string.Format("You unequip {0}", item.Name);
                }
                else
                {
                    if (commands.Count == 2)
                    {
                        msgPlayer = "Unequip what?";
                    }
                    else
                    {
                        msgPlayer = "You don't seem to be equipping that at the moment.";
                    }
                }
            }

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