Ejemplo n.º 1
0
        private void AssignByStrategy(CharacterSheet character, WeightedOptionTable <AbilityScoreTypes> abilities)
        {
            var tokens = character.GetAndRemoveAll <AbilityScoreToken>();

            foreach (var token in tokens)
            {
                var modifier = token.CreateAdjustment(abilities.ChooseRandomly());
                character.Add(modifier);
            }
        }
Ejemplo n.º 2
0
        public void ChooseClass(CharacterSheet character, WeightedOptionTable <string> classChoices)
        {
            if (classChoices.IsEmpty)
            {
                ChooseAny(character);
                return;
            }

            var choice = classChoices.ChooseRandomly();
            var cls    = classes.Find(choice);

            AssignClass(character, cls);
        }
Ejemplo n.º 3
0
        private void ChooseRace(CharacterSheet character, WeightedOptionTable <string> options)
        {
            if (options.IsEmpty)
            {
                this.SetRace(character, raceGateway.All().ToList().ChooseOne());
                return;
            }

            var choice = options.ChooseRandomly();
            var race   = raceGateway.Find(choice);

            this.SetRace(character, race);
        }
Ejemplo n.º 4
0
        public void EntriesCanBeDisabledWhichForcesADifferentOptionToBeChosen()
        {
            var table = new WeightedOptionTable <string>();

            table.AddEntry("Foo", 12);
            table.AddEntry("Bar", 100);

            table.Disable("Bar");
            for (int i = 0; i < 1000; i++)
            {
                var result = table.ChooseRandomly();
                Assert.Equal("Foo", result);
            }
        }
Ejemplo n.º 5
0
        private CharacterSkill ChooseSkill(SkillRanks skills, WeightedOptionTable <string> preferredSkills, int maxLevel)
        {
            if (!preferredSkills.IsEmpty)
            {
                var option = preferredSkills.ChooseRandomly();
                var skill  = skills.GetSkill(option);

                if (skill.Ranks < maxLevel)
                {
                    return(skill);
                }
                else
                {
                    preferredSkills.Disable(option);
                }
            }
            else
            {
                // no preferred skills so just pick class skills
                var skill = skills.GetSkills().Where(
                    x => x.ClassSkill &&
                    x.Ranks < maxLevel
                    ).ToList().ChooseOne();

                // Background skills require special attention
                // In general just take one background skill
                if (skill.Skill.IsBackgroundSkill)
                {
                    if (skill.Ranks > 0 || skills.GetSkills().Where(x => x.Skill.IsBackgroundSkill).All(x => x.Ranks == 0))
                    {
                        return(skill);
                    }
                }
                else
                {
                    return(skill);
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
        public void RandomlySelectsOptionBasedOnWeightedValue()
        {
            var table = new WeightedOptionTable<string>();
            table.AddEntry("Foo", 30);
            table.AddEntry("Bar", 10);

            var foo = 0;
            var bar = 0;
            // Run ten thousand times and it should select FOO a few more times
            for (int i = 0; i < 10000; i++)
            {
                string option = table.ChooseRandomly();
                if (option == "Foo")
                {
                    foo++;
                }
                else
                {
                    bar++;
                }

            }
        }
Ejemplo n.º 7
0
        private void SelectFeats(CharacterSheet character, WeightedOptionTable <string> preferredFeats)
        {
            foreach (var token in character.GetAndRemoveAll <FeatToken>())
            {
                FilterPreferredFeats(character, preferredFeats, token);

                Feat feat;
                if (preferredFeats.IsEmpty)
                {
                    var feats = this.feats.Where(x => FeatIsValid(x, token, character));
                    if (feats.HasChoices() == false)
                    {
                        throw new CharacterGeneratorStepFailedException(this, "Could not choose feat from token ({0})".Formatted(token.ToString()));
                    }
                    feat = feats.ChooseOne();
                }
                else
                {
                    var selection = preferredFeats.ChooseRandomly();
                    feat = feats.Find(selection);
                }
                character.Add(feat);
            }
        }
Ejemplo n.º 8
0
 public Drawback ChooseOne()
 {
     return(drawbacks.ChooseRandomly());
 }
Ejemplo n.º 9
0
        public Drawback SelectDrawback()
        {
            var table = new WeightedOptionTable <Drawback>(drawbacks.All());

            return(table.ChooseRandomly());
        }