Archived
1

Reverted /best logic, because of fuckup

This commit is contained in:
Vladimir Hodakov 2018-02-07 14:05:08 +04:00
parent 292440f411
commit bacf76fd39
2 changed files with 32 additions and 28 deletions

View File

@ -5,12 +5,13 @@ package pokedexer
import (
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
"sort"
)
// External functions
func (p *Pokedexer) getBestPokememes(playerID int) (map[int]*dbmapping.PokememeFull, bool) {
pokememesArray := make(map[int]*dbmapping.PokememeFull)
func (p *Pokedexer) getBestPokememes(playerID int) ([]*dbmapping.PokememeFull, bool) {
pokememesArray := make([]*dbmapping.PokememeFull, 0)
playerRaw, err := c.DataCache.GetPlayerByID(playerID)
if err != nil {
@ -28,49 +29,54 @@ func (p *Pokedexer) getBestPokememes(playerID int) (map[int]*dbmapping.PokememeF
}
allPokememes := c.DataCache.GetAllPokememes()
if profileRaw.LevelID < 4 {
pokememesArraySorted := make([]*dbmapping.PokememeFull, 0)
for i := range allPokememes {
if (allPokememes[i].Pokememe.Defence < profileRaw.Power) || (allPokememes[i].Pokememe.Purchaseable) {
if len(pokememesArray) < 5 {
if allPokememes[i].Pokememe.Grade == profileRaw.LevelID+1 {
pokememesArray[allPokememes[i].Pokememe.Attack] = allPokememes[i]
pokememesArraySorted = append(pokememesArraySorted, allPokememes[i])
}
sort.Slice(pokememesArraySorted, func(i, j int) bool {
return pokememesArraySorted[i].Pokememe.Attack > pokememesArraySorted[j].Pokememe.Attack
})
if profileRaw.LevelID < 4 {
for i := range pokememesArraySorted {
if (pokememesArraySorted[i].Pokememe.Defence < profileRaw.Power) || (pokememesArraySorted[i].Pokememe.Purchaseable) {
if allPokememes[i].Pokememe.Grade == profileRaw.LevelID+1 {
pokememesArray = append(pokememesArray, pokememesArraySorted[i])
}
}
}
} else if profileRaw.LevelID > 8 {
// TODO: Remove it on 10th grade pokememes arrival
for i := range allPokememes {
if allPokememes[i].Pokememe.Grade == 9 {
if pokememesArraySorted[i].Pokememe.Grade == 9 {
matchLeague := false
for j := range allPokememes[i].Elements {
if allPokememes[i].Elements[j].LeagueID == playerRaw.LeagueID {
for j := range pokememesArraySorted[i].Elements {
if pokememesArraySorted[i].Elements[j].LeagueID == playerRaw.LeagueID {
matchLeague = true
}
}
if matchLeague {
if (allPokememes[i].Pokememe.Defence < profileRaw.Power) || (allPokememes[i].Pokememe.Purchaseable) {
if len(pokememesArray) < 5 {
pokememesArray[allPokememes[i].Pokememe.Attack] = allPokememes[i]
}
if (pokememesArraySorted[i].Pokememe.Defence < profileRaw.Power) || (pokememesArraySorted[i].Pokememe.Purchaseable) {
pokememesArray = append(pokememesArray, pokememesArraySorted[i])
}
}
}
}
} else {
for i := range allPokememes {
if allPokememes[i].Pokememe.Grade == profileRaw.LevelID+1 {
if pokememesArraySorted[i].Pokememe.Grade == profileRaw.LevelID+1 {
matchLeague := false
for j := range allPokememes[i].Elements {
if allPokememes[i].Elements[j].LeagueID == playerRaw.LeagueID {
for j := range pokememesArraySorted[i].Elements {
if pokememesArraySorted[i].Elements[j].LeagueID == playerRaw.LeagueID {
matchLeague = true
}
}
if matchLeague {
if (allPokememes[i].Pokememe.Defence < profileRaw.Power) || (allPokememes[i].Pokememe.Purchaseable) {
if len(pokememesArray) < 5 {
pokememesArray[allPokememes[i].Pokememe.Attack] = allPokememes[i]
}
if (pokememesArraySorted[i].Pokememe.Defence < profileRaw.Power) || (pokememesArraySorted[i].Pokememe.Purchaseable) {
pokememesArray = append(pokememesArray, pokememesArraySorted[i])
}
}
}

View File

@ -25,14 +25,12 @@ func (p *Pokedexer) BestPokememesList(update *tgbotapi.Update, playerRaw *dbmapp
return "fail"
}
var attacks []int
for i := range pokememes {
attacks = append(attacks, i)
}
sort.Sort(sort.Reverse(sort.IntSlice(attacks)))
sort.Slice(pokememes, func(i, j int) bool {
return pokememes[i].Pokememe.Attack > pokememes[j].Pokememe.Attack
})
message := "*Лучшие покемемы для ловли*\n\n"
for _, i := range attacks {
for i := range pokememes {
pk := pokememes[i].Pokememe
pkL := pokememes[i].Locations
pkE := pokememes[i].Elements