public Item GenerateAtPower(string power)
        {
            var tableName    = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, power, ItemTypeConstants.Armor);
            var result       = typeAndAmountPercentileSelector.SelectFrom(tableName);
            var abilityCount = 0;

            while (result.Type == "SpecialAbility")
            {
                abilityCount += result.Amount;
                result        = typeAndAmountPercentileSelector.SelectFrom(tableName);
            }

            if (result.Amount == 0)
            {
                return(specificGearGenerator.GenerateFrom(power, result.Type));
            }

            var armor = new Item();

            armor.ItemType    = ItemTypeConstants.Armor;
            armor.Magic.Bonus = result.Amount;

            tableName  = string.Format(TableNameConstants.Percentiles.Formattable.ARMORTYPETypes, result.Type);
            armor.Name = percentileSelector.SelectFrom(tableName);

            tableName                    = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, armor.ItemType);
            armor.Attributes             = collectionsSelector.SelectFrom(tableName, armor.Name);
            armor.Magic.SpecialAbilities = specialAbilitiesSelector.GenerateFor(armor.ItemType, armor.Attributes, power, armor.Magic.Bonus, abilityCount);

            return(armor);
        }
        private Armor GenerateFromPrototype(Armor prototype)
        {
            if (specificGearGenerator.IsSpecific(prototype))
            {
                var specificArmor = specificGearGenerator.GenerateFrom(prototype);
                specificArmor.Quantity = 1;

                return(specificArmor as Armor);
            }

            var mundaneArmorGenerator = justInTimeFactory.Build <MundaneItemGenerator>(ItemTypeConstants.Armor);
            var armor = mundaneArmorGenerator.Generate(prototype);

            armor.Magic.Bonus            = prototype.Magic.Bonus;
            armor.Magic.Charges          = prototype.Magic.Charges;
            armor.Magic.Curse            = prototype.Magic.Curse;
            armor.Magic.Intelligence     = prototype.Magic.Intelligence;
            armor.Magic.SpecialAbilities = prototype.Magic.SpecialAbilities;

            if (armor.IsMagical)
            {
                armor.Traits.Add(TraitConstants.Masterwork);
            }

            return(armor as Armor);
        }
        private Weapon GenerateFromPrototype(Item prototype, bool allowDecoration)
        {
            if (specificGearGenerator.IsSpecific(prototype))
            {
                var specificWeapon = specificGearGenerator.GenerateFrom(prototype);
                return(specificWeapon as Weapon);
            }

            var mundaneWeaponGenerator = justInTimeFactory.Build <MundaneItemGenerator>(ItemTypeConstants.Weapon);
            var weapon = mundaneWeaponGenerator.Generate(prototype, allowDecoration);

            weapon.Magic.Bonus            = prototype.Magic.Bonus;
            weapon.Magic.Charges          = prototype.Magic.Charges;
            weapon.Magic.Curse            = prototype.Magic.Curse;
            weapon.Magic.Intelligence     = prototype.Magic.Intelligence;
            weapon.Magic.SpecialAbilities = prototype.Magic.SpecialAbilities;

            if (weapon.Attributes.Contains(AttributeConstants.Ammunition))
            {
                weapon.Magic.Intelligence = new Intelligence();
            }

            if (weapon.IsMagical)
            {
                weapon.Traits.Add(TraitConstants.Masterwork);
            }

            var magicWeapon = weapon as Weapon;

            if (!magicWeapon.IsDoubleWeapon)
            {
                return(magicWeapon);
            }

            var sameEnhancement = percentileSelector.SelectFrom(.5);

            if (!sameEnhancement)
            {
                magicWeapon.SecondaryMagicBonus   = weapon.Magic.Bonus - 1;
                magicWeapon.SecondaryHasAbilities = false;

                return(magicWeapon);
            }

            magicWeapon.SecondaryMagicBonus   = weapon.Magic.Bonus;
            magicWeapon.SecondaryHasAbilities = true;

            return(magicWeapon);
        }
        public Item GenerateAtPower(string power)
        {
            var tablename             = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, power, ItemTypeConstants.Weapon);
            var bonus                 = percentileSelector.SelectFrom(tablename);
            var specialAbilitiesCount = 0;

            while (bonus == "SpecialAbility")
            {
                specialAbilitiesCount++;
                bonus = percentileSelector.SelectFrom(tablename);
            }

            if (bonus == ItemTypeConstants.Weapon)
            {
                return(specificGearGenerator.GenerateFrom(power, bonus));
            }

            var type = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.WeaponTypes);

            tablename = string.Format(TableNameConstants.Percentiles.Formattable.WEAPONTYPEWeapons, type);
            var name = percentileSelector.SelectFrom(tablename);

            var weapon = new Item();

            if (name == AttributeConstants.Ammunition)
            {
                weapon = ammunitionGenerator.Generate();
            }
            else
            {
                weapon.ItemType = ItemTypeConstants.Weapon;
                weapon.Name     = name;

                if (weapon.Name.Contains("Composite"))
                {
                    weapon.Name = GetCompositeBowName(name);
                    var compositeStrengthBonus = GetCompositeBowBonus(name);
                    weapon.Traits.Add(compositeStrengthBonus);
                }

                tablename         = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, weapon.ItemType);
                weapon.Attributes = collectionsSelector.SelectFrom(tablename, weapon.Name);
            }

            weapon.Magic.Bonus            = Convert.ToInt32(bonus);
            weapon.Magic.SpecialAbilities = specialAbilitiesGenerator.GenerateFor(weapon.ItemType, weapon.Attributes, power, weapon.Magic.Bonus, specialAbilitiesCount);

            if (weapon.Magic.SpecialAbilities.Any(a => a.Name == SpecialAbilityConstants.SpellStoring))
            {
                var shouldStoreSpell = booleanPercentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.SpellStoringContainsSpell);

                if (shouldStoreSpell)
                {
                    var spellType = spellGenerator.GenerateType();
                    var level     = spellGenerator.GenerateLevel(PowerConstants.Minor);
                    var spell     = spellGenerator.Generate(spellType, level);

                    weapon.Contents.Add(spell);
                }
            }

            if (weapon.Attributes.Contains(AttributeConstants.Thrown) && weapon.Attributes.Contains(AttributeConstants.Melee) == false)
            {
                weapon.Quantity = dice.Roll().d20().AsSum();
            }

            return(weapon);
        }
        public void ReturnGear()
        {
            var gear = specificGearGenerator.GenerateFrom(power, gearType);

            Assert.That(gear, Is.Not.Null);
        }