private static IEnumerable <Modifier> Build(
            IIntermediateModifier modifier, IntermediateModifierEntry entry, ModifierSource originalSource,
            Entity modifierSourceEntity)
        {
            if (entry.Form == null || entry.Stat == null || entry.Value == null)
            {
                yield break;
            }

            var(form, formValueConverter) = entry.Form.Build();
            var buildParameters = new BuildParameters(originalSource, modifierSourceEntity, form);

            var statBuilder = entry.Stat;

            if (entry.Condition != null)
            {
                statBuilder = statBuilder.WithCondition(entry.Condition);
            }
            statBuilder = modifier.StatConverter(statBuilder);
            var statBuilderResults = statBuilder.Build(buildParameters);

            foreach (var(stats, source, statValueConverter) in statBuilderResults)
            {
                var valueBuilder = formValueConverter(statValueConverter(modifier.ValueConverter(entry.Value)));
                var value        = valueBuilder.Build(buildParameters);
                yield return(new Modifier(stats, form, value, source));
            }
        }
        public static ParseResult Parse(this ICoreParser @this,
                                        string modifierLine, ModifierSource modifierSource, Entity modifierSourceEntity)
        {
            var parameter = new CoreParserParameter(modifierLine, modifierSource, modifierSourceEntity);

            return(@this.Parse(parameter));
        }
        private IValue BuildValue(NodeType nodeType, ModifierSource modifierSource, BuildParameters parameters)
        {
            IStat firstStat = null;

            foreach (var(stats, _, _) in Build(parameters))
            {
                foreach (var stat in stats)
                {
                    if (firstStat is null)
                    {
                        firstStat = stat;
                    }
                    else
                    {
                        throw CreateException($"This builder built to at least {firstStat} and {stat}.");
                    }
                }
            }
            if (firstStat is null)
            {
                throw CreateException("This builder built to zero stats.");
            }

            return(new StatValue(firstStat, nodeType, modifierSource));

            ParseException CreateException(string messageSuffix)
            => new ParseException("Can only access the value of stat builders that represent a single stat. "
                                  + messageSuffix);
        }
Example #4
0
 public StatBuilderResult(
     IReadOnlyList <IStat> stats, ModifierSource modifierSource, ValueConverter valueConverter)
 {
     Stats          = stats;
     ModifierSource = modifierSource;
     ValueConverter = valueConverter;
 }
Example #5
0
        private IValue BuildValue(NodeType nodeType, ModifierSource modifierSource, BuildParameters parameters)
        {
            IStat firstStat = null;

            foreach (var(stats, _, _) in Build(parameters))
            {
                foreach (var stat in stats)
                {
                    if (firstStat is null)
                    {
                        firstStat = stat;
                    }
                    else
                    {
                        throw CreateException();
                    }
                }
            }
            if (firstStat is null)
            {
                throw CreateException();
            }

            return(new StatValue(firstStat, nodeType, modifierSource));

            ParseException CreateException()
            => new ParseException("Can only access the value of stat builders that represent a single stat");
        }
Example #6
0
        private static Modifier Build(
            IIntermediateModifier modifier, IntermediateModifierEntry entry, ModifierSource originalSource)
        {
            if (entry.Form == null || entry.Stat == null || entry.Value == null)
            {
                return(null);
            }

            var statBuilder = modifier.StatConverter(entry.Stat);

            if (entry.Condition != null)
            {
                statBuilder = statBuilder.WithCondition(entry.Condition);
            }
            var(stats, sourceConverter, statValueConverter) = statBuilder.Build();

            var(form, formValueConverter) = entry.Form.Build();

            var value =
                formValueConverter(
                    statValueConverter(
                        modifier.ValueConverter(entry.Value))).Build();

            return(new Modifier(stats, form, value, sourceConverter(originalSource)));
        }
 public IntermediateModifierBuilder(
     IIntermediateModifier modifier, ModifierSource originalSource, Entity modifierSourceEntity)
 {
     _modifier             = modifier;
     _originalSource       = originalSource;
     _modifierSourceEntity = modifierSourceEntity;
 }
