Skip to content

Commit 8085320

Browse files
committed
Implement Fight button cancelability
1 parent 163db0e commit 8085320

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

data/mods/gen1/conditions.ts

+26-19
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,23 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa
196196
onRestart() {
197197
this.effectState.duration = 2;
198198
},
199-
// onDisableMove(target) {
200-
// target.maybeDisabled = true;
201-
// },
199+
onLockMove() {
200+
// exact move doesn't matter, no move is ever actually used
201+
return 'struggle';
202+
},
203+
onDisableMove(target) {
204+
target.maybeLocked = true;
205+
},
206+
},
207+
fakepartiallytrapped: {
208+
name: 'fakepartiallytrapped',
209+
// Wrap ended this turn, but you don't know that
210+
// until you try to use an attack
211+
duration: 2,
212+
onDisableMove(target) {
213+
target.maybeLocked = true;
214+
},
202215
},
203-
// fakepartiallytrapped: {
204-
// name: 'fakepartiallytrapped',
205-
// // Wrap ended this turn, but you don't know that
206-
// // until you try to use an attack
207-
// duration: 2,
208-
// onDisableMove(target) {
209-
// target.maybeDisabled = true;
210-
// },
211-
// },
212216
partialtrappinglock: {
213217
name: 'partialtrappinglock',
214218
durationCallback() {
@@ -240,18 +244,21 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa
240244
this.add('move', pokemon, this.effectState.move, foe, `[from] ${this.effectState.move}`);
241245
this.damage(this.effectState.damage, foe, pokemon, move);
242246
if (this.effectState.duration === 1) {
243-
// if (this.effectState.totalDuration !== 5) {
244-
// pokemon.addVolatile('fakepartiallytrapped');
245-
// foe.addVolatile('fakepartiallytrapped');
246-
// }
247+
if (this.effectState.totalDuration !== 5) {
248+
pokemon.addVolatile('fakepartiallytrapped');
249+
foe.addVolatile('fakepartiallytrapped');
250+
}
247251
} else {
248252
foe.addVolatile('partiallytrapped', pokemon, move);
249253
}
250254
return false;
251255
},
252-
// onDisableMove(pokemon) {
253-
// pokemon.maybeDisabled = true;
254-
// },
256+
onLockMove() {
257+
return this.effectState.move;
258+
},
259+
onDisableMove(pokemon) {
260+
pokemon.maybeLocked = true;
261+
},
255262
},
256263
mustrecharge: {
257264
inherit: true,

sim/pokemon.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ export class Pokemon {
127127
trapped: boolean | "hidden";
128128
maybeTrapped: boolean;
129129
maybeDisabled: boolean;
130+
/** true = locked, */
131+
maybeLocked: boolean | null;
130132

131133
illusion: Pokemon | null;
132134
transformed: boolean;
@@ -418,6 +420,7 @@ export class Pokemon {
418420
this.trapped = false;
419421
this.maybeTrapped = false;
420422
this.maybeDisabled = false;
423+
this.maybeLocked = false;
421424

422425
this.illusion = null;
423426
this.transformed = false;
@@ -1048,7 +1051,7 @@ export class Pokemon {
10481051
}
10491052

10501053
getMoveRequestData() {
1051-
let lockedMove = this.getLockedMove();
1054+
let lockedMove = this.maybeLocked ? null : this.getLockedMove();
10521055

10531056
// Information should be restricted for the last active Pokémon
10541057
const isLastActive = this.isLastActive();
@@ -1068,6 +1071,9 @@ export class Pokemon {
10681071
if (this.maybeDisabled) {
10691072
data.maybeDisabled = this.maybeDisabled;
10701073
}
1074+
if (this.maybeLocked) {
1075+
data.maybeLocked = this.maybeLocked;
1076+
}
10711077
if (canSwitchIn) {
10721078
if (this.trapped === true) {
10731079
data.trapped = true;

sim/side.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ export interface PokemonSwitchRequestData {
9191
terastallized?: string;
9292
}
9393
export interface PokemonMoveRequestData {
94-
moves: { move: string, id: ID, target?: string, disabled?: string | boolean }[];
94+
moves: { move: string, id: ID, target?: string, disabled?: string | boolean, disabledSource?: string }[];
9595
maybeDisabled?: boolean;
96+
maybeLocked?: boolean;
9697
trapped?: boolean;
9798
maybeTrapped?: boolean;
9899
canMegaEvo?: boolean;
@@ -638,7 +639,20 @@ export class Side {
638639
targetLoc: lockedMoveTargetLoc,
639640
moveid: lockedMoveID,
640641
});
642+
if (moveid === 'fight') this.choice.cantUndo = true;
641643
return true;
644+
} else if (moveid === 'fight') {
645+
// test fight button
646+
if (!pokemon.maybeLocked) {
647+
return this.emitChoiceError(`Can't move: ${pokemon.name}'s Fight button is known to be safe`);
648+
}
649+
pokemon.maybeLocked = false;
650+
this.updateRequestForPokemon(pokemon, req => {
651+
delete req.maybeLocked;
652+
});
653+
this.emitChoiceError(`Can't move: ${pokemon.name} is not locked`, true);
654+
this.emitRequest(this.activeRequest!);
655+
return false;
642656
} else if (!moves.length && !zMove) {
643657
// Override action and use Struggle if there are no enabled moves with PP
644658
// Gen 4 and earlier announce a Pokemon has no moves left before the turn begins, and only to that player's side.
@@ -682,9 +696,9 @@ export class Side {
682696
}
683697
return updated;
684698
});
685-
const status = this.emitChoiceError(`Can't move: ${pokemon.name}'s ${move.name} is disabled`, includeRequest);
699+
this.emitChoiceError(`Can't move: ${pokemon.name}'s ${move.name} is disabled`, includeRequest);
686700
if (includeRequest) this.emitRequest(this.activeRequest!);
687-
return status;
701+
return false;
688702
}
689703
// The chosen move is valid yay
690704
}
@@ -769,13 +783,13 @@ export class Side {
769783
return true;
770784
}
771785

772-
updateRequestForPokemon(pokemon: Pokemon, update: (req: AnyObject) => boolean) {
786+
updateRequestForPokemon(pokemon: Pokemon, update: (req: PokemonMoveRequestData) => boolean | void) {
773787
if (!(this.activeRequest as MoveRequest)?.active) {
774788
throw new Error(`Can't update a request without active Pokemon`);
775789
}
776790
const req = (this.activeRequest as MoveRequest).active[pokemon.position];
777791
if (!req) throw new Error(`Pokemon not found in request's active field`);
778-
return update(req);
792+
return update(req) ?? true;
779793
}
780794

781795
chooseSwitch(slotText?: string) {

0 commit comments

Comments
 (0)