Skip to content

Commit

Permalink
Implement Fight button cancelability
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Mar 6, 2025
1 parent 163db0e commit 8085320
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
45 changes: 26 additions & 19 deletions data/mods/gen1/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,23 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa
onRestart() {
this.effectState.duration = 2;
},
// onDisableMove(target) {
// target.maybeDisabled = true;
// },
onLockMove() {
// exact move doesn't matter, no move is ever actually used
return 'struggle';
},
onDisableMove(target) {
target.maybeLocked = true;
},
},
fakepartiallytrapped: {
name: 'fakepartiallytrapped',
// Wrap ended this turn, but you don't know that
// until you try to use an attack
duration: 2,
onDisableMove(target) {
target.maybeLocked = true;
},
},
// fakepartiallytrapped: {
// name: 'fakepartiallytrapped',
// // Wrap ended this turn, but you don't know that
// // until you try to use an attack
// duration: 2,
// onDisableMove(target) {
// target.maybeDisabled = true;
// },
// },
partialtrappinglock: {
name: 'partialtrappinglock',
durationCallback() {
Expand Down Expand Up @@ -240,18 +244,21 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa
this.add('move', pokemon, this.effectState.move, foe, `[from] ${this.effectState.move}`);
this.damage(this.effectState.damage, foe, pokemon, move);
if (this.effectState.duration === 1) {
// if (this.effectState.totalDuration !== 5) {
// pokemon.addVolatile('fakepartiallytrapped');
// foe.addVolatile('fakepartiallytrapped');
// }
if (this.effectState.totalDuration !== 5) {
pokemon.addVolatile('fakepartiallytrapped');
foe.addVolatile('fakepartiallytrapped');
}
} else {
foe.addVolatile('partiallytrapped', pokemon, move);
}
return false;
},
// onDisableMove(pokemon) {
// pokemon.maybeDisabled = true;
// },
onLockMove() {
return this.effectState.move;
},
onDisableMove(pokemon) {
pokemon.maybeLocked = true;
},
},
mustrecharge: {
inherit: true,
Expand Down
8 changes: 7 additions & 1 deletion sim/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export class Pokemon {
trapped: boolean | "hidden";
maybeTrapped: boolean;
maybeDisabled: boolean;
/** true = locked, */
maybeLocked: boolean | null;

illusion: Pokemon | null;
transformed: boolean;
Expand Down Expand Up @@ -418,6 +420,7 @@ export class Pokemon {
this.trapped = false;
this.maybeTrapped = false;
this.maybeDisabled = false;
this.maybeLocked = false;

this.illusion = null;
this.transformed = false;
Expand Down Expand Up @@ -1048,7 +1051,7 @@ export class Pokemon {
}

getMoveRequestData() {
let lockedMove = this.getLockedMove();
let lockedMove = this.maybeLocked ? null : this.getLockedMove();

// Information should be restricted for the last active Pokémon
const isLastActive = this.isLastActive();
Expand All @@ -1068,6 +1071,9 @@ export class Pokemon {
if (this.maybeDisabled) {
data.maybeDisabled = this.maybeDisabled;
}
if (this.maybeLocked) {
data.maybeLocked = this.maybeLocked;
}
if (canSwitchIn) {
if (this.trapped === true) {
data.trapped = true;
Expand Down
24 changes: 19 additions & 5 deletions sim/side.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ export interface PokemonSwitchRequestData {
terastallized?: string;
}
export interface PokemonMoveRequestData {
moves: { move: string, id: ID, target?: string, disabled?: string | boolean }[];
moves: { move: string, id: ID, target?: string, disabled?: string | boolean, disabledSource?: string }[];
maybeDisabled?: boolean;
maybeLocked?: boolean;
trapped?: boolean;
maybeTrapped?: boolean;
canMegaEvo?: boolean;
Expand Down Expand Up @@ -638,7 +639,20 @@ export class Side {
targetLoc: lockedMoveTargetLoc,
moveid: lockedMoveID,
});
if (moveid === 'fight') this.choice.cantUndo = true;
return true;
} else if (moveid === 'fight') {
// test fight button
if (!pokemon.maybeLocked) {
return this.emitChoiceError(`Can't move: ${pokemon.name}'s Fight button is known to be safe`);
}
pokemon.maybeLocked = false;
this.updateRequestForPokemon(pokemon, req => {
delete req.maybeLocked;
});
this.emitChoiceError(`Can't move: ${pokemon.name} is not locked`, true);
this.emitRequest(this.activeRequest!);
return false;
} else if (!moves.length && !zMove) {
// Override action and use Struggle if there are no enabled moves with PP
// Gen 4 and earlier announce a Pokemon has no moves left before the turn begins, and only to that player's side.
Expand Down Expand Up @@ -682,9 +696,9 @@ export class Side {
}
return updated;
});
const status = this.emitChoiceError(`Can't move: ${pokemon.name}'s ${move.name} is disabled`, includeRequest);
this.emitChoiceError(`Can't move: ${pokemon.name}'s ${move.name} is disabled`, includeRequest);
if (includeRequest) this.emitRequest(this.activeRequest!);
return status;
return false;
}
// The chosen move is valid yay
}
Expand Down Expand Up @@ -769,13 +783,13 @@ export class Side {
return true;
}

updateRequestForPokemon(pokemon: Pokemon, update: (req: AnyObject) => boolean) {
updateRequestForPokemon(pokemon: Pokemon, update: (req: PokemonMoveRequestData) => boolean | void) {
if (!(this.activeRequest as MoveRequest)?.active) {
throw new Error(`Can't update a request without active Pokemon`);
}
const req = (this.activeRequest as MoveRequest).active[pokemon.position];
if (!req) throw new Error(`Pokemon not found in request's active field`);
return update(req);
return update(req) ?? true;
}

chooseSwitch(slotText?: string) {
Expand Down

0 comments on commit 8085320

Please sign in to comment.