mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-24 02:22:42 +02:00
breakup fight and ball commands into their own methods
This commit is contained in:
parent
4119dfbfec
commit
200db0c435
@ -147,83 +147,17 @@ export class CommandPhase extends FieldPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Remove `args` and clean this thing up
|
*
|
||||||
* Code will need to be copied over from pkty except replacing the `virtual` and `ignorePP` args with a corresponding `MoveUseMode`.
|
* @param user - The pokemon using the move
|
||||||
|
* @param cursor -
|
||||||
*/
|
*/
|
||||||
handleCommand(command: Command, cursor: number, ...args: any[]): boolean {
|
private queueFightErrorMessage(user: PlayerPokemon, cursor: number) {
|
||||||
const playerPokemon = globalScene.getPlayerField()[this.fieldIndex];
|
const move = user.getMoveset()[cursor];
|
||||||
let success = false;
|
|
||||||
|
|
||||||
switch (command) {
|
|
||||||
// TODO: We don't need 2 args for this - moveUseMode is carried over from queuedMove
|
|
||||||
case Command.TERA:
|
|
||||||
case Command.FIGHT: {
|
|
||||||
let useStruggle = false;
|
|
||||||
const turnMove: TurnMove | undefined = args.length === 2 ? (args[1] as TurnMove) : undefined;
|
|
||||||
if (
|
|
||||||
cursor === -1 ||
|
|
||||||
playerPokemon.trySelectMove(cursor, isIgnorePP(args[0] as MoveUseMode)) ||
|
|
||||||
(useStruggle = cursor > -1 && !playerPokemon.getMoveset().filter(m => m.isUsable(playerPokemon)).length)
|
|
||||||
) {
|
|
||||||
let moveId: MoveId;
|
|
||||||
if (useStruggle) {
|
|
||||||
moveId = MoveId.STRUGGLE;
|
|
||||||
} else if (turnMove !== undefined) {
|
|
||||||
moveId = turnMove.move;
|
|
||||||
} else if (cursor > -1) {
|
|
||||||
moveId = playerPokemon.getMoveset()[cursor].moveId;
|
|
||||||
} else {
|
|
||||||
moveId = MoveId.NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
const turnCommand: TurnCommand = {
|
|
||||||
command: Command.FIGHT,
|
|
||||||
cursor: cursor,
|
|
||||||
move: { move: moveId, targets: [], useMode: args[0] },
|
|
||||||
args: args,
|
|
||||||
};
|
|
||||||
const preTurnCommand: TurnCommand = {
|
|
||||||
command: command,
|
|
||||||
targets: [this.fieldIndex],
|
|
||||||
skip: command === Command.FIGHT,
|
|
||||||
};
|
|
||||||
const moveTargets: MoveTargetSet =
|
|
||||||
turnMove === undefined
|
|
||||||
? getMoveTargets(playerPokemon, moveId)
|
|
||||||
: {
|
|
||||||
targets: turnMove.targets,
|
|
||||||
multiple: turnMove.targets.length > 1,
|
|
||||||
};
|
|
||||||
if (!moveId) {
|
|
||||||
turnCommand.targets = [this.fieldIndex];
|
|
||||||
}
|
|
||||||
console.log(moveTargets, getPokemonNameWithAffix(playerPokemon));
|
|
||||||
if (moveTargets.targets.length > 1 && moveTargets.multiple) {
|
|
||||||
globalScene.phaseManager.unshiftNew("SelectTargetPhase", this.fieldIndex);
|
|
||||||
}
|
|
||||||
if (turnCommand.move && (moveTargets.targets.length <= 1 || moveTargets.multiple)) {
|
|
||||||
turnCommand.move.targets = moveTargets.targets;
|
|
||||||
} else if (
|
|
||||||
turnCommand.move &&
|
|
||||||
playerPokemon.getTag(BattlerTagType.CHARGING) &&
|
|
||||||
playerPokemon.getMoveQueue().length >= 1
|
|
||||||
) {
|
|
||||||
turnCommand.move.targets = playerPokemon.getMoveQueue()[0].targets;
|
|
||||||
} else {
|
|
||||||
globalScene.phaseManager.unshiftNew("SelectTargetPhase", this.fieldIndex);
|
|
||||||
}
|
|
||||||
globalScene.currentBattle.preTurnCommands[this.fieldIndex] = preTurnCommand;
|
|
||||||
globalScene.currentBattle.turnCommands[this.fieldIndex] = turnCommand;
|
|
||||||
success = true;
|
|
||||||
} else if (cursor < playerPokemon.getMoveset().length) {
|
|
||||||
const move = playerPokemon.getMoveset()[cursor];
|
|
||||||
globalScene.ui.setMode(UiMode.MESSAGE);
|
globalScene.ui.setMode(UiMode.MESSAGE);
|
||||||
|
|
||||||
// Decides between a Disabled, Not Implemented, or No PP translation message
|
// Decides between a Disabled, Not Implemented, or No PP translation message
|
||||||
const errorMessage = playerPokemon.isMoveRestricted(move.moveId, playerPokemon)
|
const errorMessage = user.isMoveRestricted(move.moveId, user)
|
||||||
? playerPokemon
|
? user.getRestrictingTag(move.moveId, user)!.selectionDeniedText(user, move.moveId)
|
||||||
.getRestrictingTag(move.moveId, playerPokemon)!
|
|
||||||
.selectionDeniedText(playerPokemon, move.moveId)
|
|
||||||
: move.getName().endsWith(" (N)")
|
: move.getName().endsWith(" (N)")
|
||||||
? "battle:moveNotImplemented"
|
? "battle:moveNotImplemented"
|
||||||
: "battle:moveNoPP";
|
: "battle:moveNoPP";
|
||||||
@ -240,99 +174,181 @@ export class CommandPhase extends FieldPhase {
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
/** Helper method for {@linkcode handleFightCommand} that returns the moveID for the phase
|
||||||
|
* based on the move passed in or the cursor.
|
||||||
|
*
|
||||||
|
* Does not check if the move is usable or not, that should be handled by the caller.
|
||||||
|
*/
|
||||||
|
private comptueMoveId(playerPokemon: PlayerPokemon, cursor: number, move?: TurnMove): MoveId {
|
||||||
|
return move?.move ?? (cursor > -1 ? playerPokemon.getMoveset()[cursor]?.moveId : MoveId.NONE);
|
||||||
}
|
}
|
||||||
case Command.BALL: {
|
|
||||||
const notInDex =
|
/**
|
||||||
globalScene
|
* Handle fight logic
|
||||||
.getEnemyField()
|
* @param command - The command to handle (FIGHT or TERA)
|
||||||
.filter(p => p.isActive(true))
|
* @param cursor - The index that the cursor is placed on, or -1 if no move can be selected.
|
||||||
.some(p => !globalScene.gameData.dexData[p.species.speciesId].caughtAttr) &&
|
* @param args - Any additional arguments to pass to the command
|
||||||
globalScene.gameData.getStarterCount(d => !!d.caughtAttr) < Object.keys(speciesStarterCosts).length - 1;
|
*/
|
||||||
|
private handleFightCommand(
|
||||||
|
command: Command.FIGHT | Command.TERA,
|
||||||
|
cursor: number,
|
||||||
|
useMode: MoveUseMode = MoveUseMode.NORMAL,
|
||||||
|
move?: TurnMove,
|
||||||
|
): boolean {
|
||||||
|
const playerPokemon = globalScene.getPlayerField()[this.fieldIndex];
|
||||||
|
const ignorePP = isIgnorePP(useMode);
|
||||||
|
|
||||||
|
/** Whether or not to display an error message instead of attempting to initiate the command selection process */
|
||||||
|
let canUse = cursor !== -1 || !playerPokemon.trySelectMove(cursor, ignorePP);
|
||||||
|
|
||||||
|
const useStruggle = canUse
|
||||||
|
? false
|
||||||
|
: cursor > -1 && !playerPokemon.getMoveset().some(m => m.isUsable(playerPokemon));
|
||||||
|
|
||||||
|
canUse = canUse || useStruggle;
|
||||||
|
|
||||||
|
if (!canUse) {
|
||||||
|
this.queueFightErrorMessage(playerPokemon, cursor);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const moveId = useStruggle ? MoveId.STRUGGLE : this.comptueMoveId(playerPokemon, cursor, move);
|
||||||
|
|
||||||
|
const turnCommand: TurnCommand = {
|
||||||
|
command: Command.FIGHT,
|
||||||
|
cursor: cursor,
|
||||||
|
move: { move: moveId, targets: [], useMode },
|
||||||
|
args: [useMode, move],
|
||||||
|
};
|
||||||
|
const preTurnCommand: TurnCommand = {
|
||||||
|
command: command,
|
||||||
|
targets: [this.fieldIndex],
|
||||||
|
skip: command === Command.FIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
const moveTargets: MoveTargetSet =
|
||||||
|
move === undefined
|
||||||
|
? getMoveTargets(playerPokemon, moveId)
|
||||||
|
: {
|
||||||
|
targets: move.targets,
|
||||||
|
multiple: move.targets.length > 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!moveId) {
|
||||||
|
turnCommand.targets = [this.fieldIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(moveTargets, getPokemonNameWithAffix(playerPokemon));
|
||||||
|
|
||||||
|
if (moveTargets.multiple) {
|
||||||
|
globalScene.phaseManager.unshiftNew("SelectTargetPhase", this.fieldIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (turnCommand.move && (moveTargets.targets.length <= 1 || moveTargets.multiple)) {
|
||||||
|
turnCommand.move.targets = moveTargets.targets;
|
||||||
|
} else if (
|
||||||
|
turnCommand.move &&
|
||||||
|
playerPokemon.getTag(BattlerTagType.CHARGING) &&
|
||||||
|
playerPokemon.getMoveQueue().length >= 1
|
||||||
|
) {
|
||||||
|
turnCommand.move.targets = playerPokemon.getMoveQueue()[0].targets;
|
||||||
|
} else {
|
||||||
|
globalScene.phaseManager.unshiftNew("SelectTargetPhase", this.fieldIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
globalScene.currentBattle.preTurnCommands[this.fieldIndex] = preTurnCommand;
|
||||||
|
globalScene.currentBattle.turnCommands[this.fieldIndex] = turnCommand;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private queueShowText(key: string) {
|
||||||
|
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
||||||
|
globalScene.ui.setMode(UiMode.MESSAGE);
|
||||||
|
|
||||||
|
globalScene.ui.showText(
|
||||||
|
i18next.t(key),
|
||||||
|
null,
|
||||||
|
() => {
|
||||||
|
globalScene.ui.showText("", 0);
|
||||||
|
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method for {@linkcode handleBallCommand} that checks if the pokeball can be thrown.
|
||||||
|
*
|
||||||
|
* The pokeball may not be thrown if:
|
||||||
|
* - It is a trainer battle
|
||||||
|
* - The biome is {@linkcode Biome.END} and it is not classic mode
|
||||||
|
* - The biome is {@linkcode Biome.END} and the fresh start challenge is active
|
||||||
|
* - The biome is {@linkcode Biome.END} and the player has not either caught the target before or caught all but one starter
|
||||||
|
* - The player is in a mystery encounter that disallows catching the pokemon
|
||||||
|
* @returns Whether a pokeball can be thrown
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private checkCanUseBall(): boolean {
|
||||||
if (
|
if (
|
||||||
globalScene.arena.biomeType === BiomeId.END &&
|
globalScene.arena.biomeType === BiomeId.END &&
|
||||||
(!globalScene.gameMode.isClassic || globalScene.gameMode.isFreshStartChallenge() || notInDex)
|
(!globalScene.gameMode.isClassic ||
|
||||||
|
globalScene.gameMode.isFreshStartChallenge() ||
|
||||||
|
(globalScene
|
||||||
|
.getEnemyField()
|
||||||
|
.some(p => p.isActive() && !globalScene.gameData.dexData[p.species.speciesId].caughtAttr) &&
|
||||||
|
globalScene.gameData.getStarterCount(d => !!d.caughtAttr) < Object.keys(speciesStarterCosts).length - 1))
|
||||||
) {
|
) {
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
this.queueShowText("battle:noPokeballForce");
|
||||||
globalScene.ui.setMode(UiMode.MESSAGE);
|
|
||||||
globalScene.ui.showText(
|
|
||||||
i18next.t("battle:noPokeballForce"),
|
|
||||||
null,
|
|
||||||
() => {
|
|
||||||
globalScene.ui.showText("", 0);
|
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} else if (globalScene.currentBattle.battleType === BattleType.TRAINER) {
|
} else if (globalScene.currentBattle.battleType === BattleType.TRAINER) {
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
this.queueShowText("battle:noPokeballTrainer");
|
||||||
globalScene.ui.setMode(UiMode.MESSAGE);
|
|
||||||
globalScene.ui.showText(
|
|
||||||
i18next.t("battle:noPokeballTrainer"),
|
|
||||||
null,
|
|
||||||
() => {
|
|
||||||
globalScene.ui.showText("", 0);
|
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} else if (
|
} else if (
|
||||||
globalScene.currentBattle.isBattleMysteryEncounter() &&
|
globalScene.currentBattle.isBattleMysteryEncounter() &&
|
||||||
!globalScene.currentBattle.mysteryEncounter!.catchAllowed
|
!globalScene.currentBattle.mysteryEncounter!.catchAllowed
|
||||||
) {
|
) {
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
this.queueShowText("battle:noPokeballMysteryEncounter");
|
||||||
globalScene.ui.setMode(UiMode.MESSAGE);
|
|
||||||
globalScene.ui.showText(
|
|
||||||
i18next.t("battle:noPokeballMysteryEncounter"),
|
|
||||||
null,
|
|
||||||
() => {
|
|
||||||
globalScene.ui.showText("", 0);
|
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method for {@linkcode handleCommand} that handles the logic when the selected command is to use a pokeball.
|
||||||
|
*
|
||||||
|
* @param cursor - The index of the pokeball to use
|
||||||
|
* @returns Whether the command was successfully initiated
|
||||||
|
*/
|
||||||
|
handleBallCommand(cursor: number): boolean {
|
||||||
const targets = globalScene
|
const targets = globalScene
|
||||||
.getEnemyField()
|
.getEnemyField()
|
||||||
.filter(p => p.isActive(true))
|
.filter(p => p.isActive(true))
|
||||||
.map(p => p.getBattlerIndex());
|
.map(p => p.getBattlerIndex());
|
||||||
if (targets.length > 1) {
|
if (targets.length > 1) {
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
this.queueShowText("battle:noPokeballMulti");
|
||||||
globalScene.ui.setMode(UiMode.MESSAGE);
|
return false;
|
||||||
globalScene.ui.showText(
|
}
|
||||||
i18next.t("battle:noPokeballMulti"),
|
|
||||||
null,
|
if (!this.checkCanUseBall()) {
|
||||||
() => {
|
return false;
|
||||||
globalScene.ui.showText("", 0);
|
}
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
|
||||||
},
|
if (cursor < 5) {
|
||||||
null,
|
const targetPokemon = globalScene.getEnemyPokemon();
|
||||||
true,
|
|
||||||
);
|
|
||||||
} else if (cursor < 5) {
|
|
||||||
const targetPokemon = globalScene.getEnemyField().find(p => p.isActive(true));
|
|
||||||
if (
|
if (
|
||||||
targetPokemon?.isBoss() &&
|
targetPokemon?.isBoss() &&
|
||||||
targetPokemon?.bossSegmentIndex >= 1 &&
|
targetPokemon?.bossSegmentIndex >= 1 &&
|
||||||
|
// TODO: Decouple this hardcoded exception for wonder guard and just check the target...
|
||||||
!targetPokemon?.hasAbility(AbilityId.WONDER_GUARD, false, true) &&
|
!targetPokemon?.hasAbility(AbilityId.WONDER_GUARD, false, true) &&
|
||||||
cursor < PokeballType.MASTER_BALL
|
cursor < PokeballType.MASTER_BALL
|
||||||
) {
|
) {
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
this.queueShowText("battle:noPokeballStrong");
|
||||||
globalScene.ui.setMode(UiMode.MESSAGE);
|
return false;
|
||||||
globalScene.ui.showText(
|
}
|
||||||
i18next.t("battle:noPokeballStrong"),
|
|
||||||
null,
|
|
||||||
() => {
|
|
||||||
globalScene.ui.showText("", 0);
|
|
||||||
globalScene.ui.setMode(UiMode.COMMAND, this.fieldIndex);
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
globalScene.currentBattle.turnCommands[this.fieldIndex] = {
|
globalScene.currentBattle.turnCommands[this.fieldIndex] = {
|
||||||
command: Command.BALL,
|
command: Command.BALL,
|
||||||
cursor: cursor,
|
cursor: cursor,
|
||||||
@ -341,12 +357,22 @@ export class CommandPhase extends FieldPhase {
|
|||||||
if (this.fieldIndex) {
|
if (this.fieldIndex) {
|
||||||
globalScene.currentBattle.turnCommands[this.fieldIndex - 1]!.skip = true;
|
globalScene.currentBattle.turnCommands[this.fieldIndex - 1]!.skip = true;
|
||||||
}
|
}
|
||||||
success = true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
handleCommand(command: Command, cursor: number, useMode: MoveUseMode = MoveUseMode.NORMAL, move?: TurnMove): boolean {
|
||||||
}
|
const playerPokemon = globalScene.getPlayerField()[this.fieldIndex];
|
||||||
|
let success = false;
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case Command.TERA:
|
||||||
|
case Command.FIGHT:
|
||||||
|
return this.handleFightCommand(command, cursor, useMode, move);
|
||||||
|
case Command.BALL:
|
||||||
|
return this.handleBallCommand(cursor);
|
||||||
case Command.POKEMON:
|
case Command.POKEMON:
|
||||||
case Command.RUN: {
|
case Command.RUN: {
|
||||||
const isSwitch = command === Command.POKEMON;
|
const isSwitch = command === Command.POKEMON;
|
||||||
@ -387,11 +413,11 @@ export class CommandPhase extends FieldPhase {
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const batonPass = isSwitch && (args[0] as boolean);
|
const batonPass = isSwitch && useMode;
|
||||||
const trappedAbMessages: string[] = [];
|
const trappedAbMessages: string[] = [];
|
||||||
if (batonPass || !playerPokemon.isTrapped(trappedAbMessages)) {
|
if (batonPass || !playerPokemon.isTrapped(trappedAbMessages)) {
|
||||||
currentBattle.turnCommands[this.fieldIndex] = isSwitch
|
currentBattle.turnCommands[this.fieldIndex] = isSwitch
|
||||||
? { command: Command.POKEMON, cursor: cursor, args: args }
|
? { command: Command.POKEMON, cursor: cursor }
|
||||||
: { command: Command.RUN };
|
: { command: Command.RUN };
|
||||||
success = true;
|
success = true;
|
||||||
if (!isSwitch && this.fieldIndex) {
|
if (!isSwitch && this.fieldIndex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user