Skip to content

Commit

Permalink
CalculateTopRanks rework
Browse files Browse the repository at this point in the history
  • Loading branch information
lenisko authored and Fabio1988 committed Nov 21, 2024
1 parent d3da8f3 commit 251ce19
Showing 1 changed file with 65 additions and 55 deletions.
120 changes: 65 additions & 55 deletions ohbem.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,89 +263,99 @@ func (o *Ohbem) CalculateTopRanks(maxRank int16, pokemonId int, form int, evolut
}
for leagueName, leagueOptions := range o.Leagues {
var rankings, lastRank []Ranking
var lastStat Ranking
processLevelCap := func(lvCap float64, setOnDup bool) {
combinations, sortedRanks := calculateRanksCompact(stats, leagueOptions.Cap, lvCap, ivFloor)
for i := 0; i < len(sortedRanks); i++ {
stat := &sortedRanks[i]
rank := combinations[stat.Index]
if rank > maxRank {
for len(lastRank) > i {
lastRank = lastRank[:len(lastRank)-1]
}
break
}
attack := stat.Index >> 8 % 16
defense := stat.Index >> 4 % 16
stamina := stat.Index % 16
var rankings []Ranking
if len(lastRank) > i {
lastStat = lastRank[i]
}
if lastStat.Value != 0 && stat.Level == lastStat.Level && rank == lastStat.Rank && attack == lastStat.Attack && defense == lastStat.Defense && stamina == lastStat.Stamina {
if setOnDup {
lastStat.Capped = true
if leagueName != "master" {
if leagueOptions.LittleCupRules && !(masterForm.Little || masterPokemon.Little) {
continue
}
var lastRank []Ranking
processLevelCap := func(lvCap float64, setOnDup bool) {
lastStat := &Ranking{}
combinations, sortedRanks := calculateRanksCompact(stats, leagueOptions.Cap, lvCap, ivFloor)
for i := 0; i < len(sortedRanks); i++ {
stat := sortedRanks[i]
rank := combinations[stat.Index]
if rank > maxRank {
for len(lastRank) > i {
lastRank = lastRank[:len(lastRank)-1]
}
break
}
} else if !setOnDup {
lastStat = Ranking{
Rank: rank,
Attack: attack,
Defense: defense,
Stamina: stamina,
Cap: lvCap,
Value: math.Floor(stat.Value),
Level: stat.Level,
Cp: stat.Cp,
Percentage: roundFloat(stat.Value/sortedRanks[0].Value, 5),
attack := (stat.Index >> 8) % 16
defense := (stat.Index >> 4) % 16
stamina := stat.Index % 16
if len(lastRank) > i {
lastStat = &lastRank[i]
} else {
lastStat = nil
}
rankings = append(rankings, lastStat)
}
}
}
if leagueOptions.LittleCupRules && !(masterForm.Little || masterPokemon.Little) {
continue
} else if leagueName == "master" {
for _, lvCap := range o.LevelCaps {
lvCapFloat := float64(lvCap)
maxHp := calculateHp(stats, 15, lvCapFloat)
for stamina := ivFloor; stamina < 15; stamina++ {
if calculateHp(stats, stamina, lvCapFloat) == maxHp {
if lastStat != nil && stat.Level == lastStat.Level && rank == lastStat.Rank && attack == lastStat.Attack && defense == lastStat.Defense && stamina == lastStat.Stamina {
if setOnDup {
lastStat.Capped = true
}
} else if !setOnDup {
entry := Ranking{
Attack: 15,
Defense: 15,
Rank: rank,
Attack: attack,
Defense: defense,
Stamina: stamina,
Level: lvCapFloat,
Percentage: 1,
Rank: 1,
Cap: lvCap,
Value: math.Floor(stat.Value),
Level: stat.Level,
Cp: stat.Cp,
Percentage: roundFloat(stat.Value/sortedRanks[0].Value, 5),
}
rankings = append(rankings, entry)
if len(lastRank) > i {
lastRank[i] = entry
} else {
lastRank = append(lastRank, entry)
}
}
}
}
} else {
maxed := false
for _, lvCap := range o.LevelCaps {
lvCapFloat := float64(lvCap)
if !o.IncludeHundosUnderCap && calculateCp(stats, 15, 15, 15, lvCapFloat) <= leagueOptions.Cap {
if calculateCp(stats, 15, 15, 15, lvCapFloat) <= leagueOptions.Cap {
continue
}
processLevelCap(lvCapFloat, false)
if calculateCp(stats, ivFloor, ivFloor, ivFloor, lvCapFloat+0.5) > leagueOptions.Cap {
maxed = true
for ix := range lastRank {
lastRank[ix].Capped = true
rankings[ix].Capped = true
}
break
}
}
if len(rankings) != 0 && !maxed {
processLevelCap(MaxLevel, true)
}
} else {
for _, lvCap := range o.LevelCaps {
lvCapFloat := float64(lvCap)
maxHp := calculateHp(stats, 15, lvCapFloat)
for stamina := ivFloor; stamina < 15; stamina++ {
if calculateHp(stats, stamina, lvCapFloat) == maxHp {
entry := Ranking{
Rank: 1,
Attack: 15,
Defense: 15,
Stamina: stamina,
Level: lvCapFloat,
Percentage: 1,
}
rankings = append(rankings, entry)
}
}
}
}
if len(rankings) != 0 {
result[leagueName] = rankings
Expand Down

0 comments on commit 251ce19

Please sign in to comment.