Esempio n. 1
0
        public bool useItem(Character c, bool inBattle)
        {
            if (item is Consumable)
            {
                Consumable potion = item as Consumable;
                potion.consume(c);
                if (stackSize > 1)
                {
                    stackSize--;
                }
                else
                {
                    c.inventory.Remove(this);
                }
                return true;
            }
            if (!inBattle && item is Weapon)
            {
                Weapon weapon = item as Weapon;
                if (c.weapon == null)
                {

                    c.weapon = weapon;
                    c.inventory.Remove(this);
                    c.calculateStats();
                    return true;
                }
                else
                {
                    ICollection<ItemStack> inventory = c.inventory;
                    inventory.Remove(this);
                    ItemStack oldWeapon = new ItemStack(c.weapon);
                    inventory.Add(oldWeapon);
                    c.weapon = weapon;
                    c.calculateStats();
                    return true;
                }
            }
            if (!inBattle && item is Armour)
            {
                Armour armour = item as Armour;
                switch (armour.type)
                {
                    case (ArmourType.CHEST):
                        {
                            if (c.chest == null)
                            {

                                c.chest = armour;
                                c.inventory.Remove(this);
                                c.calculateStats();
                                return true;
                            }
                            else
                            {
                                ICollection<ItemStack> inventory = c.inventory;
                                inventory.Remove(this);
                                ItemStack oldChest = new ItemStack(c.chest);
                                inventory.Add(oldChest);
                                c.chest = armour;
                                c.calculateStats();
                                return true;
                            }
                        }
                    case (ArmourType.HELM):
                        {
                            if (c.helm == null)
                            {

                                c.helm = armour;
                                c.inventory.Remove(this);
                                c.calculateStats();
                                return true;
                            }
                            else
                            {
                                ICollection<ItemStack> inventory = c.inventory;
                                inventory.Remove(this);
                                ItemStack oldHelm = new ItemStack(c.helm);
                                inventory.Add(oldHelm);
                                c.helm = armour;
                                c.calculateStats();
                                return true;
                            }
                        }
                    case (ArmourType.GLOVES):
                        {
                            if (c.gloves == null)
                            {

                                c.gloves = armour;
                                c.inventory.Remove(this);
                                c.calculateStats();
                                return true;
                            }
                            else
                            {
                                ICollection<ItemStack> inventory = c.inventory;
                                inventory.Remove(this);
                                ItemStack oldgloves = new ItemStack(c.gloves);
                                inventory.Add(oldgloves);
                                c.gloves = armour;
                                c.calculateStats();
                                return true;
                            }
                        }
                    case (ArmourType.BOOTS):
                        {
                            if (c.boots == null)
                            {

                                c.boots = armour;
                                c.inventory.Remove(this);
                                c.calculateStats();
                                return true;
                            }
                            else
                            {
                                ICollection<ItemStack> inventory = c.inventory;
                                inventory.Remove(this);
                                ItemStack oldboots = new ItemStack(c.boots);
                                inventory.Add(oldboots);
                                c.boots = armour;
                                c.calculateStats();
                                return true;
                            }
                        }
                    case (ArmourType.LEGS):
                        {
                            if (c.legs == null)
                            {

                                c.legs = armour;
                                c.inventory.Remove(this);
                                c.calculateStats();
                                return true;
                            }
                            else
                            {
                                ICollection<ItemStack> inventory = c.inventory;
                                inventory.Remove(this);
                                ItemStack oldlegs = new ItemStack(c.legs);
                                inventory.Add(oldlegs);
                                c.legs = armour;
                                c.calculateStats();
                                return true;
                            }
                        }
                }
            }
            return false;
        }
Esempio n. 2
0
 private bool retrieveNonFullItemStack(ItemStack stack)
 {
     return (stack.item.name.Equals(name) && stack.stackSize < ItemStack.MAXSTACKSIZE);
 }