예제 #1
0
        public void AddAddsFromStatLinesCorrectly()
        {
            var expected   = Helper.MockManyModifiers(4);
            var givenStats = new[]
            {
                Mock.Of <IGivenStats>(s =>
                                      s.AffectedEntities == new[] { Entity.Character, Entity.Totem } &&
                                      s.GivenStatLines == new[] { "s1", "s2" } &&
                                      s.GivenModifiers == new IIntermediateModifier[0])
            };
            var parseParameters = new[]
            {
                new CoreParserParameter("s1", GlobalSource, Entity.Character),
                new CoreParserParameter("s2", GlobalSource, Entity.Character),
                new CoreParserParameter("s1", GlobalSource, Entity.Totem),
                new CoreParserParameter("s2", GlobalSource, Entity.Totem)
            };
            var parseResults = expected.Select(m => ParseResult.Success(new[] { m }))
                               .ToList();
            var parser = Mock.Of <ICoreParser>(p =>
                                               p.Parse(parseParameters[0]) == parseResults[0] &&
                                               p.Parse(parseParameters[1]) == parseResults[1] &&
                                               p.Parse(parseParameters[2]) == parseResults[2] &&
                                               p.Parse(parseParameters[3]) == parseResults[3]);

            var actual = GivenStatsParser.Parse(parser, givenStats);

            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        public void AddThrowsIfStatLineIsNotSuccessfullyParsed()
        {
            var givenStats = new[]
            {
                Mock.Of <IGivenStats>(s =>
                                      s.AffectedEntities == new[] { Entity.Character } &&
                                      s.GivenStatLines == new[] { "s1" } &&
                                      s.GivenModifiers == new IIntermediateModifier[0])
            };
            var parseResult = ParseResult.Failure("", "");
            var parser      = Mock.Of <ICoreParser>(p =>
                                                    p.Parse(new CoreParserParameter("s1", GlobalSource, Entity.Character)) == parseResult);

            Assert.Throws <ParseException>(() => GivenStatsParser.Parse(parser, givenStats));
        }
예제 #3
0
        public void AddThrowsIfStatLineIsNotSuccessfullyParsed()
        {
            var givenStats = new[]
            {
                Mock.Of <IGivenStats>(s =>
                                      s.AffectedEntities == new[] { Entity.Character } &&
                                      s.GivenStatLines == new[] { "s1" } &&
                                      s.GivenModifiers == new IIntermediateModifier[0])
            };
            var parseResult = new ParseResult(false, "", new Modifier[0]);
            var parser      = Mock.Of <IParser>(p =>
                                                p.Parse("s1", new ModifierSource.Global(), Entity.Character) == parseResult);

            Assert.Throws <ParseException>(() => GivenStatsParser.Parse(parser, givenStats));
        }
예제 #4
0
        public static void ClassInit()
        {
            var compRoot = new CompositionRoot();

            _builderFactories = compRoot.BuilderFactories;
            _metaStats        = compRoot.MetaStats;
            var modSource = new ModifierSource.Global();

            _givenMods = GivenStatsParser.Parse(compRoot.Parser, compRoot.GivenStats.Result)
                         .Append(
                new Modifier(
                    Build(_builderFactories.StatBuilders.Level.For(_builderFactories.EntityBuilders.Enemy)),
                    Form.BaseSet, new Constant(84), modSource),
                new Modifier(
                    Build(_builderFactories.DamageTypeBuilders.Physical.Damage.Taken
                          .For(_builderFactories.EntityBuilders.Enemy)),
                    Form.Increase, new Constant(20), modSource),
                new Modifier(
                    Build(_builderFactories.DamageTypeBuilders.Physical.Resistance
                          .For(_builderFactories.EntityBuilders.Enemy)),
                    Form.BaseSet, new Constant(60), modSource),
                new Modifier(
                    Build(_builderFactories.StatBuilders.Level),
                    Form.BaseSet, new Constant(90), modSource),
                new Modifier(
                    Build(_builderFactories.DamageTypeBuilders.Physical.Damage.WithSkills),
                    Form.BaseSet, new Constant(5), modSource),
                new Modifier(
                    Build(_builderFactories.StatBuilders.Accuracy),
                    Form.BaseAdd, new Constant(1000), modSource),
                new Modifier(
                    Build(_metaStats.SkillHitDamageSource),
                    Form.BaseSet, new Constant((int)DamageSource.Attack), modSource),
                new Modifier(
                    Build(_metaStats.SkillUsesHand(AttackDamageHand.MainHand)),
                    Form.BaseSet, new Constant(true), modSource),
                new Modifier(
                    Build(_metaStats.SkillUsesHand(AttackDamageHand.OffHand)),
                    Form.BaseSet, new Constant(true), modSource),
                new Modifier(
                    Build(_builderFactories.EquipmentBuilders.Equipment[ItemSlot.MainHand].ItemTags),
                    Form.TotalOverride, new Constant((int)Tags.Sword), modSource))
                         .ToList();
        }
예제 #5
0
        public void AddAddsFromStatsCorrectly()
        {
            var expectedStats          = new[] { new StatStub(), };
            var expectedForm           = Form.BaseSet;
            var expectedValue          = new Constant(42);
            var expectedModifierSource = GlobalSource;
            var expected = new[]
            {
                new Modifier(expectedStats, expectedForm, expectedValue, expectedModifierSource)
            };

            var buildParams     = new BuildParameters(expectedModifierSource, Entity.Enemy, expectedForm);
            var formBuilderMock = new Mock <IFormBuilder>();

            formBuilderMock.Setup(b => b.Build())
            .Returns((expectedForm, Funcs.Identity));
            var statBuilderMock = new Mock <IStatBuilder>();

            statBuilderMock.Setup(b => b.Build(buildParams))
            .Returns(new[] { new StatBuilderResult(expectedStats, expectedModifierSource, Funcs.Identity), });
            var valueBuilder         = Mock.Of <IValueBuilder>(b => b.Build(buildParams) == expectedValue);
            var intermediateModifier = ModifierBuilder.Empty
                                       .WithForm(formBuilderMock.Object).WithStat(statBuilderMock.Object).WithValue(valueBuilder)
                                       .Build();
            var givenStats = new[]
            {
                Mock.Of <IGivenStats>(s =>
                                      s.AffectedEntities == new[] { Entity.Enemy } &&
                                      s.GivenStatLines == new string[0] &&
                                      s.GivenModifiers == new[] { intermediateModifier })
            };

            var actual = GivenStatsParser.Parse(Mock.Of <ICoreParser>(), givenStats);

            Assert.AreEqual(expected, actual);
        }
예제 #6
0
        public void ParseIsEmptyWithNoGivenStats()
        {
            var actual = GivenStatsParser.Parse(Mock.Of <ICoreParser>(), new IGivenStats[0]);

            Assert.IsEmpty(actual);
        }