private async Task <IReadOnlyList <ModifierNodeViewModel> > CreateFormNodesAsync(
            IStat stat, Form form, PathDefinition path)
        {
            var nodes     = new List <ModifierNodeViewModel>();
            var formNodes = await _calculator.GetFormNodeCollectionAsync(stat, form, path);

            foreach (var(node, modifier) in formNodes)
            {
                var resultNode = new CalculationNodeViewModel(stat)
                {
                    Value = await _calculator.GetNodeValueAsync(node)
                };
                if (resultNode.Value is null && stat.DataType != typeof(bool))
                {
                    continue;
                }
                nodes.Add(new ModifierNodeViewModel(form, modifier.Source, resultNode));
            }

            if (form == Form.BaseAdd || form == Form.Increase)
            {
                return(nodes
                       .GroupBy(n => (n.Form, n.IsLocal, n.ModifierSource.ToString(), n.ModifierSource.SourceName))
                       .Select(g => g.Aggregate(Accumulate))
                       .ToList());
            }
            return(nodes);

            ModifierNodeViewModel Accumulate(ModifierNodeViewModel l, ModifierNodeViewModel r)
            {
                l.Node.Value = l.Node.Value.SumWhereNotNull(r.Node.Value);
                return(l);
            }
        }
예제 #2
0
 public ModifierNodeViewModel(Form form, ModifierSource modifierSource, CalculationNodeViewModel node)
 {
     Form           = form;
     ModifierSource = modifierSource;
     Node           = node;
 }