예제 #1
0
        /// <summary>
        ///     Walk Packet
        /// </summary>
        /// <param name="walkPacket"></param>
        public void Walk(WalkPacket walkPacket)
        {
            var currentRunningSeconds =
                (DateTime.Now - Process.GetCurrentProcess().StartTime.AddSeconds(-50)).TotalSeconds;
            var distance = (int)Heuristic.Octile(Math.Abs(Session.Character.PositionX - walkPacket.XCoordinate),
                                                 Math.Abs(Session.Character.PositionY - walkPacket.YCoordinate));

            if (Session.Character.Speed < walkPacket.Speed &&
                Session.Character.LastSpeedChange.AddSeconds(5) <= DateTime.Now || distance > 60)
            {
                return;
            }

            if (Session.Character.MapInstance?.MapInstanceType == MapInstanceType.BaseMapInstance)
            {
                Session.Character.MapX = walkPacket.XCoordinate;
                Session.Character.MapY = walkPacket.YCoordinate;
            }

            Session.Character.PositionX = walkPacket.XCoordinate;
            Session.Character.PositionY = walkPacket.YCoordinate;

            Session.Character.MapInstance?.Broadcast(Session.Character.GenerateMove());
            Session.SendPacket(Session.Character.GenerateCond());
            Session.Character.LastMove = DateTime.Now;
        }
예제 #2
0
        public void PacketFactoryTest()
        {
            // this test only tests the factory, not the packets intialize factory
            PacketFactory.Initialize <WalkPacket>();

            Logger.InitializeLogger(LogManager.GetLogger(typeof(CoreTest)));

            // 1234 simulates packet header iterative number
            string      equipPacket             = "equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.720.0.0.0 5.4912.6.0.0 9.227.0.0.0 10.803.0.0.0 11.347.0.0.0 13.4146.0.0.0 14.4138.0.0.0";
            EquipPacket serializedPacket        = PacketFactory.Serialize <EquipPacket>(equipPacket);
            string      deserializedEquipPacket = PacketFactory.Deserialize(serializedPacket);

            Assert.AreEqual(equipPacket, deserializedEquipPacket);

            // 1234 simulates packet header iterative number
            string   inPacket             = "in 1 ImACharacter - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1 100 100 0 -1 0 0 0 0 0 0 0 0 -1 - 1 0 0 0 0 1 0 0 0 10 0";
            InPacket serializedInPacket   = PacketFactory.Serialize <InPacket>(inPacket);
            string   deserializedInPacket = PacketFactory.Deserialize(serializedInPacket);

            Assert.AreEqual(inPacket, deserializedInPacket);

            WalkPacket walkPacket = PacketFactory.Serialize <WalkPacket>("walk 3a0 115 1 11");

            Assert.IsNull(walkPacket);
        }
예제 #3
0
 public static void Process_WalkPacket(Player client, WalkPacket packet)
 {
     client.SendToScreen(packet, true);
     packet.Direction %= 8;
     client.X         += (ushort)Common.DeltaX[packet.Direction];
     client.Y         += (ushort)Common.DeltaY[packet.Direction];
     client.OnMove();
     client.UpdateSurroundings();
 }
        public void WalkPacket(WalkPacket packet)
        {
            ScriptManager.Instance.PosX = packet.XCoordinate;
            ScriptManager.Instance.PosY = packet.YCoordinate;
            if (ScriptManager.Instance.Num3 == 1)
            {
                ScriptManager.Instance.Flag1 = false;
            }

            ++ScriptManager.Instance.Num3;
        }
        public void Walk(Entity To)
        {
            var   dir     = Calculations.GetDirection(Location, To.Location);
            Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]);

            if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster))
            {
                //Send to screen new walk packet
                SendToScreen(WalkPacket.Create(UID, dir));
                Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                X = (ushort)tryMove.X;
                Y = (ushort)tryMove.Y;
                Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                LastMove = Common.Clock;
            }
        }
