Example #1
0
        public static SpellList CreateForTesting(string className, EntityGateway <Spell> spellList)
        {
            var sl = new SpellList(spellList);

            sl.Class = className;
            return(sl);
        }
Example #2
0
 public CreateFacialFeatures()
 {
     hairStyles = GatewayProvider.Get <HairStyle>();
     hairColors = GatewayProvider.Get <HairColor>();
     facialHair = GatewayProvider.Get <FacialHair>();
     eyeColors  = GatewayProvider.Get <EyeColor>();
 }
Example #3
0
        public RaceSelectorTests()
        {
            // Create a race
            elf             = new Race();
            elf.Name        = "Elfy";
            elf.SizeSetting = CharacterSize.Medium;
            elf.HeightRange = DiceStrings.ParseDice("10d6");
            elf.WeightRange = DiceStrings.ParseDice("20d8");
            elf.KnownLanguages.Add("Common");
            elf.KnownLanguages.Add("Elvish");
            elf.AvailableLanguages.Add("Draconic");
            elf.AvailableLanguages.Add("Celestial");

            human             = new Race();
            human.Name        = "Human";
            human.SizeSetting = CharacterSize.Medium;
            human.HeightRange = DiceStrings.ParseDice("2d8+30");
            human.WeightRange = DiceStrings.ParseDice("3d6+100");
            human.KnownLanguages.Add("Common");


            var list = new List <Race>();

            list.Add(elf);
            list.Add(human);

            // Configure Gateways
            raceGateway = EntityGateway <Race> .LoadFromList(list);

            raceSelectorSubject = new RaceSelector(raceGateway);
        }
Example #4
0
 public static IList <string> GetLastNames(this EntityGateway <NameInformation> gateway)
 {
     return(gateway
            .Where(x => x.IsLastName)
            .SelectMany(x => x.Names)
            .ToList());
 }
Example #5
0
        public void BreaksDescriptionIntoIndividualComponentsForMoreFlexibleDescriptions()
        {
            // Set up Descriptors
            var descs = new MemoryStore();

            descs.AddListItem(new MemoryStore("pattern", new string[] { "dragon" }));
            descs.AddListItem(new MemoryStore("color", new string[] { "black" }));

            // Set up Templates
            var temps = new MemoryStore();

            temps.AddListItem(new MemoryStore("template", "{{feature}} of a {{descriptor \"color\"}} {{descriptor \"pattern\"}}."));

            // Set up physical Feature
            var mem = new MemoryStore();

            mem.SetValue("name", "tattoo");
            mem.SetValue("descriptors", descs);
            mem.SetValue("templates", temps);
            var phys = new PhysicalFeature(mem);

            var gateway = EntityGateway <PhysicalFeature> .LoadWithSingleItem(phys);

            var subject = new CreatePhysicalFeatures(gateway);

            var character = new CharacterSheet(CharacterStrategy.Default());

            character.Gender = Gender.Female;

            subject.ExecuteStep(character);

            Assert.Equal(character.Appearance.PhysicalAppearance, "Tattoo of a black dragon.");
        }
Example #6
0
 public static IList <string> GetLastNames(this EntityGateway <NameInformation> gateway, string race)
 {
     return(gateway
            .Where(x => x.IsLastName &&
                   x.MatchesRace(race))
            .SelectMany(x => x.Names)
            .ToList());
 }
Example #7
0
        private EntityGateway <Weapon> GetWeapons()
        {
            if (weaponsGateway == null)
            {
                weaponsGateway = GatewayProvider.Get <Weapon>();
            }

            return(weaponsGateway);
        }
Example #8
0
        private CharacterDesigner FindDesigner(string name)
        {
            if (gateway == null)
            {
                gateway = GatewayProvider.Get <CharacterDesigner>();
            }

            return(gateway.Find(designerName));
        }
Example #9
0
        public void NeedToBeProficientWithAtLeastOneWeapon()
        {
            var longsword = new Weapon("Longsword", 1, "1d6", DamageTypes.Slashing, 20, 2, 0, WeaponType.OneHanded, WeaponGroup.HeavyBlades, WeaponTrainingLevel.Simple);
            var list      = EntityGateway <Weapon> .LoadWithSingleItem(longsword);

            var character   = CharacterTestTemplates.AverageBob();
            var weaponFocus = WeaponFocus.CreateForTesting(list);

            Assert.False(weaponFocus.IsQualified(character));
        }
Example #10
0
        public static WeaponFocus CreateForTesting(EntityGateway <Weapon> weapons)
        {
            var configure = new MemoryStore();

            configure.SetValue("name", "Weapon Focus");
            var weaponFocus = new WeaponFocus(configure);

            weaponFocus.weaponsGateway = weapons;
            return(weaponFocus);
        }
Example #11
0
        public SpellCastingTests()
        {
            spellList = SpellList.CreateForTesting("bard");
            spellList.Add(1, "magic missile");
            var gateway = EntityGateway <SpellList> .LoadWithSingleItem(spellList);

            bard         = CharacterTestTemplates.BardyBard();
            spellCasting = new SpellCasting(configuration, gateway);
            bard.Add(spellCasting);
        }
