protected override void OnTick()
            {
                if (m_attachment == null)
                {
                    return;
                }

                Item weapon = m_attachment.AttachedTo as Item;
                Item target = m_attachment.AttackTarget;

                if (weapon == null || weapon.Deleted || target == null || target.Deleted)
                {
                    Stop();
                    return;
                }

                // the weapon must be equipped
                Mobile attacker = weapon.Parent as Mobile;

                if (attacker == null || attacker.Deleted)
                {
                    Stop();
                    return;
                }

                // the attacker cannot be fighting

                if (attacker.Combatant != null)
                {
                    attacker.SendMessage("Cannot siege while fighting.");
                    Stop();
                    return;
                }

                // get the location of the attacker

                Point3D attackerloc = attacker.Location;
                Map     attackermap = attacker.Map;

                Point3D targetloc = target.Location;
                Map     targetmap = target.Map;

                if (targetmap == null || targetmap == Map.Internal || attackermap == null || attackermap == Map.Internal || targetmap != attackermap)
                {
                    // if the attacker or target has an invalid map, then stop
                    Stop();
                    return;
                }

                // compare it against previous locations.  If they have moved then break off the attack
                if (attackerloc != m_attachment.CurrentLoc || attackermap != m_attachment.CurrentMap)
                {
                    Stop();
                    return;
                }



                // attack the target
                // Animate( int action, int frameCount, int repeatCount, bool forward, bool repeat, int delay )
                int action = 26;                 // 1-H bash animation, 29=2-H mounted



                // get the layer
                switch (weapon.Layer)
                {
                case Layer.OneHanded:

                    if (attacker.Mount == null)
                    {
                        // unmounted animation
                        action = 9;
                    }
                    else
                    {
                        action = 26;
                    }
                    break;

                case Layer.TwoHanded:
                    if (attacker.Mount == null)
                    {
                        // unmounted animation
                        action = 12;
                    }
                    else
                    {
                        action = 29;
                    }
                    break;
                }

                // attack animation
                attacker.Animate(action, 7, 1, true, false, 0);

                int    basedamage = 1;
                double basedelay  = BaseWeaponDelay;

                if (weapon is BaseWeapon)
                {
                    BaseWeapon b = (BaseWeapon)weapon;
                    // calculate the siege damage based on the weapon min/max damage and the overall damage scale factor
                    basedamage = (int)(Utility.RandomMinMax(b.MinDamage, b.MaxDamage) * DamageScaleFactor);
                    // reduce the actual delay by the weapon speed
                    basedelay -= b.Speed / 10;
                }

                if (basedelay < 1)
                {
                    basedelay = 1;
                }
                if (basedamage < 1)
                {
                    basedamage = 1;
                }

                // apply siege damage, all physical
                XmlSiege.Attack(attacker, target, basedamage, 0);

                // prepare for the next attack
                m_attachment.DoTimer(TimeSpan.FromSeconds(basedelay), false);
            }
Beispiel #2
0
            protected override void OnTick()
            {
                if (m_attachment == null)
                {
                    return;
                }

                Item weapon = m_attachment.AttachedTo as Item;
                Item target = m_attachment.AttackTarget;

                if (weapon == null || weapon.Deleted || target == null || target.Deleted)
                {
                    Stop();
                    return;
                }

                // the weapon must be equipped
                Mobile attacker = weapon.Parent as Mobile;

                if (attacker == null || attacker.Deleted)
                {
                    Stop();
                    return;
                }

                // the attacker cannot be fighting

                if (attacker.Combatant != null)
                {
                    attacker.SendMessage("Cannot siege while fighting.");
                    Stop();
                    return;
                }

                // get the location of the attacker

                Point3D attackerloc = attacker.Location;
                Map     attackermap = attacker.Map;

                Point3D targetloc = target.Location;
                Map     targetmap = target.Map;

                if (targetmap == null || targetmap == Map.Internal || attackermap == null || attackermap == Map.Internal || targetmap != attackermap)
                {
                    // if the attacker or target has an invalid map, then stop
                    Stop();
                    return;
                }

                // compare it against previous locations.  If they have moved then break off the attack
                int maxRange = 2;

                if (weapon is BaseRanged)
                {
                    maxRange = ((BaseRanged)weapon).MaxRange;
                }

                int distance = (int)XmlSiege.GetDistance(attackerloc, targetloc);

                if (distance > maxRange || attackermap != m_attachment.CurrentMap)
                {
                    target.LabelTo(attacker, "You are too far to keep attacking.");
                    Stop();
                    return;
                }

                int    basedamage = 1;
                double basedelay  = BaseWeaponDelay;

                if (weapon is BaseWeapon)
                {
                    BaseWeapon b = (BaseWeapon)weapon;
                    b.PlaySwingAnimation(attacker);
                    // calculate the siege damage based on the weapon min/max damage and the overall damage scale factor
                    basedamage = (int)(Utility.RandomMinMax(b.MinDamage, b.MaxDamage) * DamageScaleFactor);
                    // reduce the actual delay by the weapon speed
                    basedelay -= b.Speed / 10.0;
                }

                if (basedelay < 1)
                {
                    basedelay = 1;
                }
                if (basedamage < 1)
                {
                    basedamage = 1;
                }

                XmlSiege.Attack(attacker, target, basedamage, 0);

                m_attachment.DoTimer(TimeSpan.FromSeconds(basedelay), false);
            }