Beispiel #1
0
        public void AnimateMarker(double duration, LatLng startPosition, List <LatLng> wayPoints, int position)
        {
            if (wayPoints == null || !wayPoints.Any() || duration == 0)
            {
                return;
            }
            if (!isInit)
            {
                totalDuration = duration;
                totalDistance = CalculatorDistance(startPosition, wayPoints);
                isInit        = true;
            }
            Handler handler      = new Handler();
            long    start        = SystemClock.UptimeMillis();
            var     interpolator = new LinearInterpolator();
            var     nextLocation = wayPoints[position];
            var     nextDuration = MapHelpers.GetDistance(startPosition.Latitude, startPosition.Longitude,
                                                          nextLocation.Latitude, nextLocation.Longitude) * 1.0 / totalDistance * totalDuration;

            handler.Post(new MoveRunnable(_mMap, handler, interpolator, _mMarker, start, startPosition, nextLocation, nextDuration,
                                          () =>
            {
                position++;
                if (wayPoints.Count > position)
                {
                    AnimateMarker(duration, _mMarker.Position, wayPoints, position);
                }
                else
                {
                    _mMarker.Remove();
                }
            }));
        }
Beispiel #2
0
 public CastleByDistanceModel GetNearestCastle(List <string> castles, double lat, double lng)
 {
     return(Castles.Where(c => castles.Contains(c.Id)).Select(c => new CastleByDistanceModel
     {
         Castle = c,
         Distance = MapHelpers.GetDistance(c.Position.Lat, c.Position.Lng, lat,
                                           lng)
     }).OrderBy(d => d.Distance).First());
 }
Beispiel #3
0
        // server recieving entitymove means its a player moving
        public void OnEntityMovePacket(EntityMovePacket packet)
        {
            var player        = Server.GetPlayerByConnectionId(packet.ClientId);
            var distanceMoved = MapHelpers.GetDistance(player.Position, packet.To);
            var timeToMove    = Formulas.GetTimeToMoveBetweenTwoTiles(player.MoveSpeed);

            Log.Info("TIME TO MOVE " + timeToMove);

            var now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            // Player tryng to hack ?
            if (distanceMoved > 1 || now < player.CanMoveAgainTime)
            {
                Log.Debug($"Player time to move {player.CanMoveAgainTime - now}");
                // send player back to the position client-side
                player.Tcp.Send(new SyncPacket()
                {
                    Position = player.Position
                });
                return;
            }

            // subtract the player latency for possibility of lag for a smoother movement
            player.CanMoveAgainTime = now + timeToMove - player.Tcp.Latency;

            var entityMoveEvent = new EntityMoveEvent()
            {
                From   = packet.From,
                To     = packet.To,
                Entity = player
            };

            Server.Events.Call(entityMoveEvent);

            if (entityMoveEvent.IsCancelled)
            {
                // send player back to the position client-side
                player.Tcp.Send(new SyncPacket()
                {
                    Position = player.Position
                });
                return;
            }

            // Updating player position locally
            player.Position.X = packet.To.X;
            player.Position.Y = packet.To.Y;

            // updating in database
            PlayerService.UpdatePlayerPosition(player.UID, player.Position.X, player.Position.Y);
        }
 private bool NeedUpdateRotation()
 {
     if (_marker == null)
     {
         return(false);
     }
     if (_lastUpdatedLocation == null)
     {
         return(true);
     }
     if (MapHelpers.GetDistance(_marker.Position.Latitude, _marker.Position.Longitude, _lastUpdatedLocation.Latitude, _lastUpdatedLocation.Longitude) * 1000 >
         3)
     {
         return(true);
     }
     return(false);
 }
Beispiel #5
0
        private double CalculatorDistance(LatLng start, List <LatLng> wayPoints)
        {
            if (!(wayPoints?.Any() ?? false))
            {
                return(0);
            }

            double distance      = 0;
            var    startLocation = start;

            for (int i = 0; i < wayPoints.Count; i++)
            {
                var nextLocation = wayPoints[i];
                distance += MapHelpers.GetDistance(startLocation.Latitude, startLocation.Longitude,
                                                   nextLocation.Latitude, nextLocation.Longitude);
                startLocation = nextLocation;
            }

            return(distance);
        }