determine mon order
This commit is contained in:
parent
4f56dd213c
commit
00b06985e4
@ -32,20 +32,62 @@ const getClosestCpMultiplierIndex = (value : number) => {
|
|||||||
return Math.max(i - 1, 0);
|
return Math.max(i - 1, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const familyOrder : Array<string> = [];
|
||||||
|
const familyEvolutionOrder : { [ key : string ] : Array<string> } = {};
|
||||||
|
const familyEncountered : { [ key : string ] : Array<IPokemon> } = {};
|
||||||
Pokemon.forEach((mon) => {
|
Pokemon.forEach((mon) => {
|
||||||
const baseAtk = mon.stats.baseAttack;
|
const baseAtk = mon.stats.baseAttack;
|
||||||
const baseDef = mon.stats.baseDefense;
|
const baseDef = mon.stats.baseDefense;
|
||||||
const baseHp = mon.stats.baseStamina;
|
const baseHp = mon.stats.baseStamina;
|
||||||
const stats : IPokemon = {
|
const pokemon : IPokemon = {
|
||||||
|
id: mon.id,
|
||||||
name: mon.name,
|
name: mon.name,
|
||||||
id: mon.dex,
|
dex: mon.dex,
|
||||||
stats: mon.stats,
|
stats: mon.stats,
|
||||||
|
family: mon.family.id,
|
||||||
pvp: {
|
pvp: {
|
||||||
great: [],
|
great: [],
|
||||||
ultra: [],
|
ultra: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// keep track of family order and membership
|
||||||
|
if (typeof familyEncountered[pokemon.family] === 'undefined') {
|
||||||
|
familyOrder.push(pokemon.family);
|
||||||
|
familyEncountered[pokemon.family] = [];
|
||||||
|
}
|
||||||
|
familyEncountered[pokemon.family].push(pokemon);
|
||||||
|
|
||||||
|
if (typeof mon.evolution.pastBranch === 'undefined' &&
|
||||||
|
typeof familyEvolutionOrder[pokemon.family] === 'undefined' &&
|
||||||
|
pokemon.id.indexOf('_ALOLA') === -1 // because RAICHU_ALOLA shows up before PICHU, but PICHU is the family origin
|
||||||
|
) {
|
||||||
|
familyEvolutionOrder[pokemon.family] = [];
|
||||||
|
if (mon.forms.length > 0) {
|
||||||
|
mon.forms.forEach((form) => {
|
||||||
|
familyEvolutionOrder[pokemon.family].push(form.id);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
familyEvolutionOrder[pokemon.family].push(pokemon.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: if `mon.forms.length > 0`, there's a chance the order will get weird by doing this:
|
||||||
|
if (typeof mon.evolution.futureBranches !== 'undefined') {
|
||||||
|
(function traverseEvolutionBranches(root) {
|
||||||
|
root.forEach((evolution) => {
|
||||||
|
familyEvolutionOrder[pokemon.family].push(evolution.id);
|
||||||
|
// unfortunate workaround for typescript limitation in JSON parsing being TOO good...
|
||||||
|
// if (typeof evolution !== 'undefined') {
|
||||||
|
if ('futureBranches' in evolution) {
|
||||||
|
// traverseEvolutionBranches(evolution.futureBranches);
|
||||||
|
traverseEvolutionBranches(evolution['futureBranches']);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(mon.evolution.futureBranches);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate stats for all possible IVs
|
||||||
const combinedStatsDistribution : IStatsDistribution = {
|
const combinedStatsDistribution : IStatsDistribution = {
|
||||||
great: {},
|
great: {},
|
||||||
ultra: {},
|
ultra: {},
|
||||||
@ -87,7 +129,7 @@ Pokemon.forEach((mon) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// process the pokemon stats for league-worthiness
|
// process the pokemon stats for league-worthiness
|
||||||
Object.keys(stats.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)).sort();
|
const orderedCombinedStats = Object.keys(combinedStatsDistribution[league]).map(cpTotal => parseInt(cpTotal)).sort();
|
||||||
@ -118,7 +160,7 @@ Pokemon.forEach((mon) => {
|
|||||||
pokemonStats.speciesGrade = Grade.D;
|
pokemonStats.speciesGrade = Grade.D;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stats.pvp[league].push(pokemonStats);
|
pokemon.pvp[league].push(pokemonStats);
|
||||||
});
|
});
|
||||||
combinedStatsDistribution[league][combinedStats].sort((a, b) => {
|
combinedStatsDistribution[league][combinedStats].sort((a, b) => {
|
||||||
if (a.total !== b.total) {
|
if (a.total !== b.total) {
|
||||||
@ -129,16 +171,43 @@ Pokemon.forEach((mon) => {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
stats.pvp[league].push(...combinedStatsDistribution[league][combinedStats]);
|
pokemon.pvp[league].push(...combinedStatsDistribution[league][combinedStats]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.mkdir(outPath, {recursive: true}, () => {
|
fs.mkdir(outPath, {recursive: true}, () => {
|
||||||
fs.writeFile(outPath + mon.id + '.json', JSON.stringify(stats), (err) => {
|
fs.writeFile(outPath + mon.id + '.json', JSON.stringify(pokemon), (err) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
return console.log(mon.name, err);
|
return console.log(mon.name, err);
|
||||||
}
|
}
|
||||||
console.log(mon.name);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pokemonOrder : Array<{ id : string, name : string }> = [];
|
||||||
|
familyOrder.forEach((familyId) => {
|
||||||
|
familyEvolutionOrder[familyId].forEach((id, order) => {
|
||||||
|
familyEncountered[familyId].some((pokemon, index) => {
|
||||||
|
if (id === pokemon.id && order !== index) {
|
||||||
|
familyEncountered[familyId].splice(order, 0, familyEncountered[familyId].splice(index, 1)[0]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
familyEncountered[familyId].forEach((pokemon) => {
|
||||||
|
pokemonOrder.push({
|
||||||
|
id: pokemon.id,
|
||||||
|
name: pokemon.name,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.mkdir(outPath, {recursive: true}, () => {
|
||||||
|
fs.writeFile(outPath + 'order.json', JSON.stringify(pokemonOrder), (err) => {
|
||||||
|
if(err) {
|
||||||
|
return console.log('order', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -16,7 +16,9 @@ export interface IBaseStats {
|
|||||||
export type League = 'great' | 'ultra';
|
export type League = 'great' | 'ultra';
|
||||||
export interface IPokemon {
|
export interface IPokemon {
|
||||||
name : string;
|
name : string;
|
||||||
id : number;
|
id : string;
|
||||||
|
family : string;
|
||||||
|
dex : number;
|
||||||
stats : IBaseStats;
|
stats : IBaseStats;
|
||||||
pvp : {
|
pvp : {
|
||||||
great : Array<IStats>;
|
great : Array<IStats>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user