Exemplo n.º 1
0
        public ItemMod Sum(ItemMod m)
        {
            var mod = new ItemMod()
            {
                Attribute  = this.Attribute,
                itemclass  = this.itemclass,
                isLocal    = this.isLocal,
                Parent     = this.Parent,
                ValueColor = this.ValueColor.ToList()
            };

            mod.Value = this.Value.Zip(m.Value, (f1, f2) => f1 + f2).ToList();

            return(mod);
        }
Exemplo n.º 2
0
        public static ItemMod CreateMod(Item item, string attribute, Regex numberfilter)
        {
            ItemClass ic     = item.Class;
            var       mod    = new ItemMod();
            var       values = new List <float>();

            foreach (Match match in numberfilter.Matches(attribute))
            {
                values.Add(float.Parse(match.Value, CultureInfo.InvariantCulture));
            }
            string at = numberfilter.Replace(attribute, "#");

            mod = new ItemMod
            {
                itemclass  = ic,
                Value      = values,
                _Attribute = at,
                isLocal    = DetermineLocal(item, at)
            };

            return(mod);
        }
Exemplo n.º 3
0
                // Creates added damage from weapon local mod.
                public static Added Create(DamageSource source, ItemMod itemMod)
                {
                    Match m = ReAddMod.Match(itemMod.Attribute);
                    if (m.Success)
                        return new Added(source, m.Groups[1].Value, itemMod.Value[0], itemMod.Value[1]);
                    else
                    {
                        m = ReAddInHandMod.Match(itemMod.Attribute);
                        if (m.Success)
                            return new Added(source, m.Groups[1].Value, itemMod.Value[0], itemMod.Value[1]) { Hand = m.Groups[2].Value == "Main" ? WeaponHand.Main : WeaponHand.Off };
                    }

                    return null;
                }
