fix cp calculation bug

This commit is contained in:
Jeff Colombo 2019-02-10 12:00:44 -05:00
parent 2e035d57fa
commit e39c660578

View File

@ -3,6 +3,8 @@ import POGOProtos from 'pogo-protos';
import { parseGameMaster } from './parseGameMaster'; import { parseGameMaster } from './parseGameMaster';
import { calculateCp, calculateMaxLevelForLeague, calculateStatAtLevel } from 'app/utils/calculator';
import { ILeaguePokemon, League, MaxCpByLeague } from 'app/models/League'; import { ILeaguePokemon, League, MaxCpByLeague } from 'app/models/League';
import { LevelMultipliers } from 'app/models/LevelMultipliers'; import { LevelMultipliers } from 'app/models/LevelMultipliers';
import { Grade, IMaxStats, IStats } from 'app/models/Pokemon'; import { Grade, IMaxStats, IStats } from 'app/models/Pokemon';
@ -126,34 +128,29 @@ fs.mkdirSync(outPath, { recursive: true });
for (let ivAtk = 15; ivAtk >= 0; ivAtk--) { for (let ivAtk = 15; ivAtk >= 0; ivAtk--) {
for (let ivDef = 15; ivDef >= 0; ivDef--) { for (let ivDef = 15; ivDef >= 0; ivDef--) {
let pokemonWithIvs : IStats; let pokemonWithIvs : IStats;
const cpMultiplier = (baseAtk + ivAtk) * Math.sqrt(baseDef + ivDef) * Math.sqrt(baseHp + ivHp);
Object.keys(MaxCpByLeague).forEach((key) => { Object.keys(MaxCpByLeague).forEach((key) => {
const league = key as League; const league = key as League;
const maxCp = MaxCpByLeague[league]; const maxLeagueLevel = calculateMaxLevelForLeague(mon.stats, ivHp, ivAtk, ivDef, league);
const maxLeagueLevelMultiplierIndex = getClosestCpMultiplierIndex(Math.sqrt((maxCp * 10) / cpMultiplier)); const maxLeagueCp = calculateCp(mon.stats, maxLeagueLevel, ivHp, ivAtk, ivDef);
const maxLeagueLevelMultiplier = LevelMultipliers[maxLeagueLevelMultiplierIndex];
const maxLeagueCp = Math.floor((cpMultiplier * Math.pow(maxLeagueLevelMultiplier, 2)) / 10);
const maxLeagueLevel = (maxLeagueLevelMultiplierIndex + 2) / 2;
pokemonWithIvs = { pokemonWithIvs = {
cp: maxLeagueCp, cp: maxLeagueCp,
level: maxLeagueLevel, level: maxLeagueLevel,
ivHp, ivHp,
ivAtk, ivAtk,
ivDef, ivDef,
hp: Math.floor((baseHp + ivHp) * maxLeagueLevelMultiplier), hp: calculateStatAtLevel(maxLeagueLevel, baseHp, ivHp),
atk: Math.floor((baseAtk + ivAtk) * maxLeagueLevelMultiplier), atk: calculateStatAtLevel(maxLeagueLevel, baseAtk, ivAtk),
def: Math.floor((baseDef + ivDef) * maxLeagueLevelMultiplier), def: calculateStatAtLevel(maxLeagueLevel, baseDef, ivDef),
total: 0, total: 0,
speciesGrade: Grade.F, speciesGrade: Grade.F,
metaGrade: Grade.F, metaGrade: Grade.F,
}; };
pokemonWithIvs.total = pokemonWithIvs.hp + pokemonWithIvs.atk + pokemonWithIvs.def; pokemonWithIvs.total = pokemonWithIvs.hp + pokemonWithIvs.atk + pokemonWithIvs.def;
const combinedStats = maxLeagueCp + pokemonWithIvs.total; const combinedStats = pokemonWithIvs.total;
combinedStatsDistribution[league][combinedStats] = combinedStatsDistribution[league][combinedStats] || []; combinedStatsDistribution[league][combinedStats] = combinedStatsDistribution[league][combinedStats] || [];
combinedStatsDistribution[league][combinedStats].push(pokemonWithIvs); combinedStatsDistribution[league][combinedStats].push(pokemonWithIvs);
// console.log(pokemonWithIvs, key);
pokemon.statMax[league].stamina.best = Math.max(pokemon.statMax[league].stamina.best, pokemonWithIvs.hp); pokemon.statMax[league].stamina.best = Math.max(pokemon.statMax[league].stamina.best, pokemonWithIvs.hp);
pokemon.statMax[league].stamina.worst = Math.min(pokemon.statMax[league].stamina.worst, pokemonWithIvs.hp); pokemon.statMax[league].stamina.worst = Math.min(pokemon.statMax[league].stamina.worst, pokemonWithIvs.hp);
@ -170,12 +167,13 @@ fs.mkdirSync(outPath, { recursive: true });
Object.keys(pokemon.pvp).forEach((key) => { Object.keys(pokemon.pvp).forEach((key) => {
const league = key as League; const league = key as League;
const orderedCombinedStats = Object.keys(combinedStatsDistribution[league]).map((cpTotal) => parseInt(cpTotal, 10)); // NOTE: ordered low to high!
const orderedCombinedStats = Object.keys(combinedStatsDistribution[league]).map((total) => parseInt(total, 10));
orderedCombinedStats.sort((a, b) => a - b); orderedCombinedStats.sort((a, b) => a - b);
const len = orderedCombinedStats.length - 1; const len = orderedCombinedStats.length - 1;
const offset = orderedCombinedStats[1]; const offset = orderedCombinedStats[0];
const max = orderedCombinedStats[len] - offset; // index 0 is always `Grade.S` const max = orderedCombinedStats[len] - offset; // index `len` is always `Grade.S`
for (let index = len; index >= 0; index--) { for (let index = len; index >= 0; index--) {
const combinedStats = orderedCombinedStats[index]; const combinedStats = orderedCombinedStats[index];
const percent = (combinedStats - offset) / max; const percent = (combinedStats - offset) / max;