fix cp calculation bug
This commit is contained in:
parent
2e035d57fa
commit
e39c660578
@ -3,6 +3,8 @@ import POGOProtos from 'pogo-protos';
|
||||
|
||||
import { parseGameMaster } from './parseGameMaster';
|
||||
|
||||
import { calculateCp, calculateMaxLevelForLeague, calculateStatAtLevel } from 'app/utils/calculator';
|
||||
|
||||
import { ILeaguePokemon, League, MaxCpByLeague } from 'app/models/League';
|
||||
import { LevelMultipliers } from 'app/models/LevelMultipliers';
|
||||
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 ivDef = 15; ivDef >= 0; ivDef--) {
|
||||
let pokemonWithIvs : IStats;
|
||||
const cpMultiplier = (baseAtk + ivAtk) * Math.sqrt(baseDef + ivDef) * Math.sqrt(baseHp + ivHp);
|
||||
|
||||
Object.keys(MaxCpByLeague).forEach((key) => {
|
||||
const league = key as League;
|
||||
const maxCp = MaxCpByLeague[league];
|
||||
const maxLeagueLevelMultiplierIndex = getClosestCpMultiplierIndex(Math.sqrt((maxCp * 10) / cpMultiplier));
|
||||
const maxLeagueLevelMultiplier = LevelMultipliers[maxLeagueLevelMultiplierIndex];
|
||||
const maxLeagueCp = Math.floor((cpMultiplier * Math.pow(maxLeagueLevelMultiplier, 2)) / 10);
|
||||
const maxLeagueLevel = (maxLeagueLevelMultiplierIndex + 2) / 2;
|
||||
const maxLeagueLevel = calculateMaxLevelForLeague(mon.stats, ivHp, ivAtk, ivDef, league);
|
||||
const maxLeagueCp = calculateCp(mon.stats, maxLeagueLevel, ivHp, ivAtk, ivDef);
|
||||
pokemonWithIvs = {
|
||||
cp: maxLeagueCp,
|
||||
level: maxLeagueLevel,
|
||||
ivHp,
|
||||
ivAtk,
|
||||
ivDef,
|
||||
hp: Math.floor((baseHp + ivHp) * maxLeagueLevelMultiplier),
|
||||
atk: Math.floor((baseAtk + ivAtk) * maxLeagueLevelMultiplier),
|
||||
def: Math.floor((baseDef + ivDef) * maxLeagueLevelMultiplier),
|
||||
hp: calculateStatAtLevel(maxLeagueLevel, baseHp, ivHp),
|
||||
atk: calculateStatAtLevel(maxLeagueLevel, baseAtk, ivAtk),
|
||||
def: calculateStatAtLevel(maxLeagueLevel, baseDef, ivDef),
|
||||
total: 0,
|
||||
speciesGrade: Grade.F,
|
||||
metaGrade: Grade.F,
|
||||
};
|
||||
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].push(pokemonWithIvs);
|
||||
// console.log(pokemonWithIvs, key);
|
||||
|
||||
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);
|
||||
@ -170,12 +167,13 @@ fs.mkdirSync(outPath, { recursive: true });
|
||||
Object.keys(pokemon.pvp).forEach((key) => {
|
||||
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);
|
||||
|
||||
const len = orderedCombinedStats.length - 1;
|
||||
const offset = orderedCombinedStats[1];
|
||||
const max = orderedCombinedStats[len] - offset; // index 0 is always `Grade.S`
|
||||
const offset = orderedCombinedStats[0];
|
||||
const max = orderedCombinedStats[len] - offset; // index `len` is always `Grade.S`
|
||||
for (let index = len; index >= 0; index--) {
|
||||
const combinedStats = orderedCombinedStats[index];
|
||||
const percent = (combinedStats - offset) / max;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user