예제 #6
0
        public void PacketFactoryTest()
        {
            // this test only tests the factory, not the packets intialize factory
            PacketFactory.Initialize <WalkPacket>();

            Logger.InitializeLogger(LogManager.GetLogger(typeof(CoreTest)));

            // mtlist packet
            const string          mtlistPacket             = "mtlist 30 3 1698 3 1703 3 1861 3 1865 3 1870 3 1873 3 1874 3 1879 3 1880 3 1882 3 1885 3 1887 3 1890 3 1896 3 1900 3 1901 3 1904 3 1908 3 1915 3 1916 3 1919 3 1923 3 1925 3 1931 3 1934 3 1935 3 1937 3 1941 3 1942 3 1946";
            MultiTargetListPacket deserializedMtlistPacket = PacketFactory.Deserialize <MultiTargetListPacket>(mtlistPacket);
            string serializedMtlistPacket = PacketFactory.Serialize(deserializedMtlistPacket);

            Assert.AreEqual(mtlistPacket, serializedMtlistPacket);

            // Equip Packet
            const string equipPacket             = "equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.720.0.0.0 5.4912.6.0.0 9.227.0.0.0 10.803.0.0.0 11.347.0.0.0 13.4146.0.0.0 14.4138.0.0.0";
            EquipPacket  deserializedEquipPacket = PacketFactory.Deserialize <EquipPacket>(equipPacket);
            string       serializedEquipPacket   = PacketFactory.Serialize(deserializedEquipPacket);

            Assert.AreEqual(equipPacket, serializedEquipPacket);

            // In Packet
            const string inPacket             = "in 1 ImACharacter - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1 100 100 0 -1 0 0 0 0 0 0 0 0 -1 - 1 0 0 0 0 1 0 0 0 10 0";
            InPacket     deserializedInPacket = PacketFactory.Deserialize <InPacket>(inPacket);
            string       serializedInPacket   = PacketFactory.Serialize(deserializedInPacket);

            Assert.AreEqual(inPacket, serializedInPacket);

            // Walk Packet
            const string walkPacket             = "walk 3 115 1 11";
            WalkPacket   deserializedWalkPacket = PacketFactory.Deserialize <WalkPacket>(walkPacket);
            string       serializedWalkPacket   = PacketFactory.Serialize(deserializedWalkPacket);

            Assert.AreEqual(walkPacket, serializedWalkPacket);

            WalkPacket invalidWalkPacket = PacketFactory.Deserialize <WalkPacket>("walk 3a0 115 1 11");

            Assert.IsNull(invalidWalkPacket);

            // Dialog Packet
            const string dialogPacket = "dlg #walk^3^115^1^11 #walk^3^115^1^11 Do you really wanna walk this way?";
            DialogPacket <WalkPacket, WalkPacket> deserializedDialogPacket = PacketFactory.Deserialize <DialogPacket <WalkPacket, WalkPacket> >(dialogPacket);
            string serializedDialogPacket = PacketFactory.Serialize(deserializedDialogPacket);

            Assert.AreEqual(dialogPacket, serializedDialogPacket);
        }
예제 #7
0
        public void TestWalkMove()
        {
            // login, create character, start game
            FakeNetworkClient client = HandlerTestHelper.InitializeTestEnvironment();

            WalkPacket walkPacket = new WalkPacket {
                Speed = 11, XCoordinate = 89, YCoordinate = 126
            };

            // send walkpacket to client
            client.ReceivePacket(walkPacket);

            string     mvPacket   = HandlerTestHelper.WaitForPacket(client, "mv");
            MovePacket movePacket = PacketFactory.Deserialize <MovePacket>(mvPacket);

            Assert.AreEqual(walkPacket.XCoordinate, movePacket.PositionX);
            Assert.AreEqual(walkPacket.YCoordinate, movePacket.PositionY);
            Assert.AreEqual(walkPacket.Speed, movePacket.Speed);

            HandlerTestHelper.ShutdownTestingEnvironment();
            Assert.Pass();
        }
