generate pokemon data
This commit is contained in:
parent
d20b76299f
commit
06125d165a
@ -1,5 +1,94 @@
|
||||
import * as fs from 'fs';
|
||||
import * as Pokemon from 'pokemongo-json-pokedex/output/pokemon.json';
|
||||
import { IPokemon, IStats, League } from 'src/ts/models/Pokemon';
|
||||
|
||||
const GREAT_LEAGUE_CP = 1500;
|
||||
const ULTRA_LEAGUE_CP = 2500;
|
||||
|
||||
const cpMultipliers : Array<number> = JSON.parse(fs.readFileSync('src/db/cpMultipliers.json', 'utf8'));
|
||||
const getClosestCpMultiplierIndex = (value : number) => {
|
||||
let i;
|
||||
for (i = 0; i < cpMultipliers.length; i++) {
|
||||
if (value < cpMultipliers[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Math.max(i - 1, 0);
|
||||
};
|
||||
|
||||
Pokemon.forEach((mon) => {
|
||||
console.log(mon.name);
|
||||
const baseAtk = mon.stats.baseAttack;
|
||||
const baseDef = mon.stats.baseDefense;
|
||||
const baseHp = mon.stats.baseStamina;
|
||||
const stats : IPokemon = {
|
||||
name: mon.name,
|
||||
id: mon.dex,
|
||||
stats: mon.stats,
|
||||
pvp: {
|
||||
great: [],
|
||||
ultra: [],
|
||||
},
|
||||
};
|
||||
|
||||
for (let ivHp = 15; ivHp >= 0; ivHp--) {
|
||||
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);
|
||||
|
||||
const maxGreatLeagueLevelMultiplierIndex = getClosestCpMultiplierIndex(Math.sqrt((GREAT_LEAGUE_CP * 10) / cpMultiplier));
|
||||
const maxGreatLeagueLevelMultiplier = cpMultipliers[maxGreatLeagueLevelMultiplierIndex];
|
||||
const maxGreatLeagueCp = ~~((cpMultiplier * Math.pow(maxGreatLeagueLevelMultiplier, 2)) / 10);
|
||||
const maxGreatLeagueLevel = (maxGreatLeagueLevelMultiplierIndex + 2) / 2;
|
||||
pokemonWithIvs = {
|
||||
cp: maxGreatLeagueCp,
|
||||
level: maxGreatLeagueLevel,
|
||||
ivHp: ivHp,
|
||||
ivAtk: ivAtk,
|
||||
ivDef: ivDef,
|
||||
hp: ~~((baseHp + ivHp) * maxGreatLeagueLevelMultiplier),
|
||||
atk: ~~((baseAtk + ivAtk) * maxGreatLeagueLevelMultiplier),
|
||||
def: ~~((baseDef + ivDef) * maxGreatLeagueLevelMultiplier),
|
||||
total: 0
|
||||
};
|
||||
pokemonWithIvs.total = pokemonWithIvs.hp + pokemonWithIvs.atk + pokemonWithIvs.def;
|
||||
stats.pvp.great.push(pokemonWithIvs);
|
||||
|
||||
const maxUltraLeagueLevelMultiplierIndex = getClosestCpMultiplierIndex(Math.sqrt((ULTRA_LEAGUE_CP * 10) / cpMultiplier));
|
||||
const maxUltraLeagueLevelMultiplier = cpMultipliers[maxUltraLeagueLevelMultiplierIndex];
|
||||
const maxUltraLeagueCp = ~~((cpMultiplier * Math.pow(maxUltraLeagueLevelMultiplier, 2)) / 10);
|
||||
const maxUltraLeagueLevel = (maxUltraLeagueLevelMultiplierIndex + 2) / 2;
|
||||
pokemonWithIvs = {
|
||||
cp: maxUltraLeagueCp,
|
||||
level: maxUltraLeagueLevel,
|
||||
ivHp: ivHp,
|
||||
ivAtk: ivAtk,
|
||||
ivDef: ivDef,
|
||||
hp: ~~((baseHp + ivHp) * maxUltraLeagueLevelMultiplier),
|
||||
atk: ~~((baseAtk + ivAtk) * maxUltraLeagueLevelMultiplier),
|
||||
def: ~~((baseDef + ivDef) * maxUltraLeagueLevelMultiplier),
|
||||
total: 0
|
||||
};
|
||||
pokemonWithIvs.total = pokemonWithIvs.hp + pokemonWithIvs.atk + pokemonWithIvs.def;
|
||||
stats.pvp.ultra.push(pokemonWithIvs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(stats.pvp).forEach((league) => {
|
||||
const keys = league as League;
|
||||
stats.pvp[keys].sort((a, b) => {
|
||||
if (a.cp === b.cp) {
|
||||
return a.cp > b.cp ? 0 : 1;
|
||||
}
|
||||
return a.total > b.total ? 0 : 1;
|
||||
});
|
||||
});
|
||||
|
||||
fs.writeFile('./dist/db/' + mon.name + '.json', JSON.stringify(stats), (err) => {
|
||||
if(err) {
|
||||
return console.log(mon.name, err);
|
||||
}
|
||||
console.log(mon.name);
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
"@babel/preset-env": "^7.2.3",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@babel/preset-typescript": "^7.1.0",
|
||||
"@types/node": "^10.12.18",
|
||||
"@types/react": "^16.7.18",
|
||||
"@types/react-dom": "^16.0.11",
|
||||
"babel-loader": "^8.0.4",
|
||||
|
||||
81
src/db/cpMultipliers.json
Normal file
81
src/db/cpMultipliers.json
Normal file
@ -0,0 +1,81 @@
|
||||
[
|
||||
0.094,
|
||||
0.135137432,
|
||||
0.16639787,
|
||||
0.192650919,
|
||||
0.21573247,
|
||||
0.236572661,
|
||||
0.25572005,
|
||||
0.273530381,
|
||||
0.29024988,
|
||||
0.306057377,
|
||||
0.3210876,
|
||||
0.335445036,
|
||||
0.34921268,
|
||||
0.362457751,
|
||||
0.37523559,
|
||||
0.387592406,
|
||||
0.39956728,
|
||||
0.411193551,
|
||||
0.42250001,
|
||||
0.432926419,
|
||||
0.44310755,
|
||||
0.4530599578,
|
||||
0.46279839,
|
||||
0.472336083,
|
||||
0.48168495,
|
||||
0.4908558,
|
||||
0.49985844,
|
||||
0.508701765,
|
||||
0.51739395,
|
||||
0.525942511,
|
||||
0.53435433,
|
||||
0.542635767,
|
||||
0.55079269,
|
||||
0.558830576,
|
||||
0.56675452,
|
||||
0.574569153,
|
||||
0.58227891,
|
||||
0.589887917,
|
||||
0.59740001,
|
||||
0.604818814,
|
||||
0.61215729,
|
||||
0.619399365,
|
||||
0.62656713,
|
||||
0.633644533,
|
||||
0.64065295,
|
||||
0.647576426,
|
||||
0.65443563,
|
||||
0.661214806,
|
||||
0.667934,
|
||||
0.674577537,
|
||||
0.68116492,
|
||||
0.687680648,
|
||||
0.69414365,
|
||||
0.700538673,
|
||||
0.70688421,
|
||||
0.713164996,
|
||||
0.71939909,
|
||||
0.725571552,
|
||||
0.7317,
|
||||
0.734741009,
|
||||
0.73776948,
|
||||
0.740785574,
|
||||
0.74378943,
|
||||
0.746781211,
|
||||
0.74976104,
|
||||
0.752729087,
|
||||
0.75568551,
|
||||
0.758630378,
|
||||
0.76156384,
|
||||
0.764486065,
|
||||
0.76739717,
|
||||
0.770297266,
|
||||
0.7731865,
|
||||
0.776064962,
|
||||
0.77893275,
|
||||
0.781790055,
|
||||
0.78463697,
|
||||
0.787473578,
|
||||
0.79030001
|
||||
]
|
||||
28
src/ts/models/Pokemon.ts
Normal file
28
src/ts/models/Pokemon.ts
Normal file
@ -0,0 +1,28 @@
|
||||
export interface IBaseStats {
|
||||
baseAttack : number;
|
||||
baseDefense : number;
|
||||
baseStamina : number;
|
||||
}
|
||||
|
||||
export type League = 'great' | 'ultra';
|
||||
export interface IPokemon {
|
||||
name : string;
|
||||
id : number;
|
||||
stats : IBaseStats;
|
||||
pvp : {
|
||||
great : Array<IStats>;
|
||||
ultra : Array<IStats>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IStats {
|
||||
cp : number;
|
||||
level : number;
|
||||
ivHp : number;
|
||||
ivAtk : number;
|
||||
ivDef : number;
|
||||
hp : number;
|
||||
atk : number;
|
||||
def : number;
|
||||
total : number;
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
// for use with https://github.com/pokemongo-dev-contrib/pokemongo-json-pokedex
|
||||
import { IBaseStats } from 'src/ts/models/Pokemon';
|
||||
|
||||
declare module "pokemongo-json-pokedex/output/pokemon.json" {
|
||||
interface IMove {
|
||||
@ -7,12 +8,6 @@ declare module "pokemongo-json-pokedex/output/pokemon.json" {
|
||||
legacy : boolean;
|
||||
}
|
||||
|
||||
interface IStats {
|
||||
baseAttack : number;
|
||||
baseDefense : number;
|
||||
baseStamina : number;
|
||||
}
|
||||
|
||||
interface IFamily {
|
||||
id : string;
|
||||
name : string;
|
||||
@ -34,7 +29,7 @@ declare module "pokemongo-json-pokedex/output/pokemon.json" {
|
||||
cinematicMoves : Array<IMove>;
|
||||
quickMoves : Array<IMove>;
|
||||
family : IFamily;
|
||||
stats : IStats;
|
||||
stats : IBaseStats;
|
||||
types : Array<IType>;
|
||||
forms : Array<IForme>
|
||||
}
|
||||
@ -12,7 +12,7 @@
|
||||
"baseUrl": ".",
|
||||
"traceResolution": false,
|
||||
"paths": {
|
||||
"pokemongo-json-pokedex/output/pokemon.json": ["./src/ts/typings/pokemon.json.d.ts"]
|
||||
"pokemongo-json-pokedex/output/pokemon.json": ["./src/ts/models/pokemon.json.d.ts"]
|
||||
},
|
||||
"plugins": [{
|
||||
"name": "tslint-language-service",
|
||||
|
||||
@ -719,6 +719,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
|
||||
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
|
||||
|
||||
"@types/node@^10.12.18":
|
||||
version "10.12.18"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
|
||||
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==
|
||||
|
||||
"@types/prop-types@*":
|
||||
version "15.5.8"
|
||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.8.tgz#8ae4e0ea205fe95c3901a5a1df7f66495e3a56ce"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user