Example #12
0
        public LanguageSelectorTests()
        {
            var languages = new List <Language> ();

            languages.Add(new Language("Elvish", "Foo"));
            languages.Add(new Language("Boo", "foo"));
            languages.Add(new Language("Giant", "Rawr"));
            languages.Add(new Language("Corgi", "woof"));
            languageGateway = EntityGateway <Language> .LoadFromList(languages);
        }
Example #13
0
        public void ChoosesFromListOfOptionsAndAssignsToHistory()
        {
            var circumstance = new BirthCircumstance("Nothing exciting", 10);
            var character    = CharacterTestTemplates.AverageBob();
            var subject      = new BirthCircumstanceSelector(EntityGateway <BirthCircumstance> .LoadWithSingleItem(circumstance));

            subject.ExecuteStep(character);
            var history = character.Get <History>();

            Assert.Equal(circumstance, history.BirthCircumstance);
        }
Example #14
0
        public void CanForceGatewayToASpecificList()
        {
            var list = new List <TestObject>();

            list.Add(new TestObject("hello1"));
            list.Add(new TestObject("hello2"));
            var gateway = EntityGateway <TestObject> .LoadFromList(list);

            Assert.Equal(2, gateway.Count());
            Assert.NotNull(gateway.Find("hello2"));
        }
Example #15
0
        public void CanSelectWeaponsBasedOnProficiencies()
        {
            var repo = EntityGateway <Weapon> .LoadFromList(WeaponYamlFile.ParseYaml().Load <Weapon>());

            var prof = new WeaponProficiency("dagger");

            var results = repo.FindByProficient(new WeaponProficiency[] { prof });

            Assert.Equal(1, results.Count());
            Assert.Equal("Dagger", results.First().Name);
        }
Example #16
0
        public void UsesCustomSerializerIfPossible()
        {
            var data = new MemoryStore();

            data.SetValue("name", "Foo");
            var gateway = EntityGateway <TestSerialized> .LoadFromObjectStore(new IObjectStore[] { data });

            var first = gateway.All().First();

            Assert.Equal(first.Name, "Foo");
        }
Example #17
0
        public void SelectsABackgroundStoryToGenerate()
        {
            var backgroundStoryTemplate = new Descriptor("background-story", new string[] { "{{name}} was born in a shack." });
            var writer    = new BackgroundStorywriter(EntityGateway <Descriptor> .LoadWithSingleItem(backgroundStoryTemplate));
            var character = new CharacterSheet(CharacterStrategy.Default());

            character.FirstName = "Foo";

            writer.ExecuteStep(character);
            Assert.Equal("Foo was born in a shack.", character.Get <BackgroundStory>().GetStory());
        }
Example #18
0
        public StartingWealthTests()
        {
            var list   = new List <CharacterWealth>();
            var wealth = new CharacterWealth();

            wealth.Name = "adventurer";
            wealth.Levels.Add(new CharacterWealth.CharacterWealthLevel(1, 0));
            wealth.Levels.Add(new CharacterWealth.CharacterWealthLevel(2, 2000));
            list.Add(wealth);
            wealthGateway = EntityGateway <CharacterWealth> .LoadFromList(list);
        }
Example #19
0
        public void DonotBuyThingsYouCannotAfford()
        {
            var clothes  = new Clothes("Outfit", 2000, 5);
            var purchase = new PurchaseClothing(EntityGateway <Clothes> .LoadWithSingleItem(clothes));
            var bob      = CharacterTestTemplates.AverageBob();

            bob.Inventory.CoinPurse.AddGold(1);

            purchase.ExecuteStep(bob);
            Assert.Null(bob.Inventory.Find(clothes));
        }
Example #20
0
        public void ChoosingADescriptorLoadsFromGatewayDescriptorsMatchingName()
        {
            var color   = new Descriptor("color", new string[] { "Red" });
            var gateway = EntityGateway <Descriptor> .LoadWithSingleItem(color);

            var choose             = ChooseDescriptor.CreateIsolatedForUnitTesting(gateway, "choose-testing");
            var handleBarsTemplate = Handlebars.Compile("{{choose-testing \"color\"}}");
            var result             = handleBarsTemplate(string.Empty);

            Assert.Equal("Red", result);
        }
Example #21
0
        public void CustomLoaderCanBeUsedToExpandAndInstantiateAGroupOfEntities()
        {
            var data = new MemoryStore();

            data.SetValue("loader", "Tests.Serialization.EntityGatewayTests+TestObjectLoader");
            var gateway = EntityGateway <TestObject> .LoadFromObjectStore(new IObjectStore[] { data });

            var all = gateway.All();

            Assert.Equal(3, all.Count());
            Assert.Equal("Loader 1", all.First().Name);
        }
Example #22
0
        public PurchaseShieldTests()
        {
            shield           = new Armor();
            shield.ArmorType = ArmorType.Shield;
            gateway          = EntityGateway <Armor> .LoadWithSingleItem(shield);

            proficientCharacter = CharacterTestTemplates.AverageBob();
            proficientCharacter.Defense.AddArmorProficiencies(new string[] { "shield" });
            incapableCharacter = CharacterTestTemplates.AverageBob();

            subject = new PurchaseShield(gateway);
        }
