Пример #1
0
        public FilterResult Evaluate(ItemCraft item, ItemProperties props, IDictionary <string, double> stats)
        {
            if (Weights == null)
            {
                return new FilterResult()
                       {
                           Match = true
                       }
            }
            ;
            IDictionary <string, double> info = new Dictionary <string, double>();
            double tally = 0;

            foreach (string template in Weights.Keys)
            {
                double?v = ItemParser.GetValueByName(template, item, props, stats);

                if (v != null)
                {
                    if (template.IndexOf("[pseudo]") == 0 && !info.ContainsKey(template))
                    {
                        info.Add(template, v.Value);
                    }
                    tally += v.Value * Weights[template];
                }
            }
            info.Add("Weight", tally);
            bool match = (Min == null || tally >= Min) && (Max == null || tally <= Max);

            return(new FilterResult()
            {
                Match = match, Info = info
            });
        }
Пример #2
0
        public int Compare(ItemCraft x, ItemCraft y)
        {
            ItemProperties props;
            IDictionary <string, double> stats;

            if (Cache.ContainsKey(x))
            {
                props = Cache[x].Properties;
                stats = Cache[x].Stats;
            }
            else
            {
                props = ItemParser.ParseProperties(x);
                stats = ItemParser.ParseItem(x);
                Cache.Add(x, new ItemParams()
                {
                    Properties = props, Stats = stats
                });
            }
            double?vx = ItemParser.GetValueByName(Key, x, props, stats);

            if (Cache.ContainsKey(y))
            {
                props = Cache[y].Properties;
                stats = Cache[y].Stats;
            }
            else
            {
                props = ItemParser.ParseProperties(y);
                stats = ItemParser.ParseItem(y);
                Cache.Add(y, new ItemParams()
                {
                    Properties = props, Stats = stats
                });
            }
            double?vy = ItemParser.GetValueByName(Key, y, props, stats);

            if (vx != null)
            {
                if (vy != null)
                {
                    return(vx.Value.CompareTo(vy.Value));
                }
                else
                {
                    return(1);
                }
            }
            else
            {
                if (vy != null)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
        }
Пример #3
0
        public FilterResult Evaluate(ItemCraft item, ItemProperties props, IDictionary <string, double> stats)
        {
            if (Template == null)
            {
                return new FilterResult()
                       {
                           Match = true
                       }
            }
            ;
            double?v = ItemParser.GetValueByName(Template, item, props, stats);

            if (v == null)
            {
                return new FilterResult()
                       {
                           Match = false
                       }
            }
            ;
            IDictionary <string, double> info = null;

            if (Template.IndexOf("[pseudo]") == 0)
            {
                info = new Dictionary <string, double>()
                {
                    { Template, v.Value }
                }
            }
            ;
            if (Min != null && v < Min)
            {
                return new FilterResult()
                       {
                           Match = false, Info = info
                       }
            }
            ;
            if (Max != null && v > Max)
            {
                return new FilterResult()
                       {
                           Match = false, Info = info
                       }
            }
            ;
            return(new FilterResult()
            {
                Match = true, Info = info
            });
        }
Пример #4
0
 public static FilterResult Evaluate(ItemCraft item, FilterCondition condition)
 {
     //call ParseProperties and ParseItem here and pass the results so they don't have to be repeatedly called during evaluation
     return(condition.Evaluate(item, ItemParser.ParseProperties(item), ItemParser.ParseItem(item)));
 }