private int GetBonus(Feat feat, string savingThrow)
        {
            if (feat.Foci.Contains(FeatConstants.Foci.All) || feat.Foci.Contains(savingThrow))
                return feat.Power;

            return 0;
        }
        public IEnumerable<Feat> GenerateWith(Race race, Dictionary<string, Skill> skills, Dictionary<string, Stat> stats)
        {
            var baseRacialFeatSelections = featsSelector.SelectRacial(race.BaseRace);
            var metaracialFeatSelections = featsSelector.SelectRacial(race.Metarace);
            var featToIncreasePower = collectionsSelector.SelectFrom(TableNameConstants.Set.Collection.FeatGroups, GroupConstants.AddMonsterHitDiceToPower);

            foreach (var selection in metaracialFeatSelections)
                if (featToIncreasePower.Contains(selection.Feat))
                    selection.Power += GetMonsterHitDice(race.BaseRace);

            var metaraceSpeciesFeatSelections = featsSelector.SelectRacial(race.MetaraceSpecies);
            var allRacialFeatSelections = baseRacialFeatSelections.Union(metaracialFeatSelections).Union(metaraceSpeciesFeatSelections);

            var monsterHitDice = GetMonsterHitDice(race.BaseRace);
            var applicableRacialFeatSelections = allRacialFeatSelections.Where(s => s.RequirementsMet(race, monsterHitDice, stats));
            var feats = new List<Feat>();

            foreach (var racialFeatSelection in applicableRacialFeatSelections)
            {
                var feat = new Feat();
                feat.Name = racialFeatSelection.Feat;

                var focus = featFocusGenerator.GenerateAllowingFocusOfAllFrom(racialFeatSelection.Feat, racialFeatSelection.FocusType, skills);
                if (string.IsNullOrEmpty(focus) == false)
                    feat.Foci = feat.Foci.Union(new[] { focus });

                feat.Frequency = racialFeatSelection.Frequency;
                feat.Power = racialFeatSelection.Power;

                feats.Add(feat);
            }

            return feats;
        }
        public void ArmorClassesAreSummed()
        {
            armorBonuses["shield"] = 1;
            armorBonuses["armor"] = 1;
            adjustedDexterityBonus = 1;

            var feat = new Feat();
            feat.Name = "feat 1";
            feat.Power = 1;
            feats.Add(feat);

            var otherFeat = new Feat();
            otherFeat.Name = "feat 2";
            otherFeat.Power = 1;
            feats.Add(otherFeat);

            mockCollectionsSelector.Setup(s => s.SelectFrom(TableNameConstants.Set.Collection.ArmorClassModifiers, GroupConstants.Deflection))
                .Returns(new[] { "ring" });
            mockCollectionsSelector.Setup(s => s.SelectFrom(TableNameConstants.Set.Collection.ArmorClassModifiers, GroupConstants.NaturalArmor))
                .Returns(new[] { "feat 1" });
            mockCollectionsSelector.Setup(s => s.SelectFrom(TableNameConstants.Set.Collection.ArmorClassModifiers, GroupConstants.DodgeBonus))
                .Returns(new[] { "feat 2" });

            equipment.Armor = new Item { Name = "armor" };
            equipment.Armor.Magic.Bonus = 1;
            equipment.OffHand = new Item { Name = "shield" };
            equipment.OffHand.Magic.Bonus = 1;
            equipment.OffHand.ItemType = ItemTypeConstants.Armor;
            equipment.OffHand.Attributes = new[] { AttributeConstants.Shield };

            var ring = new Item();
            ring.Name = "ring";
            ring.Magic.Bonus = 1;

            equipment.Treasure.Items = new[] { ring };

            sizeModifiers[race.Size] = 1;

            var armorClass = GenerateAndAssertArmorClass(19, 17, 14);
            Assert.That(armorClass.ArmorBonus, Is.EqualTo(2));
            Assert.That(armorClass.DeflectionBonus, Is.EqualTo(1));
            Assert.That(armorClass.DodgeBonus, Is.EqualTo(1));
            Assert.That(armorClass.NaturalArmorBonus, Is.EqualTo(1));
            Assert.That(armorClass.ShieldBonus, Is.EqualTo(2));
            Assert.That(armorClass.SizeModifier, Is.EqualTo(1));
        }
        private Feat BuildFeatFrom(CharacterClassFeatSelection selection, string focus, IEnumerable<Feat> earnedFeat, Dictionary<string, Stat> stats, CharacterClass characterClass, Dictionary<string, Skill> skills)
        {
            var feat = new Feat();
            feat.Name = selection.Feat;

            if (string.IsNullOrEmpty(focus) == false)
                feat.Foci = feat.Foci.Union(new[] { focus });

            feat.Frequency = selection.Frequency;
            feat.Power = selection.Power;

            if (string.IsNullOrEmpty(selection.FrequencyQuantityStat) == false)
                feat.Frequency.Quantity += stats[selection.FrequencyQuantityStat].Bonus;

            if (feat.Frequency.Quantity < 0)
                feat.Frequency.Quantity = 0;

            return feat;
        }
 private bool RequirementHasFocus(IEnumerable<string> requiredFeatNames, Feat feat)
 {
     return requiredFeatNames.Contains(feat.Name) && feat.Foci.Any();
 }
        private void SetUpFeats()
        {
            for (var i = 0; i < 8; i++)
            {
                var feat = new Feat();
                feat.Name = string.Format("Feat{0}", i);
                feat.Power = i + 1;

                feats.Add(feat);
            }

            feats[0].Foci = new[] { FeatConstants.Foci.All };
            feats[1].Foci = new[] { SavingThrowConstants.Fortitude };
            feats[2].Foci = new[] { SavingThrowConstants.Reflex };
            feats[3].Foci = new[] { SavingThrowConstants.Will };

            allSaveFeats.Add(feats[0].Name);
            allSaveFeats.Add(feats[1].Name);
            allSaveFeats.Add(feats[2].Name);
            allSaveFeats.Add(feats[3].Name);
            fortitudeSaveFeats.Add(feats[4].Name);
            reflexSaveFeats.Add(feats[5].Name);
            willSaveFeats.Add(feats[6].Name);
        }
        private bool CanRemoveStrength(Feat feat, IEnumerable<Feat> allFeats)
        {
            if (feat.Frequency.TimePeriod != string.Empty)
                return false;

            var featNamesAllowingMultipleTakes = collectionsSelector.SelectFrom(TableNameConstants.Set.Collection.FeatGroups, GroupConstants.TakenMultipleTimes);
            if (featNamesAllowingMultipleTakes.Contains(feat.Name))
                return false;

            var count = allFeats.Count(f => f.Name == feat.Name
                                        && f.Foci.Except(feat.Foci).Any() == false
                                        && f.Frequency.TimePeriod == string.Empty);

            return count > 1;
        }
        private bool CanCombineFoci(Feat feat, IEnumerable<Feat> allFeats)
        {
            if (feat.Frequency.TimePeriod != string.Empty)
                return false;

            if (feat.Foci.Any() == false || feat.Foci.Contains(FeatConstants.Foci.All))
                return false;

            var count = allFeats.Count(f => f.Name == feat.Name
                                        && f.Foci.Any()
                                        && f.Foci.Contains(FeatConstants.Foci.All) == false
                                        && f.Power == feat.Power
                                        && f.Frequency.TimePeriod == string.Empty);

            return count > 1;
        }
        private bool CanCombine(Feat feat, IEnumerable<Feat> allFeats)
        {
            if (feat.Frequency.TimePeriod == string.Empty)
                return false;

            var count = allFeats.Count(f => f.Name == feat.Name
                                        && f.Foci.Except(feat.Foci).Any() == false
                                        && f.Power == feat.Power
                                        && FrequenciesCanCombine(f.Frequency, feat.Frequency));

            return count > 1;
        }
 private bool FeatsMatch(Feat feat, AdditionalFeatSelection additionalFeatSelection)
 {
     return feat.Frequency.TimePeriod == string.Empty && feat.Name == additionalFeatSelection.Feat
            && feat.Power == additionalFeatSelection.Power
            && feat.Foci.Any() && string.IsNullOrEmpty(additionalFeatSelection.FocusType) == false;
 }
        private List<Feat> PopulateFeatsFrom(CharacterClass characterClass, Dictionary<string, Stat> stats, Dictionary<string, Skill> skills, BaseAttack baseAttack, IEnumerable<Feat> preselectedFeats, IEnumerable<AdditionalFeatSelection> sourceFeats, Int32 quantity)
        {
            var feats = new List<Feat>();
            var chosenFeats = preselectedFeats;
            var availableFeats = GetAvailableFeats(sourceFeats, chosenFeats);

            while (quantity-- > 0 && availableFeats.Any())
            {
                var featSelection = collectionsSelector.SelectRandomFrom(availableFeats);

                var preliminaryFocus = featFocusGenerator.GenerateFrom(featSelection.Feat, featSelection.FocusType, skills, featSelection.RequiredFeats, chosenFeats, characterClass);
                if (preliminaryFocus == FeatConstants.Foci.All)
                {
                    quantity++;
                    sourceFeats = sourceFeats.Except(new[] { featSelection });
                    availableFeats = GetAvailableFeats(sourceFeats, chosenFeats);

                    continue;
                }

                var feat = new Feat();
                var hasMatchingFeat = feats.Any(f => FeatsMatch(f, featSelection));

                if (hasMatchingFeat)
                {
                    feat = feats.First(f => FeatsMatch(f, featSelection));
                }
                else
                {
                    feat.Name = featSelection.Feat;
                    feat.Frequency = featSelection.Frequency;
                    feat.Power = featSelection.Power;

                    if (featSelection.Feat == FeatConstants.SpellMastery)
                        feat.Power = stats[StatConstants.Intelligence].Bonus;

                    feats.Add(feat);
                }

                chosenFeats = preselectedFeats.Union(feats);
                availableFeats = GetAvailableFeats(sourceFeats, chosenFeats);

                if (string.IsNullOrEmpty(preliminaryFocus) == false)
                    feat.Foci = feat.Foci.Union(new[] { preliminaryFocus });

                var featFociQuantity = 0;
                if (featSelection.Feat == FeatConstants.SkillMastery)
                    featFociQuantity = stats[StatConstants.Intelligence].Bonus + featSelection.Power - 1;

                while (featFociQuantity-- > 0 && preliminaryFocus != FeatConstants.Foci.All && string.IsNullOrEmpty(preliminaryFocus) == false)
                {
                    preliminaryFocus = featFocusGenerator.GenerateFrom(featSelection.Feat, featSelection.FocusType, skills, featSelection.RequiredFeats, chosenFeats, characterClass);
                    feat.Foci = feat.Foci.Union(new[] { preliminaryFocus });
                }
            }

            return feats;
        }
        private bool HasCircumstantialBonus(Feat feat)
        {
            var saveFoci = new[]
            {
                FeatConstants.Foci.All,
                SavingThrowConstants.Fortitude,
                SavingThrowConstants.Reflex,
                SavingThrowConstants.Will
            };

            return feat.Foci.Intersect(saveFoci).Any() == false;
        }
Exemple #13
0
 public void Setup()
 {
     feat = new Feat();
 }
        public void CannotPickAPreselectedFeat()
        {
            var feat = new Feat();
            feat.Name = "feat1";
            preselectedFeats.Add(feat);

            AddFeatSelections(2);

            var feats = additionalFeatsGenerator.GenerateWith(characterClass, race, stats, skills, baseAttack, preselectedFeats);
            var featNames = feats.Select(f => f.Name);
            Assert.That(featNames.Single(), Is.EqualTo("feat2"));
        }