public void AddStatBuildsToCorrectResultIfBuffActive() { var expectedStat = "stat"; var expectedValue = (NodeValue?)3; var statBuilder = StatBuilderUtils.FromIdentity(StatFactory, expectedStat, null); var valueBuilder = new ValueBuilderImpl(2); var activeStat = new Stat("test.Active"); var buffActiveStat = new Stat("test.BuffActive"); var buffSourceStat = new Stat("test.BuffSourceIs(Enemy)"); var effectStat = new Stat($"test.EffectOn({default(Entity)})", Entity.Enemy); var context = Mock.Of <IValueCalculationContext>(c => c.GetValue(activeStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)true && c.GetValue(buffActiveStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)true && c.GetValue(buffSourceStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)true && c.GetValue(effectStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)1.5); var sut = CreateSut(); var addStat = sut.AddStat(statBuilder); var(stats, _, valueConverter) = addStat.BuildToSingleResult(); var actualStat = stats.Single().Identity; var actualValue = valueConverter(valueBuilder).Build().Calculate(context); Assert.AreEqual(expectedStat, actualStat); Assert.AreEqual(expectedValue, actualValue); }
public void FromMinAndMaxReturnsCorrectResult(double?min, double?max) { var expected = min.HasValue && max.HasValue ? new NodeValue(min.Value, max.Value) : (NodeValue?)null; var minBuilder = new ValueBuilderImpl(min); var maxBuilder = new ValueBuilderImpl(max); var sut = CreateSut(); var actual = sut.FromMinAndMax(minBuilder, maxBuilder).Build().Calculate(null); Assert.AreEqual(expected, actual); }
public void InPastXSecondsBuildsToCorrectResultIfLastOccurenceIsNull() { var secondsValue = new ValueBuilderImpl(5); var lastOccurenceStat = new Stat("test.LastOccurrence"); var context = Mock.Of <IValueCalculationContext>(c => c.GetValue(lastOccurenceStat, NodeType.Total, PathDefinition.MainPath) == null); var sut = CreateSut(); var result = sut.InPastXSeconds(secondsValue).Build(); var actual = result.Value.Calculate(context); Assert.IsFalse(actual.IsTrue()); }
public ValueBuilder Count(Func <TBuilder, IConditionBuilder> predicate) { var conditions = this.Select(predicate).ToList(); var valueBuilder = new ValueBuilderImpl( ps => Build(ps, conditions), c => ((IBuilderCollection <TBuilder>)Resolve(c)).Count(predicate)); return(new ValueBuilder(valueBuilder)); IValue Build(BuildParameters parameters, IEnumerable <IConditionBuilder> cs) { var builtConditions = cs.Select(c => BuildConditionToValue(c, parameters)).ToList(); return(new CountingValue(builtConditions)); } }
public void InPastXSecondsBuildsToCorrectResult(int seconds) { var lastOccurence = 3; var expected = lastOccurence <= seconds; var secondsValue = new ValueBuilderImpl(seconds); var lastOccurenceStat = new Stat("test.LastOccurrence"); var context = Mock.Of <IValueCalculationContext>(c => c.GetValue(lastOccurenceStat, NodeType.Total, PathDefinition.MainPath) == new NodeValue(lastOccurence)); var sut = CreateSut(); var result = sut.InPastXSeconds(secondsValue).Build(); Assert.IsFalse(result.HasStatConverter); Assert.IsTrue(result.HasValue); var actual = result.Value.Calculate(context); Assert.AreEqual(expected, actual.IsTrue()); }
public void WithSpellSkillsBuildsToCorrectValueConverters() { var valueBuilder = new ValueBuilderImpl(10); var statFactory = new StatFactory(); var spellDamageStat = statFactory.ConcretizeDamage(new Stat("test"), new SkillDamageSpecification(DamageSource.Spell)); var context = Mock.Of <IValueCalculationContext>(c => c.GetValue(statFactory.ApplyModifiersToSkillDamage(spellDamageStat, DamageSource.Attack, default), NodeType.Total, PathDefinition.MainPath) == new NodeValue(50) && c.GetValue(statFactory.ApplyModifiersToSkillDamage(spellDamageStat, DamageSource.Secondary, default), NodeType.Total, PathDefinition.MainPath) == new NodeValue(20) && c.GetValue(statFactory.ApplyModifiersToSkillDamage(spellDamageStat, DamageSource.OverTime, default), NodeType.Total, PathDefinition.MainPath) == null && c.GetValue(statFactory.ApplyModifiersToAilmentDamage(spellDamageStat, default), NodeType.Total, PathDefinition.MainPath) == new NodeValue(10)); var sut = CreateSut(); var values = sut.WithSkills(DamageSource.Spell) .Build(default)
public void AddStatBuildsToCorrectResult(bool effectActive) { var expectedStat = "stat"; var expectedValue = effectActive ? (NodeValue?)2 : null; var statBuilder = StatBuilderUtils.FromIdentity(new StatFactory(), expectedStat, null); var valueBuilder = new ValueBuilderImpl(2); var activeStat = new Stat("test.Active"); var context = Mock.Of <IValueCalculationContext>(c => c.GetValue(activeStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)effectActive); var sut = CreateSut(); var addedStat = sut.AddStat(statBuilder); var(stats, _, valueConverter) = addedStat.BuildToSingleResult(); var actualStat = stats.Single().Identity; var actualValue = valueConverter(valueBuilder).Build().Calculate(context); Assert.AreEqual(expectedStat, actualStat); Assert.AreEqual(expectedValue, actualValue); }
public void AddStatBuildsToCorrectResultIfNotAsBuffActive() { var expectedStat = "stat"; var expectedValue = (NodeValue?)2; var statBuilder = StatBuilderUtils.FromIdentity(StatFactory, expectedStat, typeof(double)); var valueBuilder = new ValueBuilderImpl(2); var activeStat = new Stat("test.Active"); var buffActiveStat = new Stat("test.BuffActive"); var context = Mock.Of <IValueCalculationContext>(c => c.GetValue(activeStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)true && c.GetValue(buffActiveStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?)false); var sut = CreateSut(); var addStat = sut.AddStat(statBuilder); var(stats, _, valueConverter) = addStat.BuildToSingleResult(); var actualStat = stats.Single().Identity; var actualValue = valueConverter(valueBuilder).Build().Calculate(context); Assert.AreEqual(expectedStat, actualStat); Assert.AreEqual(expectedValue, actualValue); }
public IEnumerable <StatBuilderResult> Build(BuildParameters parameters) { var results = new List <StatBuilderResult>(); var entities = _entity.Build(parameters.ModifierSourceEntity); foreach (var entity in entities) { var resultsForEntity = _inner.WithEntity(new EntityBuilder(entity)) .Build(parameters) .Select(r => new StatBuilderResult(r.Stats, r.ModifierSource, r.ValueConverter.AndThen(ConvertValue))); results.AddRange(resultsForEntity); IValueBuilder ConvertValue(IValueBuilder left) { var right = new ValueBuilderImpl(_buildValue(parameters, entity)); return(_combineValues(left, right)); } } return(results); }