Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 53 additions & 54 deletions decoder/api_pokemon_common.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
package decoder

import (
"github.com/UnownHash/gohbem"
"github.com/UnownHash/gohbem"
)

func buildApiPokemonResult(pokemon *Pokemon) ApiPokemonResult {
return ApiPokemonResult{
Id: pokemon.Id,
PokestopId: pokemon.PokestopId,
SpawnId: pokemon.SpawnId,
Lat: pokemon.Lat,
Lon: pokemon.Lon,
Weight: pokemon.Weight,
Size: pokemon.Size,
Height: pokemon.Height,
ExpireTimestamp: pokemon.ExpireTimestamp,
Updated: pokemon.Updated,
PokemonId: pokemon.PokemonId,
Move1: pokemon.Move1,
Move2: pokemon.Move2,
Gender: pokemon.Gender,
Cp: pokemon.Cp,
AtkIv: pokemon.AtkIv,
DefIv: pokemon.DefIv,
StaIv: pokemon.StaIv,
Iv: pokemon.Iv,
Form: pokemon.Form,
Level: pokemon.Level,
Weather: pokemon.Weather,
Costume: pokemon.Costume,
FirstSeenTimestamp: pokemon.FirstSeenTimestamp,
Changed: pokemon.Changed,
CellId: pokemon.CellId,
ExpireTimestampVerified: pokemon.ExpireTimestampVerified,
DisplayPokemonId: pokemon.DisplayPokemonId,
IsDitto: pokemon.IsDitto,
SeenType: pokemon.SeenType,
Shiny: pokemon.Shiny,
Username: pokemon.Username,
Pvp: func() map[string][]gohbem.PokemonEntry {
if ohbem != nil {
pvp, err := ohbem.QueryPvPRank(int(pokemon.PokemonId),
int(pokemon.Form.ValueOrZero()),
int(pokemon.Costume.ValueOrZero()),
int(pokemon.Gender.ValueOrZero()),
int(pokemon.AtkIv.ValueOrZero()),
int(pokemon.DefIv.ValueOrZero()),
int(pokemon.StaIv.ValueOrZero()),
float64(pokemon.Level.ValueOrZero()))
if err != nil {
return nil
}
return pvp
}
return nil
}(),
}
return ApiPokemonResult{
Id: pokemon.Id,
PokestopId: pokemon.PokestopId,
SpawnId: pokemon.SpawnId,
Lat: pokemon.Lat,
Lon: pokemon.Lon,
Weight: pokemon.Weight,
Size: pokemon.Size,
Height: pokemon.Height,
ExpireTimestamp: pokemon.ExpireTimestamp,
Updated: pokemon.Updated,
PokemonId: pokemon.PokemonId,
Move1: pokemon.Move1,
Move2: pokemon.Move2,
Gender: pokemon.Gender,
Cp: pokemon.Cp,
AtkIv: pokemon.AtkIv,
DefIv: pokemon.DefIv,
StaIv: pokemon.StaIv,
Iv: pokemon.Iv,
Form: pokemon.Form,
Level: pokemon.Level,
Weather: pokemon.Weather,
Costume: pokemon.Costume,
FirstSeenTimestamp: pokemon.FirstSeenTimestamp,
Changed: pokemon.Changed,
CellId: pokemon.CellId,
ExpireTimestampVerified: pokemon.ExpireTimestampVerified,
DisplayPokemonId: pokemon.DisplayPokemonId,
IsDitto: pokemon.IsDitto,
SeenType: pokemon.SeenType,
Shiny: pokemon.Shiny,
Background: pokemon.Background,
Username: pokemon.Username,
Pvp: func() map[string][]gohbem.PokemonEntry {
if ohbem != nil {
pvp, err := ohbem.QueryPvPRank(int(pokemon.PokemonId),
int(pokemon.Form.ValueOrZero()),
int(pokemon.Costume.ValueOrZero()),
int(pokemon.Gender.ValueOrZero()),
int(pokemon.AtkIv.ValueOrZero()),
int(pokemon.DefIv.ValueOrZero()),
int(pokemon.StaIv.ValueOrZero()),
float64(pokemon.Level.ValueOrZero()))
if err != nil {
return nil
}
return pvp
}
return nil
}(),
}
}


