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

Automatically activate Booster Energy during weather/terrain changes #10832

Open
wants to merge 19 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
36 changes: 31 additions & 5 deletions data/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
},
onUpdate(pokemon) {
if (this.gameType !== 'doubles') return;
// don't run between when a Pokemon switches in and the resulting onSwitchIn event
// don't run between when a Pokemon switches in and the resulting SwitchIn event
if (this.queue.peek()?.choice === 'runSwitch') return;

const ally = pokemon.allies()[0];
Expand Down Expand Up @@ -3438,8 +3438,21 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
// Protosynthesis is not affected by Utility Umbrella
if (this.field.isWeather('sunnyday')) {
pokemon.addVolatile('protosynthesis');
} else if (!pokemon.volatiles['protosynthesis']?.fromBooster && !this.field.isWeather('sunnyday')) {
pokemon.removeVolatile('protosynthesis');
} else {
if (!pokemon.volatiles['protosynthesis']?.fromBooster) {
pokemon.removeVolatile('protosynthesis');
}
if (!pokemon.volatiles['protosynthesis'] && pokemon.hasItem('boosterenergy')) {
pokemon.useItem(pokemon, this.dex.abilities.get('protosynthesis'));
}
}
},
onUpdate(pokemon) {
// don't run between when a Pokemon switches in and the resulting SwitchIn event
if (this.queue.peek()?.choice === 'runSwitch') return;

if (!pokemon.volatiles['protosynthesis'] && !this.field.isWeather('sunnyday') && pokemon.hasItem('boosterenergy')) {
pokemon.useItem(pokemon, this.dex.abilities.get('protosynthesis'));
}
},
onEnd(pokemon) {
Expand Down Expand Up @@ -3574,8 +3587,21 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
onTerrainChange(pokemon) {
if (this.field.isTerrain('electricterrain')) {
pokemon.addVolatile('quarkdrive');
} else if (!pokemon.volatiles['quarkdrive']?.fromBooster) {
pokemon.removeVolatile('quarkdrive');
} else {
if (!pokemon.volatiles['quarkdrive']?.fromBooster) {
pokemon.removeVolatile('quarkdrive');
}
if (!pokemon.volatiles['quarkdrive'] && pokemon.hasItem('boosterenergy')) {
pokemon.useItem(pokemon, this.dex.abilities.get('quarkdrive'));
}
}
},
onUpdate(pokemon) {
// don't run between when a Pokemon switches in and the resulting SwitchIn event
if (this.queue.peek()?.choice === 'runSwitch') return;

if (!pokemon.volatiles['quarkdrive'] && !this.field.isTerrain('electricterrain') && pokemon.hasItem('boosterenergy')) {
pokemon.useItem(pokemon, this.dex.abilities.get('quarkdrive'));
}
},
onEnd(pokemon) {
Expand Down
17 changes: 4 additions & 13 deletions data/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,20 +613,11 @@ export const Items: import('../sim/dex-items').ItemDataTable = {
fling: {
basePower: 30,
},
onSwitchInPriority: -2,
onStart(pokemon) {
this.effectState.started = true;
((this.effect as any).onUpdate as (p: Pokemon) => void).call(this, pokemon);
onUseItem(item, pokemon, source, sourceEffect) {
return pokemon === source && ['protosynthesis', 'quarkdrive'].includes(sourceEffect.id);
},
onUpdate(pokemon) {
if (!this.effectState.started || pokemon.transformed) return;

if (pokemon.hasAbility('protosynthesis') && !this.field.isWeather('sunnyday') && pokemon.useItem()) {
pokemon.addVolatile('protosynthesis');
}
if (pokemon.hasAbility('quarkdrive') && !this.field.isTerrain('electricterrain') && pokemon.useItem()) {
pokemon.addVolatile('quarkdrive');
}
onUse(pokemon, source, sourceEffect) {
pokemon.addVolatile(sourceEffect.id);
},
onTakeItem(item, source) {
if (source.baseSpecies.tags.includes("Paradox")) return false;
Expand Down
10 changes: 7 additions & 3 deletions data/mods/gen9dlc1/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export const Abilities: import('../../../sim/dex-abilities').ModdedAbilityDataTa
// Protosynthesis is not affected by Utility Umbrella
if (this.field.isWeather('sunnyday')) {
pokemon.addVolatile('protosynthesis');
} else if (!pokemon.volatiles['protosynthesis']?.fromBooster && this.field.weather !== 'sunnyday') {
// Protosynthesis will not deactivite if Sun is suppressed, hence the direct ID check (isWeather respects supression)
pokemon.removeVolatile('protosynthesis');
} else {
if (!pokemon.volatiles['protosynthesis']?.fromBooster && this.field.weather !== 'sunnyday') {
pokemon.removeVolatile('protosynthesis');
}
if (!pokemon.volatiles['protosynthesis'] && pokemon.hasItem('boosterenergy')) {
pokemon.useItem(pokemon, this.dex.abilities.get('protosynthesis'));
}
}
},
condition: {
Expand Down
2 changes: 1 addition & 1 deletion sim/dex-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export interface EventMethods {
onTryMove?: MoveEventMethods['onTryMove'];
onTryPrimaryHit?: (this: Battle, target: Pokemon, source: Pokemon, move: ActiveMove) => boolean | null | number | void;
onType?: (this: Battle, types: string[], pokemon: Pokemon) => string[] | void;
onUseItem?: (this: Battle, item: Item, pokemon: Pokemon) => void;
onUseItem?: (this: Battle, item: Item, pokemon: Pokemon, source: Pokemon, sourceEffect: Effect) => void;
onUpdate?: (this: Battle, pokemon: Pokemon) => void;
onWeather?: (this: Battle, target: Pokemon, source: null, effect: Condition) => void;
onWeatherModifyDamage?: CommonHandlers['ModifierSourceMove'];
Expand Down
2 changes: 1 addition & 1 deletion sim/dex-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Item extends BasicEffect implements Readonly<BasicEffect> {
declare readonly boosts?: SparseBoostsTable | false;

declare readonly onEat?: ((this: Battle, pokemon: Pokemon) => void) | false;
declare readonly onUse?: ((this: Battle, pokemon: Pokemon) => void) | false;
declare readonly onUse?: ((this: Battle, pokemon: Pokemon, source: Pokemon, sourceEffect: Effect) => void) | false;
declare readonly onStart?: (this: Battle, target: Pokemon) => void;
declare readonly onEnd?: (this: Battle, target: Pokemon) => void;

Expand Down
5 changes: 1 addition & 4 deletions sim/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1493,9 +1493,6 @@ export class Pokemon {

this.volatileStaleness = undefined;

delete this.abilityState.started;
delete this.itemState.started;

this.setSpecies(this.baseSpecies);
}

Expand Down Expand Up @@ -1757,7 +1754,7 @@ export class Pokemon {
// if an item is telling us to eat it but we aren't holding it, we probably shouldn't eat what we are holding
return false;
}
if (this.battle.runEvent('UseItem', this, null, null, item)) {
if (this.battle.runEvent('UseItem', this, source, sourceEffect, item)) {
switch (item.id) {
case 'redcard':
this.battle.add('-enditem', this, item, '[of] ' + source);
Expand Down
15 changes: 15 additions & 0 deletions test/sim/items/boosterenergy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,19 @@ describe('Booster Energy', function () {
assert.equal(bundle.volatiles['quarkdrive'].bestStat, 'spa',
`Iron Bundle's Speed should have been lowered before Booster Energy activated, boosting its SpA instead.`);
});

it(`should activate right after weather changes`, function () {
battle = common.createBattle({gameType: 'doubles'}, [[
{species: 'Ninetales-Alola', ability: 'snowwarning', moves: ['sleeptalk']},
{species: 'Roaring Moon', item: 'boosterenergy', ability: 'protosynthesis', moves: ['sleeptalk']},
], [
{species: 'Incineroar', ability: 'intimidate', moves: ['sleeptalk']},
{species: 'Torkoal', ability: 'drought', moves: ['sleeptalk']},
]]);

const roaringMoon = battle.p1.active[1];
assert(roaringMoon.volatiles['protosynthesis'].fromBooster);
assert.equal(roaringMoon.volatiles['protosynthesis'].bestStat, 'atk');
assert.equal(battle.field.weather, 'sunnyday');
});
});