2017-10-13 03:05:26 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
2017-11-21 06:06:32 +04:00
|
|
|
|
package pokedexer
|
2017-10-13 03:05:26 +04:00
|
|
|
|
|
|
|
|
|
import (
|
2018-01-21 23:28:53 +04:00
|
|
|
|
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
2018-02-07 14:05:08 +04:00
|
|
|
|
"sort"
|
2018-02-07 14:37:50 +04:00
|
|
|
|
"strconv"
|
2017-10-13 03:05:26 +04:00
|
|
|
|
)
|
|
|
|
|
|
2018-02-07 14:05:08 +04:00
|
|
|
|
func (p *Pokedexer) getBestPokememes(playerID int) ([]*dbmapping.PokememeFull, bool) {
|
|
|
|
|
pokememesArray := make([]*dbmapping.PokememeFull, 0)
|
2018-01-29 23:50:25 +04:00
|
|
|
|
|
|
|
|
|
playerRaw, err := c.DataCache.GetPlayerByID(playerID)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
2018-01-29 23:50:25 +04:00
|
|
|
|
c.Log.Error(err.Error())
|
2017-10-18 09:39:50 +04:00
|
|
|
|
return pokememesArray, false
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
2018-01-29 23:50:25 +04:00
|
|
|
|
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
2018-01-29 23:50:25 +04:00
|
|
|
|
c.Log.Error(err.Error())
|
2017-10-18 09:39:50 +04:00
|
|
|
|
return pokememesArray, false
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
if playerRaw.LeagueID == 0 {
|
|
|
|
|
return pokememesArray, false
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
allPokememes := c.DataCache.GetAllPokememes()
|
2018-02-07 14:05:08 +04:00
|
|
|
|
|
|
|
|
|
for i := range allPokememes {
|
2018-02-07 14:37:50 +04:00
|
|
|
|
// Adding only affordable pokememes...
|
|
|
|
|
if (allPokememes[i].Pokememe.Defence < profileRaw.Power) || allPokememes[i].Pokememe.Purchaseable {
|
|
|
|
|
// ...and only of needed grade (+1 until 9)
|
|
|
|
|
neededGrade := 0
|
|
|
|
|
if profileRaw.LevelID < 9 {
|
|
|
|
|
neededGrade = profileRaw.LevelID + 1
|
|
|
|
|
} else {
|
|
|
|
|
neededGrade = 9
|
2018-01-29 23:50:25 +04:00
|
|
|
|
}
|
2018-02-07 14:37:50 +04:00
|
|
|
|
if allPokememes[i].Pokememe.Grade == neededGrade {
|
|
|
|
|
// ...and only of our elements if our level past 4
|
2018-01-30 00:55:14 +04:00
|
|
|
|
matchLeague := false
|
2018-02-07 14:37:50 +04:00
|
|
|
|
if profileRaw.LevelID < 4 {
|
|
|
|
|
matchLeague = true
|
|
|
|
|
} else {
|
|
|
|
|
for j := range allPokememes[i].Elements {
|
|
|
|
|
if allPokememes[i].Elements[j].LeagueID == playerRaw.LeagueID {
|
|
|
|
|
matchLeague = true
|
|
|
|
|
}
|
2018-01-30 00:55:14 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if matchLeague {
|
2018-02-07 14:37:50 +04:00
|
|
|
|
pokememesArray = append(pokememesArray, allPokememes[i])
|
2018-01-30 00:55:14 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-07 14:37:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Log.Debug(strconv.Itoa(len(pokememesArray)) + " pokememes passed initial /best filtration.")
|
|
|
|
|
|
|
|
|
|
// As we have already filtered this array, we need to sort it and pass to view
|
|
|
|
|
sort.Slice(pokememesArray, func(i, j int) bool {
|
|
|
|
|
return pokememesArray[i].Pokememe.Attack > pokememesArray[j].Pokememe.Attack
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if len(pokememesArray) > 5 {
|
|
|
|
|
idx := 0
|
|
|
|
|
|
|
|
|
|
pokememesArrayShorted := make([]*dbmapping.PokememeFull, 0)
|
|
|
|
|
|
|
|
|
|
for i := range pokememesArray {
|
|
|
|
|
if idx < 5 {
|
|
|
|
|
pokememesArrayShorted = append(pokememesArrayShorted, pokememesArray[i])
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
2018-02-07 14:37:50 +04:00
|
|
|
|
idx++
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
2018-02-07 14:37:50 +04:00
|
|
|
|
|
|
|
|
|
pokememesArray = pokememesArrayShorted
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
return pokememesArray, true
|
2017-10-13 03:05:26 +04:00
|
|
|
|
}
|
2018-02-07 15:00:04 +04:00
|
|
|
|
|
|
|
|
|
func (p *Pokedexer) getHighPricedPokememes(playerID int) ([]*dbmapping.PokememeFull, bool) {
|
|
|
|
|
pokememesArray := make([]*dbmapping.PokememeFull, 0)
|
|
|
|
|
|
|
|
|
|
playerRaw, err := c.DataCache.GetPlayerByID(playerID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
|
|
|
|
return pokememesArray, false
|
|
|
|
|
}
|
|
|
|
|
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
|
|
|
|
return pokememesArray, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if playerRaw.LeagueID == 0 {
|
|
|
|
|
return pokememesArray, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
allPokememes := c.DataCache.GetAllPokememes()
|
|
|
|
|
|
|
|
|
|
for i := range allPokememes {
|
|
|
|
|
// Adding only affordable pokememes...
|
|
|
|
|
// Only by force: who need to buy pokememe for selling?
|
|
|
|
|
if allPokememes[i].Pokememe.Defence < profileRaw.Power {
|
|
|
|
|
// ...and only of needed grade (+1 until 9)
|
|
|
|
|
neededGrade := 0
|
|
|
|
|
if profileRaw.LevelID < 9 {
|
|
|
|
|
neededGrade = profileRaw.LevelID + 1
|
|
|
|
|
} else {
|
|
|
|
|
neededGrade = 9
|
|
|
|
|
}
|
|
|
|
|
if allPokememes[i].Pokememe.Grade == neededGrade {
|
|
|
|
|
pokememesArray = append(pokememesArray, allPokememes[i])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Log.Debug(strconv.Itoa(len(pokememesArray)) + " pokememes passed initial /advice filtration.")
|
|
|
|
|
|
|
|
|
|
// As we have already filtered this array, we need to sort it and pass to view
|
|
|
|
|
sort.Slice(pokememesArray, func(i, j int) bool {
|
|
|
|
|
return pokememesArray[i].Pokememe.Price > pokememesArray[j].Pokememe.Price
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if len(pokememesArray) > 10 {
|
|
|
|
|
idx := 0
|
|
|
|
|
|
|
|
|
|
pokememesArrayShorted := make([]*dbmapping.PokememeFull, 0)
|
|
|
|
|
|
|
|
|
|
for i := range pokememesArray {
|
|
|
|
|
if idx < 10 {
|
|
|
|
|
pokememesArrayShorted = append(pokememesArrayShorted, pokememesArray[i])
|
|
|
|
|
}
|
|
|
|
|
idx++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pokememesArray = pokememesArrayShorted
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pokememesArray, true
|
|
|
|
|
}
|