Example #23
0
 public ArcaneBond(EntityGateway <Familiar> familiars)
 {
     this.familiars = familiars;
     items          = new IGear[]
     {
         new Gear("amulet", 0, 0),
         new Gear("ring", 0, 0),
         new Gear("staff", 0, 0),
         new Gear("wand", 0, 0),
         new Gear("ring", 0, 0)
     };
 }
Example #24
0
 public SpontaneousCastingTests()
 {
     spellList = SpellList.CreateForTesting("bard");
     spellList.Add(0, "cantrip1");
     spellList.Add(0, "cantrip2");
     spellList.Add(1, "level1.1");
     spellList.Add(1, "level1.2");
     spellList.Add(2, "level2.1");
     spellList.Add(2, "level2.2");
     bard         = CharacterTestTemplates.BardyBard();
     spellCasting = new SpontaneousCasting(configuration, EntityGateway <SpellList> .LoadWithSingleItem(spellList));
     bard.Add(spellCasting);
 }
Example #25
0
        public ClassSelectorTests()
        {
            var classes   = new List <Class>();
            var hero      = Class.CreateForTesting("Fighter", DiceSides.d10);
            var bartender = Class.CreateForTesting("Bartender", DiceSides.d4);

            classes.Add(hero);
            classes.Add(bartender);

            classGateway = EntityGateway <Class> .LoadFromList(classes);

            subject = new ClassSelector(classGateway);
        }
Example #26
0
        public void ProcessCreatesADescriptionCombiningColorAndStyle()
        {
            var colors = new HairColor[] { new HairColor("copper") };
            var styles = new HairStyle[] { new HairStyle("ponytail") };

            styles[0].Descriptors.Add("descriptor", new string[] { "long" });

            var subject   = new CreateHair(EntityGateway <HairColor> .LoadFromList(colors), EntityGateway <HairStyle> .LoadFromList(styles));
            var character = new CharacterSheet(CharacterStrategy.Default());

            subject.ExecuteStep(character);
            Assert.Equal(colors[0], character.Appearance.HairColor);
            Assert.Equal(styles[0], character.Appearance.HairStyle);
        }
Example #27
0
        public void FlagAsUnqualifiedIfAlreadyHasWeaponFocus()
        {
            var longsword = new Weapon("Longsword", 1, "1d6", DamageTypes.Slashing, 20, 2, 0, WeaponType.OneHanded, WeaponGroup.HeavyBlades, WeaponTrainingLevel.Simple);
            var list      = EntityGateway <Weapon> .LoadWithSingleItem(longsword);

            var weaponFocus = WeaponFocus.CreateForTesting(list);
            var bob         = CharacterTestTemplates.AverageBob();

            bob.Offense.AddWeaponProficiency("simple");
            bob.Add(weaponFocus);
            var newFocus = WeaponFocus.CreateForTesting(list);

            Assert.False(newFocus.IsQualified(bob));
        }
Example #28
0
        public SpellCasting(IObjectStore configuration, EntityGateway <SpellList> spellLists)
        {
            this.SpellListName      = configuration.GetString("list");
            this.SpellList          = spellLists.Find(this.SpellListName);
            this.SpellType          = configuration.GetEnum <SpellType>("spell-type");
            this.castingAbilityType = configuration.GetEnum <AbilityScoreTypes>("casting-ability");
            var slots = configuration.GetObject("spell-slots");

            foreach (var slot in slots.Keys)
            {
                var spellCounts = slots.GetList(slot).Select(x => x.ToInteger()).ToArray();
                spellSlots.Add(slot.ToInteger(), spellCounts);
            }
        }
Example #29
0
        public void ChoosingAWordAddsToContextIfPossible()
        {
            var color   = new Descriptor("color", new string[] { "Red" });
            var gateway = EntityGateway <Descriptor> .LoadWithSingleItem(color);

            var     choose             = ChooseDescriptor.CreateIsolatedForUnitTesting(gateway, "choose-testing");
            var     handleBarsTemplate = Handlebars.Compile("{{choose-testing \"color\"}}");
            var     context            = new PhraseContext();
            dynamic contextObj         = context.CreateObject();
            var     result             = handleBarsTemplate(contextObj);

            Assert.Equal("Red", context.GetValue <string>("color"));
            Assert.Equal("Red", contextObj.color);
        }
Example #30
0
        public void ChooseFromFavoredEnemyList()
        {
            var aberration = new CreatureType("Aberration");
            var ctGateway  = EntityGateway <CreatureType> .LoadWithSingleItem(aberration);

            var configureStep = new SelectFavoredEnemy(ctGateway);
            var character     = new CharacterSheet(CharacterStrategy.Default());

            configureStep.ExecuteStep(character);

            var favEnemy = character.Get <FavoredEnemy>();

            Assert.Contains(aberration, favEnemy.CreatureTypes);
        }