コード例 #1
0
ファイル: TestContext.cs プロジェクト: seshbot/campaigns
        public TestRules()
        {
            _attributesDb = new InMemoryEntityRepository<Campaigns.Model.Attribute>();
            _contributionsDb = new InMemoryEntityRepository<AttributeContribution>();
            _contributionsDb.AddForeignStore(_attributesDb);

            _contributingAttributes = new HashSet<Campaigns.Model.Attribute>();

            //
            // create attributes
            //

            _races = new Dictionary<string, Campaigns.Model.Attribute>
            {
                { "human", CreateAttribute("human", "races", isStandard: false) },
                { "gnome", CreateAttribute("gnome", "races", isStandard: false) }
            };

            _abilities = new Dictionary<string, Campaigns.Model.Attribute>
            {
                { "str", CreateAttribute("str", "abilities", isStandard: true) },
                { "int", CreateAttribute("int", "abilities", isStandard: true) }
            };

            _abilityMods =
                _abilities.Values
                .Select(attrib => CreateAttribute(attrib.Name, "ability-modifiers", isStandard: true))
                .ToDictionary(m => m.Name);

            _skills = new Dictionary<string, Campaigns.Model.Attribute>
            {
                { "athletics", CreateAttribute("athletics", "skills", isStandard: true) },
                { "arcana", CreateAttribute("arcana", "skills", isStandard: true) }
            };

            // TODO: this should be standard behaviour
            // ensure all standard attributes are contributing
            foreach (var attrib in AllAttributes.Where(a => a.IsStandard))
            {
                SetInitialValue(attrib, 0);
            }

            //
            // create attribute contribution links
            //

            foreach (var mod in _abilities.Keys)
            {
                var contribution = _abilities[mod].ContributionTo(_abilityMods[mod], srcVal => (srcVal / 2) - 5);
                _contributionsDb.Add(contribution);
            }

            // TODO:
            //  - only one contributing link between src and target allowed (overwrite)

            _contributionsDb.Add(_races["gnome"].ConstantContributionTo(_abilities["int"], 2));

            _contributionsDb.Add(_skills["athletics"].CopyContributionFrom(_abilityMods["str"]));
            _contributionsDb.Add(_skills["arcana"].CopyContributionFrom(_abilityMods["int"]));
        }
コード例 #2
0
ファイル: TestContext.cs プロジェクト: seshbot/campaigns
        public TestRules()
        {
            _attributesDb    = new InMemoryEntityRepository <Campaigns.Model.Attribute>();
            _contributionsDb = new InMemoryEntityRepository <AttributeContribution>();
            _contributionsDb.AddForeignStore(_attributesDb);

            _contributingAttributes = new HashSet <Campaigns.Model.Attribute>();

            //
            // create attributes
            //

            _races = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "human", CreateAttribute("human", "races", isStandard: false) },
                { "gnome", CreateAttribute("gnome", "races", isStandard: false) }
            };

            _abilities = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "str", CreateAttribute("str", "abilities", isStandard: true) },
                { "int", CreateAttribute("int", "abilities", isStandard: true) }
            };

            _abilityMods =
                _abilities.Values
                .Select(attrib => CreateAttribute(attrib.Name, "ability-modifiers", isStandard: true))
                .ToDictionary(m => m.Name);

            _skills = new Dictionary <string, Campaigns.Model.Attribute>
            {
                { "athletics", CreateAttribute("athletics", "skills", isStandard: true) },
                { "arcana", CreateAttribute("arcana", "skills", isStandard: true) }
            };

            // TODO: this should be standard behaviour
            // ensure all standard attributes are contributing
            foreach (var attrib in AllAttributes.Where(a => a.IsStandard))
            {
                SetInitialValue(attrib, 0);
            }

            //
            // create attribute contribution links
            //

            foreach (var mod in _abilities.Keys)
            {
                var contribution = _abilities[mod].ContributionTo(_abilityMods[mod], srcVal => (srcVal / 2) - 5);
                _contributionsDb.Add(contribution);
            }

            // TODO:
            //  - only one contributing link between src and target allowed (overwrite)

            _contributionsDb.Add(_races["gnome"].ConstantContributionTo(_abilities["int"], 2));

            _contributionsDb.Add(_skills["athletics"].CopyContributionFrom(_abilityMods["str"]));
            _contributionsDb.Add(_skills["arcana"].CopyContributionFrom(_abilityMods["int"]));
        }
コード例 #3
0
        public void InitTests()
        {
            _people = new InMemoryEntityRepository <Person>();
            _groups = new InMemoryEntityRepository <Group>();
            _pets   = new InMemoryEntityRepository <Pet>();

            _groups.AddForeignStore(_people);
            _people.AddForeignStore(_groups);
            _pets.AddForeignStore(_people);

            var g1 = new Group {
                Name = "Students"
            };

            _groups.Add(g1);

            var p1 = new Person {
                Name = "Amy", Group = g1
            };

            _people.Add(p1);
            _people.Add(new Person {
                Name = "Bernie", GroupId = g1.Id
            });

            _pets.Add(new Pet {
                Name = "Charlie", Owner = p1
            });
            _pets.Add(new Pet {
                Name = "Dover", OwnerId = p1.Id
            });
        }
