public void ExplicitlyRegistered() { var sut = Calculator.CreateCalculator(); var stat = new Stat("stat", explicitRegistrationType: ExplicitRegistrationTypes.UserSpecifiedValue()); IStat actual = null; sut.ExplicitlyRegisteredStats.CollectionChanged += (sender, args) => { Assert.IsNull(actual); Assert.AreEqual(CollectionChangeAction.Add, args.Action); actual = (((ICalculationNode, IStat))args.Element).Item2; }; sut.NewBatchUpdate().AddModifier(stat, Form.BaseAdd, new Constant(0)).DoUpdate(); Assert.AreEqual(stat, actual); }
public void ExplicitlyRegistered() { var sut = Calculator.Create(); var modifierStat = new Stat("m"); var registeredStat = new Stat("r", explicitRegistrationType: ExplicitRegistrationTypes.UserSpecifiedValue(0)); var value = new StatValue(registeredStat); IStat actual = null; sut.ExplicitlyRegisteredStats.CollectionChanged += (sender, args) => { Assert.IsNull(actual); Assert.AreEqual(1, args.AddedItems.Count); Assert.IsEmpty(args.RemovedItems); actual = args.AddedItems.First().Item2; }; sut.NewBatchUpdate().AddModifier(modifierStat, Form.BaseAdd, value).DoUpdate(); Assert.IsNull(actual); var _ = sut.NodeRepository.GetNode(modifierStat).Value; Assert.AreEqual(registeredStat, actual); }
private IValue BuildTemporaryBuffCondition <T>(T condition, BuildParameters parameters) where T : struct, Enum { var stat = _statFactory.FromIdentity(typeof(T).Name, parameters.ModifierSourceEntity, typeof(T), ExplicitRegistrationTypes.UserSpecifiedValue(0)); return(new ConditionalValue(c => (int?)c.GetValue(stat).SingleOrNull() == Enums.ToInt32(condition), $"{stat} == {condition}")); }
public IStatBuilder Temporary(IStatBuilder gainedStat) { var statBuilder = gainedStat.WithCondition(new ValueConditionBuilder(BuildCondition)); return(MultiplyValueByEffectModifier(statBuilder, "Buff", new ModifierSourceEntityBuilder())); IValue BuildCondition(BuildParameters parameters) { var stat = _statFactory.FromIdentity($"Is {parameters.ModifierSource.SourceName} active?", parameters.ModifierSourceEntity, typeof(bool), ExplicitRegistrationTypes.UserSpecifiedValue(false)); return(new StatValue(stat)); } }
public IStatBuilder Unique(string name, Type type) => FromIdentity(name, type, ExplicitRegistrationTypes.UserSpecifiedValue());
protected IStatBuilder InternalOn(IEntityBuilder target) => FromIdentity("Active", typeof(bool), OnIsUserSpecified ? ExplicitRegistrationTypes.UserSpecifiedValue(false) : null) .For(target);
public AilmentBuilders(IStatFactory statFactory) { _allAilments = new AilmentBuilderCollection(statFactory, Enums.GetValues <Ailment>().ToList()); Elemental = new AilmentBuilderCollection(statFactory, new[] { Ailment.Ignite, Ailment.Shock, Ailment.Chill, Ailment.Freeze }); ShockEffect = StatBuilderUtils.FromIdentity(statFactory, "Shock.Effect", typeof(double)); IncreasedDamageTakenFromShocks = StatBuilderUtils.FromIdentity(statFactory, "Shock.IncreasedDamageTaken", typeof(uint), ExplicitRegistrationTypes.UserSpecifiedValue(15)); ChillEffect = StatBuilderUtils.FromIdentity(statFactory, "Chill.Effect", typeof(double)); ReducedActionSpeedFromChill = StatBuilderUtils.FromIdentity(statFactory, "Chill.ReducedActionSpeed", typeof(uint), ExplicitRegistrationTypes.UserSpecifiedValue(10)); }
private IValue CreateValue(BuildParameters ps, string identity) => StatBuilderUtils.FromIdentity(_statFactory, identity, typeof(bool), ExplicitRegistrationTypes.UserSpecifiedValue(false)) .Value.Build(ps);