Prevent RandomMoveAttr from Using Banned Moves

This commit is contained in:
xsn34kzx 2025-08-07 00:53:33 -04:00
parent 3ca944efa6
commit da2b69280e

View File

@ -124,7 +124,7 @@ export abstract class Move implements Localizable {
/** /**
* Check if the move is of the given subclass without requiring `instanceof`. * Check if the move is of the given subclass without requiring `instanceof`.
* *
* Does _not_ work for {@linkcode ChargingAttackMove} and {@linkcode ChargingSelfStatusMove} subclasses. For those, * ! Does _not_ work for {@linkcode ChargingAttackMove} and {@linkcode ChargingSelfStatusMove} subclasses. For those,
* use {@linkcode isChargingMove} instead. * use {@linkcode isChargingMove} instead.
* *
* @param moveKind - The string name of the move to check against * @param moveKind - The string name of the move to check against
@ -6906,13 +6906,19 @@ export class RandomMoveAttr extends CallMoveAttr {
* @param move Move being used * @param move Move being used
* @param args Unused * @param args Unused
*/ */
override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { override apply(user: Pokemon, target: Pokemon, _move: Move, args: any[]): boolean {
// TODO: Move this into the constructor to avoid constructing this every call
const moveIds = getEnumValues(MoveId).map(m => !this.invalidMoves.has(m) && !allMoves[m].name.endsWith(" (N)") ? m : MoveId.NONE); const moveIds = getEnumValues(MoveId).map(m => !this.invalidMoves.has(m) && !allMoves[m].name.endsWith(" (N)") ? m : MoveId.NONE);
let moveId: MoveId = MoveId.NONE; let moveId: MoveId = MoveId.NONE;
const moveStatus = new BooleanHolder(true);
do { do {
moveId = this.getMoveOverride() ?? moveIds[user.randBattleSeedInt(moveIds.length)]; moveId = this.getMoveOverride() ?? moveIds[user.randBattleSeedInt(moveIds.length)];
moveStatus.value = moveId !== MoveId.NONE;
if (user.isPlayer()) {
applyChallenges(ChallengeType.POKEMON_MOVE, moveId, moveStatus);
} }
while (moveId === MoveId.NONE); }
while (!moveStatus.value);
return super.apply(user, target, allMoves[moveId], args); return super.apply(user, target, allMoves[moveId], args);
} }
} }