Example #8
0
        public void ModifierSourceSkillBuildsToCorrectSkill(ModifierSource modifierSource)
        {
            var sut = CreateSut();

            var builder = sut.ModifierSourceSkill;
            var actual  = Build(builder, modifierSource);

            Assert.AreEqual(SkillDefinition, actual);
        }
Example #9
0
 public void Init(ModifierType type, ModifierSource source, float value, float duration, float remaining)
 {
     Type          = type;
     Source        = source;
     Value         = value;
     Duration      = duration;
     Expired       = false;
     TimeRemaining = remaining;
 }
        /// <summary>
        /// Create a new <see cref="ModifierSourceUpdateEventArgs"/>.
        /// </summary>
        /// <param name="modifierSource">
        /// The <see cref="ModifierSource"/> being updated.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="modifierSource"/> cannot be null.
        /// </exception>
        public ModifierSourceUpdateEventArgs(ModifierSource modifierSource)
        {
            if (modifierSource == null)
            {
                throw new ArgumentNullException("modifierSource");
            }

            this.modifierSource = modifierSource;
        }
        protected DamageModifier(string name, string tooltip, DamageSource damageSource, double gainPerStack, DamageType srctype, DamageType compareType, ModifierSource src, string icon, GainComputer gainComputer, DamageLogChecker dlChecker, ulong minBuild, ulong maxBuild)
        {
            Tooltip      = tooltip;
            Name         = name;
            _dmgSrc      = damageSource;
            GainPerStack = gainPerStack;
            _compareType = compareType;
            _srcType     = srctype;
            Src          = src;
            Icon         = icon;
            GainComputer = gainComputer;
            DLChecker    = dlChecker;
            MaxBuild     = maxBuild;
            MinBuild     = minBuild;
            switch (_dmgSrc)
            {
            case DamageSource.All:
                Tooltip += "<br>Actor + Minions";
                break;

            case DamageSource.NoPets:
                Tooltip += "<br>No Minions";
                break;
            }
            switch (_srcType)
            {
            case DamageType.All:
                Tooltip += "<br>All Damage type";
                break;

            case DamageType.Power:
                Tooltip += "<br>Power Damage only";
                break;

            case DamageType.Condition:
                Tooltip += "<br>Condition Damage only";
                break;
            }
            switch (_compareType)
            {
            case DamageType.All:
                Tooltip += "<br>Compared against All Damage";
                break;

            case DamageType.Power:
                Tooltip += "<br>Compared against Power Damage";
                break;

            case DamageType.Condition:
                Tooltip += "<br>Compared against Condition Damage";
                break;
            }
            if (!Multiplier)
            {
                Tooltip += "<br>Non multiplier";
            }
        }
 private static ItemSlot GetItemSlot(ModifierSource modifierSource)
 {
     if (modifierSource is ModifierSource.Local.Item itemSource)
     {
         return(itemSource.Slot);
     }
     throw new ParseException(
               "IStatBuilder.AsItemProperty can only be used with a source of type ModifierSource.Local.Item");
 }
 /// <summary>
 /// Builds <paramref name="modifier"/> by creating a <see cref="Modifier"/> from each of its entries.
 /// The <see cref="IIntermediateModifier.StatConverter"/> is applied to each stat and
 /// <see cref="IIntermediateModifier.ValueConverter"/> to each value. Entries with null form, stat or value
 /// are ignored.
 /// </summary>
 public static IReadOnlyList <Modifier> Build(this IIntermediateModifier modifier,
                                              ModifierSource originalSource, Entity modifierSourceEntity)
 {
     return((
                from entry in modifier.Entries
                from m in Build(modifier, entry, originalSource, modifierSourceEntity)
                select m
                ).ToList());
 }
            private static Modifier CreateModifier(IReadOnlyList <IStat> stats, Form form, IValue value,
                                                   ModifierSource source)
            {
                if (form == Form.TotalOverride && source is ModifierSource.Local localSource)
                {
                    source = new ModifierSource.Global(localSource);
                }

                return(new Modifier(stats, form, value, source));
            }
