Esempio n. 1
0
        public void BeginAttackTarget(Mobile from, Item target, Point3D targetloc)
        {
            if (from == null || target == null)
            {
                return;
            }

            // check the target line of sight
            Point3D adjustedloc = new Point3D(targetloc.X, targetloc.Y, targetloc.Z + target.ItemData.Height);
            Point3D fromloc     = new Point3D(from.Location.X, from.Location.Y, from.Location.Z + 14);

            if (!from.Map.LineOfSight(fromloc, adjustedloc))
            {
                from.SendMessage("Cannot see target.");
                return;
            }

            int distance = (int)XmlSiege.GetDistance(from.Location, targetloc);

            if (distance <= MaxDistance)
            {
                CurrentLoc = from.Location;
                CurrentMap = from.Map;
                TargetLoc  = target.Location;
                TargetMap  = target.Map;

                AttackTarget = target;
            }
            else
            {
                from.SendLocalizedMessage(500446);                 // That is too far away.
            }
        }
Esempio n. 2
0
        public void BeginAttackTarget(Mobile from, Item target, Point3D targetloc)
        {
            if (from == null || target == null)
            {
                return;
            }

            // check the target line of sight
            Point3D adjustedloc = new Point3D(targetloc.X, targetloc.Y, targetloc.Z + target.ItemData.Height);
            Point3D fromloc     = new Point3D(from.Location.X, from.Location.Y, from.Location.Z + 14);

            if (!from.Map.LineOfSight(fromloc, adjustedloc))
            {
                from.SendMessage("Cannot see target.");
                return;
            }

            Item weapon = from.FindItemOnLayer(Layer.OneHanded);

            if (weapon == null)
            {
                weapon = from.FindItemOnLayer(Layer.TwoHanded);
            }

            int range = MaxDistance;

            if (weapon != null && weapon is BaseRanged)
            {
                range = ((BaseRanged)weapon).MaxRange;
            }

            int distance = (int)XmlSiege.GetDistance(from.Location, targetloc);

            if (distance <= range)
            {
                CurrentLoc = from.Location;
                CurrentMap = from.Map;
                TargetLoc  = target.Location;
                TargetMap  = target.Map;

                AttackTarget = target;
            }
            else
            {
                from.SendLocalizedMessage(500446);                 // That is too far away.
            }
        }
Esempio n. 3
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);
            }