Beispiel #1
0
        private static void LoadItemAttributes(Item item, List <Attribute> attributes, List <Attribute> independentAttributes)
        {
            foreach (var attr in item.Properties)
            {
                // Show all properties except quality in the group for this slot.
                if (attr.Attribute == "Quality: +#%")
                {
                    continue;
                }
                attributes.Add(new Attribute(attr.Attribute, attr.Value, item.Slot.ToString()));
            }

            var modsAffectingProperties = item.GetModsAffectingProperties().SelectMany(pair => pair.Value).ToList();

            foreach (var mod in item.Mods)
            {
                if (mod.IsLocal)
                {
                    // Show local mods in the group for this slot
                    // if they are not already represented by affecting properties.
                    if (mod.Attribute.StartsWith("Adds") || modsAffectingProperties.Contains(mod))
                    {
                        continue;
                    }
                    var attTo = attributes.Find(ad => ad.TextAttribute == mod.Attribute && ad.Group == item.Slot.ToString());
                    AddAttribute(mod, item.Slot.ToString(), attributes, attTo);
                }
                else
                {
                    // Show all non-local mods in the Independent group.
                    var attTo = independentAttributes.Find(ad => ad.TextAttribute == mod.Attribute && ad.Group == "Independent");
                    AddAttribute(mod, "Independent", independentAttributes, attTo);
                }
            }
        }
Beispiel #2
0
        private void ApplyLocals()
        {
            foreach (var pair in Item.GetModsAffectingProperties())
            {
                ItemMod        prop      = pair.Key;
                List <ItemMod> applymods = pair.Value;

                List <ItemMod> percm  = applymods.Where(m => Regex.IsMatch(m.Attribute, @"(?<!\+)#%")).ToList();
                List <ItemMod> valuem = applymods.Except(percm).ToList();

                if (valuem.Count > 0)
                {
                    IReadOnlyList <float> val = valuem
                                                .Select(m => m.Values)
                                                .Aggregate((l1, l2) => l1.Zip(l2, (f1, f2) => f1 + f2)
                                                           .ToList());
                    IReadOnlyList <float> nval = prop.Values
                                                 .Zip(val, (f1, f2) => f1 + f2)
                                                 .ToList();
                    prop.ValueColors = prop.ValueColors
                                       .Select((c, i) => val[i] == nval[i] ? prop.ValueColors[i] : ValueColoring.LocallyAffected)
                                       .ToList();
                    prop.Values = nval;
                }

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

                if (prop.Attribute.Contains("Critical"))
                {
                    roundf = f => (float)(Math.Round(f * 10) / 10);
                }
                else if (prop.Attribute.Contains("per Second"))
                {
                    roundf = f => (float)(Math.Round(f * 100) / 100);
                }

                if (percm.Count > 0)
                {
                    var perc = 1f + percm.Select(m => m.Values[0]).Sum() / 100f;
                    prop.ValueColors = prop.ValueColors.Select(c => ValueColoring.LocallyAffected).ToList();
                    prop.Values      = prop.Values.Select(v => roundf(v * perc)).ToList();
                }
            }
        }