Example #15
0
        private IValue BuildValue(NodeType nodeType, ModifierSource modifierSource, BuildParameters parameters)
        {
            var stats = Build(parameters).Select(r => r.Stats).Flatten().ToList();

            if (stats.Count != 1)
            {
                throw new ParseException("Can only access the value of stat builders that represent a single stat");
            }

            return(new StatValue(stats.Single(), nodeType, modifierSource));
        }
Example #16
0
        private StatBuilderResult Build(
            ModifierSource originalModifierSource, StatBuilderResult source, StatBuilderResult target)
        {
            VerifyStats(source.Stats, target.Stats);
            VerifyModifierSource(originalModifierSource, source.ModifierSource, target.ModifierSource);

            var stats          = BuildStats(source.Stats, target.Stats);
            var valueConverter = BuildValueConverter(source.ValueConverter, target.ValueConverter);

            return(new StatBuilderResult(stats.ToList(), originalModifierSource, valueConverter));
        }
Example #17
0
 private static void VerifyModifierSource(
     ModifierSource originalSource, ModifierSource sourceSource, ModifierSource targetSource)
 {
     if (originalSource != sourceSource)
     {
         throw new ParseException("The source stat of conversions must not be ModifierSource specific");
     }
     if (originalSource != targetSource)
     {
         throw new ParseException("The target stat of conversions must not be ModifierSource specific");
     }
 }
 private static ushort GetPassiveNodeId(ModifierSource modifierSource)
 {
     if (modifierSource is ModifierSource.Global globalSource)
     {
         modifierSource = globalSource.LocalSource;
     }
     if (modifierSource is ModifierSource.Local.PassiveNode nodeSource)
     {
         return(nodeSource.NodeId);
     }
     throw new ParseException(
               "IStatBuilder.AsPassiveNodeProperty can only be used with a source of type ModifierSource.Local.PassiveNode");
 }
