Example #1
0
        // note that this method will be called when attached to either a mobile or a weapon
        // when attached to a weapon, only that weapon will do additional damage
        // when attached to a mobile, any weapon the mobile wields will do additional damage
        public override void OnWeaponHit(Mobile attacker, Mobile defender, BaseWeapon weapon, int damageGiven)
        {
            if (m_Chance <= 0 || Utility.Random(100) > m_Chance)
            {
                return;
            }

            if (defender != null && attacker != null && m_EnemyType != XmlMobFactions.GroupTypes.End_Unused)
            {
                // check to the owner's faction levels
                ArrayList list = XmlAttach.FindAttachments(XmlAttach.MobileAttachments, attacker, typeof(XmlMobFactions), "Standard");

                if (list != null && list.Count > 0)
                {
                    XmlMobFactions x = list[0] as XmlMobFactions;

                    double increase = 0;

                    // go through all of the factions the defender might belong to
                    ArrayList glist = XmlMobFactions.FindGroups(defender);

                    if (glist != null && glist.Count > 0)
                    {
                        foreach (XmlMobFactions.GroupTypes targetgroup in glist)
                        {
                            // found the group that matches the enemy type for this attachment
                            if (targetgroup == m_EnemyType)
                            {
                                // get the percent damage increase based upon total faction level of opponent groups
                                int totalfac = 0;

                                // get the target enemy group
                                XmlMobFactions.Group g = XmlMobFactions.FindGroup(m_EnemyType);

                                if (g.Opponents != null)
                                {
                                    // go through all of the opponents of this group
                                    for (int i = 0; i < g.Opponents.Length; i++)
                                    {
                                        // and sum the faction levels
                                        try{
                                            totalfac += (int)(x.GetFactionLevel(g.Opponents[i].GroupType) * g.OpponentGain[i]);
                                        } catch {}
                                    }
                                }

                                // what is the damage increase based upon the total opponent faction level
                                increase = (double)ComputeIncrease(totalfac) / 100.0;

                                break;
                            }
                        }
                    }

                    if (increase > 0)
                    {
                        // apply the additional damage if any
                        defender.Damage((int)(damageGiven * increase), attacker);
                    }
                }
            }
        }