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

Add test and fix gen 7 onSwitchInPriority #10842

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c5e4827
Mirror Herb: Copy simultaneous boosts from Howl, etc.
pyuk-bot Dec 18, 2024
d95b679
Actually send End single events for Items on switch out
pyuk-bot Dec 18, 2024
d2a78a1
Overhaul 'SwitchIn' event for more accurate effect resolution order
pyuk-bot Dec 26, 2024
8481063
Unskip a passing Eject Pack test
pyuk-bot Dec 26, 2024
e112313
Keep speed tie resolution consistent across the SwitchIn event
pyuk-bot Dec 27, 2024
ea7433a
Actually pre-sort by speed for better PRNG usage
pyuk-bot Dec 27, 2024
212fb74
Split failing Commander switch out test and band-aid-fix Commander + …
pyuk-bot Dec 27, 2024
fcbe2a9
Don't break Commander and Booster Energy if onStart is skipped
pyuk-bot Jan 2, 2025
7980cc0
Minimize risk of event depth overflow crashes
pyuk-bot Jan 2, 2025
918ebde
Fix unintended changes to speed ties in other events
pyuk-bot Jan 3, 2025
ce522f8
Fix serialization
pyuk-bot Jan 3, 2025
fe0e77b
Fix White Herb timing when holder is not the one switching in
pyuk-bot Jan 19, 2025
a460633
Fix Commander/Pastel Veil when holder is not the one switching in
pyuk-bot Jan 19, 2025
c387934
Move EffectState initialization handling to Battle functions
pyuk-bot Jan 20, 2025
e38cd95
Improve Primal Orb immunity to negation
pyuk-bot Jan 21, 2025
7b5183f
Some simplifications (#73)
andrebastosdias Jan 21, 2025
fb28665
Fix onSwitchInPriority for OMs and healreplacement Z-power
pyuk-bot Jan 22, 2025
6fac206
Give Klutz an onSwitchInPriority
pyuk-bot Jan 22, 2025
899f325
Update Perish Body's subOrder
pyuk-bot Jan 22, 2025
a3371bb
Update tests
pyuk-bot Jan 22, 2025
84578f9
Don't activate Commander early if only Dondozo is switching in
pyuk-bot Jan 22, 2025
1eb9267
Add Magician and Throat Spray test
andrebastosdias Jan 22, 2025
f97ca83
Gen7 Healing Wish and Lunar Dance onSwitchInPriority
andrebastosdias Jan 22, 2025
6765303
Refactor battle-queue orders
andrebastosdias Jan 22, 2025
4acdba1
Add Move to suborders
andrebastosdias Jan 22, 2025
e3edc3c
Fix test name
andrebastosdias Jan 22, 2025
a65b2d0
Refactor condition
andrebastosdias Jan 22, 2025
2212edb
'Showdownic' way
andrebastosdias Jan 28, 2025
9d9361e
Merge remote-tracking branch 'upstream/master' into mirrorherb
andrebastosdias Jan 29, 2025
0d316a6
Fix merge error
andrebastosdias Jan 29, 2025
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
10 changes: 5 additions & 5 deletions data/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
onSwitchIn(pokemon) {
// Air Lock does not activate when Skill Swapped or when Neutralizing Gas leaves the field
this.add('-ability', pokemon, 'Air Lock');
((this.effect as any).onStart as (p: Pokemon) => void).call(this, pokemon);
this.singleEvent('Start', this.effect, this.effectState, pokemon);
},
onStart(pokemon) {
pokemon.abilityState.ending = false; // Clear the ending flag
Expand Down Expand Up @@ -538,7 +538,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
onSwitchIn(pokemon) {
// Cloud Nine does not activate when Skill Swapped or when Neutralizing Gas leaves the field
this.add('-ability', pokemon, 'Cloud Nine');
((this.effect as any).onStart as (p: Pokemon) => void).call(this, pokemon);
this.singleEvent('Start', this.effect, this.effectState, pokemon);
},
onStart(pokemon) {
pokemon.abilityState.ending = false; // Clear the ending flag
Expand Down Expand Up @@ -598,10 +598,10 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
commander: {
onAnySwitchInPriority: -2,
onAnySwitchIn() {
((this.effect as any).onUpdate as (p: Pokemon) => void).call(this, this.effectState.target);
this.singleEvent('Update', this.effect, this.effectState, this.effectState.target);
},
onStart(pokemon) {
((this.effect as any).onUpdate as (p: Pokemon) => void).call(this, pokemon);
this.singleEvent('Update', this.effect, this.effectState, pokemon);
},
onUpdate(pokemon) {
if (this.gameType !== 'doubles') return;
Expand Down Expand Up @@ -3121,7 +3121,7 @@ export const Abilities: import('../sim/dex-abilities').AbilityDataTable = {
}
},
onAnySwitchIn() {
((this.effect as any).onStart as (p: Pokemon) => void).call(this, this.effectState.target);
this.singleEvent('Start', this.effect, this.effectState, this.effectState.target);
},
onSetStatus(status, target, source, effect) {
if (!['psn', 'tox'].includes(status.id)) return;
Expand Down
6 changes: 3 additions & 3 deletions data/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export const Items: import('../sim/dex-items').ItemDataTable = {
onSwitchInPriority: -2,
onStart(pokemon) {
this.effectState.started = true;
((this.effect as any).onUpdate as (p: Pokemon) => void).call(this, pokemon);
this.singleEvent('Update', this.effect, this.effectState, pokemon);
},
onUpdate(pokemon) {
if (!this.effectState.started || pokemon.transformed) return;
Expand Down Expand Up @@ -7193,10 +7193,10 @@ export const Items: import('../sim/dex-items').ItemDataTable = {
},
onAnySwitchInPriority: -2,
onAnySwitchIn() {
((this.effect as any).onUpdate as (p: Pokemon) => void).call(this, this.effectState.target);
this.singleEvent('Update', this.effect, this.effectState, this.effectState.target);
},
onStart(pokemon) {
((this.effect as any).onUpdate as (p: Pokemon) => void).call(this, pokemon);
this.singleEvent('Update', this.effect, this.effectState, pokemon);
},
onUpdate(pokemon) {
let activate = false;
Expand Down
2 changes: 0 additions & 2 deletions data/mods/gen7/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
inherit: true,
condition: {
duration: 2,
onSwitchInPriority: 1,
onSwitchIn(target) {
if (!target.fainted) {
target.heal(target.maxhp);
Expand Down Expand Up @@ -610,7 +609,6 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
inherit: true,
condition: {
duration: 2,
onSwitchInPriority: 1,
onSwitchIn(target) {
if (!target.fainted) {
target.heal(target.maxhp);
Expand Down
14 changes: 6 additions & 8 deletions sim/battle-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,12 @@ export class BattleQueue {
beforeTurnMove: 5,
revivalblessing: 6,

runSwitch: 101,
switch: 103,
megaEvo: 104,
megaEvoX: 104,
megaEvoY: 104,
runDynamax: 105,
terastallize: 106,
priorityChargeMove: 107,
runSwitch: 100,
switch: 101,
megaEvo: 102, megaEvoX: 102, megaEvoY: 102,
runDynamax: 103,
terastallize: 104,
priorityChargeMove: 105,

shift: 200,
// default is 200 (for moves)
Expand Down
3 changes: 2 additions & 1 deletion sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ export class Battle {
// https://www.smogon.com/forums/threads/sword-shield-battle-mechanics-research.3655528/page-59#post-8685465
const effectTypeOrder: {[k in EffectType]?: number} = {
// Z-Move: 1,
Move: 2,
Condition: 2,
// Slot Condition: 3,
// Side Condition: 4,
Expand Down Expand Up @@ -946,7 +947,7 @@ export class Battle {
handler.subOrder = 5;
}
} else if (handler.effect.effectType === 'Ability') {
if (handler.effect.name === 'Poison Touch' || handler.effect.name === 'Perish Body') {
if (['Perish Body', 'Poison Touch'].includes(handler.effect.name)) {
handler.subOrder = 6;
} else if (handler.effect.name === 'Stall') {
handler.subOrder = 9;
Expand Down
10 changes: 10 additions & 0 deletions test/sim/abilities/magician.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ describe('Magician', function () {
battle.makeChoices();
assert.false.holdsItem(battle.p1.active[0], 'Klefki should not have stolen Weakness Policy.');
});

it(`should not steal an item on the turn Throat Spray activates`, function () {
battle = common.createBattle([[
{species: 'klefki', ability: 'magician', item: 'throatspray', moves: ['psychicnoise']},
], [
{species: 'hatterene', item: 'tr69', moves: ['sleeptalk']},
]]);
battle.makeChoices();
assert.false.holdsItem(battle.p1.active[0], 'Klefki should not have stolen an item.');
});
});