Exemplo n.º 4
0
        private void Init(ItemClass iClass, JObject val)
        {
            JSONBase = val;

            Attributes = new Dictionary <string, List <float> >();
            Mods       = new List <ItemMod>();
            Class      = iClass;

            Width  = val["w"].Value <int>();
            Height = val["h"].Value <int>();
            if (val["x"] != null)
            {
                X = val["x"].Value <int>();
            }
            if (val["y"] != null)
            {
                Y = val["y"].Value <int>();
            }

            if (val["name"] != null)
            {
                NameLine = val["name"].Value <string>();
            }

            TypeLine = BaseType = val["typeLine"].Value <string>();

            Frame = (FrameType)val["frameType"].Value <int>();

            if (val["properties"] != null)
            {
                foreach (JObject obj in (JArray)val["properties"])
                {
                    var    values = new List <float>();
                    string s      = "";

                    foreach (JArray jva in (JArray)obj["values"])
                    {
                        s += " " + jva[0].Value <string>();
                    }
                    s = s.TrimStart();

                    if (s == "")
                    {
                        Properties.Add(ItemMod.CreateMod(this, obj["name"].Value <string>(), numberfilter));

                        Keywords = new List <string>();
                        string[] sl = obj["name"].Value <string>().Split(',');
                        foreach (string i in sl)
                        {
                            Keywords.Add(i.Trim());
                        }
                        continue;
                    }

                    foreach (Match m in numberfilter.Matches(s))
                    {
                        if (m.Value == "")
                        {
                            values.Add(float.NaN);
                        }
                        else
                        {
                            values.Add(float.Parse(m.Value, CultureInfo.InvariantCulture));
                        }
                    }
                    string cs = obj["name"].Value <string>() + ": " + (numberfilter.Replace(s, "#"));

                    var mod = ItemMod.CreateMod(this, obj, numberfilter2);
                    Properties.Add(mod);


                    mod.ValueColor = ((JArray)obj["values"]).Select(a =>
                    {
                        var floats = ((JArray)a)[0].Value <string>().Split('-');
                        return(floats.Select(f => (ItemMod.ValueColoring)((JArray)a)[1].Value <int>()));
                    }).SelectMany(c => c).ToList();

                    Attributes.Add(cs, values);
                }
            }

            if (val["requirements"] != null)
            {
                string       reqs    = "";
                List <float> numbers = new List <float>();
                List <ItemMod.ValueColoring> affects = new List <ItemMod.ValueColoring>();

                foreach (JObject obj in (JArray)val["requirements"])
                {
                    var n = obj["name"].Value <string>();

                    if (obj["displayMode"].Value <int>() == 0)
                    {
                        n = n + " #";
                    }
                    else
                    {
                        n = "# " + n;
                    }

                    numbers.Add(((JArray)((JArray)obj["values"])[0])[0].Value <float>());
                    affects.Add((ItemMod.ValueColoring)((JArray)((JArray)obj["values"])[0])[1].Value <int>());

                    if (!string.IsNullOrEmpty(reqs))
                    {
                        reqs += ", " + n;
                    }
                    else
                    {
                        reqs += n;
                    }
                }

                var m = ItemMod.CreateMod(this, "Requires " + reqs, numberfilter);
                m.Value      = numbers;
                m.ValueColor = affects;
                Requirements.Add(m);
            }


            if (val["implicitMods"] != null)
            {
                foreach (string s in val["implicitMods"].Values <string>())
                {
                    List <ItemMod> mods = ItemMod.CreateMods(this, s.Replace("Additional ", ""), numberfilter);
                    Mods.AddRange(mods);

                    ImplicitMods.Add(ItemMod.CreateMod(this, s, numberfilter));
                }
            }
            if (val["explicitMods"] != null)
            {
                foreach (string s in val["explicitMods"].Values <string>())
                {
                    List <ItemMod> mods = ItemMod.CreateMods(this, s.Replace("Additional ", ""), numberfilter);
                    Mods.AddRange(mods);

                    ExplicitMods.Add(ItemMod.CreateMod(this, s, numberfilter));
                }
            }

            if (val["craftedMods"] != null)
            {
                foreach (string s in val["craftedMods"].Values <string>())
                {
                    List <ItemMod> mods = ItemMod.CreateMods(this, s.Replace("Additional ", ""), numberfilter);
                    Mods.AddRange(mods);

                    CraftedMods.Add(ItemMod.CreateMod(this, s, numberfilter));
                }
            }

            if (val["flavourText"] != null)
            {
                FlavourText = string.Join("\r\n", val["flavourText"].Values <string>());
            }


            if (iClass == ItemClass.Gem)
            {
                switch (val["colour"].Value <string>())
                {
                case "S":
                    Keywords.Add("Strength");
                    break;

                case "D":
                    Keywords.Add("Dexterity");
                    break;

                case "I":
                    Keywords.Add("Intelligence");
                    break;
                }
            }
            else
            {
                Gems = new List <Item>();
            }

            var Sockets = new List <int>();

            if (val["sockets"] != null)
            {
                foreach (JObject obj in (JArray)val["sockets"])
                {
                    Sockets.Add(obj["group"].Value <int>());
                }
            }
            if (val["socketedItems"] != null)
            {
                int socket = 0;
                foreach (JObject obj in (JArray)val["socketedItems"])
                {
                    var item = new Item(ItemClass.Gem, obj);
                    item.SocketGroup = Sockets[socket++];
                    Gems.Add(item);
                }
            }
        }
Exemplo n.º 5
0
        public ItemMod ToItemMod(params float[] values)
        {
            if (values.Length != 0 && values.All(v => v == values[0]))
            {
                values = new float[] { values[0] };
            }
            else if (values.Length == 0)
            {
                if (Range.From == Range.To)
                {
                    values = new float[] { Range.To }
                }
                ;
                else
                {
                    values = new float[] { Range.From, Range.To }
                };
            }

            if (values.Length == 0 || values.Length > 2)
            {
                throw new NotImplementedException();
            }

            bool singleVal = values.Length == 1;

            string modval = singleVal ? "#" : "#-#";

            var im = new ItemMod()
            {
                Parent = this
            };

            string name = this.NameAlias;


            int insetpos = name.IndexOf('%');

            if (insetpos < 0)
            {
                insetpos = name.IndexOf("  ");
                if (insetpos >= 0)
                {
                    insetpos++;
                }
                else
                {
                    insetpos = name.IndexOf(" - ");
                    if (insetpos >= 0)
                    {
                        name = name.Replace(" - ", "  ");
                        insetpos++;
                    }
                }
            }

            if (insetpos >= 0)
            {
                im.Attribute = name.Insert(insetpos, modval);
            }
            else if (name[0] == ' ' || Char.IsLower(name[0]))
            {
                im.Attribute = modval + name;
            }
            else if (Char.IsUpper(Name[0])) //value at end
            {
                im.Attribute = name + ": " + modval;
            }
            else
            {
                throw new NotImplementedException();
            }

            im.Value      = values.ToList();
            im.ValueColor = values.Select(_ => ItemMod.ValueColoring.White).ToList();

            return(im);
        }
    }
