Previously, battle queue stuff was just strewn around `battle.ts`.
This gives it a new home: `battle-queue.ts`.
This was intended to make `battle.ts` slightly more tractable, although
the difference is so small that maybe I shouldn't bother. Oh, well,
every little bit helps.
This is a really hacky implementation of Emergency Exit, but Emergency
Exit itself is a huge mess on cart, too.
Our previous implementation:
- activated Emergency Exit at AfterMoveSecondary timing for move damage
- activated Emergency Exit immediately after dealing any other damage
This new one:
- activates Emergency Exit only in three situations:
- right after AfterMoveSecondary timing, for move damage
- right after DamagingHit timing, for DamagingHit residual damage
(Rough Skin, Iron Barbs, Rocky Helmet)
- right after the switch update, for switch-hazard residual damage
(Stealth Rock, Spikes)
- does not otherwise activate (so Substitute, Hail, Toxic, etc no
longer activate Emergency Exit)
This should much accurately simulate Emergency Exit behavior, including
most famously timing it after healing berries after hazards, as
documented in:
https://www.smogon.com/forums/threads/pokemon-sun-moon-battle-mechanics-research.3586701/#post-7075354Fixes#6309
Fixes#6346
The `AfterDamage` event has been replaced with `DamagingHit`, which
which happens for damaging moves after secondaries.
The `AfterHit` event has also been moved after `DamagingHit`, to make
sure Knock Off still procs after Rocky Helmet.
`AfterHit` is no longer a valid event on `secondary` and `self` blocks,
because it's meaningless in those blocks, anyway. All `self.onAfterHit`
and `secondary.onAfterHit` handlers have been moved to `onHit`, which
should have the same timing in practice.
Pokemon that are holding an Item that enables Mega Evolution, Primal Revision, or the use of a Z-Move cannot Dynamax. A Rayquaza that can Mega Evolve also cannot Dynamax.
Also fixes an alias loop with the national dex format/ruleset.
Specifically we now check the battle.canDynamax method when
notifying a player about their pokemon's eligibility to dynamax.
This enforces the fact that pokemon that are transformed into
dynamax ineligible pokemon cannot dynamax themselves.
As a result of this change the pokemon.canDynamax flag is unnessecary
and has been refactored to a side.canDynamax flag. All pokemon specific
dynamax checks should use the battle.canDynamax method.
`item.itemUser` replaces `item.zMoveUser`, and is a new field
representing a list of possible users of an item, for items that are
restricted to specific species.
`item.zMoveUser` is a base forme for items that affect every forme, and
a forme name otherwise (forme name is currently only used for
`forcedForme` uses).
Arceus is a weird case. Both generic Z crystals and Plates, while
having unique effects on Arceus, also have effects on other Pokémon.
For this reason, Arceus isn't listed as an `itemUser` of either of
these item types - use-cases that want this should also check
`item.forcedForme`.
This is mostly intended to be useful to move-searching and custom
rules (like NatDex, which will only allow past-gen items associated
with removed species).
- Centiskorch was misspelled in formats-data, causing a crash in the
egg validator
- A few validation errors were due to Gen 6 not inheriting from Gen 7,
Gen 7 not having a scripts file, and Gen 8 having a gen of 7
- Intimidate (Gen 7) wasn't inheriting from Intimidate (Gen 8), giving
it no name, causing a few validation errors
(Technically not a build error, but I also added Keen Eye to the list
of Intimidate immunities, as reported by SadisticMystic.)
- A lot of tests relied on Teleport always failing; these have been
switched to Gen 7 or swapped Teleport for Celebrate
- Inverse Mod suddenly stopped working; its implementation was a huge
hack and I can't figure out what went wrong, so I've switched it to
using the same system the other mod tests use. It's still a huge
hack, but I don't have the free time to fix it right now.
In most other similar systems, like TeamValidator, we use `thing.dex` instead of having it extend `ModdedDex`. Battle has always extended `ModdedDex`, though. This changes Battle to match the others.
This should fix an issue with `Battle.data` not being cached.
This also frees up Battle to extend ObjectReadWriteStream<string> in a future update.
In certain cases, a spread move that KOed an opponent would send an
incorrect message which could crash the client. This fixes that while
also simplifying the code.
It turns out Template is the only remotely-easy type to merge the class
and interface for.
The others all have a bunch of event methods which would need to be
redefined on the class.
The point of this check was to end a multi-hit move if you fell asleep to Effect Spore in the middle of the move, not be applied to every move (i.e. Doom Desire and Future Sight).