예제 #1
0
        public static Spawnpoint FromPokemon(WildPokemonProto wild)
        {
            var now        = DateTime.UtcNow.ToTotalSeconds();
            var spawnpoint = new Spawnpoint
            {
                Id        = Convert.ToUInt64(wild.SpawnPointId, 16),
                Latitude  = wild.Latitude,
                Longitude = wild.Longitude,
                Updated   = now,
            };
            var tthMs = wild.TimeTillHiddenMs;

            if (tthMs > 0 && tthMs <= 90000)
            {
                //wild.LastModifiedMs
                var unixDate      = DateTime.UtcNow;
                var secondsOfHour = unixDate.Minute * 60 + unixDate.Second;
                var despawnSec    = (int)Math.Round(tthMs / 1000.0);
                var offset        = secondsOfHour + despawnSec;
                if (offset > 3600)
                {
                    offset -= 3600;
                }
                spawnpoint.DespawnSecond = (ushort)(secondsOfHour + offset);
            }
            return(spawnpoint);
        }
예제 #2
0
        public async Task <Spawnpoint> HandleSpawnpoint(int timeTillHiddenMs, ulong timestampMs)
        {
            var now = DateTime.UtcNow.ToTotalSeconds();

            if (timeTillHiddenMs <= 90000 && timeTillHiddenMs > 0)
            {
                ExpireTimestamp           = Convert.ToUInt64(timestampMs + Convert.ToDouble(timeTillHiddenMs)) / 1000;
                IsExpireTimestampVerified = true;
                var unixDate     = timestampMs.FromMilliseconds();
                var secondOfHour = unixDate.Second + (unixDate.Minute * 60);
                return(new Spawnpoint
                {
                    Id = SpawnId ?? 0,
                    Latitude = Latitude,
                    Longitude = Longitude,
                    Updated = now,
                    DespawnSecond = (ushort)secondOfHour,
                    FirstSeenTimestamp = now,
                });
            }
            else
            {
                IsExpireTimestampVerified = false;
            }

            if (!IsExpireTimestampVerified && SpawnId != null)
            {
                Spawnpoint spawnpoint = null;
                try
                {
                    if (SpawnId != null)
                    {
                        // spawnpoint = await _spawnpointRepository.GetByIdAsync(SpawnId ?? 0).ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    ConsoleExt.WriteError($"[Pokemon] Error: {ex}");
                    spawnpoint = null;
                }
                if (spawnpoint != null && spawnpoint?.DespawnSecond != null)
                {
                    var unixDate      = timestampMs.FromMilliseconds();
                    var secondOfHour  = unixDate.Second + (unixDate.Minute * 60);
                    var despawnOffset = spawnpoint.DespawnSecond - secondOfHour;
                    if (spawnpoint.DespawnSecond < secondOfHour)
                    {
                        despawnOffset += 3600;
                    }
                    ExpireTimestamp           = now + (ulong)(despawnOffset ?? 0);
                    IsExpireTimestampVerified = true;
                }
                else
                {
                    spawnpoint = new Spawnpoint
                    {
                        Id                 = SpawnId ?? 0,
                        Latitude           = Latitude,
                        Longitude          = Longitude,
                        Updated            = now,
                        DespawnSecond      = null,
                        FirstSeenTimestamp = now,
                    };
                }
                return(await Task.FromResult(spawnpoint).ConfigureAwait(false));
            }

            if (ExpireTimestamp == 0)
            {
                //Console.WriteLine($"[Pokemon] ExpireTimestamp == 0");
                ExpireTimestamp           = DateTime.UtcNow.ToTotalSeconds();
                IsExpireTimestampVerified = false;
            }
            return(null);
        }