Move cancellation logic back to tag

Wanted to increase similarity to the existing code base to avoid that stupid hyper beam error but it's still happening here
This commit is contained in:
Zach Day 2024-08-09 19:50:32 -04:00
parent b6a5f29873
commit f6b41e33f1
3 changed files with 24 additions and 16 deletions

View File

@ -101,14 +101,27 @@ export abstract class DisablingBattlerTag extends BattlerTag {
public abstract moveIsDisabled(move: Moves): boolean;
constructor(tagType: BattlerTagType, turnCount: integer, sourceMove?: Moves, sourceId?: integer) {
super(tagType, BattlerTagLapseType.TURN_END, turnCount, sourceMove, sourceId);
super(tagType, [ BattlerTagLapseType.PRE_MOVE, BattlerTagLapseType.TURN_END ], turnCount, sourceMove, sourceId);
}
lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
if (lapseType === BattlerTagLapseType.PRE_MOVE) {
// Cancel the affected pokemon's selected move
const phase = pokemon.scene.getCurrentPhase() as MovePhase;
const move = phase.move;
if (!this.moveIsDisabled(move.moveId)) {
return true;
}
pokemon.scene.queueMessage(this.interruptedText(pokemon, move.moveId));
phase.fail();
} else if (lapseType === BattlerTagLapseType.TURN_END) {
// On turn end, subtract from lifetime and remove this tag if 0
if (!super.lapse(pokemon, lapseType)) {
// Duration has expired
return false;
}
}
return true;
}

View File

@ -3634,7 +3634,7 @@ export class PlayerPokemon extends Pokemon {
if (!this.isFainted()) {
// If this Pokemon hasn't fainted, make sure the HP wasn't set over the new maximum
this.hp = Math.min(this.hp, this.stats[Stat.HP]);
this.status = getRandomStatus(this.status, pokemon.status); // Get a random valid status between the two
this.status = getRandomStatus(this.status!, pokemon.status!); // Get a random valid status between the two // TODO: are the bangs correct?
} else if (!pokemon.isFainted()) {
// If this Pokemon fainted but the other hasn't, make sure the HP wasn't set to zero
this.hp = Math.max(this.hp, 1);
@ -4331,12 +4331,12 @@ export class PokemonMove {
* @param ignorePp If true, skips the PP check
* @returns True if the move can be selected and used by the Pokemon, otherwise false.
*/
isUsable(pokemon: Pokemon, ignorePp?: boolean): boolean {
isUsable(pokemon: Pokemon, ignorePp?: boolean, ignoreDisableTags?: boolean): boolean {
if (!this.moveId) {
return false;
}
if (pokemon.isMoveDisabled(this.moveId)) {
if (!ignoreDisableTags && pokemon.isMoveDisabled(this.moveId)) {
return false;
}

View File

@ -2666,8 +2666,8 @@ export class MovePhase extends BattlePhase {
this.cancelled = false;
}
canMove(): boolean {
return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon, this.ignorePp) && !!this.targets.length;
canMove(ignoreDisableTags?: boolean): boolean {
return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon, this.ignorePp, ignoreDisableTags) && !!this.targets.length;
}
/**Signifies the current move should fail but still use PP */
@ -2685,13 +2685,8 @@ export class MovePhase extends BattlePhase {
console.log(Moves[this.move.moveId]);
if (!this.canMove()) {
if (this.move.moveId && this.pokemon.isMoveDisabled(this.move.moveId)) {
const interruptingTag = this.pokemon.getDisablingTag(this.move.moveId)!;
this.scene.queueMessage(interruptingTag.interruptedText(this.pokemon, this.move.moveId));
this.pokemon.pushMoveHistory({ move: this.move.moveId, result: MoveResult.FAIL, virtual: false });
this.fail();
} else if (this.pokemon.isActive(true) && this.move.ppUsed >= this.move.getMovePp()) { // if the move PP was reduced from Spite or otherwise, the move fails
if (!this.canMove(true)) {
if (this.pokemon.isActive(true) && this.move.ppUsed >= this.move.getMovePp()) { // if the move PP was reduced from Spite or otherwise, the move fails
this.fail();
this.showMoveText();
this.showFailedText();