Exemplo n.º 6
0
        public static ItemMod CreateMod(Item item, JObject obj, Regex numberfilter)
        {
            ItemClass ic  = item.Class;
            var       mod = new ItemMod();

            int    dmode = (obj["displayMode"] != null) ? obj["displayMode"].Value <int>() : 0;
            string at    = obj["name"].Value <string>();

            at = numberfilter.Replace(at, "#");

            var parsed = ((JArray)obj["values"]).Select(a =>
            {
                var str    = ((JArray)a)[0].Value <string>();
                var floats = new List <float>();
                var parts  = str.Split('-');

                if (dmode != 3)
                {
                    if (parts.Length > 1)
                    {
                        at += ": ";
                    }
                    else
                    {
                        at += " ";
                    }
                }

                for (int i = 0; i < parts.Length; i++)
                {
                    string v  = parts[i];
                    float val = 0;
                    if (float.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out val))
                    {
                        floats.Add(val);
                        if (dmode != 3)
                        {
                            at += "#";
                        }
                    }
                    else
                    {
                        foreach (Match m in numberfilter.Matches(v))
                        {
                            floats.Add(float.Parse(m.Value, CultureInfo.InvariantCulture));
                        }

                        at += " " + numberfilter.Replace(v, "#");
                    }

                    if (i < parts.Length - 1)
                    {
                        if (dmode != 3)
                        {
                            at += "-";
                        }
                    }
                }

                var cols = floats.Select(f => (ItemMod.ValueColoring)((JArray)a)[1].Value <int>()).ToList();
                return(new { floats, cols });
            }).ToList();


            mod = new ItemMod
            {
                itemclass  = ic,
                Value      = parsed.Select(p => p.floats).SelectMany(v => v).ToList(),
                ValueColor = parsed.Select(p => p.cols).SelectMany(v => v).ToList(),
                _Attribute = at,
                isLocal    = DetermineLocal(item, at)
            };

            return(mod);
        }
Exemplo n.º 7
0
 public bool DetermineLocalFor(Item itm)
 {
     return(ItemMod.DetermineLocal(itm, this._Attribute));
 }
