Exemplo n.º 1
0
 /// <summary>
 /// Follow the Monsters target to it's position.
 /// </summary>
 /// <param name="targetSession">The TargetSession to follow</param>
 private void FollowTarget(ClientSession targetSession)
 {
     if (IsMoving)
     {
         if (!Path.Any() && targetSession != null)
         {
             short xoffset = (short)ServerManager.Instance.RandomNumber(-1, 1);
             short yoffset = (short)ServerManager.Instance.RandomNumber(-1, 1);
             try
             {
                 List <Node> list = BestFirstSearch.TracePath(new Node()
                 {
                     X = MapX, Y = MapY
                 }, targetSession.Character.BrushFire, targetSession.Character.MapInstance.Map.Grid);
                 Path = list;
             }
             catch (Exception ex)
             {
                 Logger.Log.Error($"Pathfinding using Pathfinder failed. Map: {MapId} StartX: {MapX} StartY: {MapY} TargetX: {(short)(targetSession.Character.PositionX + xoffset)} TargetY: {(short)(targetSession.Character.PositionY + yoffset)}", ex);
                 RemoveTarget();
             }
         }
         if (targetSession == null || MapId != targetSession.Character.MapInstance.Map.MapId)
         {
             RemoveTarget();
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Follow the Monsters target to it's position.
        /// </summary>
        /// <param name="targetSession">The TargetSession to follow</param>
        private void FollowTarget(ClientSession targetSession)
        {
            if (IsMoving)
            {
                short maxDistance = 22;
                int   distance    = 0;
                if (!Path.Any() && targetSession != null)
                {
                    short xoffset = (short)ServerManager.Instance.RandomNumber(-1, 1);
                    short yoffset = (short)ServerManager.Instance.RandomNumber(-1, 1);
                    try
                    {
                        List <Node> list = BestFirstSearch.TracePath(new Node()
                        {
                            X = MapX, Y = MapY
                        }, targetSession.Character.BrushFire, targetSession.Character.MapInstance.Map.Grid);
                        Path = list;
                    }
                    catch (Exception ex)
                    {
                        Logger.Log.Error($"Pathfinding using Pathfinder failed. Map: {MapId} StartX: {MapX} StartY: {MapY} TargetX: {(short)(targetSession.Character.PositionX + xoffset)} TargetY: {(short)(targetSession.Character.PositionY + yoffset)}", ex);
                        RemoveTarget();
                    }
                }
                if (Monster != null && DateTime.Now > LastMove && Monster.Speed > 0 && Path.Any())
                {
                    int    maxindex    = Path.Count > Monster.Speed / 2 ? Monster.Speed / 2 : Path.Count;
                    short  mapX        = Path.ElementAt(maxindex - 1).X;
                    short  mapY        = Path.ElementAt(maxindex - 1).Y;
                    double waitingtime = Map.GetDistance(new MapCell {
                        X = mapX, Y = mapY
                    }, new MapCell {
                        X = MapX, Y = MapY
                    }) / (double)Monster.Speed;
                    MapInstance.Broadcast(new BroadcastPacket(null, $"mv 3 {MapMonsterId} {mapX} {mapY} {Monster.Speed}", ReceiverType.All, xCoordinate: mapX, yCoordinate: mapY));
                    LastMove = DateTime.Now.AddSeconds(waitingtime > 1 ? 1 : waitingtime);

                    Observable.Timer(TimeSpan.FromMilliseconds((int)((waitingtime > 1 ? 1 : waitingtime) * 1000))).Subscribe(x =>
                    {
                        MapX = mapX;
                        MapY = mapY;
                    });
                    distance = (int)Path.First().F;
                    Path.RemoveRange(0, maxindex);
                }

                if (targetSession == null || MapId != targetSession.Character.MapInstance.Map.MapId || distance > maxDistance)
                {
                    RemoveTarget();
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Follow the Monsters target to it's position.
 /// </summary>
 /// <param name="targetSession">The TargetSession to follow</param>
 private void FollowTarget()
 {
     if (Monster == null || !IsAlive || HasBuff(CardType.Move, (byte)AdditionalTypes.Move.MovementImpossible) || !IsMoving)
     {
         return;
     }
     if (!Target?.IsTargetable(SessionType()) ?? true)
     {
         RemoveTarget();
         return;
     }
     if (!Path.Any() && Target.MapInstance != null)
     {
         Path = BestFirstSearch.TracePath(new Node()
         {
             X = MapX, Y = MapY
         }, Target.GetBrushFire(), MapInstance.Map.Grid);
     }
     Move(); // follow the target
 }
Exemplo n.º 4
0
        /// <summary>
        /// Follow the Monsters target to it's position.
        /// </summary>
        /// <param name="targetSession">The TargetSession to follow</param>
        private void followTarget(ClientSession targetSession)
        {
            if (IsMoving && !_noMove)
            {
                const short maxDistance = 22;
                int         distance    = Map.GetDistance(new MapCell()
                {
                    X = targetSession.Character.PositionX, Y = targetSession.Character.PositionY
                }, new MapCell()
                {
                    X = MapX, Y = MapY
                });
                if (targetSession != null)
                {
                    if (targetSession.Character.LastMonsterAggro.AddSeconds(5) < DateTime.Now || targetSession.Character.BrushFire == null)
                    {
                        targetSession.Character.UpdateBushFire();
                    }
                    targetSession.Character.LastMonsterAggro = DateTime.Now;
                }
                if (Path.Count == 0 && targetSession != null)
                {
                    short xoffset = (short)ServerManager.Instance.RandomNumber(-1, 1);
                    short yoffset = (short)ServerManager.Instance.RandomNumber(-1, 1);
                    try
                    {
                        Path = BestFirstSearch.TracePath(new Node()
                        {
                            X = MapX, Y = MapY
                        }, targetSession.Character.BrushFire, targetSession.Character.MapInstance.Map.Grid);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error($"Pathfinding using Pathfinder failed. Map: {MapId} StartX: {MapX} StartY: {MapY} TargetX: {(short)(targetSession.Character.PositionX + xoffset)} TargetY: {(short)(targetSession.Character.PositionY + yoffset)}", ex);
                        RemoveTarget();
                    }
                }
                if (Monster != null && DateTime.Now > LastMove && Monster.Speed > 0 && Path.Count > 0)
                {
                    int    maxindex    = Path.Count > Monster.Speed / 2 ? Monster.Speed / 2 : Path.Count;
                    short  mapX        = Path[maxindex - 1].X;
                    short  mapY        = Path[maxindex - 1].Y;
                    double waitingtime = Map.GetDistance(new MapCell {
                        X = mapX, Y = mapY
                    }, new MapCell {
                        X = MapX, Y = MapY
                    }) / (double)Monster.Speed;
                    MapInstance.Broadcast(new BroadcastPacket(null, PacketFactory.Serialize(StaticPacketHelper.Move(UserType.Monster, MapMonsterId, mapX, mapY, Monster.Speed)), ReceiverType.All, xCoordinate: mapX, yCoordinate: mapY));
                    LastMove = DateTime.Now.AddSeconds(waitingtime > 1 ? 1 : waitingtime);

                    Observable.Timer(TimeSpan.FromMilliseconds((int)((waitingtime > 1 ? 1 : waitingtime) * 1000))).Subscribe(x =>
                    {
                        MapX = mapX;
                        MapY = mapY;
                    });
                    distance = (int)Path[0].F;
                    Path.RemoveRange(0, maxindex > Path.Count ? Path.Count : maxindex);
                }

                if (targetSession == null || MapId != targetSession.Character.MapInstance.Map.MapId || distance > (maxDistance) + 3)
                {
                    RemoveTarget();
                }
            }
        }