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

Fix Receiver's interaction with Soul-Heart #10894

Open
wants to merge 4 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
42 changes: 34 additions & 8 deletions data/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3308,12 +3308,25 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
num: 211,
},
powerofalchemy: {
onAllyFaint(target) {
if (!this.effectState.target.hp) return;
onAllyFaint(target, source, effect) {
const pokemon: Pokemon = this.effectState.target;
if (!pokemon.hp) return;
const ability = target.getAbility();
if (ability.flags['noreceiver'] || ability.id === 'noability') return;
if (this.effectState.target.setAbility(ability)) {
this.add('-ability', this.effectState.target, ability, '[from] ability: Power of Alchemy', `[of] ${target}`);
if (pokemon.setAbility(ability)) {
this.add('-ability', pokemon, ability, '[from] ability: Power of Alchemy', `[of] ${target}`);
const handlers: any[] = [];
for (const event of ['AllyFaint', 'AnyFaint']) {
const callbackName = 'on' + event;
// @ts-expect-error dynamic lookup
const callback = ability[callbackName];
if (callback !== undefined) {
handlers.push(this.resolvePriority({
effect: ability, callback, state: pokemon.abilityState, end: pokemon.clearAbility, effectHolder: pokemon,
}, callbackName));
}
}
this.runHandlers(handlers, 'Faint', target, source, effect);
}
},
flags: { failroleplay: 1, noreceiver: 1, noentrain: 1, notrace: 1 },
Expand Down Expand Up @@ -3697,12 +3710,25 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
num: 155,
},
receiver: {
onAllyFaint(target) {
if (!this.effectState.target.hp) return;
onAllyFaint(target, source, effect) {
const pokemon: Pokemon = this.effectState.target;
if (!pokemon.hp) return;
const ability = target.getAbility();
if (ability.flags['noreceiver'] || ability.id === 'noability') return;
if (this.effectState.target.setAbility(ability)) {
this.add('-ability', this.effectState.target, ability, '[from] ability: Receiver', `[of] ${target}`);
if (pokemon.setAbility(ability)) {
this.add('-ability', pokemon, ability, '[from] ability: Receiver', `[of] ${target}`);
const handlers: any[] = [];
for (const event of ['AllyFaint', 'AnyFaint']) {
const callbackName = 'on' + event;
// @ts-expect-error dynamic lookup
const callback = ability[callbackName];
if (callback !== undefined) {
handlers.push(this.resolvePriority({
effect: ability, callback, state: pokemon.abilityState, end: pokemon.clearAbility, effectHolder: pokemon,
}, callbackName));
}
}
this.runHandlers(handlers, 'Faint', target, source, effect);
}
},
flags: { failroleplay: 1, noreceiver: 1, noentrain: 1, notrace: 1 },
Expand Down
16 changes: 16 additions & 0 deletions sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,22 @@ export class Battle {
}, `on${eventid}`));
}
}
return this.runHandlers(handlers, eventid, target, source, sourceEffect, relayVar, fastExit);
}

runHandlers(
handlers: EventListener[], eventid: string, target?: Pokemon | Pokemon[] | Side | Battle | null,
source?: string | Pokemon | false | null, sourceEffect?: Effect | null, relayVar?: any, fastExit?: boolean
) {
if (this.eventDepth >= 8) {
// oh fuck
this.add('message', 'STACK LIMIT EXCEEDED');
this.add('message', 'PLEASE REPORT IN BUG THREAD');
this.add('message', 'Event: ' + eventid);
this.add('message', 'Parent event: ' + this.event.id);
throw new Error("Stack overflow");
}
if (!target) target = this;

if (['Invulnerability', 'TryHit', 'DamagingHit', 'EntryHazard'].includes(eventid)) {
handlers.sort(Battle.compareLeftToRightOrder);
Expand Down
4 changes: 2 additions & 2 deletions test/sim/abilities/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe(`Receiver`, () => {
battle.destroy();
});

it.skip(`should gain a boost immediately if taking over a KO boost Ability`, () => {
it(`should gain a boost immediately if taking over a KO boost Ability`, () => {
battle = common.createBattle({ gameType: 'doubles' }, [[
{ species: 'whimsicott', ability: 'soulheart', moves: ['memento'] },
{ species: 'passimian', ability: 'receiver', moves: ['sleeptalk'] },
Expand All @@ -23,7 +23,7 @@ describe(`Receiver`, () => {
assert.statStage(passimian, 'spa', 1);
});

it.skip(`should do weird stuff with multiple Soul-Heart and multiple Receiver`, () => {
it(`should do weird stuff with multiple Soul-Heart and multiple Receiver`, () => {
battle = common.createBattle({ gameType: 'doubles' }, [[
{ species: 'Passimian', ability: 'receiver', moves: ['earthquake'] },
{ species: 'Magearna', ability: 'soulheart', level: 1, moves: ['sleeptalk'] },
Expand Down