Exemplo n.º 8
0
        private void RecalculateItem()
        {
            if (SkipRedraw)
                return;


            Item.NameLine = "";
            Item.TypeLine = Item.BaseType;

            if (_selectedPreff.Length + _selectedSuff.Length == 0)
            {
                Item.Frame = FrameType.White;
            }
            else if (_selectedPreff.Length <= 1 && _selectedSuff.Length <= 1)
            {
                Item.Frame = FrameType.Magic;
                string typeline = "";

                if (_selectedPreff.Length > 0)
                    typeline = _selectedPreff[0].SelectedAffix.Query(_selectedPreff[0].SelectedValues.Select(v => (_selectedPreff[0].SelectedAffix.Name.Contains(" per second")) ? (float)v * 60f : (float)v).ToArray()).First().Name + " ";

                typeline += Item.BaseType;

                if (_selectedSuff.Length > 0)
                    typeline += " " + _selectedSuff[0].SelectedAffix.Query(_selectedSuff[0].SelectedValues.Select(v => (_selectedSuff[0].SelectedAffix.Name.Contains(" per second")) ? (float)v * 60f : (float)v).ToArray()).First().Name;

                Item.TypeLine = typeline.Replace(" (Master Crafted)", "");
            }
            else
            {
                Item.Frame = FrameType.Rare;
                Item.NameLine = "Crafted " + Item.BaseType;
            }


            var prefixes = _selectedPreff.Select(p => p.GetExactMods()).SelectMany(m => m).ToList();
            var suffixes = _selectedSuff.Select(p => p.GetExactMods()).SelectMany(m => m).ToList();
            var allmods = prefixes.Concat(suffixes)
                .GroupBy(m => m.Attribute)
                .Select(g => g.Aggregate((m1, m2) => m1.Sum(m2)))
                .ToList();


            Item.ExplicitMods = allmods.Where(m => m.Parent == null || m.Parent.ParentTier == null || !m.Parent.ParentTier.IsMasterCrafted).ToList();
            Item.CraftedMods = allmods.Where(m => m.Parent != null && m.Parent.ParentTier != null && m.Parent.ParentTier.IsMasterCrafted).ToList();

            if (msImplicitMods.Affixes != null)
            {
                Item.ImplicitMods = msImplicitMods.GetExactMods().ToList();
            }

            var ibase = ((ItemBase)cbBaseSelection.SelectedItem);
            var plist = ibase.GetRawProperties();


            var localmods = allmods.Where(m => m.DetermineLocalFor(Item)).ToList();

            var r = new Regex(@"(?<!\B)(?:to |increased |decreased |more |less |Adds #-# )(?!\B)|(?:#|%|:|\s\s)\s*?(?=\s?)|^\s+|\s+$", RegexOptions.IgnoreCase);

            var localnames = localmods.Select(m =>
                r.Replace(m.Attribute, "")
                    .Split(new[] { "and", "," }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(s =>
                        s.Trim().Replace("Attack Speed", "Atacks Per Second"))
                        .ToList())
                .ToList();

            if (localmods.Count > 0)
            {
                for (int j = 0; j < plist.Count; j++)
                {

                    var applymods = localmods.Where((m, i) => localnames[i].Any(n => plist[j].Attribute.Contains(n))).ToList();
                    var percm = applymods.Where(m => m.Attribute.Contains('%')).ToList();
                    var valuem = applymods.Except(percm).ToList();

                    if (valuem.Count > 0)
                    {
                        var val = valuem.Select(m => m.Value).Aggregate((l1, l2) => l1.Zip(l2, (f1, f2) => f1 + f2).ToList());
                        var nval = plist[j].Value.Zip(val, (f1, f2) => f1 + f2).ToList();
                        plist[j].ValueColor = plist[j].ValueColor.Select((c, i) => ((val[i] == nval[i]) ? plist[j].ValueColor[i] : ItemMod.ValueColoring.LocallyAffected)).ToList();
                        plist[j].Value = nval;

                    }

                    Func<float, float> roundf = (float val) => (float)Math.Round(val);

                    if (plist[j].Attribute.Contains("Critical"))
                    {
                        roundf = (f) => (float)(Math.Round(f * 10) / 10);
                    }
                    else if (plist[j].Attribute.Contains("Per Second"))
                    {
                        roundf = (f) => (float)(Math.Round(f * 100) / 100);
                    }


                    if (percm.Count > 0)
                    {
                        var perc = 1f + percm.Select(m => m.Value[0]).Sum() / 100f;
                        plist[j].ValueColor = plist[j].ValueColor.Select(c => ItemMod.ValueColoring.LocallyAffected).ToList();
                        plist[j].Value = plist[j].Value.Select(v => roundf(v * perc)).ToList();
                    }
                }

            }

            if (Item.IsWeapon)
            {
                var elementalmods = allmods.Where(m => m.Attribute.StartsWith("Adds") && (m.Attribute.Contains("Fire") || m.Attribute.Contains("Cold") || m.Attribute.Contains("Lightning"))).ToList();
                if (elementalmods.Count > 0)
                {
                    List<float> values = new List<float>();

                    var fmod = elementalmods.FirstOrDefault(m => m.Attribute.Contains("Fire"));
                    var cmod = elementalmods.FirstOrDefault(m => m.Attribute.Contains("Cold"));
                    var lmod = elementalmods.FirstOrDefault(m => m.Attribute.Contains("Lightning"));

                    List<string> mods = new List<string>();
                    List<ItemMod.ValueColoring> cols = new List<ItemMod.ValueColoring>();

                    if (fmod != null)
                    {
                        values.AddRange(fmod.Value);
                        mods.Add("#-#");
                        cols.Add(ItemMod.ValueColoring.Fire);
                        cols.Add(ItemMod.ValueColoring.Fire);
                    }

                    if (cmod != null)
                    {
                        values.AddRange(cmod.Value);
                        mods.Add("#-#");
                        cols.Add(ItemMod.ValueColoring.Cold);
                        cols.Add(ItemMod.ValueColoring.Cold);
                    }

                    if (lmod != null)
                    {
                        values.AddRange(lmod.Value);
                        mods.Add("#-#");
                        cols.Add(ItemMod.ValueColoring.Lightning);
                        cols.Add(ItemMod.ValueColoring.Lightning);
                    }

                    string mname = "Elemental Damage: ";
                    ItemMod mod = new ItemMod()
                    {
                        Attribute = mname + string.Join(", ", mods),
                        Value = values,
                        ValueColor = cols,
                    };

                    plist.Add(mod);
                }
            }

            Item.Properties = plist;

            Item.FlavourText = "Crafted by Power - PoeSkillTree";
        }
Exemplo n.º 9
0
 public override string ToString()
 {
     return("ItemMod: " + Mod + " {" + ItemMod.Range(Mod) + "}");
 }
Exemplo n.º 10
0
        public static ItemMod CreateMod(Item item, JObject obj, Regex numberfilter)
        {
            ItemClass ic = item.Class;
            var mod = new ItemMod();

            int dmode = (obj["displayMode"] != null) ? obj["displayMode"].Value<int>() : 0;
            string at = obj["name"].Value<string>();
            at = numberfilter.Replace(at, "#");

            var parsed = ((JArray)obj["values"]).Select(a =>
            {
                var str = ((JArray)a)[0].Value<string>();
                var floats = new List<float>();
                var parts = str.Split('-');

                if (dmode != 3)
                    if (parts.Length > 1)
                        at += ": ";
                    else
                        at += " ";

                for (int i = 0; i < parts.Length; i++)
                {
                    string v = parts[i];
                    float val = 0;
                    if (float.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out val))
                    {
                        floats.Add(val);
                        if (dmode != 3)
                            at += "#";
                    }
                    else
                    {
                        foreach (Match m in numberfilter.Matches(v))
                            floats.Add(float.Parse(m.Value, CultureInfo.InvariantCulture));

                        at += " " + numberfilter.Replace(v, "#");
                    }

                    if (i < parts.Length - 1)
                    {
                        if (dmode != 3)
                            at += "-";
                    }
                }

                var cols = floats.Select(f => (ItemMod.ValueColoring)((JArray)a)[1].Value<int>()).ToList();
                return new { floats, cols };
            }).ToList();


            mod = new ItemMod
            {
                itemclass = ic,
                Value = parsed.Select(p => p.floats).SelectMany(v => v).ToList(),
                ValueColor = parsed.Select(p => p.cols).SelectMany(v => v).ToList(),
                _Attribute = at,
                isLocal = DetermineLocal(item, at)
            };

            return mod;
        }
