Beispiel #1
0
        public void Complex()
        {
            var barFooConversion = new[] { _barFooConversion, _barConversion, _barSkillConversion };
            var localSource      = new ModifierSource.Local.Given();
            var skillSource      = new ModifierSource.Local.Skill();

            _sut.NewBatchUpdate()
            .AddModifier(_bar, Form.BaseAdd, 3)
            .AddModifier(_bar, Form.BaseAdd, 2, localSource)
            .AddModifier(barFooConversion, Form.BaseAdd, 50, skillSource)
            .AddModifier(barFooConversion, Form.BaseAdd, 30)
            .AddModifier(barFooConversion, Form.BaseAdd, 30)
            .AddModifier(_barFooGain, Form.BaseAdd, 20)
            .AddModifier(_foo, Form.Increase, 50)
            .AddModifier(_foo, Form.Increase, 50, localSource)
            .AddModifier(_foo, Form.BaseAdd, 1)
            .AddModifier(_foo, Form.BaseAdd, 2, localSource)
            .DoUpdate();

            var globalPath = (3 * (1 + 0.2) + 1) * 1.5;
            var localPath  = (2 * (1 + 0.2) + 2) * 2;

            Assert.AreEqual(new NodeValue(110), GetValue(_barConversion));
            Assert.AreEqual(new NodeValue(50), GetValue(_barSkillConversion));
            Assert.AreEqual(new NodeValue(0), GetValue(_bar));
            Assert.AreEqual(new NodeValue(20), GetValue(_barFooGain));
            Assert.AreEqual(new NodeValue(100), GetValue(_barFooConversion));
            Assert.AreEqual(new NodeValue(globalPath + localPath), GetValue(_foo));
        }
        public void ParseReturnsCorrectResult()
        {
            var untranslatedStats = new[]
            {
                new UntranslatedStat("a", 1),
                new UntranslatedStat("b", 2),
                new UntranslatedStat("c", 3),
            };
            var modifierLines        = new[] { "a1", "b2" };
            var statTranslatorResult = new StatTranslatorResult(modifierLines, new UntranslatedStat[0]);
            var translator           = Mock.Of <IStatTranslator>(t => t.Translate(untranslatedStats) == statTranslatorResult);
            var localSource          = new ModifierSource.Local.Skill();
            var globalSource         = new ModifierSource.Global(localSource);
            var coreParserParameters = new[]
            {
                new CoreParserParameter(modifierLines[0], globalSource, Entity.Character),
                new CoreParserParameter(modifierLines[1], globalSource, Entity.Character),
            };
            var parseResults = new[]
            {
                ParseResult.Empty,
                ParseResult.Failure("b2", ""),
            };
            var coreParser = Mock.Of <ICoreParser>(p =>
                                                   p.Parse(coreParserParameters[0]) == parseResults[0] &&
                                                   p.Parse(coreParserParameters[1]) == parseResults[1]);

            var sut             = new UntranslatedStatParser(translator, coreParser);
            var parserParameter = new UntranslatedStatParserParameter(localSource, untranslatedStats);
            var expected        = ParseResult.Aggregate(parseResults);

            var actual = sut.Parse(parserParameter);

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void BlasphemyParsesPassiveStatsWithParsedSkillIsActiveSkillCondition(bool isActiveSkill)
        {
            var expected = isActiveSkill ? (NodeValue?)10 : null;

            var(activeDefinition, activeSkill)   = CreateEnfeebleDefinition();
            var(supportDefinition, supportSkill) = CreateBlasphemyDefinition();
            var source      = new ModifierSource.Local.Skill("Enfeeble", null);
            var parseResult = ParseResult.Success(new[]
                                                  { MockModifier(new Stat("Blasphemy.EffectOn(Character)"), value: new Constant(10)) });
            var parameter = new UntranslatedStatParserParameter(source, new[]
                                                                { new UntranslatedStat("curse_effect_+%", 10), });
            var statParser = Mock.Of <IParser <UntranslatedStatParserParameter> >(p =>
                                                                                  p.Parse(parameter) == parseResult &&
                                                                                  p.Parse(EmptyParserParameter(source)) == EmptyParseResult);
            var sut     = CreateSut(activeDefinition, supportDefinition, statParser);
            var context = MockValueCalculationContextForActiveSkill(activeSkill,
                                                                    ("Blasphemy.ActiveSkillItemSlot", isActiveSkill ? (double?)supportSkill.ItemSlot : null),
                                                                    ("Blasphemy.ActiveSkillSocketIndex", 1));

            var result = sut.Parse(activeSkill, supportSkill);

            var actual = GetValueForIdentity(result.Modifiers, "Blasphemy.EffectOn(Character)").Calculate(context);

            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        public void PointBlankTranslatesKeystoneStatCorrectly()
        {
            var(activeDefinition, activeSkill)   = CreateEnfeebleDefinition();
            var(supportDefinition, supportSkill) = CreatePointBlankDefinition();
            var source      = new ModifierSource.Local.Skill("Enfeeble", null);
            var parseResult = ParseResult.Success(new[]
                                                  { CreateModifier("PointBlank", Form.TotalOverride, 1) });
            var parameter = new UntranslatedStatParserParameter(source, new[]
                                                                { new UntranslatedStat("keystone_point_blank", 1), });
            var mainStatParser = Mock.Of <IParser <UntranslatedStatParserParameter> >(p =>
                                                                                      p.Parse(parameter) == parseResult &&
                                                                                      p.Parse(EmptyParserParameter(source)) == EmptyParseResult);
            var emptyStatParser = Mock.Of <IParser <UntranslatedStatParserParameter> >(p =>
                                                                                       p.Parse(EmptyParserParameter(source)) == EmptyParseResult);
            var sut = CreateSut(activeDefinition, supportDefinition, GetStatParser);

            var result = sut.Parse(activeSkill, supportSkill);

            Assert.IsTrue(AnyModifierHasIdentity(result.Modifiers, "PointBlank"));

            IParser <UntranslatedStatParserParameter> GetStatParser(IReadOnlyList <string> translationFileNames)
            => translationFileNames[0] == StatTranslationFileNames.Main
                    ? mainStatParser
                    : emptyStatParser;
        }
Beispiel #5
0
        public void ParseFrenzyReturnsCorrectResult()
        {
            var frenzyGem                   = new Gem("Frenzy", 20, 20, ItemSlot.Boots, 0, 0, true);
            var frenzy                      = Skill.FromGem(frenzyGem, true);
            var definition                  = _skillDefinitions.GetSkillById("Frenzy");
            var levelDefinition             = definition.Levels[20];
            var local                       = new ModifierSource.Local.Skill("Frenzy", "Frenzy");
            var global                      = new ModifierSource.Global(local);
            var valueCalculationContextMock = new Mock <IValueCalculationContext>();
            var isMainSkillStat             = SetupIsActiveSkillInContext(valueCalculationContextMock, frenzy);
            var offHandTagsStat             = new Stat("OffHand.ItemTags");

            valueCalculationContextMock.Setup(c => c.GetValue(offHandTagsStat, NodeType.Total, PathDefinition.MainPath))
            .Returns(new NodeValue(Tags.Weapon.EncodeAsDouble()));
            var mainHandTagsStat = new Stat("MainHand.ItemTags");

            valueCalculationContextMock
            .Setup(c => c.GetValue(mainHandTagsStat, NodeType.Total, PathDefinition.MainPath))
            .Returns(new NodeValue(Tags.Ranged.EncodeAsDouble()));
            var frenzyAmountStat = new Stat("Frenzy.Amount");

            valueCalculationContextMock
            .Setup(c => c.GetValue(frenzyAmountStat, NodeType.Total, PathDefinition.MainPath))
            .Returns(new NodeValue(3));
            var baseCostStat = new Stat("Boots.0.0.Cost");

            valueCalculationContextMock
            .Setup(c => c.GetValue(baseCostStat, NodeType.Total, PathDefinition.MainPath))
            .Returns((NodeValue?)levelDefinition.ManaCost);
            var expectedModifiers =
                new (string stat, Form form, double?value, ModifierSource source, bool mainSkillOnly)[]
 public SkillPreParseResult(
     SkillDefinition skillDefinition, SkillLevelDefinition levelDefinition, SkillDefinition mainSkillDefinition,
     ModifierSource.Local.Skill localSource, ModifierSource.Global globalSource, Entity modifierSourceEntity,
     IConditionBuilder isMainSkill, IConditionBuilder isActiveSkill)
 {
     SkillDefinition      = skillDefinition;
     LevelDefinition      = levelDefinition;
     MainSkillDefinition  = mainSkillDefinition;
     LocalSource          = localSource;
     GlobalSource         = globalSource;
     ModifierSourceEntity = modifierSourceEntity;
     IsMainSkill          = isMainSkill;
     IsActiveSkill        = isActiveSkill;
 }
Beispiel #7
0
        public void TemporaryTBuildsToCorrectResult(BuffRotationStage activeStage)
        {
            var temporaryStage    = BuffRotationStage.Stage1;
            var expectedCondition = temporaryStage == activeStage;
            var modifierSource    = new ModifierSource.Local.Skill("skill node");
            var stageStat         = new Stat($"Current {modifierSource} stage");
            var context           = Mock.Of <IValueCalculationContext>(c =>
                                                                       c.GetValue(stageStat, NodeType.Total, PathDefinition.MainPath) == new NodeValue((int)activeStage));
            var sut = CreateSut();

            var(stats, _, valueConverter) = sut.Temporary(sut.Fortify, temporaryStage)
                                            .BuildToSingleResult(modifierSource);
            var value           = valueConverter(new ValueBuilderImpl(1)).Build();
            var actualCondition = value.Calculate(context).IsTrue();

            Assert.That(stats, Has.Exactly(3).Items);
            Assert.AreEqual("Fortify.Active", stats[0].Identity);
            Assert.AreEqual(expectedCondition, actualCondition);
        }
Beispiel #8
0
        public void TemporaryBuildsToCorrectResult(bool expectedCondition)
        {
            var expectedValue     = expectedCondition ? (NodeValue?)3 : null;
            var gainedStatBuilder = StatBuilderUtils.FromIdentity(StatFactory, "s", null);
            var modifierSource    = new ModifierSource.Local.Skill("skill node");
            var conditionStat     = new Stat($"Is {modifierSource} active?");
            var buffEffectStat    = new Stat($"Buff.EffectOn({default(Entity)})");
            var context           = Mock.Of <IValueCalculationContext>(c =>
                                                                       c.GetValue(conditionStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)expectedCondition &&
                                                                       c.GetValue(buffEffectStat, NodeType.Total, PathDefinition.MainPath) == new NodeValue(1.5));
            var sut = CreateSut();

            var(stats, _, valueConverter) = sut.Temporary(gainedStatBuilder)
                                            .BuildToSingleResult(modifierSource);
            var actualValue = valueConverter(new ValueBuilderImpl(2)).Build().Calculate(context);

            Assert.That(stats, Has.One.Items);
            Assert.AreEqual("s", stats[0].Identity);
            Assert.AreEqual(expectedValue, actualValue);
        }