Example #19
0
        protected DamageModifier(string name, string tooltip, DamageSource damageSource, double gainPerStack, DamageType srctype, DamageType compareType, ModifierSource src, string url, GainComputer gainComputer, DamageLogChecker dlChecker = null)
        {
            Tooltip      = tooltip;
            Name         = name;
            _dmgSrc      = damageSource;
            GainPerStack = gainPerStack;
            _compareType = compareType;
            _srcType     = srctype;
            Src          = src;
            Url          = url;
            GainComputer = gainComputer;
            DLChecker    = dlChecker;
            switch (_dmgSrc)
            {
            case DamageSource.All:
                Tooltip += "<br>Actor + Minions";
                break;

            case DamageSource.NoPets:
                Tooltip += "<br>No Minions";
                break;
            }
            switch (_srcType)
            {
            case DamageType.All:
                Tooltip += "<br>All Damage type";
                break;

            case DamageType.Power:
                Tooltip += "<br>Power Damage only";
                break;

            case DamageType.Condition:
                Tooltip += "<br>Condition Damage only";
                break;
            }
            switch (_compareType)
            {
            case DamageType.All:
                Tooltip += "<br>Compared against All Damage";
                break;

            case DamageType.Power:
                Tooltip += "<br>Compared against Power Damage";
                break;

            case DamageType.Condition:
                Tooltip += "<br>Compared against Condition Damage";
                break;
            }
        }
        private ParseResult ParseTransformationModifier(string modifier, ModifierSource modifierSource,
                                                        IEnumerable <PassiveNodeDefinition> nodesInRadius)
        {
            var transformedNodeModifiers = _transformationParser.ApplyTransformation(modifier, nodesInRadius).ToList();
            var results = new List <ParseResult>(transformedNodeModifiers.Count);

            foreach (var transformedModifier in transformedNodeModifiers)
            {
                var parseResult = _coreParser.Parse(transformedModifier.Modifier, modifierSource, ModifierSourceEntity)
                                  .ApplyMultiplier(transformedModifier.ValueMultiplier.Build, ModifierSourceEntity);
                results.Add(parseResult);
            }
            return(ParseResult.Aggregate(results));
        }
        /// <summary>
        /// Create a <see cref="UnmetPrerequisiteException"/>.
        /// </summary>
        /// <param name="requirement">
        /// The requirement that was not satisfied, e.g. "level 11+", "Charisma 15+", "Two-Weapon Fighting feat", "Fighter class", etc.
        /// This should identify the requirement, e.g. "Prime Shot", and what it is, e.g. "class feature".
        /// </param>
        /// <param name="modifierSource">
        /// The <see cref="ModifierSource"/> whose prerequisites were not met.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public UnmetPrerequisiteException(string requirement, ModifierSource modifierSource)
            : base(string.Empty)
        {
            if (string.IsNullOrEmpty(requirement))
            {
                throw new ArgumentNullException("requirement");
            }
            if (modifierSource == null)
            {
                throw new ArgumentNullException("source");
            }

            this.modifierSource = modifierSource;
            this.requirement = requirement;
        }
        /// <summary>
        /// Create a new <see cref="PowerEntry"/>. All arguments to this method are assumed 
        /// to be escaped for HTML already.
        /// </summary>
        /// <param name="heading">
        /// The heading <see cref="Block"/>. This cannot be null.
        /// </param>
        /// <param name="flavorText">
        /// The flavor text <see cref="Block"/>. This may be null.
        /// </param>
        /// <param name="detail">
        /// The detail <see cref="Block"/>.  This cannot be null.
        /// </param>
        /// <param name="modifierSource">
        /// The <see cref="ModifierSource"/> that this <see cref="PowerEntry"/> was created for.
        /// This may be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Only <paramref name="modifierSource"/> can be null.
        /// </exception>
        public PowerEntry(Block heading, Block flavorText, Block detail, ModifierSource modifierSource)
        {
            if (heading == null)
            {
                throw new ArgumentNullException("heading");
            }
            if (detail == null)
            {
                throw new ArgumentNullException("detail");
            }

            Heading = heading;
            FlavorText = flavorText;
            Detail = detail;
            ModifierSource = modifierSource;
        }
Example #23
0
        private void Add(
            IStatBuilder stat, Form form, IValueBuilder value, IConditionBuilder?condition,
            ModifierSource modifierSource)
        {
            var builder = _modifierBuilder
                          .WithStat(stat)
                          .WithForm(_builderFactories.FormBuilders.From(form))
                          .WithValue(value);

            if (condition != null)
            {
                builder = builder.WithCondition(condition);
            }
            var intermediateModifier = builder.Build();

            _modifiers.AddRange(intermediateModifier.Build(modifierSource, _modifierSourceEntity));
        }
 /// <summary>
 /// Builds <paramref name="modifier"/> by creating a <see cref="Modifier"/> from each of its entries.
 /// The <see cref="IIntermediateModifier.StatConverter"/> is applied to each stat and
 /// <see cref="IIntermediateModifier.ValueConverter"/> to each value. Entries with null form, stat or value
 /// are ignored.
 /// </summary>
 public static IReadOnlyList <Modifier> Build(
     this IIntermediateModifier modifier, ModifierSource originalSource, Entity modifierSourceEntity)
 => new IntermediateModifierBuilder(modifier, originalSource, modifierSourceEntity).Build();
 public ValueBuilder ValueFor(NodeType nodeType, ModifierSource modifierSource = null)
 => new ValueBuilder(new ValueBuilderImpl(
                         ps => BuildValue(nodeType, modifierSource ?? new ModifierSource.Global(), ps),
                         c => Resolve(c).ValueFor(nodeType, modifierSource)));
 /// <summary>
 /// Create a <see cref="UnmetPrerequisiteException"/>.
 /// </summary>
 /// <param name="info">
 /// <see cref="SerializationInfo"/> to load details about the exception from.
 /// </param>
 /// <param name="context">
 /// Metadata about the serialization.
 /// </param>
 protected UnmetPrerequisiteException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     requirement = info.GetString(requirementKey);
     modifierSource = (ModifierSource) info.GetValue(modifierSourceKey, typeof(ModifierSource));
 }
