Esempio n. 1
0
        // Adds gem to deserialized gems.
        public void Add(Gem gem)
        {
            if (!Gems.Exists(g => g.Name == gem.Name))
            {
                gem.Optimize();

                if (gem.Attributes != null)
                {
                    Comparer <Value> comparer = new ValueLogicalComparer();
                    foreach (GemAttribute attr in gem.Attributes)
                    {
                        attr.Values.Sort(comparer);
                    }
                }

                Gems.Add(gem);
            }
        }
Esempio n. 2
0
        // Merges attributes of specified gem.
        public void Merge(Gem gem)
        {
            // Take properties from parameter if they are not specified here.
            if (!ExcludeFormSpecified && gem.ExcludeFormSpecified)
            {
                ExcludeForm = gem.ExcludeForm;
            }
            if (!ExcludeFormSupportSpecified && gem.ExcludeFormSupportSpecified)
            {
                ExcludeFormSupport = gem.ExcludeFormSupport;
            }
            if (!ExcludeSourceSpecified && gem.ExcludeSourceSpecified)
            {
                ExcludeSource = gem.ExcludeSource;
            }
            if (!HitsPerAttackSpecified && gem.HitsPerAttackSpecified)
            {
                HitsPerAttack = gem.HitsPerAttack;
            }
            if (!IncludeFormSpecified && gem.IncludeFormSpecified)
            {
                IncludeForm = gem.IncludeForm;
            }
            if (!RequiresEquippedShieldSpecified && gem.RequiresEquippedShieldSpecified)
            {
                RequiresEquippedShield = gem.RequiresEquippedShield;
            }
            if (!RequiredHandSpecified && gem.RequiredHandSpecified)
            {
                RequiredHand = gem.RequiredHand;
            }
            if (!RequiredWeaponSpecified && gem.RequiredWeaponSpecified)
            {
                RequiredWeapon = gem.RequiredWeapon;
            }
            if (!StrikesWithBothWeaponsSpecified && gem.StrikesWithBothWeaponsSpecified)
            {
                StrikesWithBothWeapons = gem.StrikesWithBothWeapons;
            }
            if (!UnarmedSpecified && gem.UnarmedSpecified)
            {
                Unarmed = gem.Unarmed;
            }

            if (gem.Attributes != null)
            {
                if (Attributes == null)
                {
                    Attributes = new List <GemAttribute>();
                }

                foreach (GemAttribute attr in gem.Attributes)
                {
                    attr.Optimize();
                    // Find existing attribute to merge with.
                    GemAttribute with = Attributes.Find(a => a.Name == attr.Name);
                    if (with == null)
                    {
                        Attributes.Add(attr);
                    }
                    else
                    {
                        if (!with.NoUpdate)
                        {
                            // Sort values by priority so less specific values won't overwrite more specific ones.
                            attr.Values.Sort(new ValuePriorityComparer {
                                Reversed = true
                            });

                            foreach (Value value in attr.Values)
                            {
                                with.Merge(value);
                            }

                            with.CleanUp();
                        }
                    }
                }

                // Sort gem attribute values logically.
                Comparer <Value> comparer = new ValueLogicalComparer();
                foreach (GemAttribute attr in Attributes)
                {
                    attr.Values.Sort(comparer);
                }
            }
        }