Add egg moves logic
This commit is contained in:
1 parent
7f77507d2b
commit
649717a3cd
7 files changed
+151
-16
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { Moves } from "./enums/moves";
|
||||
import { Species } from "./enums/species";
|
||||
import { allMoves } from "./move";
|
||||
import * as Utils from "../utils";
|
||||
|
||||
|
||||
export const speciesEggMoves = {
|
||||
};
|
||||
|
||||
function parseEggMoves(content: string): void {
|
||||
let output = '';
|
||||
|
||||
const speciesNames = Utils.getEnumKeys(Species);
|
||||
const speciesValues = Utils.getEnumValues(Species);
|
||||
const lines = content.split(/\n/g);
|
||||
|
||||
lines.forEach((line, l) => {
|
||||
const cols = line.split(',').slice(0, 5);
|
||||
const moveNames = allMoves.map(m => m.name.replace(/ \([A-Z]\)$/, '').toLowerCase());
|
||||
const enumSpeciesName = cols[0].toUpperCase().replace(/[ -]/g, '_');
|
||||
const species = speciesValues[speciesNames.findIndex(s => s === enumSpeciesName)];
|
||||
|
||||
let eggMoves: Moves[] = [];
|
||||
|
||||
for (let m = 0; m < 4; m++) {
|
||||
const moveName = cols[m + 1].trim();
|
||||
const moveIndex = moveName !== 'N/A' ? moveNames.findIndex(mn => mn === moveName.toLowerCase()) : -1;
|
||||
eggMoves.push(moveIndex > -1 ? moveIndex as Moves : Moves.NONE);
|
||||
}
|
||||
|
||||
if (eggMoves.find(m => m !== Moves.NONE))
|
||||
output += `[Species.${Species[species]}]: [ ${eggMoves.map(m => `Moves.${Moves[m]}`).join(', ')} ],\n`;
|
||||
});
|
||||
|
||||
console.log(output);
|
||||
}
|
||||
|
||||
const eggMovesStr = ``;
|
||||
if (eggMovesStr) {
|
||||
setTimeout(() => {
|
||||
parseEggMoves(eggMovesStr);
|
||||
}, 1000);
|
||||
}
|
||||
@@ -7,7 +7,8 @@ import { Type } from './type';
|
||||
import { LevelMoves, pokemonFormLevelMoves, pokemonFormLevelMoves as pokemonSpeciesFormLevelMoves, pokemonSpeciesLevelMoves } from './pokemon-level-moves';
|
||||
import { uncatchableSpecies } from './biomes';
|
||||
import * as Utils from '../utils';
|
||||
import { StarterMoveset } from '../system/game-data';
|
||||
import { StarterEggMoveData, StarterMoveset } from '../system/game-data';
|
||||
import { speciesEggMoves } from './egg-moves';
|
||||
|
||||
export enum Region {
|
||||
NORMAL,
|
||||
@@ -98,6 +99,13 @@ export abstract class PokemonSpeciesForm {
|
||||
this.genderDiffs = genderDiffs;
|
||||
}
|
||||
|
||||
getRootSpeciesId(): Species {
|
||||
let ret = this.speciesId;
|
||||
while (pokemonPrevolutions.hasOwnProperty(ret))
|
||||
ret = pokemonPrevolutions[ret];
|
||||
return ret;
|
||||
}
|
||||
|
||||
isOfType(type: integer): boolean {
|
||||
return this.type1 === type || (this.type2 !== null && this.type2 === type);
|
||||
}
|
||||
@@ -261,8 +269,14 @@ export abstract class PokemonSpeciesForm {
|
||||
return ret;
|
||||
}
|
||||
|
||||
validateStarterMoveset(moveset: StarterMoveset): boolean {
|
||||
validateStarterMoveset(moveset: StarterMoveset, eggMoves: integer): boolean {
|
||||
const rootSpeciesId = this.getRootSpeciesId();
|
||||
for (let moveId of moveset) {
|
||||
if (speciesEggMoves.hasOwnProperty(rootSpeciesId)) {
|
||||
const eggMoveIndex = speciesEggMoves[rootSpeciesId].findIndex(m => m === moveId);
|
||||
if (eggMoveIndex > -1 && eggMoves & Math.pow(2, eggMoveIndex))
|
||||
continue;
|
||||
}
|
||||
if (pokemonFormLevelMoves.hasOwnProperty(this.speciesId) && pokemonFormLevelMoves[this.speciesId].hasOwnProperty(this.formIndex)) {
|
||||
if (!pokemonFormLevelMoves[this.speciesId][this.formIndex].find(lm => lm[0] <= 5 && lm[1] === moveId))
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user