예제 #8
0
        public void PacketFactoryTest()
        {
            // this test only tests the factory, not the packets intialize factory
            PacketFactory.Initialize <WalkPacket>();

            Logger.InitializeLogger(LogManager.GetLogger(typeof(CoreTest)));

            // Equip Packet
            string      equipPacket             = "equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.720.0.0.0 5.4912.6.0.0 9.227.0.0.0 10.803.0.0.0 11.347.0.0.0 13.4146.0.0.0 14.4138.0.0.0";
            EquipPacket deserializedEquipPacket = PacketFactory.Deserialize <EquipPacket>(equipPacket);
            string      serializedEquipPacket   = PacketFactory.Serialize(deserializedEquipPacket);

            Assert.AreEqual(equipPacket, serializedEquipPacket);

            // In Packet
            string   inPacket             = "in 1 ImACharacter - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1 100 100 0 -1 0 0 0 0 0 0 0 0 -1 - 1 0 0 0 0 1 0 0 0 10 0";
            InPacket deserializedInPacket = PacketFactory.Deserialize <InPacket>(inPacket);
            string   serializedInPacket   = PacketFactory.Serialize(deserializedInPacket);

            Assert.AreEqual(inPacket, serializedInPacket);

            // Walk Packet
            string     walkPacket             = "walk 3 115 1 11";
            WalkPacket deserializedWalkPacket = PacketFactory.Deserialize <WalkPacket>(walkPacket);
            string     serializedWalkPacket   = PacketFactory.Serialize(deserializedWalkPacket);

            Assert.AreEqual(walkPacket, serializedWalkPacket);

            WalkPacket invalidWalkPacket = PacketFactory.Deserialize <WalkPacket>("walk 3a0 115 1 11");

            Assert.IsNull(invalidWalkPacket);

            // Dialog Packet
            string dialogPacket = "dlg #walk^3^115^1^11 #walk^3^115^1^11 Do you really wanna walk this way?";
            DialogPacket <WalkPacket, WalkPacket> deserializedDialogPacket = PacketFactory.Deserialize <DialogPacket <WalkPacket, WalkPacket> >(dialogPacket);
            string serializedDialogPacket = PacketFactory.Serialize(deserializedDialogPacket);

            Assert.AreEqual(dialogPacket, serializedDialogPacket);
        }
예제 #9
0
        /// <summary>
        ///     Walk Packet
        /// </summary>
        /// <param name="walkPacket"></param>
        public void Walk(WalkPacket walkPacket)
        {
            var distance = (int)Heuristic.Octile(Math.Abs(Session.Character.PositionX - walkPacket.XCoordinate),
                                                 Math.Abs(Session.Character.PositionY - walkPacket.YCoordinate));

            if ((Session.Character.Speed < walkPacket.Speed &&
                 Session.Character.LastSpeedChange.AddSeconds(5) <= DateTime.Now) || distance > 60)
            {
                return;
            }

            if (Session.Character.MapInstance?.MapInstanceType == MapInstanceType.BaseMapInstance)
            {
                Session.Character.MapX = walkPacket.XCoordinate;
                Session.Character.MapY = walkPacket.YCoordinate;
            }

            Session.Character.PositionX = walkPacket.XCoordinate;
            Session.Character.PositionY = walkPacket.YCoordinate;

            Session.Character.MapInstance?.Sessions.SendPacket(Session.Character.GenerateMove());
            Session.SendPacket(Session.Character.GenerateCond());
            Session.Character.LastMove = DateTime.Now;
        }