Example #27
0
 public static Modifier CreateModifier(string stat, Form form, double value, ModifierSource source = null)
 => CreateModifier(stat, form, new NodeValue(value), source);
Example #28
0
 public static Modifier CreateModifier(string stat, Form form, IValue value, ModifierSource source = null)
 => new Modifier(new[] { new Stat(stat), }, form, value, source ?? new ModifierSource.Global());
 public static StatBuilderResult BuildToSingleResult(this IStatBuilder @this,
                                                     ModifierSource modifierSource = null, Entity entity = default) =>
 @this.Build(new BuildParameters(modifierSource, entity, default)).Single();
Example #30
0
 public ParseResult ParseRawModifier(
     string modifierLine, ModifierSource modifierSource, Entity modifierSourceEntity)
 => _coreParser.Parse(modifierLine, modifierSource, modifierSourceEntity);
 public ModifierNodeViewModel(Form form, ModifierSource modifierSource, ResultNodeViewModel node)
 {
     Form           = form;
     ModifierSource = modifierSource;
     Node           = node;
 }
 public static IReadOnlyList <IStat> BuildToStats(this IStatBuilder @this,
                                                  ModifierSource modifierSource = null, Entity entity = default) =>
 @this.Build(new BuildParameters(modifierSource, entity, default)).SelectMany(r => r.Stats).ToList();
Example #33
0
 public static Modifier CreateModifier(string stat, Form form, NodeValue?value, ModifierSource source = null)
 => CreateModifier(stat, form, new Constant(value), source);
        /// <summary>
        /// Add a <see cref="ModifierSource"/> to the list of scores for this AttackDetails.
        /// </summary>
        /// <param name="modifierSource">
        /// The <see cref="ModifierSource"/> to add.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// score cannot be null.
        /// </exception>
        protected void AddModifierSource(ModifierSource modifierSource)
        {
            if (modifierSource == null)
            {
                throw new ArgumentNullException("modifierSource");
            }

            modifierSources.Add(modifierSource);
        }
Example #35
0
 public ModifierNodeViewModel(Form form, ModifierSource modifierSource, CalculationNodeViewModel node)
 {
     Form           = form;
     ModifierSource = modifierSource;
     Node           = node;
 }
        /// <summary>
        /// Get the default priority for the given <see cref="ModifierSource"/>.
        /// </summary>
        /// <param name="modifierSource">
        /// The <see cref="ModifierSource"/> to get the priority for. This can be null.
        /// </param>
        /// <returns>
        /// A <see cref="PowerEntryPriority"/> for the given <see cref="ModifierSource"/>.
        /// </returns>
        private static int GetPriority(ModifierSource modifierSource)
        {
            Power power;
            int result;

            result = 0;

            power = modifierSource as Power;
            if (power != null)
            {
                if (power.Frequency == PowerFrequency.AtWill)
                {
                    result = 100;
                }
                else if (power.Frequency == PowerFrequency.Encounter)
                {
                    result = 200;
                }
                else if (power.Frequency == PowerFrequency.Consumable)
                {
                    result = 400;
                }
                else
                {
                    result = 500;
                }
            }
            else
            {
                result = 500;
            }

            return result;
        }