diff --git a/decoder/api_pokemon_common.go b/decoder/api_pokemon_common.go index d492a0f0..d62381a0 100644 --- a/decoder/api_pokemon_common.go +++ b/decoder/api_pokemon_common.go @@ -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 + }(), + } } - - diff --git a/decoder/api_pokemon_scan_v1.go b/decoder/api_pokemon_scan_v1.go index c0f6f35e..4b3fcb65 100644 --- a/decoder/api_pokemon_scan_v1.go +++ b/decoder/api_pokemon_scan_v1.go @@ -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"` @@ -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 { diff --git a/decoder/pokemon.go b/decoder/pokemon.go index 9244cc2b..a8322c36 100644 --- a/decoder/pokemon.go +++ b/decoder/pokemon.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "golbat/util" "strconv" "strings" "sync" @@ -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"` @@ -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, @@ -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) @@ -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) || @@ -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 { @@ -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 "+ @@ -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, @@ -775,6 +781,7 @@ func (pokemon *Pokemon) setDittoAttributes(mode string, isDitto bool, old, new * pokemon.IsDitto = true pokemon.DisplayPokemonId = null.IntFrom(int64(pokemon.PokemonId)) pokemon.PokemonId = int16(pogo.HoloPokemonId_DITTO) + pokemon.Form = null.IntFrom(0) } else { log.Debugf("[POKEMON] %d: %s not Ditto found %s -> %s", pokemon.Id, mode, old, new) } @@ -1243,6 +1250,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(), @@ -1266,6 +1274,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) } diff --git a/sql/50_pokemon_background.up.sql b/sql/50_pokemon_background.up.sql new file mode 100644 index 00000000..8dcf5d0a --- /dev/null +++ b/sql/50_pokemon_background.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE pokemon + add `background` smallint unsigned DEFAULT NULL AFTER `shiny`;