private IValue BuildAddStatMultiplier(
            string identity, IReadOnlyCollection <Entity> possibleSources, Entity target)
        {
            var buffActiveValue  = new StatValue(BuildBuffActiveStat(target, identity));
            var buffSourceValues = possibleSources.ToDictionary(Funcs.Identity,
                                                                e => new StatValue(BuildBuffSourceStat(e, target, identity)));
            var buffEffectValues = possibleSources.ToDictionary(Funcs.Identity,
                                                                e => new StatValue(BuildEffectStat(e, target, identity)));

            return(new FunctionalValue(Calculate,
                                       $"AddStatMultiplier(buffActive:{buffActiveValue}, buffSources:{string.Join(",", buffSourceValues)}, " +
                                       $"buffEffects:{string.Join(",", buffEffectValues)})"));

            NodeValue?Calculate(IValueCalculationContext context)
            {
                if (!buffActiveValue.Calculate(context).IsTrue())
                {
                    return(new NodeValue(1));
                }

                // If multiple entities apply the same (de-)buff, it depends on the buff which one would actually apply.
                // Because that shouldn't happen in these calculations, simply the first one is taken.
                var sourceEntity = possibleSources.First(e => buffSourceValues[e].Calculate(context).IsTrue());

                return(buffEffectValues[sourceEntity].Calculate(context));
            }
        }
        private IValue BuildTargetPoolValue(BuildParameters parameters, IStat targetPoolStat)
        {
            var entity          = parameters.ModifierSourceEntity;
            var targetPoolValue = new StatValue(targetPoolStat);

            return(new FunctionalValue(
                       c => c.GetValue(TargetPoolValueStat(targetPoolValue.Calculate(c))),
                       $"Value of Pool {targetPoolValue}"));

            IStat TargetPoolValueStat(NodeValue?targetPool)
            {
                var targetPoolString = ((Pool)targetPool.Single()).ToString();

                return(StatFactory.FromIdentity(targetPoolString, entity, typeof(uint)));
            }
        }