Check whether the move is a max move. If it isn't, then resolve the choice as usual. Otherwise, do not add the move to the queue, and let the runDynamax mechanic handle move resolution.
Added regression test to check for focus punch message in both dynamaxed and regular use
- `Obtainable` and `Team Preview` are now part of `Standard`
- `minSourceGen: 8` is now a part of `-Unreleased` (which is part of
`Obtainable`) in Gen 8. Instead, it's NatDex that overrides it with
`minSourceGen: 1`. This allows `!Standard, Standard NatDex` and
`!Standard NatDex, Standard` to work as intended.
- Duplicate rules are now checked for (does not apply to subrules, so
multiple inheritance is still possible)
- It is now possible to inherit `minSourceGen` from rules.
Custom rules can now use whitelists instead of blacklists.
Whitelist rules look like:
`- all moves, + Metronome`
(Metronome Battle does not use this ruleset currently, because its
scripted check displays a better error message than a whitelist rule,
which can't actually display the whitelist as of the current
implementation.)
This merges the Glitch and Pokestar tags into a new Unobtainable tag that defines Pokemon that are only obtainable through hacking (such as Floette-Eternal and Missingno.). These Pokemon are legal in Hackmons of their specific generation only. Custom is used in future gens instead of Past because of National Dex legality.
New research shows that only Zacian-Crowned and Zamazenta-Crowned are unobtainable out-of-battle. So, reverting the validateForme changes and hardcoding it in BH instead of using Obtainable Formes.
- Cherrim should revert if given a Utility Umbrella in Sun.
- Castform shouldn't keep transforming if it holds a Utility Umbrella.
- Leaf guard Utility Umbrella check works but is just inconsistent placement.
- Sun/Rain affected recovery moves should heal 50% with Utility Umbrella.
- Solar moves power should halve in sand or hail even with Utility Umbrella.
- Weather Ball should double in power if Magic Room blocks Utility Umbrella.
Struggle is now coded as a locked move, meaning you can't use Z-moves,
mega, or dynamax if you're forced to Struggle.
In addition, Dynamax undisables all moves for its duration.
Fixes#6088
`Dex.installFormat` has been deprecated and removed. Formats are now
directly created and cached by our unit test framework. This should
lead to fewer weird bugs.
Keldeo-R is not a battle forme and is possible to hack without Secret Sword, unlike most other formes. It should be restricted by the rule that prevents hacks and not the rule that validates battle formes. This is mostly relevant for Hackmons.
- In gen 8, Silvally is able to enter battles in different types if it doesn't have RKS System (i.e. it doesn't require a Memory).
- In gen 8, formes that transform in battle are no longer able to start in that forme (relevant to BH).
We now track `baseMaxhp`, the pre-Dynamax max HP. We also have a new
function `getUndynamaxedHP` for use by moves that use it (famously,
Endeavor).
- `baseStoredStats` is unused outside of the mouseover stats display.
I updated its implementation to reflect this.
- Power Construct doesn't have a defined behavior during Dynamax. I
ended up implementing an approximation of what it should probably do.
- Endeavor, Pain Split, Super Fang, and Nature's Madness now work on
undynamaxed HP.
- Moves that deal or heal percentage damage now do it based on
undynamaxed max HP, other than G-Max Finale.
Fixes#6131Fixes#6087
This adds new properties `isUnreleased: 'Past'` and
`unreleasedHidden: 'Past'`, which mark a Pokémon or Hidden Ability as
released in past gens, but not in the current gen. This allows them
to be banned in present-gen-only formats, but not in past-gen-transfer
formats.
We have a new command:
`./pokemon-showdown simulate-battle --replay`
which will extract the omniscient log from an input log.
Remember: debugging is as easy as running `simulate-battle` and pasting
an input log. `--replay` will just make the output easier to read.
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.
In Generation 8, a Pokemon's speed updates dynamically. Meaning that it can move sooner than expected if its speed is modified by something such as tailwind or swift swim. This is different from past generations where the Pokemon's updated speed would only take effect the next turn.
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).
Like gmaxPower, Z-move powers mostly follow a formula, which can be
applied to newer moves.
(In the future, we can save some bytes by not listing the powers.)
PS apparently doesn't have gen-accurate Ability data for Pokémon in
Gen 3 that gained Abilities between Gen 3 and Gen 4 (like Pidgeot
still has Tangled Feet in Gen 3), but that will have to be left for
a future commit.
- 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.
PS already tracks which evolution level an egg move or event pokemon
learns a move from, but apparently this was not tracked for DW moves.
This fixes a compatibility interaction between DW Marill and Azurill
moves.
This happened because the father checker was simplistic enough
that it didn't think to check Duskull for Pain Split, since
Dusclops learns it in future gens.
- Tyranitar egg moves are fixed
- Staravia egg moves are now properly supported
(9742ecf62f was a hack that caused the Tyranitar problem)
- Some Pokemon evolve by having a move in their learnset (like Piloswine
with Ancient Power). These can only carry three other moves from their
prevo, because the fourth move must be the evo move. This restriction
doesn't apply to gen 6+ eggs, which can get around the restriction with
the relearner.
Fixes#2287
(Except Shiftry and friends, but those are already tracked in
`rulesets:obtainablemoves`.)
Previously, we split gen 2-5 egg move validation into two phases,
`checkLearnset` where we searched for a valid father, and
`reconcileLearnset` where we made sure the father could learn the move
combination.
Egg move validation has now been completely moved out of these
functions and into `validateSource`, which calls `findEggMoveFathers`.
The new algorithm no longer requires `C` moves to be hardcoded into
`learnsets.js`, now doing a more thorough check validation for the
father's move combination. This should be slower than before, but
net performance should be massively improved due to two other
optimizations in this refactor:
- We no longer do any father-searching if the moveset can be obtained
any other way - in particular, this means no more father validation
in gen 6+ where all egg move combinations are legal anyway.
- We only check fully-evolved pokemon as fathers (because anything a
prevo can learn, its evos can learn, too - yes, we remember to make
exceptions for Salazzle, Combee, and future-gen evos)
In addition, `/learn` should now provide significantly better
information for egg move breeding, since it uses a more thorough check
instead of the validator's short-circuiting the moment it finds a valid
father.
This also improves some baby-only move validation, specifically fixing
the issue with Seismic Toss Charm Chansey.
- Repealing rules now always works, regardless of rule order
(Fixes AAA validation)
- Fix a check for egg move hidden ability validation
(Fixes a Gen 4 Dragon Dance Charizard set)
- Always ban AG when banning Uber
(Fixes allowing Rayquaza-Mega in lower tiers)
- Fix ability validation in Let's Go
- Fix valid-move-combo dexsearch
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.
* Refactor validator
This is a major refactor intended to make the default rules easier to
understand, and also easier for OMs to bypass.
Removed rules:
- `Pokemon`: This is now `-Nonexistent`. Its previous name was intended
to be interpreted as "simulate the Pokémon games exactly, and only
allow what they allow". The new name should make it clearer that it
mainly bans CAPs and other nonexistent Pokémon and functionality.
- `-Illegal`: This is now `Obtainable` (see below).
- `Allow CAP`: This is now `+CAP`. Instead of having a hardcoded rule,
OMs can now be manually whitelist any pokemon/item/etc or group of
them, overriding `-Nonexistent`.
- `Ignore Illegal Abilities`: This is now `!Obtainable Abilities` (see
below).
`Obtainable` was previously `-Illegal`, and does the same thing: Makes
sure you have a regular Pokémon game with only Pokémon that can be
obtained without hacking.
But instead of being a ban, it's now a rule that does nothing by
itself, except contain more rules:
- `Obtainable Moves`
- `Obtainable Abilities`
- `Obtainable Formes`
- `Obtainable Misc`
- `-Nonexistent`
- `-Unreleased`
This allows OMs to piecemeal repeal and unban any of these individual
rules, instead of the previous approach of unbanning them all and
manually reimplementing every single validation you wanted to keep.
* Refactor PokemonSources into a class
This mostly just makes a lot of the weirder checks in the validator
substantially more readable.
This also renames `lsetData` to `setSources`, which should also help
readability.
* Validate Bottle Cap HP types
Fixes an issue reported here:
https://github.com/Zarel/Pokemon-Showdown/issues/5742#issuecomment-533850288
* Fix several move validation issues
Fixes#5742
We have a new MoveSource type: R for Restricted. R moves work like
level-up/tutor/TM moves, except you're limited to one R move.
- Shedinja move stolen from Ninjask in Gen 3-4 are now R moves instead
of event moves. This allows them to coexist with Nincada egg moves.
- Necrozma-DW/DM now inherit moves/events from Necrozma (like Rotom,
but with event validation). This allows them to be shiny.
- Pokemon can now get egg moves from their own evolutions. This fixes
some Tyrogue, Charmander, and Treecko sets mentioned in #5742
- Some more C moves were added, fixing some Hitmontop and Chatot sets
mentioned in #5742
* Improve ability/move compatibility validator
- New ability ratings
- Improve move pools
- Allow non-status moves to be re-rolled if rejected (this fixes all undesired move set combinations)
- Update move & ability rejections
- New item possibilities
0|1|H|S saves minimal space over the ability ID and requires parsers have the data files, in addition to limiting the ability to search abilities in the teambuilder. Similar, gender can be elided most of the time and just chosen randomly if not specified.
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.
`canUseRandomTeam` was a feature intended to allow random teams to be
generated in custom games. I never added a UI for it, and nowadays we
have more than one Random Battle format anyway, so this flag no longer
makes any sense.
The new plan is to support "random team" custom rules, which should be
easier to implement and easier for users to understand.
`import =` and `export =` are really only intended for backwards
compatibility with CommonJS. While I really don't like the new module
system TC39 has designed for us, it's what we should be using, and
consistency is important.
They were previously some weird interface where their actual types
were properties. I guess whoever wrote this was unaware that TypeScript
namespaces were designed for this exact use-case.
This is actually three refactors:
- swap around thing:slot for slot:thing in MoveHitData
- add Pokemon#getSlot
- remove the ActiveMove class; it's back to being an interface
See #5415 for context - having these methods is unsafe and leads
to crashes because not all ActiveMoves are created through the
Data.ActiveMove constructor. Instead of Pokemon, these could
alternatively be static methods on ActiveMove (or the ActiveMove
class could be completely abolished and reverted back to an
interface), but #5415 will deal with ActiveMove long term, this just
fixes the crashes.
`default` papers over AI logic errors. This change fixes those
errors instead:
- handle maybeDisabled/maybeTrapped properly
- use 0 PP and ally-less 'adjacentAlly' moves if necessary.
When I originally wrote the Streams library, TypeScript-in-JS didn't
support generics. But now the library can have significantly nicer
typing, and so it now does.
The modern `__esModule` fallback isn't compatible with Node, and also
entirely unnecessary in practice.
The approach of disabling all the fallback code allows us to once again
`import * as fs`.
Rollforward of 7a20245 which retains the `hasOwnProperty` checks.
Also changes the method to call `toId` earlier and use the id
as the key to the cache to ensure 'Stealth Rock' and 'stealthrock'
return the same. NOTE: 'move: Stealth Rock' and 'Stealth Rock' will
still continue to return different results.
Even though 31c6a32 added caching to make this method less of a
hotspot, there's no reason to use a pattern which is an order of
magnitude slower (https://jsperf.com/pokemon-showdown-getEffect).
Also, rearranges Format to get checked first as pkmn.cc/optimize
finds it to be the most frequently accessed.
- rename `thing` when we know what it will be.
- simplify `resolveLastPriority`
- remove `findBattleEventHandlers` param given that its always this
- avoid multiple lookups of the same attribute
These functions related to finding events are very hot
(pkmn.cc/optimize) and microbenchmarks indicate TurboFan is unable
to extract out the constants for us. As a side benefit, there's less
`// @ts-ignore` required, and future optimizations will use the
constants anyway. More extraction can be done in findEventHandlers,
but that will be left for a future change where the need becomes
more obvious.
This fixes getRelevantEffects's massively confusing call structure.
Most parameters relating to bubbling up and down have been removed
entirely, and traversing the many possible event handler types is now
simply done outside the callers.
In addition, a lot of variables/functions have been renamed for much
better clarity.
As outlined by pkmn.cc/optimize, this change should result in a ~30%
increase in Battle performance over repeated runs. Caching the
resultant effect is safe provided nothing mutates it.
This fixes an obscure issue where we sent a formechange-to-self on
faint in certain obscure situations (apparently including Gen 4
Custap?)
In case anyone wants to investigate the details (this commit just
patches over some symptoms), the relevant replay is here:
https://replay.pokemonshowdown.com/smogtours-gen4ou-425031
PS prefers to keep battle streams open (for `/evalbattle`) until
manually ended, but this is confusing some other users. We now
automatically end streams unless the `keepAlive` option is set.
Fixes#5157
Also move mods/ to data/mods/
This makes PS more monorepo-like. The intent is to further separate
the sim and the server code, but without fully committing to splitting
the repository itself.
We now support `./pokemon-showdown start` in addition to
`./pokemon-showdown`. I'm not clear which I want to be the default
yet.
Battle protocol documentation, instead of being strewn between
`PROTOCOL.md` and `sim/README.md`, is now in `sim/SIM-PROTOCOL.md`.
Also added:
- documentation for how to do searches and challenges
- documentation for packed team format
Fixes#5005
Numbers in Pokemon are 32-bit integers, which means that they're
truncated (rounded towards 0) as well as overflowing at 32-bit
limits.
We've been using `Math.floor`, but JavaScript has many functions for
coercing to 32-bit integers which already do everything we want. So
this commit changes to doing that.
It's done in a new function Battle#trunc which is overridden in
Custom Games where players might prefer to play without integer
overflow issues.
(Custom Game _still_ needs a UI rework, blah blah Preact...)
Fixes#4820Closes#4962
So the Pursuit unit test is broken in Node 0.11, because PS relies on
the sort function deterministically calling the comparison function,
and due to a recent V8 update, the call order changed.
This was a good thing, anyway, since PS didn't handle 3+-way speed ties
correctly, anyway, and it reminded me to go and fix that. Which I did.
This is as cartridge-accurate as possible, given the description given
to me by V4 in #1157.
Fixes#1157
This commit makes it so players are always informed about their own
Pressure activations. This fixes Pressure PP tracking for players.
PP tracking for spectators will still be wrong; there's no fix for
that.
Fixes https://github.com/Zarel/Pokemon-Showdown-Client/issues/766
move.zPowered is renamed move.isZPowered. It's now documented in JSDoc
exactly how it differs from move.isZ.
This commit includes several minor refactors to Z-move mechanics,
including a bug fix: Z-boosted called Weather Ball is now correctly
typed.
The types Template, Move, Ability, and Item are now read-only. This
should guard against accidental writing to types that shouldn't be
written to.
A new type, ActiveMove, has been introduced. Like it sounds, it's
used for moves that are currently actively being used. A lot of
attributes that are only relevant to active moves, such as
`hasBounced`, are now only available on ActiveMove, not on Move.
ActiveMoves are mutable, unlike Moves.
getMoveCopy has been renamed getActiveMove, to better reflect its
role. `isCopy` has been deprecated, and distinguishing Moves from
ActiveMoves is now done by `typeof move.hit === 'number'` where
necessary.
ActiveMoves now internally track which hit of a multihit move
they're on, in move.hit, so move.hit doesn't need to be manually
incremented by Triple Kick and Parental Bond anymore.
move.hasParentalBond has been replaced by a more generic
move.multihitType.
PS is inconsistent about which parts do or don't support partial
choices.
This change makes it so battle.choose no longer supports partial
choices, while side.choose still does.
This fixes the bug where making a partial choice caused a battle
freeze.
Normally, Illusion copies everything except the level, so if Zoroark is
a different level from the pokemon it's copying, it's very obvious that
it's a copy. This isn't a problem normally (because everyone is 50 or
100), but in randbats, it's a big tell, and makes Zoroark weaker than
it's supposed to be.
And, unrelatedly, everyone thinks it's a bug even though it's not.
TODO: Not this. Calling moves that select multi-turn moves currently use the target of the calling move on the second turn, which is probably the user and would otherwise fail if not for being re-targeted again. Maybe store a locking move's randomly selected target in a Pokemon or move volatile instead.
Often, you just need a random item in an array. Throughout Pokemon
Showdown's code, there are many instances of the following pattern:
let randomThing = things[this.random(things.length)];
Make this code easier to read by factoring the indexing into the
PRNG#sample function:
let randomThing = this.sample(things);
Run the following sed script to refactor lots of code to use sample:
s/\([a-zA-Z0-9.]\{1,\}\)\[this\.random(\1\.length)\]/this.sample(\1)/
This commit should not change behaviour. In particular, PRNG#next is
called the same number of times with the same number of parameter as
before this commit, and PRNG#next's results are interpreted in the same
way as before this commit.
According to `git grep getResidualStatuses`, the
Battle#getResidualStatuses function isn't referenced anywhere. Delete
the definition of that unused function.
Mechanically refactor code which uses PRNG#random for booleans to use
PRNG#randomChance instead.
Take advantage of the following properties:
random(x) < y is equivalent to randomChance(y, x)
random(x) <= y is equivalent to random(x) < (y + 1), i.e. randomChance(y + 1, x)
random(x) >= y is equivalent to !(random(x) < y), i.e. !randomChance(y, x)
random(x) > y is equivalent to random(x) >= (y + 1), i.e. !randomChance(y + 1, x)
random(x) === 0 is equivalent to random(x) < 1, i.e. randomChance(1, x)
!random(x) is equivalent to random(x) === 0, i.e. randomChance(1, x)
Boolean(random(x)) is equivalent to random(x) > 0, i.e. !randomChance(1, x)
This commit should not change behaviour. In particular, PRNG#next is
called the same number of times with the same number of parameter as
before this commit, and PRNG#next's results are interpreted in the same
way as before this commit.
Often, you just need a random boolean. Throughout Pokemon Showdown's
code, there are many creative ways of requesting random booleans. For
example:
if (this.random(10) < 3) {
if (this.isWeather(['sunnyday', 'desolateland']) || this.random(2) === 0) {
let shiny = !this.random(1024);
if (uberCount > 1 && this.random(5) >= 1) continue;
if (!this.random(3)) ability = ability1.name;
} else if ((ability === 'Iron Barbs' || ability === 'Rough Skin') && this.random(2)) {
if (typeof secondary.chance === 'undefined' || this.random(256) <= effectChance) {
if (accuracy !== true && this.random(256) > accuracy) {
Enable these methods to converge by introducing the PRNG#randomChance
function. It accepts a probability and returns true with that
probability.
Run the following sed script to refactor many common patterns to use
randomChance:
s/this\.random(\([0-9]\{1,\}\)) >= \([0-9]\{1,\}\)/!this.randomChance(\2, \1)/g
s/this\.random(\([0-9]\{1,\}\)) < \([0-9]\{1,\}\)/this.randomChance(\2, \1)/g
s/this\.random(\([0-9]\{1,\}\)) === 0/this.randomChance(1, \1)/g
s/!this\.random(\([0-9]\{1,\}\))/this.randomChance(1, \1)/g
The sed script takes advantage of the following properties:
random(x) < y is equivalent to randomChance(y, x)
random(x) >= y is equivalent to !(random(x) < y), i.e. !randomChance(y, x)
random(x) === 0 is equivalent to random(x) < 1, i.e. randomChance(1, x)
!random(x) is equivalent to random(x) === 0, i.e. randomChance(1, x)
This commit should not change behaviour. In particular, PRNG#next is
called the same number of times with the same number of parameter as
before this commit, and PRNG#next's results are interpreted in the same
way as before this commit.
Various functions call ModdedDex#getEffect with null, undefined, or an
empty string. For example, in the common case, Battle#getWeather calls
getEffect with an empty string. In these cases, getEffect basically
returns the same object each time: a PureEffect indicating that no
effect with the given name exists.
Creating the dummy PureEffect is expensive and puts pressure on the
JavaScript garbage collector. Memoize the creation in getEffect to
improve performance.
(As a bonus, special-casing null, undefined, and empty strings also lets
us drop some noisy truthiness checks in getEffect.)
On my machine, this commit speeds up Pokemon Showdown's tests by 11%.
Methodology: With and without this commit, I ran mocha four times with
zsh' 'time' builtin, dropped the first result, and averaged the wall
times:
mocha times before this commit:
18.20s user 0.33s system 118% cpu 15.704 total
17.91s user 0.34s system 118% cpu 15.454 total
18.11s user 0.33s system 118% cpu 15.558 total
mocha times after this commit:
16.53s user 0.35s system 120% cpu 13.994 total
16.43s user 0.34s system 120% cpu 13.918 total
16.54s user 0.32s system 120% cpu 14.009 total
Hardware:
Mid 2012 MacBook Pro
2.6 GHz Intel Core i7
Software:
Node v9.0.0
macOS 10.10.5
Battle#getRelevantEffectsInner performs a lookup for the base species of
every Pokemon with ModdedDex#getEffect, then invokes callbacks. The
lookup is expensive, and callbacks very rare. In fact, there are only
ever two callbacks: one for Arceus (SwitchIn) and one for Silvally
(SwitchIn).
Instead of an expensive ModdedDex#getEffect lookup for the callbacks,
put the callbacks directly on the Pokemon's Template object.
On my machine, this commit speeds up Pokemon Showdown's tests by 20%.
Methodology: With and without this commit, I ran mocha four times with
zsh' 'time' builtin, dropped the first result, and averaged the wall
times:
mocha times before this commit:
18.20s user 0.33s system 118% cpu 15.704 total
17.91s user 0.34s system 118% cpu 15.454 total
18.11s user 0.33s system 118% cpu 15.558 total
mocha times after this commit:
15.58s user 0.33s system 122% cpu 13.028 total
15.32s user 0.33s system 121% cpu 12.890 total
15.56s user 0.32s system 121% cpu 13.068 total
Hardware:
Mid 2012 MacBook Pro
2.6 GHz Intel Core i7
Software:
Node v9.0.0
macOS 10.10.5
Also allow passing "HA" or "Hidden" to /learn, to do some basic
checking for Hidden Ability legality. This doesn't currently do full
validation - event abilities aren't checked, for instance.
I originally thought this would have to be hardcoded, but actually this
can be coded slightly less hardly than expected!
Getting a Blissey with Present + Heal Bell in Gen 2 works like this:
- Teach Smeargle Present + Heal Bell
- Breed Present + Heal Bell into Snubbull
- Chainbreed Present + Heal Bell into Blissey
The main issue is that checking chainbreeding is very hard, so PS
mostly just takes the stance of "chainbreeding multiple moves is
probably impossible; hardcode exceptions".
BUT! BUT!!!!
Instead of hardcoding this exact move combination, we can actually
just hardcode the fact "the first step of chainbreeding is always legal
if the first father is Smeargle". Which I did and it works!
A battle's inputLog is now stored separately from the output log. It's
not an exact log of inputs, but rather just a collection of the inputs
that resulted in the battle: a default choice expands to the choice
that was actually used, and the starting seed is logged whether or not
it was explicitly passed into the battle stream.
Fixes#4348Fixes#3201
This contains a lot of minor refactors, but the main thing that's going
on here is that battle stream writes have been streamlined to be a lot
easier for others to use.
We even support:
./pokemon-showdown simulate-battle
which provides a stdio interface for anyone using any programming
language to simulate a battle.
./pokemon-showdown help
will now display all the possible ways to use PS on the command-line,
of which there are several new ones:
./pokemon-showdown validate-team
./pokemon-showdown unpack-team
./pokemon-showdown pack-team
The previous complement of way too many message types:
- update, winupdate, sideupdate, request, score, log
are now only:
- update, sideupdate, end
`score` was removed in the previous commit, and this commit adds a new
message type `end`. `end` replaces the previous `log`, and also
contains the data for `winupdate` and `score`.
`request` was also folded into `sideupdate`.
`Sim.construct` no longer exists. Battles are now constructed directly
with `new Battle()`. Parameters other than formatid are now passed as
`options`.
This is specifically made to fix Nasty Plot + Surf Raichu.
Specifically, prevo moves are no longer compatible with evo event
moves.
Other incompatibilities (specifically, modern prevo moves with old-gen
evo moves) will be harder to fix, unfortunately.
Process Manager is now lib/process-manager.js
It's been entirely rewritten to reflect what I think a process manager
API should look like.
In particular, there are now two Process Managers, QueryProcessManager
and StreamProcessManager.
Pass QueryProcessManager a pure-ish query function (sync or async) that
takes a JSON value and returns a JSON value, and PM.query() will
execute that function in a subprocess, and return a Promise for its
return value.
StreamProcessManager is the same idea: Pass it a function to create an
ObjectReadWriteStream, and PM.createStream() will create a stream in a
subprocess and return a stream connected to it.
It turns out, battle.getFormat() is run once per invocation of
battle.runEvent(), which is a lot.
Especially with the new rule validator.
...It's cached now.
Ladder is now a subclass of Matchmaker, and all the APIs previously
attached to Matchmaker are now directly available in Ladder.
In addition, all functions that take a formatid are now of the form
`Ladders(formatid).function(other arguments)`
TODO: Reverse polarity; it makes more sense for Matchmaker to be
a subclass of Ladder. Fortunately, this wouldn't involve API changes.
The old code, for allowing unreleased pokemon if they were obtainable
by breeding, was a workaround for a very specific case which as far
as I can tell is no longer necessary.
In the future, a template should just not be marked as unreleased if
it's available by breeding.
pokemon.moveset is now pokemon.moveSlots, which is at least slightly
clearer about what it's doing (tracking move state, mainly PP).
Mostly, this gives a consistent naming scheme for `move` (a Move
object) vs `moveSlot` (a MoveSlot object).
This also refactors a lot of existing `moveSlot` accesses to be modern,
including using `for...of`.
We are now tracking source effects for switch actions, if they're
initiated by effects such as U-turn or Baton Pass. This will lead
to better messages client-side.
New functions:
battle.makeChoices([side 1], [side 2]);
Intended to be a replacement for the previous .choose/.commitDecisions
API.
If we can get all the test code on it, we can maybe finally actually
deprecate LEGACY_API_DO_NOT_USE.
It's now used in Healing Wish, where I think it makes a very readable
test.