Ejemplo n.º 1
0
        public void ChoosingClassFromWeightedOptionTableSelectsFromThoseClasses()
        {
            var character = new CharacterSheet(CharacterStrategy.Default());
            var choices   = new WeightedOptionTable <string>();

            choices.AddEntry("Fighter", 10);

            subject.ChooseClass(character, choices);

            Assert.Equal("Fighter", character.Class.Name);
        }
Ejemplo n.º 2
0
        public WeightedOptionTable <Homeland> GetRacialOptions(string race)
        {
            var table   = new WeightedOptionTable <Homeland>();
            var options = homelands.Where(x => string.Equals(x.Race, race, StringComparison.OrdinalIgnoreCase));

            foreach (var opt in options)
            {
                table.AddEntry(opt, opt.Weighting);
            }
            return(table);
        }
Ejemplo n.º 3
0
        public WeightedOptionTable <ClassOrigin> GetClassOriginOptions(string cls)
        {
            var table   = new WeightedOptionTable <ClassOrigin>();
            var origins = classOrigins.Where(x => string.Equals(x.Class, cls, StringComparison.OrdinalIgnoreCase));

            foreach (var origin in origins)
            {
                table.AddEntry(origin, origin.Weighting);
            }
            return(table);
        }
Ejemplo n.º 4
0
 private void FillInMissingAbilities(WeightedOptionTable <AbilityScoreTypes> abilityTable)
 {
     //build empty table
     foreach (var a in EnumHelpers.GetValues <AbilityScoreTypes>())
     {
         if (!abilityTable.HasOption(a))
         {
             abilityTable.AddEntry(a, 1);
         }
     }
 }
Ejemplo n.º 5
0
        public ClassOriginGroup(IObjectStore data)
        {
            Origins = new WeightedOptionTable <ClassOrigin>();
            Name    = data.GetString("class");
            var table = data.GetObjectList("table");

            foreach (var entry in table)
            {
                var origin = new ClassOrigin(Name, entry);
                Origins.AddEntry(origin, origin.Weighting);
            }
        }
Ejemplo n.º 6
0
 private void ParseYaml(YamlNodeWrapper yaml)
 {
     drawbacks = new WeightedOptionTable <Drawback>();
     foreach (var node in yaml.Children())
     {
         var drawback = new Drawback();
         drawback.Name      = node.GetString("name");
         drawback.Weighting = node.GetInteger("weight");
         drawback.Traits.Add(node.GetCommaStringOptional("traits"));
         drawbacks.AddEntry(drawback, drawback.Weighting);
     }
 }
Ejemplo n.º 7
0
        public HomelandGroup(IObjectStore data)
        {
            Homelands = new WeightedOptionTable <Homeland>();
            Name      = data.GetString("race");
            var table = data.GetObjectList("table");

            foreach (var entry in table)
            {
                var homeland = new Homeland(Name, entry);
                Homelands.AddEntry(homeland, homeland.Weighting);
            }
        }
Ejemplo n.º 8
0
        private void BuildAbilityTable(WeightedOptionTable <AbilityScoreTypes> abilityTable, IEnumerable <IObjectStore> nodes)
        {
            if (nodes != null)
            {
                foreach (var child in nodes)
                {
                    abilityTable.AddEntry(child.GetEnum <AbilityScoreTypes>("name"), child.GetInteger("weight"));
                }
            }

            FillInMissingAbilities(abilityTable);
        }
Ejemplo n.º 9
0
        public void IfAllPreferredSkillsAreMaxedAssignAPointToRemainingClassSkills()
        {
            var strategy = new WeightedOptionTable <string>();

            strategy.AddEntry("Climb", 1);

            //Set Knowledge (Arcana) as a class skill
            skills.SetClassSkill("Knowledge (Arcana)");

            distributor.AssignSkillPoints(skills, strategy, 2, 1);
            Assert.Equal(1, skills.GetSkill("Climb").Ranks);
            Assert.Equal(1, skills.GetSkill("Knowledge (Arcana)").Ranks);
        }
Ejemplo n.º 10
0
        public void DisabledEntriesCanBeReenabled()
        {
            var table = new WeightedOptionTable <string>();

            table.AddEntry("Foo", 483);
            var entry       = table.All.First();
            var originalMax = entry.MaximumValue;

            table.Disable("Foo");
            Assert.True(entry.Disabled);
            table.Enable("Foo");
            Assert.False(entry.Disabled);
            Assert.Equal(originalMax, entry.MaximumValue);
        }
Ejemplo n.º 11
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++;
                }

            }
        }