public PokemonLocation AddLocation(PokemonLocation location) { var locations = _db.GetCollection <PokemonLocation>("PokemonLocations"); locations.Insert(location); return(location); }
public PokemonLocation UpdateInstances(PokemonLocation location) { var locations = _db.GetCollection <PokemonLocation>("PokemonLocations"); var idQuery = Query <PokemonLocation> .EQ(e => e.Id, location.Id); var update = Update <PokemonLocation> .Set(x => x.Times, location.Times) .Set(x => x.LastSighted, location.LastSighted) .Set(x => x.FirstClusterId, location.FirstClusterId) .Set(x => x.SecondClusterId, location.SecondClusterId) .Set(x => x.ThirdClusterId, location.ThirdClusterId) .Set(x => x.FourthClusterId, location.FourthClusterId); var result = locations.FindAndModify(idQuery, SortBy.Descending("Id"), update); return(location); }
public ActionResult AddPokemonLocation(int pokeIndexNum, double lng, double lat, DateTime date) { if (IsSpam(Request.UserHostAddress, Request.UserAgent)) { return(Json("Nope", JsonRequestBehavior.AllowGet)); } if (date > DateTime.UtcNow) // Bug.. Not going to be accurate between UTC and client Date. Maybe check if it's more than 1 day in the future? Fix it { date = DateTime.UtcNow; } var dateTime = new HourMinute() { DayOfWeek = date.DayOfWeek.ToString(), TimeOfDay = (date.Hour > 12) ? "PM" : "AM", Minute = date.Minute, Hour = ((date.Hour == 0 ? 12 : date.Hour) > 12 ? date.Hour - 12 : date.Hour), DateAdded = DateTime.UtcNow }; var location = new PokemonLocation { Location = new GeoJson2DGeographicCoordinates(lng, lat), LastSighted = date, DateCreated = DateTime.UtcNow, PokemonName = LookupTable.GetPokemonName(pokeIndexNum), PokeIndexNum = pokeIndexNum, IpAddress = Request.UserHostAddress, UserAgent = Request.UserAgent, Times = new List <HourMinute> { dateTime } }; var pokemon = _mongoService.AddLocation(location); return(Json(pokemon, JsonRequestBehavior.AllowGet)); }
public bool Equals(PokemonLocation obj) { return(Math.Abs(latitude - obj.latitude) < 0.0001 && Math.Abs(longitude - obj.longitude) < 0.0001); }
public bool Equals(PokemonLocation obj) { return Math.Abs(latitude - obj.latitude) < 0.0001 && Math.Abs(longitude - obj.longitude) < 0.0001; }
public async Task <ObservableCollection <PokemonLocation> > LoadPokemonEncountersAsync(int pokemonId, GameVersion version, int displayLanguage, CancellationToken token) { try { string query = "SELECT enc.id, MIN(enc.min_level) AS min_level, MAX(enc.max_level) AS max_level, enc.location_area_id, SUM(es.rarity) AS rarity, ecvm.encounter_condition_value_id, ec.id AS condition_id, es.encounter_method_id FROM pokemon_v2_encounter enc\n" + "LEFT JOIN pokemon_v2_encounterslot es ON es.id = enc.encounter_slot_id\n" + "LEFT JOIN pokemon_v2_encountermethod em ON em.id = es.encounter_method_id\n" + "LEFT JOIN pokemon_v2_encounterconditionvaluemap ecvm ON ecvm.encounter_id = enc.id\n" + "LEFT JOIN pokemon_v2_encounterconditionvalue ecv ON ecv.id = ecvm.encounter_condition_value_id\n" + "LEFT JOIN pokemon_v2_encountercondition ec ON ecv.encounter_condition_id = ec.id\n" + "WHERE enc.pokemon_id = ? AND enc.version_id = ?\n" + "GROUP BY enc.location_area_id, es.encounter_method_id, ecvm.encounter_condition_value_id\n" + "ORDER BY enc.location_area_id, ec.id, ecvm.encounter_condition_value_id"; IEnumerable <DbPokemonEncounter> encounters = await _connection.QueryAsync <DbPokemonEncounter>(token, query, new object[] { pokemonId, version.Id }); var result = new ObservableCollection <PokemonLocation>(); foreach (DbPokemonEncounter encounter in encounters) { PokemonLocation location = null; //Check if there is another encounter on the same area with the same condition or null condition but another slot PokemonLocation location2 = result.FirstOrDefault(f => f.Location.AreaId == encounter.LocationAreaId && encounter.EncounterMethodId == f.EncounterMethod.Id && (encounter.EncounterConditionValueId == null || f.Conditions.Any() == false || (f.Conditions.Any() && f.Conditions.FirstOrDefault(x => x.Id == (int)encounter.EncounterConditionValueId) != null))); // Merge encounter with same area and condition if (location2 != null) { location2.Rarity += encounter.Rarity; location = location2; } else { location = result.FirstOrDefault(f => f.Id == encounter.Id); } if (location == null) { location = new PokemonLocation { Id = encounter.Id, MaxLevel = encounter.MaxLevel, MinLevel = encounter.MinLevel, Rarity = encounter.Rarity }; location.EncounterMethod = await GetEncounterMethodAsync(encounter.EncounterMethodId); location.Location = await LoadLocationFromAreaAsync(encounter.LocationAreaId, version, displayLanguage, token); } // Filter out double encounter conditions if (encounter.EncounterConditionValueId != null && location.Conditions.FirstOrDefault(f => f.Id == (int)encounter.EncounterConditionValueId) == null) { //if (encounter.EncounterConditionValueId != null) location.Conditions.Add(await GetEncounterConditionAsync((int)encounter.EncounterConditionValueId)); } if (location2 == null) { result.Add(location); } } return(result); } catch (Exception) { return(new ObservableCollection <PokemonLocation>()); } }