예제 #10
0
        public void Monster_Timer()
        {
            //Perform all monster logic here
            switch (Mode)
            {
            case MonsterMode.Attack:
            {
                var target = Map.Search <Entity>(TargetID);
                if (target == null || !target.Alive || target.HasEffect(ClientEffect.Fly))
                {
                    Mode = MonsterMode.Idle; return;
                }
                var dist = Calculations.GetDistance(Location, target.Location);
                if (dist > BaseMonster.ViewRange)
                {
                    Mode = MonsterMode.Idle;
                }
                else if (dist > BaseMonster.AttackRange)
                {
                    Mode = MonsterMode.Walk;
                }
                else if (Common.Clock - LastAttack > BaseMonster.AttackSpeed)
                {
                    LastAttack = Common.Clock;
                    CombatEngine.ProcessInteractionPacket(InteractPacket.Create(UID, TargetID, target.X, target.Y, InteractAction.Attack, 0));
                }

                break;
            }

            case MonsterMode.Idle:
            {
                var d1 = BaseMonster.ViewRange;
                foreach (var t in Map.QueryScreen <Entity>(this))
                {
                    if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection))
                    {
                        continue;
                    }
                    var d2 = Calculations.GetDistance(Location, t.Location);
                    if (d2 < d1)
                    {
                        d1       = d2;
                        TargetID = t.UID;
                        if (d2 <= BaseMonster.AttackRange)
                        {
                            break;
                        }
                    }
                }

                var Target = Map.Search <Entity>(TargetID);

                /*if ((Life < MaximumLife) && (isSearching == false))    //Get the target that is range attacking
                 * {
                 *  var searchRange = 30;
                 *  foreach (var t in Map.QueryScreen<Entity>(this))
                 *  {
                 *      if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection))
                 *          continue;
                 *      var d2 = Calculations.GetDistance(Location, t.Location);
                 *      if (d2 < searchRange)
                 *      {
                 *          searchRange = d2;
                 *          TargetID = t.UID;
                 *      }
                 *  }
                 *  Target = Map.Search<Entity>(TargetID);
                 *  Mode = MonsterMode.Search;
                 * }*/


                if (Life < isAttacked)
                {
                    Mode       = MonsterMode.Search;
                    isAttacked = Life;

                    foreach (var t in Map.QueryScreen <Entity>(this))
                    {
                        if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection))
                        {
                            continue;
                        }
                        var d2 = Calculations.GetDistance(Location, t.Location);
                        if (d2 < 30)           //Range of searching
                        {
                            TargetID = t.UID;
                            if (d2 <= BaseMonster.AttackRange)
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (Target != null)
                    {
                        var dist = Calculations.GetDistance(Location, Target.Location);
                        if (dist < BaseMonster.AttackRange)
                        {
                            Mode = MonsterMode.Attack;
                        }
                        else if (dist < BaseMonster.ViewRange)
                        {
                            Mode = MonsterMode.Walk;
                        }
                    }
                    else if (BaseMonster.Mesh != 900 && Common.Clock - LastMove > BaseMonster.MoveSpeed * 4)
                    {
                        var   dir     = (byte)Common.Random.Next(9);
                        Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]);
                        if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster))
                        {
                            //Send to screen new walk packet
                            SendToScreen(WalkPacket.Create(UID, dir));
                            Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            X         = (ushort)tryMove.X;
                            Y         = (ushort)tryMove.Y;
                            Direction = dir;
                            Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            LastMove = Common.Clock;
                            UpdateSurroundings();
                        }
                    }
                }
                break;
            }

            case MonsterMode.Walk:
            {
                var target = Map.Search <Entity>(TargetID);
                if (target == null || !target.Alive || (BaseMonster.Mesh != 900 && target.HasEffect(ClientEffect.Fly) || target.HasStatus(ClientStatus.ReviveProtection)))
                {
                    Mode = MonsterMode.Idle;
                }
                else if (Common.Clock - LastMove > BaseMonster.MoveSpeed)
                {
                    var dist = Calculations.GetDistance(Location, target.Location);
                    if (dist > BaseMonster.ViewRange)
                    {
                        Mode = MonsterMode.Idle;
                    }
                    else if (dist > BaseMonster.AttackRange)
                    {
                        var   dir     = Calculations.GetDirection(Location, target.Location);
                        Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]);
                        if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster))
                        {
                            //Send to screen new walk packet
                            SendToScreen(WalkPacket.Create(UID, dir));
                            Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            X         = (ushort)tryMove.X;
                            Y         = (ushort)tryMove.Y;
                            Direction = dir;
                            Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            LastMove = Common.Clock;
                        }
                        else if (Common.Clock - LastMove > BaseMonster.MoveSpeed * 5)
                        {
                            Mode = MonsterMode.Encircle;
                        }
                    }
                    else
                    {
                        LastAttack = Common.Clock - AttackSpeed + 100;
                        Mode       = MonsterMode.Attack;
                    }
                }
                break;
            }

            case MonsterMode.Encircle:
            {
                var Target = Map.Search <Entity>(TargetID);
                if (Target != null)
                {
                    var dir = (byte)Common.Random.Next(9);           //This should move to turn around an object. Now is random.

                    for (int i = 0; i < Common.Random.Next(2, 5); i++)
                    {
                        Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]);
                        if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster))
                        {
                            //Send to screen new walk packet
                            SendToScreen(WalkPacket.Create(UID, dir));
                            Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            X         = (ushort)tryMove.X;
                            Y         = (ushort)tryMove.Y;
                            Direction = dir;
                            Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            LastMove = Common.Clock;
                            //UpdateSurroundings();
                        }
                    }
                }

                Mode = MonsterMode.Idle;

                break;
            }

            case MonsterMode.Search:
            {
                var target = Map.Search <Entity>(TargetID);

                if (target == null || !target.Alive || (BaseMonster.Mesh != 900 && target.HasEffect(ClientEffect.Fly) || target.HasStatus(ClientStatus.ReviveProtection)))
                {
                    Mode = MonsterMode.Idle;
                }
                else if (Common.Clock - LastMove > BaseMonster.MoveSpeed)
                {
                    var dist = Calculations.GetDistance(Location, target.Location);
                    if (dist > 30)                           //Max range of search.
                    {
                        Mode = MonsterMode.Idle;
                    }
                    else if (dist > BaseMonster.AttackRange)
                    {
                        var   dir     = Calculations.GetDirection(Location, target.Location);
                        Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]);
                        if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster))
                        {
                            //Send to screen new walk packet
                            SendToScreen(WalkPacket.Create(UID, dir));
                            Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            X         = (ushort)tryMove.X;
                            Y         = (ushort)tryMove.Y;
                            Direction = dir;
                            Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            LastMove = Common.Clock;
                        }
                        else if (Common.Clock - LastMove > BaseMonster.MoveSpeed * 5)
                        {
                            Mode = MonsterMode.Encircle;
                        }
                    }
                    else
                    {
                        LastAttack = Common.Clock - AttackSpeed + 100;
                        Mode       = MonsterMode.Attack;
                    }
                }

                break;
            }
            }
        }