Exemplo n.º 11
0
        public ItemMod Sum(ItemMod m)
        {
            var mod = new ItemMod()
            {
                Attribute = this.Attribute,
                itemclass = this.itemclass,
                isLocal = this.isLocal,
                Parent = this.Parent,
                ValueColor = this.ValueColor.ToList()
            };

            mod.Value = this.Value.Zip(m.Value, (f1, f2) => f1 + f2).ToList();

            return mod;
        }
Exemplo n.º 12
0
        public static ItemMod CreateMod(Item item, string attribute, Regex numberfilter)
        {
            ItemClass ic = item.Class;
            var mod = new ItemMod();
            var values = new List<float>();
            foreach (Match match in numberfilter.Matches(attribute))
            {
                values.Add(float.Parse(match.Value, CultureInfo.InvariantCulture));
            }
            string at = numberfilter.Replace(attribute, "#");

            mod = new ItemMod
            {
                itemclass = ic,
                Value = values,
                _Attribute = at,
                isLocal = DetermineLocal(item, at)
            };

            return mod;
        }
Exemplo n.º 13
0
        private static SolidColorBrush GetColoringFor(ItemMod mod, int i)
        {
            if (mod.ValueColor.Count > i && i >= 0)
                switch (mod.ValueColor[i])
                {
                    case ItemMod.ValueColoring.LocallyAffected:
                        return locallyAffectedColor;
                    case ItemMod.ValueColoring.Fire:
                        return fireAffectedColor;
                    case ItemMod.ValueColoring.Cold:
                        return coldAffectedColor;
                    case ItemMod.ValueColoring.Lightning:
                        return lightningAffectedColor;
                }

            return Brushes.White;
        }