mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-02 05:32:24 +02:00
Added learn move utility function
This commit is contained in:
parent
10e0f9f0de
commit
8dcccd8ceb
@ -1,8 +1,10 @@
|
||||
import { BattlerIndex } from "#app/battle";
|
||||
import { Button } from "#app/enums/buttons";
|
||||
import type Pokemon from "#app/field/pokemon";
|
||||
import { PokemonMove } from "#app/field/pokemon";
|
||||
import Overrides from "#app/overrides";
|
||||
import { CommandPhase } from "#app/phases/command-phase";
|
||||
import { LearnMovePhase } from "#app/phases/learn-move-phase";
|
||||
import { MoveEffectPhase } from "#app/phases/move-effect-phase";
|
||||
import { Command } from "#app/ui/command-ui-handler";
|
||||
import { Mode } from "#app/ui/ui";
|
||||
@ -75,9 +77,10 @@ export class MoveHelper extends GameManagerHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when the normal moveset override can't be used (such as when it's necessary to check updated properties of the moveset).
|
||||
* @param pokemon - The pokemon being modified
|
||||
* @param moveset - The moveset to use
|
||||
* Changes a pokemon's moveset to the given move(s).
|
||||
* Used when the normal moveset override can't be used (such as when it's necessary to check or update properties of the moveset).
|
||||
* @param pokemon - The {@linkcode Pokemon} being modified
|
||||
* @param moveset - The {@linkcode Moves} (single or array) to change the Pokemon's moveset to
|
||||
*/
|
||||
public changeMoveset(pokemon: Pokemon, moveset: Moves | Moves[]): void {
|
||||
if (!Array.isArray(moveset)) {
|
||||
@ -90,4 +93,41 @@ export class MoveHelper extends GameManagerHelper {
|
||||
const movesetStr = moveset.map((moveId) => Moves[moveId]).join(", ");
|
||||
console.log(`Pokemon ${pokemon.species.name}'s moveset manually set to ${movesetStr} (=[${moveset.join(", ")}])!`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates learning a move for a player pokemon.
|
||||
* @param move The {@linkcode Moves} being learnt
|
||||
* @param partyIndex The party position of the {@linkcode PlayerPokemon} learning the move (defaults to 0)
|
||||
* @param slot The move slot index (0-4) to replace if existent move slots are full;
|
||||
* defaults to 0 (first slot) and 4 aborts the procedure
|
||||
* @returns a promise that resolves once the move has been successfully learnt
|
||||
*/
|
||||
public async learnMove(move: Moves, partyIndex?: number, slot?: integer) {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
if (partyIndex === undefined || partyIndex >= this.game.scene.getPlayerParty().length) {
|
||||
partyIndex = 0;
|
||||
}
|
||||
this.game.scene.pushPhase(new LearnMovePhase(this.game.scene, partyIndex, move));
|
||||
|
||||
// if slots are full, queue up inputs to replace existing moves
|
||||
if (this.game.scene.getPlayerParty()[partyIndex].moveset.filter(m => m).length === 4) {
|
||||
this.game.onNextPrompt("LearnMovePhase", Mode.CONFIRM, () => {
|
||||
this.game.scene.ui.processInput(Button.ACTION);
|
||||
});
|
||||
this.game.onNextPrompt("LearnMovePhase", Mode.SUMMARY, () => {
|
||||
for (let x = 0; x < (slot ?? 0); x++) {
|
||||
this.game.scene.ui.processInput(Button.DOWN);
|
||||
}
|
||||
this.game.scene.ui.processInput(Button.ACTION);
|
||||
if (slot === 4) { // confirm 1 last time to give up on learning move
|
||||
this.game.scene.ui.processInput(Button.ACTION);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await this.game.phaseInterceptor.to(LearnMovePhase).catch(e => reject(e));
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user