Exemple #1
0
        // Applies item modifiers.
        public void Apply(Item item)
        {
            // Add skill gem attributes.
            Local.Add(GemDB.Instance.AttributesOf(Gem, item));

            CreateSources();

            // Lists of damage added, increased and multipliers to apply.
            List <Damage.Added>     adds      = new List <Damage.Added>();
            List <Damage.Increased> increases = new List <Damage.Increased>();
            List <Damage.More>      mores     = new List <Damage.More>();

            // Collect damage conversions from gems, equipment and tree.
            // Collect damage added from gems and equipment.
            foreach (var attr in Local)
            {
                Damage.Converted conv = Damage.Converted.Create(DamageConversionSource.Gem, attr);
                if (conv != null)
                {
                    Converts.Add(conv);
                }

                // Damage added from gems is always applied.
                Damage.Added added = Damage.Added.Create(Nature.Source, attr);
                if (added != null)
                {
                    adds.Add(added);
                }
            }

            foreach (var attr in Equipment)
            {
                Damage.Converted conv = Damage.Converted.Create(DamageConversionSource.Equipment, attr);
                if (conv != null)
                {
                    Converts.Add(conv);
                }

                // Whether damage added from equipment applies to the current DamageSource is decided in Create().
                Damage.Added added = Damage.Added.Create(Nature.Source, attr);
                if (added != null)
                {
                    adds.Add(added);
                }
            }

            foreach (var attr in Tree)
            {
                Damage.Converted conv = Damage.Converted.Create(DamageConversionSource.Tree, attr);
                if (conv != null)
                {
                    Converts.Add(conv);
                }
            }

            // Merge local gems and global attributes.
            AttributeSet attrs = Compute.Global.Merge(Local);

            // Iron Grip.
            if (Compute.IronGrip || attrs.ContainsKey("Strength's damage bonus applies to Projectile Attacks made with Supported Skills"))
            {
                // Create projectile attack damage bonus from value of implicit melee physical damage increase.
                float bonus = Implicit["#% increased Melee Physical Damage"][0];
                attrs.AddAsSum("#% increased Projectile Weapon Damage", bonus);
            }

            // Iron Will.
            if (attrs.ContainsKey("Strength's damage bonus applies to Spell Damage as well for Supported Skills"))
            {
                // Create spell damage bonus from value of implicit melee physical damage increase.
                float bonus = Implicit["#% increased Melee Physical Damage"][0];
                attrs.AddAsSum("#% increased Spell Damage", bonus);
            }

            // Collect damage gains, increases and multipliers.
            foreach (var attr in attrs)
            {
                var gained = Damage.Gained.Create(attr);
                if (gained != null)
                {
                    Gains.Add(gained);
                }

                var increased = Damage.Increased.Create(attr);
                if (increased != null)
                {
                    increases.Add(increased);
                }

                var more = Damage.More.Create(attr, Compute);
                if (more != null)
                {
                    mores.Add(more);
                }
            }

            foreach (AttackSource source in Sources)
            {
                ApplyAttackSource(adds, increases, mores, attrs, source);
            }
        }