Example #1
0
        private Item GetItem(int numOfItems)
        {
            var rngNum = RandomGenerator.Randomize(1, 100);
            var rarity = Rarity.GetRandomRarity();
            var rarityType = rarity.Keys.First();
            var rarityCoef = rarity.Values.First();
            var dropX = (int)this.Velocity.X + this.Width / (2 - numOfItems) - KufTheGame.ItemSize / 2;
            var dropY = (int)this.Velocity.Y + this.Height / 2 - KufTheGame.ItemSize / 2;

            if (rngNum <= 25)
            {
                var weaponType = RandomGenerator.GetRandomItem<Weapons>();
                var wep = new Weapon(dropX, dropY, KufTheGame.ItemSize, KufTheGame.ItemSize, rarityType, weaponType, 10 * rarityCoef);
                return wep;
            }

            if (rngNum > 25 && rngNum <= 65)
            {
                var armorType = RandomGenerator.GetRandomItem<Armors>();
                var armor =
                    new Armor(dropX, dropY, KufTheGame.ItemSize, KufTheGame.ItemSize, rarityType, armorType, 5 * rarityCoef);
                return armor;
            }

            if (rngNum > 65)
            {
                var rngPotionNum = RandomGenerator.Randomize(1, 100);
                if (rngPotionNum <= 40)
                {
                    var potion =
                        new ImmortalilyPotion(dropX, dropY, KufTheGame.ItemSize, KufTheGame.ItemSize, rarityType, (int)(150 * rarityCoef));
                    return potion;
                }

                if (rngPotionNum > 40)
                {
                    var potion =
                        new HealthPotion(dropX, dropY, KufTheGame.ItemSize, KufTheGame.ItemSize, rarityType, 10 * rarityCoef);
                    return potion;
                }
            }

            return null;
        }
Example #2
0
 public void SetArmor(Armor armor)
 {
     try
     {
         if (this.ArmorSet.All(t => t.ArmorType != armor.ArmorType))
         {
             this.ArmorSet.Add(armor);
         }
         else
         {
             throw new ArmorException("You already have this armor type!");
         }
     }
     catch (ArmorException)
     {
         var currArmor = this.ArmorSet.Find(t => t.ArmorType == armor.ArmorType);
         if (currArmor.DefencePoints < armor.DefencePoints)
         {
             this.ArmorSet.Remove(currArmor);
             this.ArmorSet.Add(armor);
         }
     }
 }