2 changes: 2 additions & 0 deletions decoder/api_pokemon_scan_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ApiPokemonResult struct {
IsDitto bool `json:"is_ditto"`
SeenType null.String `json:"seen_type"`
Shiny null.Bool `json:"shiny"`
Background null.Int `json:"background"`
Username null.String `json:"username"`
Capture1 null.Float `json:"capture_1"`
Capture2 null.Float `json:"capture_2"`
Expand Down Expand Up @@ -308,6 +309,7 @@ func GetPokemonInArea(retrieveParameters ApiPokemonScan) []*ApiPokemonResult {
IsDitto: pokemon.IsDitto,
SeenType: pokemon.SeenType,
Shiny: pokemon.Shiny,
Background: pokemon.Background,
Username: pokemon.Username,
Pvp: func() map[string][]gohbem.PokemonEntry {
if ohbem != nil {
Expand Down
16 changes: 12 additions & 4 deletions decoder/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"golbat/util"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -68,6 +69,7 @@ type Pokemon struct {
IsDitto bool `db:"is_ditto" json:"is_ditto"`
SeenType null.String `db:"seen_type" json:"seen_type"`
Shiny null.Bool `db:"shiny" json:"shiny"`
Background null.Int `db:"background" json:"background"`
Username null.String `db:"username" json:"username"`
Capture1 null.Float `db:"capture_1" json:"capture_1"`
Capture2 null.Float `db:"capture_2" json:"capture_2"`
Expand Down Expand Up @@ -109,6 +111,7 @@ type Pokemon struct {
//`display_pokemon_id` smallint unsigned DEFAULT NULL,
//`seen_type` enum('wild','encounter','nearby_stop','nearby_cell') DEFAULT NULL,
//`shiny` tinyint(1) DEFAULT '0',
//`background` smallint unsigned DEFAULT NULL,
//`username` varchar(32) DEFAULT NULL,
//`capture_1` double(18,14) DEFAULT NULL,
//`capture_2` double(18,14) DEFAULT NULL,
Expand Down Expand Up @@ -148,7 +151,7 @@ func getPokemonRecord(ctx context.Context, db db.DbDetails, encounterId uint64)
"SELECT id, pokemon_id, lat, lon, spawn_id, expire_timestamp, atk_iv, def_iv, sta_iv, golbat_internal, iv, "+
"move_1, move_2, gender, form, cp, level, strong, weather, costume, weight, height, size, "+
"display_pokemon_id, is_ditto, pokestop_id, updated, first_seen_timestamp, changed, cell_id, "+
"expire_timestamp_verified, shiny, username, pvp, is_event, seen_type "+
"expire_timestamp_verified, shiny, background, username, pvp, is_event, seen_type "+
"FROM pokemon WHERE id = ?", strconv.FormatUint(encounterId, 10))

statsCollector.IncDbQuery("select pokemon", err)
Expand Down Expand Up @@ -211,6 +214,7 @@ func hasChangesPokemon(old *Pokemon, new *Pokemon) bool {
old.IsDitto != new.IsDitto ||
old.SeenType != new.SeenType ||
old.Shiny != new.Shiny ||
old.Background != new.Background ||
old.IsEvent != new.IsEvent ||
!floatAlmostEqual(old.Lat, new.Lat, floatTolerance) ||
!floatAlmostEqual(old.Lon, new.Lon, floatTolerance) ||
Expand Down Expand Up @@ -315,12 +319,12 @@ func savePokemonRecordAsAtTime(ctx context.Context, db db.DbDetails, pokemon *Po
"spawn_id, expire_timestamp, atk_iv, def_iv, sta_iv, golbat_internal, iv, move_1, move_2,"+
"gender, form, cp, level, strong, weather, costume, weight, height, size,"+
"display_pokemon_id, is_ditto, pokestop_id, updated, first_seen_timestamp, changed, cell_id,"+
"expire_timestamp_verified, shiny, username, %s is_event, seen_type) "+
"expire_timestamp_verified, shiny, background, username, %s is_event, seen_type) "+
"VALUES (\"%d\", :pokemon_id, :lat, :lon, :spawn_id, :expire_timestamp, :atk_iv, :def_iv, :sta_iv,"+
":golbat_internal, :iv, :move_1, :move_2, :gender, :form, :cp, :level, :strong, :weather, :costume,"+
":weight, :height, :size, :display_pokemon_id, :is_ditto, :pokestop_id, :updated,"+
":first_seen_timestamp, :changed, :cell_id, :expire_timestamp_verified, :shiny, :username, %s :is_event,"+
":seen_type)", pvpField, pokemon.Id, pvpValue), pokemon)
":first_seen_timestamp, :changed, :cell_id, :expire_timestamp_verified, :shiny, :background, :username,"+
"%s :is_event, :seen_type)", pvpField, pokemon.Id, pvpValue), pokemon)

statsCollector.IncDbQuery("insert pokemon", err)
if err != nil {
Expand Down Expand Up @@ -369,6 +373,7 @@ func savePokemonRecordAsAtTime(ctx context.Context, db db.DbDetails, pokemon *Po
"is_ditto = :is_ditto, "+
"seen_type = :seen_type, "+
"shiny = :shiny, "+
"background = :background, "+
"username = :username, "+
"%s"+
"is_event = :is_event "+
Expand Down Expand Up @@ -476,6 +481,7 @@ func createPokemonWebhooks(ctx context.Context, db db.DbDetails, old *Pokemon, n
"capture_2": new.Capture2.ValueOrZero(),
"capture_3": new.Capture3.ValueOrZero(),
"shiny": new.Shiny,
"background": new.Background,
"username": new.Username,
"display_pokemon_id": new.DisplayPokemonId,
"is_event": new.IsEvent,
Expand Down Expand Up @@ -1243,6 +1249,7 @@ func (pokemon *Pokemon) setPokemonDisplay(pokemonId int16, display *pogo.Pokemon
if oldId != pokemonId || pokemon.Form != null.IntFrom(int64(display.Form)) ||
pokemon.Costume != null.IntFrom(int64(display.Costume)) ||
pokemon.Gender != null.IntFrom(int64(display.Gender)) ||
pokemon.Background != null.IntFromPtr(util.ExtractBackgroundFromDisplay(display)) ||
pokemon.IsStrong.ValueOrZero() != display.IsStrongPokemon {
log.Debugf("Pokemon %d changed from (%d,%d,%d,%d,%t) to (%d,%d,%d,%d,%t)", pokemon.Id, oldId,
pokemon.Form.ValueOrZero(), pokemon.Costume.ValueOrZero(), pokemon.Gender.ValueOrZero(),
Expand All @@ -1266,6 +1273,7 @@ func (pokemon *Pokemon) setPokemonDisplay(pokemonId int16, display *pogo.Pokemon
pokemon.Gender = null.IntFrom(int64(display.Gender))
pokemon.Form = null.IntFrom(int64(display.Form))
pokemon.Costume = null.IntFrom(int64(display.Costume))
pokemon.Background = null.IntFromPtr(util.ExtractBackgroundFromDisplay(display))
if !pokemon.isNewRecord() {
pokemon.repopulateIv(int64(display.WeatherBoostedCondition), display.IsStrongPokemon)
}
Expand Down
2 changes: 2 additions & 0 deletions sql/50_pokemon_background.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE pokemon
add `background` smallint unsigned DEFAULT NULL AFTER `shiny`;