コード例 #4
0
ファイル: RulesTests.cs プロジェクト: seshbot/campaigns
        public void TestInit()
        {
            _attributes = new InMemoryEntityRepository<Campaigns.Model.Attribute>();
            _contributions = new InMemoryEntityRepository<Campaigns.Model.AttributeContribution>();
            _contributions.AddForeignStore(_attributes);

            _characterSheets = new InMemoryEntityRepository<Campaigns.Model.CharacterSheet>();
            _characters = new InMemoryEntityRepository<Campaigns.Model.Character>();
            _characters.AddForeignStore(_characterSheets);

            _attributes.AddRange(new[]
            {
                new Campaigns.Model.Attribute { Name = "human", Category = "race", IsStandard = false },
                new Campaigns.Model.Attribute { Name = "gnome", Category = "race", IsStandard = false },
                new Campaigns.Model.Attribute { Name = "str", Category = "abilities", IsStandard = true },
                new Campaigns.Model.Attribute { Name = "int", Category = "abilities", IsStandard = true },
                new Campaigns.Model.Attribute { Name = "str", Category = "ability-mods", IsStandard = true },
                new Campaigns.Model.Attribute { Name = "int", Category = "ability-mods", IsStandard = true },
            });

            _contributions.AddRange(new[]
            {
                Attrib("gnome", "race").ConstantContributionTo(Attrib("int", "abilities"), 2),
                Attrib("str", "abilities").ContributionTo(Attrib("str", "ability-mods"), n => n / 2 - 5),
                Attrib("int", "abilities").ContributionTo(Attrib("int", "ability-mods"), n => n / 2 - 5),
            });

            _rules = new RulesService(
                _attributes,
                _contributions,
                _characterSheets,
                _characters);

            _gnomeAllocations = new []
            {
                new AttributeAllocation { Attribute = Attrib("gnome", "race") },
                new AttributeAllocation { Attribute = Attrib("str", "abilities"), Value = 8 },
                new AttributeAllocation { Attribute = Attrib("int", "abilities"), Value = 8 },
            };

            _superStrongUpdate = new CharacterUpdate
            {
                AddedOrUpdatedAllocations = new []
                {
                    new AttributeAllocation { Attribute = Attrib("str", "abilities"), Value = 20 },
                }
            };
        }
コード例 #5
0
        public void InitTests()
        {
            _people = new InMemoryEntityRepository<Person>();
            _groups = new InMemoryEntityRepository<Group>();
            _pets = new InMemoryEntityRepository<Pet>();

            _groups.AddForeignStore(_people);
            _people.AddForeignStore(_groups);
            _pets.AddForeignStore(_people);

            var g1 = new Group { Name = "Students" };
            _groups.Add(g1);

            var p1 = new Person { Name = "Amy", Group = g1 };
            _people.Add(p1);
            _people.Add(new Person { Name = "Bernie", GroupId = g1.Id });

            _pets.Add(new Pet { Name = "Charlie", Owner = p1 });
            _pets.Add(new Pet { Name = "Dover", OwnerId = p1.Id });
        }
コード例 #6
0
ファイル: RulesTests.cs プロジェクト: seshbot/campaigns
        public void TestInit()
        {
            _attributes    = new InMemoryEntityRepository <Campaigns.Model.Attribute>();
            _contributions = new InMemoryEntityRepository <Campaigns.Model.AttributeContribution>();
            _contributions.AddForeignStore(_attributes);

            _characterSheets = new InMemoryEntityRepository <Campaigns.Model.CharacterSheet>();
            _characters      = new InMemoryEntityRepository <Campaigns.Model.Character>();
            _characters.AddForeignStore(_characterSheets);

            _attributes.AddRange(new[]
            {
                new Campaigns.Model.Attribute {
                    Name = "human", Category = "race", IsStandard = false
                },
                new Campaigns.Model.Attribute {
                    Name = "gnome", Category = "race", IsStandard = false
                },
                new Campaigns.Model.Attribute {
                    Name = "str", Category = "abilities", IsStandard = true
                },
                new Campaigns.Model.Attribute {
                    Name = "int", Category = "abilities", IsStandard = true
                },
                new Campaigns.Model.Attribute {
                    Name = "str", Category = "ability-mods", IsStandard = true
                },
                new Campaigns.Model.Attribute {
                    Name = "int", Category = "ability-mods", IsStandard = true
                },
            });

            _contributions.AddRange(new[]
            {
                Attrib("gnome", "race").ConstantContributionTo(Attrib("int", "abilities"), 2),
                Attrib("str", "abilities").ContributionTo(Attrib("str", "ability-mods"), n => n / 2 - 5),
                Attrib("int", "abilities").ContributionTo(Attrib("int", "ability-mods"), n => n / 2 - 5),
            });

            _rules = new RulesService(
                _attributes,
                _contributions,
                _characterSheets,
                _characters);

            _gnomeAllocations = new []
            {
                new AttributeAllocation {
                    Attribute = Attrib("gnome", "race")
                },
                new AttributeAllocation {
                    Attribute = Attrib("str", "abilities"), Value = 8
                },
                new AttributeAllocation {
                    Attribute = Attrib("int", "abilities"), Value = 8
                },
            };

            _superStrongUpdate = new CharacterUpdate
            {
                AddedOrUpdatedAllocations = new []
                {
                    new AttributeAllocation {
                        Attribute = Attrib("str", "abilities"), Value = 20
                    },
                }
            };
        }