Added PRE_MOVE lapse code to handle early tag expiration from PP-less encored move

This commit is contained in:
frutescens 2024-11-06 13:05:45 -08:00
parent 2772fc5b30
commit a0994c0151

View File

@ -917,7 +917,7 @@ export class EncoreTag extends MoveRestrictionBattlerTag {
public moveId: Moves;
constructor(sourceId: number) {
super(BattlerTagType.ENCORE, BattlerTagLapseType.AFTER_MOVE, 3, Moves.ENCORE, sourceId);
super(BattlerTagType.ENCORE, [ BattlerTagLapseType.PRE_MOVE, BattlerTagLapseType.AFTER_MOVE ], 3, Moves.ENCORE, sourceId);
}
/**
@ -973,6 +973,24 @@ export class EncoreTag extends MoveRestrictionBattlerTag {
}
}
/**
* If the encored move has run out of PP, Encore ends early. Otherwise, Encore lapses based on the AFTER_MOVE battler tag lapse type.
* @param pokemon
* @param lapseType
* @returns `true` to persist | `false` to end and be removed
*/
override lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
if (lapseType === BattlerTagLapseType.PRE_MOVE) {
const encoredMove = pokemon.getMoveset().find(m => m?.moveId === this.moveId);
if (encoredMove && encoredMove?.getPpRatio() > 0) {
return true;
}
return false;
} else {
return super.lapse(pokemon, lapseType);
}
}
/**
* Checks if the move matches the moveId stored within the tag and returns a boolean value
* @param move {@linkcode Moves} the move selected