예제 #11
0
        public void Monster_Timer()
        {
            //Perform all monster logic here
            switch (Mode)
            {
            case MonsterMode.Attack:
            {
                var target = Map.Search <Entity>(TargetID);
                if (target == null || !target.Alive || target.HasEffect(ClientEffect.Fly))
                {
                    Mode = MonsterMode.Idle; return;
                }
                var dist = Calculations.GetDistance(Location, target.Location);
                if (dist > BaseMonster.ViewRange)
                {
                    Mode = MonsterMode.Idle;
                }
                else if (dist > BaseMonster.AttackRange)
                {
                    Mode = MonsterMode.Walk;
                }
                else if (Common.Clock - LastAttack > BaseMonster.AttackSpeed)
                {
                    LastAttack = Common.Clock;
                    CombatEngine.ProcessInteractionPacket(InteractPacket.Create(UID, TargetID, target.X, target.Y, InteractAction.Attack, 0));
                }

                break;
            }

            case MonsterMode.Idle:
            {
                var d1 = BaseMonster.ViewRange;
                foreach (var t in Map.QueryScreen <Entity>(this))
                {
                    if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection))
                    {
                        continue;
                    }
                    var d2 = Calculations.GetDistance(Location, t.Location);
                    if (d2 < d1)
                    {
                        d1       = d2;
                        TargetID = t.UID;
                        if (d2 <= BaseMonster.AttackRange)
                        {
                            break;
                        }
                    }
                }
                var Target = Map.Search <Entity>(TargetID);
                if (Target == null)
                {
                    return;
                }
                var dist = Calculations.GetDistance(Location, Target.Location);
                if (dist < BaseMonster.AttackRange)
                {
                    Mode = MonsterMode.Attack;
                }
                else if (dist < BaseMonster.ViewRange)
                {
                    Mode = MonsterMode.Walk;
                }
                else if (BaseMonster.Mesh != 900 && Common.Clock - LastMove > BaseMonster.MoveSpeed * 4)
                {
                    var   dir     = (byte)Common.Random.Next(9);
                    Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]);
                    if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster))
                    {
                        //Send to screen new walk packet
                        SendToScreen(WalkPacket.Create(UID, dir));
                        Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                        X         = (ushort)tryMove.X;
                        Y         = (ushort)tryMove.Y;
                        Direction = dir;
                        Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                        LastMove = Common.Clock;
                        UpdateSurroundings();
                    }
                }
                break;
            }

            case MonsterMode.Walk:
            {
                var target = Map.Search <Entity>(TargetID);
                if (target == null || !target.Alive || (BaseMonster.Mesh != 900 && target.HasEffect(ClientEffect.Fly)))
                {
                    Mode = MonsterMode.Idle;
                }
                else if (Common.Clock - LastMove > BaseMonster.MoveSpeed)
                {
                    var dist = Calculations.GetDistance(Location, target.Location);
                    if (dist > BaseMonster.ViewRange)
                    {
                        Mode = MonsterMode.Idle;
                    }
                    else if (dist > BaseMonster.AttackRange)
                    {
                        var   dir     = Calculations.GetDirection(Location, target.Location);
                        Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]);
                        if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster))
                        {
                            //Send to screen new walk packet
                            SendToScreen(WalkPacket.Create(UID, dir));
                            Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            X = (ushort)tryMove.X;
                            Y = (ushort)tryMove.Y;
                            Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster);
                            LastMove = Common.Clock;
                        }
                        else if (Common.Clock - LastMove > BaseMonster.MoveSpeed * 5)
                        {
                            Mode = MonsterMode.Idle;
                        }
                    }
                    else
                    {
                        LastAttack = Common.Clock;
                        Mode       = MonsterMode.Attack;
                    }
                }
                break;
            }
            }
        }