Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 public void AddItemToInventory(Items.Iitem item)
 {
     item.Owner = playerID;
     item.Save();
     inventory.Add(item);
 }
Ejemplo n.º 5
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.º 6
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.º 7
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);
        }