Documentation ¶
Index ¶
- Constants
- Variables
- func RankingComparatorDefault(a, b *PvPRankingStats) int
- func RankingComparatorPreferHigherCp(a, b *PvPRankingStats) int
- func RankingComparatorPreferLowerCp(a, b *PvPRankingStats) int
- type Evolution
- type Form
- type League
- type Logger
- type Ohbem
- func (o *Ohbem) CalculateCp(pokemonId, form, evolution, attack, defense, stamina int, level float64) (int, error)
- func (o *Ohbem) ClearCache()
- func (o *Ohbem) FetchPokemonData() error
- func (o *Ohbem) FilterLevelCaps(entries []PokemonEntry, interestedLevelCaps []int) []PokemonEntry
- func (o *Ohbem) FindBaseStats(pokemonId int, form int, evolution int) (PokemonStats, error)
- func (o *Ohbem) IsMegaUnreleased(pokemonId int, evolution int) (bool, error)
- func (o *Ohbem) LoadPokemonData(filePath string) error
- func (o *Ohbem) QueryPvPRank(pokemonId int, form int, costume int, gender int, attack int, defense int, ...) (map[string][]PokemonEntry, error)
- func (o *Ohbem) SavePokemonData(filePath string) error
- func (o *Ohbem) StopWatchingPokemonData() error
- func (o *Ohbem) WatchPokemonData() error
- type Pokemon
- type PokemonData
- type PokemonEntry
- type PokemonStats
- type PvPRankingStats
- type Ranking
- type RankingComparator
Constants ¶
const MasterFileURL = "https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/master-latest-basics.json"
MasterFileURL is a remote address used to fetch MasterFile.
const MaxLevel = 100
MaxLevel handled by gohbem.
const VERSION = "0.10.0"
VERSION of gohbem, follows Semantic Versioning. (http://semver.org/)
Variables ¶
var ErrLeaguesMissing = errors.New("leagues configuration is empty")
ErrLeaguesMissing is returned when Leagues configuration is empty.
var ErrLevelCapsMissing = errors.New("levelCaps configuration is empty")
ErrLevelCapsMissing is returned when levelCaps configuration is empty.
var ErrMasterFileDecode = errors.New("can't decode remote MasterFile")
ErrMasterFileDecode is returned when decode of MasterFile fail.
var ErrMasterFileFetch = errors.New("can't fetch remote MasterFile")
ErrMasterFileFetch is returned when remote fetch of MasterFile fail.
var ErrMasterFileMarshall = errors.New("can't marshal MasterFile")
ErrMasterFileMarshall is returned when Marshal of MasterFile fail.
var ErrMasterFileOpen = errors.New("can't open MasterFile")
ErrMasterFileOpen is returned when MasterFile can't be open.
var ErrMasterFileSave = errors.New("can't save MasterFile")
ErrMasterFileSave is returned when MasterFile can't be saved.
var ErrMasterFileUnloaded = errors.New("masterFile unloaded")
ErrMasterFileUnloaded is returned when MasterFile wasn't loaded but there was a need to use it.
var ErrMasterFileUnmarshall = errors.New("can't unmarshal MasterFile")
ErrMasterFileUnmarshall is returned when UnMarshal of MasterFile fail.
var ErrMissingPokemon = errors.New("missing pokemonID in MasterFile")
ErrMissingPokemon is returned when Pokemon is missing in MasterFile.
var ErrNilChannel = errors.New("can't close nil channel")
ErrNilChannel is returned when o.watcherChan is uninitialized.
var ErrPvpStatBestCp = errors.New("bestCP > cap")
ErrPvpStatBestCp is returned when BestCP > Cap in calculatePvPStat function.
var ErrQueryInputOutOfRange = errors.New("one of input arguments 'Attack, Defense, Stamina, Level' is out of range")
ErrQueryInputOutOfRange is returned when wrong arguments are passed to QueryPvPRank function.
var ErrWatcherStarted = errors.New("MasterFile Watcher Already Started")
ErrWatcherStarted is returned when MasterFile Watcher is already running.
Functions ¶
func RankingComparatorDefault ¶ added in v0.10.0
func RankingComparatorDefault(a, b *PvPRankingStats) int
RankingComparatorDefault ranks everything by stat product descending then by attack descending. This is the default behavior, since in general, a higher stat product is usually preferable; and in case of tying stat products, higher attack means that you would be more likely to win CMP ties.
func RankingComparatorPreferHigherCp ¶ added in v0.10.0
func RankingComparatorPreferHigherCp(a, b *PvPRankingStats) int
RankingComparatorPreferHigherCp in addition to the default rules, also compare by CP descending in the end. While ties are not meaningfully different most of the time, the rationale here is that a higher CP looks more intimidating.
func RankingComparatorPreferLowerCp ¶ added in v0.10.0
func RankingComparatorPreferLowerCp(a, b *PvPRankingStats) int
RankingComparatorPreferLowerCp in addition to the default rules, also compare by CP ascending in the end. While ties are not meaningfully different most of the time, the rationale here is that you can flex beating your opponent using one with a lower CP.
Types ¶
type Evolution ¶
type Evolution struct { Pokemon int `json:"pokemon"` Form int `json:"form,omitempty"` GenderRequirement int `json:"gender_requirement,omitempty"` }
Evolution entry represents row of Pokemon -> Evolution.
type Form ¶
type Form struct { Attack int `json:"attack,omitempty"` Defense int `json:"defense,omitempty"` Stamina int `json:"stamina,omitempty"` Little bool `json:"little,omitempty"` Evolutions []Evolution `json:"evolutions,omitempty"` TempEvolutions map[int]PokemonStats `json:"temp_evolutions,omitempty"` CostumeOverrideEvolutions []int `json:"costume_override_evos,omitempty"` }
Form entry represents row of Pokemon -> Form.
type Logger ¶ added in v0.11.1
type Logger interface {
Print(message string)
}
Logger interface
Example implementation:
type CustomLogger struct{} func (cl *CustomLogger) Print(message string) { fmt.Println("CustomLogger:", message) } logger := &CustomLogger{} ohbem := Ohbem{Logger: logger, ...}
Notes:
- The implementation of the Logger interface defines the specific behavior of the logging operation.
- The method should handle the formatting and output of the Log message according to the logger's rules.
type Ohbem ¶
type Ohbem struct { PokemonData PokemonData LevelCaps []int Leagues map[string]League DisableCache bool RankingComparator RankingComparator IncludeHundosUnderCap bool WatcherInterval time.Duration Logger Logger // contains filtered or unexported fields }
Ohbem struct is holding main configuration, cache and channels.
func (*Ohbem) CalculateCp ¶ added in v0.10.0
func (o *Ohbem) CalculateCp(pokemonId, form, evolution, attack, defense, stamina int, level float64) (int, error)
CalculateCp calculates CP for your pokemon. Errors if pokemon cannot be found in master.
func (*Ohbem) ClearCache ¶
func (o *Ohbem) ClearCache()
func (*Ohbem) FetchPokemonData ¶
FetchPokemonData Fetch remote MasterFile and keep it in memory.
func (*Ohbem) FilterLevelCaps ¶
func (o *Ohbem) FilterLevelCaps(entries []PokemonEntry, interestedLevelCaps []int) []PokemonEntry
FilterLevelCaps Filter the output of queryPvPRank with a subset of interested level caps.
func (*Ohbem) FindBaseStats ¶
FindBaseStats Look up base stats of a Pokémon.
func (*Ohbem) IsMegaUnreleased ¶
IsMegaUnreleased Check whether the stats for a given mega is speculated.
func (*Ohbem) LoadPokemonData ¶
LoadPokemonData Load MasterFile from provided filePath and keep it in memory.
func (*Ohbem) QueryPvPRank ¶
func (o *Ohbem) QueryPvPRank(pokemonId int, form int, costume int, gender int, attack int, defense int, stamina int, level float64) (map[string][]PokemonEntry, error)
QueryPvPRank Query all ranks for a specific Pokémon, including its possible evolutions.
func (*Ohbem) SavePokemonData ¶
SavePokemonData Save MasterFile from memory to provided location.
func (*Ohbem) StopWatchingPokemonData ¶
StopWatchingPokemonData Stop watching for remote MasterFile changes.
func (*Ohbem) WatchPokemonData ¶
WatchPokemonData Watch for remote MasterFile changes. When new, auto-update and clean cache.
type Pokemon ¶
type Pokemon struct { Attack int `json:"attack"` Defense int `json:"defense"` Stamina int `json:"stamina"` Little bool `json:"little,omitempty"` Evolutions []Evolution `json:"evolutions,omitempty"` TempEvolutions map[int]PokemonStats `json:"temp_evolutions,omitempty"` CostumeOverrideEvolutions []int `json:"costume_override_evos,omitempty"` Forms map[int]Form `json:"forms"` }
Pokemon entry represents row of Pokemon data from MasterFile
type PokemonData ¶
type PokemonData struct { Initialized bool `json:"-"` Pokemon map[int]Pokemon `json:"pokemon"` Costumes map[int]bool `json:"costumes"` }
PokemonData is a struct holding MasterFile data.
type PokemonEntry ¶
type PokemonEntry struct { Pokemon int `json:"pokemon"` Form int `json:"form,omitempty"` Cap float64 `json:"cap,omitempty"` Value float64 `json:"value,omitempty"` Level float64 `json:"level"` Cp int `json:"cp,omitempty"` Percentage float64 `json:"percentage"` Rank int16 `json:"rank"` Capped bool `json:"capped,omitempty"` Evolution int `json:"evolution,omitempty"` }
PokemonEntry is holding a row of result for QueryPvPRank and FilterLevelCaps functions.
type PokemonStats ¶
type PokemonStats struct { Attack int `json:"attack,omitempty"` Defense int `json:"defense,omitempty"` Stamina int `json:"stamina,omitempty"` Unreleased bool `json:"unreleased,omitempty"` }
PokemonStats entry represents basic Pokemon stats and mega release state.
type PvPRankingStats ¶ added in v0.10.0
PvPRankingStats internal struct for comparison.
type Ranking ¶
type Ranking struct { Value float64 `json:"value"` Level float64 `json:"level"` Cp int `json:"cp"` Percentage float64 `json:"percentage"` Rank int16 `json:"rank"` Attack int `json:"attack"` Defense int `json:"defense"` Stamina int `json:"stamina"` Cap float64 `json:"cap"` Capped bool `json:"capped,omitempty"` Index int `json:"index,omitempty"` }
Ranking entry represents PvP row for Pokemon.
type RankingComparator ¶ added in v0.10.0
type RankingComparator func(a, b *PvPRankingStats) int
RankingComparator specifies how to sort rankings.