Fixed Failed Moves Not Using PP (#634)

Fixed an issue where if a move failed, it would not use power points.
This commit is contained in:
Benjamin Odom 2024-05-08 15:51:56 -05:00 committed by GitHub
parent 4509e08dc6
commit ea5e535f9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 15 deletions

View File

@ -3206,6 +3206,14 @@ export class PokemonMove {
return allMoves[this.moveId];
}
/**
* Sets {@link ppUsed} for this move and ensures the value does not exceed {@link getMovePp}
* @param {number} count Amount of PP to use
*/
usePp(count: number = 1) {
this.ppUsed = Math.min(this.ppUsed + count, this.getMovePp());
}
getMovePp(): integer {
return this.getMove().pp + this.ppUp * Math.max(Math.floor(this.getMove().pp / 5), 1);
}

View File

@ -2158,6 +2158,7 @@ export class MovePhase extends BattlePhase {
public targets: BattlerIndex[];
protected followUp: boolean;
protected ignorePp: boolean;
protected failed: boolean;
protected cancelled: boolean;
constructor(scene: BattleScene, pokemon: Pokemon, targets: BattlerIndex[], move: PokemonMove, followUp?: boolean, ignorePp?: boolean) {
@ -2168,6 +2169,7 @@ export class MovePhase extends BattlePhase {
this.move = move;
this.followUp = !!followUp;
this.ignorePp = !!ignorePp;
this.failed = false;
this.cancelled = false;
}
@ -2175,6 +2177,12 @@ export class MovePhase extends BattlePhase {
return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon, this.ignorePp) && !!this.targets.length;
}
/**Signifies the current move should fail but still use PP */
fail(): void {
this.failed = true;
}
/**Signifies the current move should cancel and retain PP */
cancel(): void {
this.cancelled = true;
}
@ -2214,7 +2222,7 @@ export class MovePhase extends BattlePhase {
this.targets[0] = attacker.getBattlerIndex();
}
if (this.targets[0] === BattlerIndex.ATTACKER) {
this.cancel();
this.fail(); // Marks the move as failed for later in doMove
this.showMoveText();
this.showFailedText();
}
@ -2235,10 +2243,23 @@ export class MovePhase extends BattlePhase {
this.pokemon.lapseTags(BattlerTagLapseType.PRE_MOVE);
let ppUsed = 1;
// Filter all opponents to include only those this move is targeting
const targetedOpponents = this.pokemon.getOpponents().filter(o => this.targets.includes(o.getBattlerIndex()));
for (let opponent of targetedOpponents) {
if (this.move.ppUsed + ppUsed >= this.move.getMovePp()) // If we're already at max PP usage, stop checking
break;
if (opponent.hasAbilityWithAttr(IncreasePpAbAttr)) // Accounting for abilities like Pressure
ppUsed++;
}
if (!this.followUp && this.canMove() && !this.cancelled) {
this.pokemon.lapseTags(BattlerTagLapseType.MOVE);
}
if (this.cancelled) {
if (this.cancelled || this.failed) {
if (this.failed)
this.move.usePp(ppUsed); // Only use PP if the move failed
this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL });
return this.end();
}
@ -2253,23 +2274,12 @@ export class MovePhase extends BattlePhase {
if ((moveQueue.length && moveQueue[0].move === Moves.NONE) || !targets.length) {
moveQueue.shift();
this.cancel();
}
if (this.cancelled) {
this.pokemon.pushMoveHistory({ move: Moves.NONE, result: MoveResult.FAIL });
return this.end();
}
if (!moveQueue.length || !moveQueue.shift().ignorePP) {
this.move.ppUsed++;
const targetedOpponents = this.pokemon.getOpponents().filter(o => this.targets.includes(o.getBattlerIndex()));
for (let opponent of targetedOpponents) {
if (this.move.ppUsed === this.move.getMove().pp)
break;
if (opponent.hasAbilityWithAttr(IncreasePpAbAttr))
this.move.ppUsed = Math.min(this.move.ppUsed + 1, this.move.getMovePp());
}
}
if (!moveQueue.length || !moveQueue.shift().ignorePP) // using .shift here clears out two turn moves once they've been used
this.move.usePp(ppUsed);
if (!allMoves[this.move.moveId].getAttrs(CopyMoveAttr).length)
this.scene.currentBattle.lastMove = this.move.moveId;