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; } }
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; } } }
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; } } }