Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Dancer using the battle queue and the AnyAfterMove event #10975

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion data/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,50 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
dancer: {
flags: {},
name: "Dancer",
// implemented in runMove in scripts.js
onAnyAfterMovePriority: -200,
onAnyAfterMove(source, target, move) {
const dancer = this.effectState.target as Pokemon;
if (dancer === source || dancer.isSemiInvulnerable() || !move.flags['dance'] ||
!this.lastSuccessfulMoveThisTurn || move.isExternal) return;
const targetOf1stDance = this.activeTarget!;
dancer.addVolatile('dancer');
const dancersTarget = !targetOf1stDance.isAlly(dancer) && source.isAlly(dancer) ?
targetOf1stDance : source;
const dancersTargetLoc = dancer.getLocOf(dancersTarget);
// Dancer activates in order of lowest speed stat to highest
// Note that the speed stat used is after any volatile replacements like Speed Swap,
// but before any multipliers like Agility or Choice Scarf
// Ties go to whichever Pokemon has had the ability for the least amount of time
this.queue.insertChoice({
choice: 'move',
order: 198,
speed: -source.storedStats['spe'],
effectOrder: dancer.abilityState.effectOrder,
pokemon: dancer,
moveid: move.id,
targetLoc: dancersTargetLoc,
sourceEffect: this.dex.abilities.get('dancer'),
externalMove: true,
});
},
condition: {
noCopy: true, // doesn't get copied by Baton Pass
onBeforeMovePriority: 200,
onBeforeMove(source, target, move) {
if (move.isExternal) {
this.add('-activate', source, 'ability: Dancer');
this.effectState.noLock = move.isExternal && !source.volatiles['lockedmove'];
}
},
onTryAddVolatile(status) {
if (status.id === 'lockedmove' && this.effectState.noLock) return null;
},
onAfterMove(source, target, move) {
if (move.isExternal) {
delete source.volatiles['dancer'];
}
},
},
rating: 1.5,
num: 216,
},
Expand Down
34 changes: 0 additions & 34 deletions sim/battle-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ export class BattleActions {
pokemon.moveUsed(move, targetLoc);
}

// Dancer Petal Dance hack
// TODO: implement properly
const noLock = externalMove && !pokemon.volatiles['lockedmove'];

if (zMove) {
if (pokemon.illusion) {
this.battle.singleEvent('End', this.dex.abilities.get('Illusion'), pokemon.abilityState, pokemon);
Expand All @@ -313,36 +309,6 @@ export class BattleActions {
this.battle.add('-hint', `Some effects can force a Pokemon to use ${move.name} again in a row.`);
}

// TODO: Refactor to use BattleQueue#prioritizeAction in onAnyAfterMove handlers
// Dancer's activation order is completely different from any other event, so it's handled separately
if (move.flags['dance'] && moveDidSomething && !move.isExternal) {
const dancers = [];
for (const currentPoke of this.battle.getAllActive()) {
if (pokemon === currentPoke) continue;
if (currentPoke.hasAbility('dancer') && !currentPoke.isSemiInvulnerable()) {
dancers.push(currentPoke);
}
}
// Dancer activates in order of lowest speed stat to highest
// Note that the speed stat used is after any volatile replacements like Speed Swap,
// but before any multipliers like Agility or Choice Scarf
// Ties go to whichever Pokemon has had the ability for the least amount of time
dancers.sort(
(a, b) => -(b.storedStats['spe'] - a.storedStats['spe']) || b.abilityState.effectOrder - a.abilityState.effectOrder
);
const targetOf1stDance = this.battle.activeTarget!;
for (const dancer of dancers) {
if (this.battle.faintMessages()) break;
if (dancer.fainted) continue;
this.battle.add('-activate', dancer, 'ability: Dancer');
const dancersTarget = !targetOf1stDance.isAlly(dancer) && pokemon.isAlly(dancer) ?
targetOf1stDance :
pokemon;
const dancersTargetLoc = dancer.getLocOf(dancersTarget);
this.runMove(move.id, dancer, dancersTargetLoc, { sourceEffect: this.dex.abilities.get('dancer'), externalMove: true });
}
}
if (noLock && pokemon.volatiles['lockedmove']) delete pokemon.volatiles['lockedmove'];
this.battle.faintMessages();
this.battle.checkWin();

Expand Down
4 changes: 3 additions & 1 deletion sim/battle-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { Battle } from './battle';
export interface MoveAction {
/** action type */
choice: 'move' | 'beforeTurnMove' | 'priorityChargeMove';
order: 3 | 5 | 200 | 201 | 199 | 106;
order: 3 | 5 | 107 | 198 | 199 | 200 | 201;
/** priority of the action (lower first) */
priority: number;
/** fractional priority of the action (lower first) */
Expand All @@ -44,6 +44,8 @@ export interface MoveAction {
maxMove?: string;
/** effect that called the move (eg Instruct) if any */
sourceEffect?: Effect | null;
/** if external, skips LockMove and PP deduction, mostly for use by Dancer */
externalMove?: boolean;
}

/** A switch action */
Expand Down
4 changes: 2 additions & 2 deletions sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,7 @@ export class Battle {

if (!action.pokemon) {
action.speed = 1;
} else {
} else if (!action.externalMove) { // FIXME HACK
action.speed = action.pokemon.getActionSpeed();
}
}
Expand Down Expand Up @@ -2682,7 +2682,7 @@ export class Battle {
if (!action.pokemon.isActive) return false;
if (action.pokemon.fainted) return false;
this.actions.runMove(action.move, action.pokemon, action.targetLoc, {
sourceEffect: action.sourceEffect, zMove: action.zmove,
sourceEffect: action.sourceEffect, zMove: action.zmove, externalMove: action.externalMove,
maxMove: action.maxMove, originalTarget: action.originalTarget,
});
break;
Expand Down
1 change: 1 addition & 0 deletions sim/dex-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export interface EventMethods {
onAfterMoveSecondarySelfPriority?: number;
onAfterMoveSelfPriority?: number;
onAfterSetStatusPriority?: number;
onAnyAfterMovePriority?: number;
onAnyBasePowerPriority?: number;
onAnyInvulnerabilityPriority?: number;
onAnyModifyAccuracyPriority?: number;
Expand Down
15 changes: 15 additions & 0 deletions test/sim/abilities/dancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,19 @@ describe('Dancer', () => {
assert.equal(fletchinder.boosts.atk, -2);
assert.equal(squawkabilly.boosts.atk, -4);
});

it('should activate after Eject Button', () => {
battle = common.createBattle({ gameType: 'doubles' }, [[
{ species: 'oricoriopau', ability: 'dancer', moves: ['sleeptalk'] },
{ species: 'volcarona', moves: ['fierydance'] },
], [
{ species: 'fletchinder', item: 'ejectbutton', moves: ['sleeptalk'] },
{ species: 'squawkabilly', moves: ['sleeptalk'] },
{ species: 'suicune', moves: ['sleeptalk'] },
]]);
const suicune = battle.p2.pokemon[2];
battle.makeChoices('move sleeptalk, move fierydance 1', 'move sleeptalk, move sleeptalk');
battle.makeChoices();
assert.notEqual(suicune.hp, suicune.fullHP);
});
});