Beispiel #1
0
        private void Move()
        {
            if (Monster == null || !IsAlive || HasBuff(CardType.Move, (byte)AdditionalTypes.Move.MovementImpossible))
            {
                return;
            }

            if (IsMoving && Monster.Speed > 0)
            {
                if (!Path.Any() && (DateTime.Now - LastMove).TotalMilliseconds > _movetime && Target == null
                    ) // Basic Move
                {
                    short mapX = FirstX, mapY = FirstY;
                    if (MapInstance.Map?.GetFreePosition(ref mapX, ref mapY,
                                                         (byte)ServerManager.Instance.RandomNumber(0, 2), (byte)_random.Next(0, 2)) ?? false)
                    {
                        int distance = Map.GetDistance(new MapCell {
                            X = mapX, Y = mapY
                        }, GetPos());
                        double value = 1000d * distance / (2 * Monster.Speed);
                        Observable.Timer(TimeSpan.FromMilliseconds(value)).Subscribe(x =>
                        {
                            MapX = mapX;
                            MapY = mapY;
                        });
                        LastMove = DateTime.Now.AddMilliseconds(value);
                        MapInstance.Broadcast(new BroadcastPacket(null, GenerateMv3(), ReceiverType.All));
                    }
                }
                else if (DateTime.Now > LastMove && Path.Any()) // Follow target || move back to original pos
                {
                    byte   speedIndex  = (byte)(Monster.Speed / 2 < 1 ? 1 : Monster.Speed / 2);
                    int    maxindex    = Path.Count > speedIndex ? speedIndex : Path.Count;
                    short  smapX       = Path[maxindex - 1].X;
                    short  smapY       = Path[maxindex - 1].Y;
                    double waitingtime = Map.GetDistance(new MapCell {
                        X = smapX, Y = smapY
                    }, GetPos()) /
                                         (double)Monster.Speed;
                    MapInstance.Broadcast(new BroadcastPacket(null,
                                                              $"mv 3 {MapMonsterId} {smapX} {smapY} {Monster.Speed}", ReceiverType.All, xCoordinate: smapX,
                                                              yCoordinate: smapY));
                    LastMove = DateTime.Now.AddSeconds(waitingtime > 1 ? 1 : waitingtime);
                    Observable.Timer(TimeSpan.FromMilliseconds((int)((waitingtime > 1 ? 1 : waitingtime) * 1000)))
                    .Subscribe(x =>
                    {
                        MapX = smapX;
                        MapY = smapY;
                    });
                    if (Target != null && (int)Path[0].F > _maxDistance
                        ) // Remove Target if distance between target & monster is > max Distance
                    {
                        RemoveTarget();
                        return;
                    }

                    if (maxindex <= Path.Count)
                    {
                        Path.RemoveRange(0, maxindex);
                    }
                }
            }

            HostilityTarget();
        }
Beispiel #2
0
 public void Initialize(MapInstance currentMapInstance)
 {
     MapInstance = currentMapInstance;
     Initialize();
 }