Commit Graph

1124 Commits

Author SHA1 Message Date
Marty-D
d5f9b427de
Validator: Check Secret Sword Keldeo-Ordinary origin 2018-05-06 10:35:21 -04:00
Quinton Lee
cf50a3d642 Typescript the rest of mods/ (#4588) 2018-05-05 14:56:45 -05:00
Marty-D
6bf35eeb2c Rename BLs 2018-04-24 20:29:06 -04:00
urkerab
8d82a3d373 Show only one tier validation problem (#4615) 2018-04-21 21:40:01 -05:00
asgdf
40280a12c0 Fix name of Arceus/Silvally templates (#4603) 2018-04-18 17:32:10 -05:00
asgdf
d5c9a241f3 Fix /dt always displaying normal forme of Arceus/Silvally (#4600) 2018-04-17 07:57:13 -05:00
Guangcong Luo
a1a88999ad Support Doubles in battle-stream-example.js 2018-04-15 17:08:08 -05:00
Guangcong Luo
467b545496 Add example code for using the Sim API 2018-04-15 06:10:08 -05:00
MacChaeger
95e0f30027 Spite: Show actual PP reduction (#4590) 2018-04-15 01:40:49 -05:00
Kris Johnson
61076ec11f Change all Smogon links to https (#4587) 2018-04-13 12:24:42 -04:00
urkerab
0ff06a45ee Properly check for battle before logging crash (#4583) 2018-04-13 08:04:52 -05:00
Quinton Lee
acd812c71e Typescript gens 1-4 (#4556) 2018-04-11 22:11:25 -05:00
Guangcong Luo
925706083e
Sim readme: Fix choice spec 2018-04-06 14:15:07 -05:00
Quinton Lee
b45d595519 Update Typescript to 2.8 (#4532) 2018-04-05 17:33:35 -05:00
MacChaeger
27afe1b6b8 Gen VI-VII: Transform should copy Focus Energy (#4546) 2018-04-05 09:19:43 -04:00
Marty-D
3049e0e172
Fix rated/debug battles 2018-03-28 23:58:35 -04:00
Andi Wang
6621b84efa Gen IV: Fix Disable/Encore interaction with switching effects (#4519)
Specifically, Healing Wish/Lunar Dance/Baton Pass/U-turn.
2018-03-27 22:30:23 -04:00
Quinton Lee
c799393710 Typescript data/ and config/formats (#4513)
Also removes Battle Factory methods accidentally re-added in d0a4a689a7
2018-03-26 09:50:51 -05:00
KrisXV
3bf1aeb79f Refactor for...length to for...of where applicable (#4516) 2018-03-24 14:47:40 -07:00
Marty-D
dc3f9bd0ab Fix Sky Drop interaction with Follow Me/Rage Powder/Snatch 2018-03-16 10:14:47 -04:00
Matthew Glazar
81208685d1 Refactor some code to use sample
Mechanically refactor code which uses PRNG#random to calculate a random
array index to use PRNG#sample instead.
2018-03-12 05:53:33 +09:00
Matthew Glazar
6c2350f5b6 Refactor random indexes into sample function
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.
2018-03-12 05:53:33 +09:00
strager
5a5b4182a3 Delete dead code (#4477)
According to `git grep getResidualStatuses`, the
Battle#getResidualStatuses function isn't referenced anywhere. Delete
the definition of that unused function.
2018-03-10 14:44:30 +09:00
Matthew Glazar
df5988bacf Refactor some code to use randomChance
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.
2018-03-08 20:11:33 +09:00
Matthew Glazar
45a876917d Refactor random booleans into randomChance function
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.
2018-03-08 20:11:33 +09:00
strager
5d08426faa Optimize no-op effects (#4460)
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
2018-03-05 17:27:55 +09:00
strager
423509bceb Cache species-specific effects (e.g. Arceus); 20% overall perf win (#4459)
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
2018-03-05 17:24:14 +09:00
Guangcong Luo
d9bf6742ff
Sim readme: Improve stream-consuming example code 2018-03-02 03:13:59 +09:00
urkerab
586861eb79 Fix Endless Battle Clause messages (#4437) 2018-02-26 17:12:16 +08:00
The Immortal
101099b27e Fix Endless Battles Clause message 2018-02-23 21:05:06 +08:00
Guangcong Luo
e14bdfca36 Fix canceling switches against Wobbuffet in Gen 2 2018-02-18 19:10:40 +09:00
urkerab
77c4e32dba Overriding a template should not unban the Mega (#4423) 2018-02-18 16:27:02 +09:00
Guangcong Luo
add2f2efbb Don't inputlog >version if Git isn't installed 2018-02-14 12:54:37 +09:00
Guangcong Luo
2ba6a770fe Validator: Fix message for Hidden Abliity checking
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.
2018-02-13 22:07:58 +09:00
Guangcong Luo
643b364055 Fix "maybe trapped" detection for ability bans 2018-02-13 13:34:42 +09:00
Guangcong Luo
8b19a546b8 Fix chainbreeding validator 2018-02-01 21:06:37 -06:00
Guangcong Luo
fa057d86bf Validator: Fix past-gen-only-move error message 2018-02-01 20:59:53 -06:00
Guangcong Luo
c91bd2f831 Crash battles more gracefully 2018-02-01 17:44:11 -06:00
Marty-D
2b18b09155
Fix crash in Gen 4 Transform 2018-02-01 16:29:10 -05:00
Guangcong Luo
78c327028e Fix Blissey Present + Heal Bell egg move bug
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!
2018-01-31 21:53:11 -06:00
KrisXV
a4cf9f3ab1 Fix Mimikyu-Busted-Totem's tiers (#4390)
handled in https://git.io/vN7tU
2018-01-31 11:30:48 -06:00
Guangcong Luo
c4d3b1f80f Improve move validation phrasing 2018-01-30 11:07:10 -06:00
Guangcong Luo
ba4e9870d4 Fix getChoice
It now returns a valid choice string for Team Preview choices.
2018-01-29 20:59:52 -06:00
Guangcong Luo
b58e08e215 Improve Sim documentation 2018-01-28 22:04:41 -06:00
Guangcong Luo
4af43bd698 Document choice specifications 2018-01-28 21:56:37 -06:00
Guangcong Luo
1c62891008 Document new Sim API 2018-01-28 21:23:06 -06:00
Guangcong Luo
4c0699abc6 Implement inputLog
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 #4348

Fixes #3201
2018-01-28 21:23:06 -06:00
Guangcong Luo
1531b662c6 Refactor battle stream system
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.
2018-01-28 21:06:49 -06:00
Guangcong Luo
a0da191024 Improve ./pokemon-showdown commands
./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
2018-01-28 21:06:49 -06:00
Guangcong Luo
b9aba16b52 BattleStream: Refactor message types
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`.
2018-01-28 21:06:49 -06:00
Guangcong Luo
6f2b1c0cd8 Battle protocol: Remove score message
score sending is now combined with the log message.
2018-01-28 21:06:49 -06:00
Guangcong Luo
f756b22dc7 Implement |bigerror|
Battles now send their errors using |bigerror|, which requires less
escaping and also correctly reports errors.
2018-01-28 21:06:49 -06:00
Guangcong Luo
9c037b17fe Refactor Battle constructor
`Sim.construct` no longer exists. Battles are now constructed directly
with `new Battle()`. Parameters other than formatid are now passed as
`options`.
2018-01-28 21:06:49 -06:00
urkerab
cdb12bd696 Fix last item handling (#4383) 2018-01-28 20:05:44 -06:00
Guangcong Luo
de7c58aad7 Validator: Fix egg move checking 2018-01-28 15:37:18 -05:00
Guangcong Luo
b19e1b819e
Fix typo in previous commit 2018-01-28 13:30:00 -06:00
Guangcong Luo
bf67a69606
Team Validator: Fix babyOnly check 2018-01-28 13:29:03 -06:00
Guangcong Luo
cd946a0a41
Correctly refactor Mew/Celebi checks 2018-01-28 12:24:42 -06:00
Marty-D
f0e180db0b
Validator: Refactor Mew/Celebi checks 2018-01-28 18:20:34 +00:00
Marty-D
a9d9e199b3
Validator: Add VC level and Ball requirements 2018-01-28 17:17:30 +00:00
Guangcong Luo
4f64074b6c Improve evolution move validation
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.
2018-01-28 10:37:43 -06:00
Guangcong Luo
74143b652d Workaround for Celebi VC validation 2018-01-27 22:38:56 -06:00
Marty-D
27dc108d6c
Fix forme tiering in past gens 2018-01-27 04:22:50 +00:00
Guangcong Luo
a22d1d7b20 Fix doublesTier
Should now correctly display NFE and LC tiers.
2018-01-26 18:40:24 -06:00
Guangcong Luo
c9b075ce1f Fix Doubles tiers 2018-01-26 14:26:09 -06:00
KrisXV
aefa8c986a Add doublesTier (#4339) 2018-01-26 14:23:38 -06:00
Dan Huang
9c37960ab6 Use PRNG in sim/ files (#4365) 2018-01-24 12:27:07 -06:00
HoeenHero
f59912a56a Fix /evalbattle (#4372) 2018-01-23 19:25:18 -06:00
urkerab
f0c93655c4 Fix Protective Pads mechanics (#4362) 2018-01-23 11:19:07 -05:00
Guangcong Luo
aae46ffd46 Support checkLearnset in format rules
Fixes #4356
2018-01-20 02:05:21 -06:00
Guangcong Luo
fcfd7c9c25 TypeScript: Add otherFormes to Template 2018-01-19 23:50:22 -06:00
Guangcong Luo
327b004b74 Better support for destroying streams 2018-01-18 04:14:58 -06:00
Guangcong Luo
ab1f995daa Rewrite Process Manager
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.
2018-01-18 03:34:16 -06:00
Guangcong Luo
d395424fd3 TeamValidator: Return null, not false, for valid team
As usual, having `T | false` be our optional is a really old PHP
convention; we should be using `T | null` basically everywhere.
2018-01-18 03:32:32 -06:00
Marty-D
6bce102f66
Gen VII: Update critical hit rate 2018-01-17 05:00:13 +00:00
urkerab
297af3b111 Allow formats to override checkLearnset (#4341) 2018-01-16 04:16:48 -06:00
urkerab
99d682ca26 Change lastMove from a string to a Move (#4298) 2018-01-03 11:54:35 -06:00
The Immortal
5d9a98f061 Fix Alphabet Cup validation 2018-01-03 18:23:03 +08:00
Kris Johnson
c30d5baa0e Fix formats.noLearn validation (#4303)
Also i changed the for loops that i had a stroke over in TI's commit to
for...of loops

@theimmortal
2018-01-03 03:29:38 +08:00
The Immortal
9cdb80f28a Fix Alphabet Cup validation 2018-01-02 22:37:32 +08:00
Guangcong Luo
334103f284 Implement 1000-turn limit for Endless Battle Clause 2017-12-29 18:18:45 -05:00
urkerab
59616d8eb7 Ban Mega formes by name (#4292) 2017-12-28 20:03:30 -06:00
urkerab
4cd0a0e389 Allow formats to reorder all six Pokémon (#4281) 2017-12-27 05:51:11 -06:00
The Immortal
c916f2ae9d Remove remnant from old OMotM 2017-12-27 13:20:03 +08:00
CheeseMuffin
def2697f33 Finish typescripting chat.js (#4277) 2017-12-24 00:45:49 -06:00
urkerab
2873bd8366 Remove an unused parameter from eatItem and useItem (#4210) 2017-12-23 21:36:51 -06:00
Guangcong Luo
0a06bb97ef Better support multiline responses in /eval 2017-12-23 21:32:16 -06:00
Guangcong Luo
b9e9a2b7c4 Simplify Promise support in /eval 2017-12-23 21:31:42 -06:00
Guangcong Luo
b8be497142 Improve /eval output 2017-12-19 21:30:47 -05:00
Quinton Lee
361b4d03cc
Fix crash in Dex.getFormat 2017-12-18 19:25:56 -06:00
Guangcong Luo
9542ae2444 Include chat/etc in battle logs 2017-12-18 18:32:58 -06:00
MacChaeger
8d571be74e Fix certain Abilities not being overwritten by most forme changes (#4245) 2017-12-14 11:45:12 -05:00
urkerab
dc3945ff86 Protect should not affect Clangorous Soulblaze's other target (#4237)
Closes #4232
2017-12-11 09:02:24 -05:00
Guangcong Luo
b9e532426a Hardcode VC Entei/Raikou/Suicune validation 2017-12-10 20:03:21 -05:00
Marty-D
439e9654de
Add Z-Moves bypassing protection message 2017-12-10 16:03:43 -05:00
Guangcong Luo
7d9fff71bd Improve custom format performance
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.
2017-12-10 02:01:19 -05:00
Guangcong Luo
1a68294d6a Fix VC Celebi check
I messed up the capitalization, but more importantly Marty apparently
already implemented this another way.
2017-12-09 23:19:01 -06:00
Guangcong Luo
52f34f42f5 Improve VC move validator 2017-12-09 21:11:20 -06:00
Guangcong Luo
799a6a1e44 Improve Matchmaker API
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.
2017-12-09 15:04:29 -06:00
Spandan Punwatkar
a1270cac7a Fix Ability Aliases (#4228) 2017-12-09 01:48:05 -06:00
Guangcong Luo
e0490ef41f Mark custom rules as non-searchable
This is just a safety precaution that may simplify some future code; we
don't currently allow custom rules in the matchmaker at all.
2017-12-09 00:25:16 -06:00
Guangcong Luo
5260bf6ac3 Fix unreleased template checking
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.
2017-12-08 22:41:53 -06:00
Guangcong Luo
5d11ec89f1 Fix base-pokemon banning 2017-12-08 22:27:30 -06:00
Guangcong Luo
0613939874 Refactor tournament rule validation
It was happening in two different places. It's been consolidated now.
2017-12-08 21:04:05 -06:00
Guangcong Luo
bb598ed6c2 Add rule validator for format rules 2017-12-07 22:07:12 -06:00
MacChaeger
801883c53a Implement Stomping Tantrum (#4175) 2017-12-07 18:36:19 -06:00
Guangcong Luo
c0da44c482 Refactor moveset -> moveSlots
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`.
2017-12-05 11:12:44 -06:00
Kris Johnson
06de38fe6d STABmons: Fix Necrozma type inheriting (#4214) 2017-12-05 15:49:07 +08:00
Guangcong Luo
08d079037d Pass source effect of switches to client
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.
2017-12-04 19:14:13 -06:00
Guangcong Luo
f3dbfbe685 Refactor Decision -> Action
"Decision" and "Choice" were always kind of unclear, so Decision is now
Action. It should now be a lot clearer.

Actions are also now strongly typed.
2017-12-02 11:34:55 -06:00
Marty-D
dc7c46b427 Update Ability-changing effects
Fixes #3230, closes #3245
2017-12-02 11:37:36 -05:00
Guangcong Luo
f97ab41cb6
FIx bug 2017-12-02 10:19:18 -06:00
Guangcong Luo
70a5f3cf6d Fix Pursuit KO canceling a switch in Gen 3 2017-12-02 08:27:44 -06:00
Guangcong Luo
1ac2745c3e Refactor Pursuit hack
Pursuit no longer uses `moveThisTurn`, but rather `willMove`, which
involves significantly fewer Pursuit hacks.
2017-12-01 15:59:13 -06:00
Guangcong Luo
461706baa5 Correct Gen 2 faint mechanics
Described by Marty here:

https://www.smogon.com/forums/threads/gen-3-on-ps-final-fixes.3527268/#post-5989318
2017-12-01 15:59:03 -06:00
Guangcong Luo
ba9a41c669 Skip switches in gen 2-3 upon faint 2017-12-01 13:06:11 -06:00
Guangcong Luo
f4e535bbd6 Enforce consistent key spacing
This was previously not enforced because we used `:1` in too many
places, but those places seem to all be refactored out at this point.
2017-12-01 08:16:23 -06:00
Guangcong Luo
9bdf674d5f Refactor more tables to arrays
See #4079

Now we're just missing oldgens.
2017-11-30 19:40:16 -06:00
Guangcong Luo
8473c3f4fa Improve test engine
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.
2017-11-30 10:56:01 -06:00
Guangcong Luo
97d773226a Support switching to pokemon by name 2017-11-30 10:56:01 -06:00
Guangcong Luo
80c9a7c5a1 Fix Healing Wish properly
Broken in #4120
2017-11-30 10:39:21 -06:00
urkerab
53ef680bcf Put Rockruff-Dusk's template into the cache (#4185) 2017-11-26 10:02:46 -06:00
urkerab
aea93f25db Fix set name in validation reasons (#4181) 2017-11-25 19:08:06 -06:00
CheeseMuffin
0b3e09b06a Fix generation for totem mons (#4177) 2017-11-24 18:56:33 -06:00
urkerab
802db51ea8 Use ModifyMove to handle Photon Geyser mechanics (#4179) 2017-11-24 18:54:56 -06:00
Guangcong Luo
022839335f Add Gen 2 Virtual Console moves 2017-11-24 18:51:32 -06:00
MacChaeger
b0ba793257 Fix Totem tiers (#4176) 2017-11-24 13:55:47 -05:00
Marty-D
ff16589722 Correct Photon Geyser mechanics 2017-11-23 22:47:20 -05:00
urkerab
c7f9aa009c Fix spread Z-Moves interaction with protection (#4163) 2017-11-18 14:41:47 -05:00
Marty-D
77039602e3
Release Hidden Ability Orange and White Flower Florges line
Thanks, Kaphotics!
2017-11-18 09:15:41 -05:00
Guangcong Luo
e716e9edc7 Implement Ultra Burst 2017-11-17 00:01:09 -06:00
Guangcong Luo
e25eeb9eb0 Correctly validate Rockruff-Dusk 2017-11-16 21:45:24 -06:00
Kris Johnson
f2caefba9b Ultra Sun and Ultra Moon update (#4151) 2017-11-16 20:34:43 -06:00
MacChaeger
6f82808c34 Fix clearing volatiles (#4120) 2017-11-12 22:09:52 -05:00
Guangcong Luo
b9ea17e014 TypeScript: Correctly mark args as optional 2017-11-12 01:57:53 -06:00
Guangcong Luo
9a1cb36882 Support three arguments in addVolatile 2017-11-12 01:22:31 -06:00
Guangcong Luo
6dc65e48cf MODULE_NOT_FOUND is now ENOENT in Node 8 2017-11-09 14:43:43 -06:00
Guangcong Luo
56190af620 Fix up TypeScript errors
Also suppress TypeScript validation of various files we don't want
validated right now.
2017-11-08 01:23:04 -06:00
Guangcong Luo
e377d69395 Fix core team-validation intersection check 2017-11-05 00:11:51 -07:00
Guangcong Luo
7904e7791b Fix Gen 2 Hidden Power IV validation 2017-11-05 00:11:51 -07:00
Kris Johnson
4c5518320b Use standard formatting for STABmons move checking (#4123) 2017-11-04 13:54:54 -07:00
Guangcong Luo
c5d438b7be Fix TypeScript error in validator
...we should probably add TypeScript to CI sometime soon...
2017-11-04 12:14:47 -07:00
Kris Johnson
475e70b822 STABmons: Fix move validation error (#4121) 2017-11-03 15:42:37 +08:00
Guangcong Luo
17015189f1 Don't crash when validating impossible moves 2017-11-02 14:35:26 -05:00
Kris Johnson
c7e11d5469 Fix error in STABmons (#4118) 2017-11-02 14:02:18 -05:00
Guangcong Luo
011528bd5a Fix Hidden Ability validation
Previously, a mix of past-gen and modern event sources for a move would
confuse the validator. This case is now properly handled.
2017-11-02 13:36:05 -05:00
Guangcong Luo
528a6745cb TypeScript: Use GenderName alias in Template 2017-11-02 13:00:41 -05:00
Guangcong Luo
fed55531f1 Make the dexes table null-prototype
Fixes a 'constructor' issue in Dex.mod()
2017-11-02 13:00:40 -05:00
Guangcong Luo
e8d245f97b Support Pomeg Glitch 2017-11-02 13:52:24 -04:00
whales
c28a387a2f Fix Dex#getType (#4116) 2017-11-02 10:29:49 -04:00
urkerab
d86b272145 Other Metagames of the Month November 2017 (#4108) 2017-11-02 14:44:21 +08:00
Guangcong Luo
2d9fc18280 TypeScript sim/team-validator.js 2017-11-02 00:15:04 -05:00
Guangcong Luo
0e728281e6 Move team-validator to sim/team-validator 2017-11-01 05:22:37 -05:00
Guangcong Luo
6a6bc18d44 Work around ESLint 4.1.0 trailing spaces bug 2017-10-23 09:22:30 -05:00
Guangcong Luo
246dfa1da3 Refactor in-object-literal to array-includes (#4079)
Previously, if we wanted to test if A was either 'B' or 'C', we would use
the pattern:

    A in {B:1, C:1}

I actually don't know how common this pattern is; I just started using
it because I was tired of typing `A === 'B' || A === 'C'` all the time.
I never really liked it, though; the `:1` part made it kind of
blatantly a hack.

I did some testing and `['B', 'C'].includes(A)` is overall faster.

(A switch statement is around 20x faster still, but who wants to type
that much code?)

Anyway, the new standard is

    ['B', 'C'].includes(A)

Something something progress!
2017-10-23 09:19:15 -05:00
Marty-D
97bb5af755 Fix crash in confusion damage 2017-10-21 09:28:40 -04:00
Guangcong Luo
c640a69ffc Don't send Rated text for normal rated battles 2017-10-21 03:43:12 -05:00
Marty-D
312f93c47c Revert "Fix confusion interaction with HP-checking items (#4045)"
This reverts commit
6651c5dadb.
2017-10-20 21:05:49 -04:00
Quinton Lee
a0b8228592 TypeScript: Improve Sim typing (#4069)
Also improves intellisense for Visual Studio and Visual Studio Code.
2017-10-20 07:53:26 -05:00
Guangcong Luo
a207147a48 Support custom rated battle message
Currently, the bold circled "Rated" marker in battle logs is only used
for rated battles. This change also supports using them to mark tour
battles.
2017-10-18 05:41:03 -05:00
QuiteQuiet
6651c5dadb Fix confusion interaction with HP-checking items (#4045) 2017-10-17 09:26:27 -04:00
Guangcong Luo
110b6a5511 Implement tiebreaker
This is the tiebreaker used for timeouts in Gen 6-7 (I think), but it's
not currently used anywhere.
2017-10-08 03:39:58 -05:00
Ben Davies
77b4c77864 Dex: constructor is not a format alias 2017-09-18 21:20:03 -03:00
Guangcong Luo
6b870967e0 Fix bug in support for >10 pokemon in Team Preview 2017-09-09 20:31:54 -04:00
Guangcong Luo
737d9dbba0 Support more than 10 Pokemon in Team Preview 2017-09-09 20:19:24 -04:00
Guangcong Luo
066d970b54 Fix >6-pokemon Custom Games 2017-09-09 19:41:55 -04:00
Guangcong Luo
b42a322ecb Support over 6 Pokemon in Custom Game 2017-09-09 18:25:26 -04:00
Guangcong Luo
1e87e989cc Hacky fix to the 6-move bug 2017-09-08 18:20:08 -04:00
Guangcong Luo
057e6b4e89 Alias formats without gen number to Gen 7 formats
Closes #3785
2017-09-08 10:27:20 -04:00
urkerab
bd6743bbe7 Reveal own Ability in Gen 7 (#3969) 2017-09-06 23:21:19 -04:00
Guangcong Luo
25d0079b4f Sim: Fix Berries not activating after weather
Previously, Berries would not activate after weather damage and before
other residual damage/healing.

According to: https://www.youtube.com/watch?v=FRI5PSekhR4

They should activate then. More research is needed to determine what
other situations Berries should activate but don't.
2017-09-05 07:00:55 -04:00
Guangcong Luo
7785375d14 Sim: Faint-switch in fainted pokemon Spe order
Now, if multiple Pokemon fainted in one turn, they will be switched
out in Speed order (of the fainted Pokemon).
2017-09-05 06:53:56 -04:00
Ghoulean Algebra
f067ee13ee Gen II: Fix Hidden Power's power calculation (#3925)
Before : HP_Power=(5*(v+2w+4x+8y)+min(Z, 3))/2 + 31 
After: HP_Power=(5*(v+2w+4x+8y)+(Z % 4))/2 + 31 

where 
* v is 1 if SpcIV>=8; otherwise 0, 
* w is 1 if SpeIV>=8; otherwise 0, 
* x is 1 if DefIV>=8; otherwise 0, 
* y is 1 if AtkIV>=8; otherwise 0, 
* Z = SpcIV

See: 
http://tasvideos.org/forum/viewtopic.php?p=361950#361950
https://github.com/pret/pokecrystal/blob/master/battle/hidden_power.asm#L52
2017-08-27 20:22:05 -04:00
Quinton Lee
0c94145c40 Fix remaining custom format issues (#3910)
Rules for custom formats are once again sanitized and can be passed
around more easily by attaching them to the format's id.

Fixes:
- "Rule:" being required to add or remove a rule
- ruleset changes not being shown in battles
- the display of custom rules being affected by user input
- custom formats being broken by /hotpatch formats
2017-08-23 22:27:09 -07:00
Guangcong Luo
18d656519c Fix chooseMove again 2017-08-09 21:52:30 -05:00
Guangcong Luo
29bfa41f79 Fix crash in autoChoose 2017-08-09 20:28:25 -05:00
Marty-D
5aa7045900 Fix Solar Blade redirection issue 2017-08-05 12:32:35 -04:00
Guangcong Luo
4df6548cf4 Fix bugs in VGC auto-move resolver 2017-08-02 07:02:32 -04:00
HoeenHero
4af068a710 Fix custom banlists (#3832) 2017-07-31 02:18:24 -04:00
Guangcong Luo
bbf7bc98d2 Fix random battle sets
(There were doubles sets in singles games)
2017-07-27 17:49:38 -04:00
Guangcong Luo
acc165d4db Fix bugs in previous commits 2017-07-27 17:24:55 -04:00
Guangcong Luo
7f72f09e5d Rename Dex.format -> Dex.forFormat 2017-07-27 17:10:44 -04:00
Guangcong Luo
0e792dad80 Update default gen for formats to gen 7 2017-07-25 03:37:55 -04:00
Guangcong Luo
4cdf39f13c Remove prototype hack for Battle
Simulator instances still get their scripts included somewhat hackily,
but it's overall much less hacky than before. In particular, the
init code is now an actual constructor, allowing TypeScript to perhaps
validate it one future day.
2017-07-25 02:59:59 -04:00
Guangcong Luo
0ba508bbd3 Support ./pokemon-showdown generate-team
I might regret supporting this syntax, but it's now possible to make
PS generate teams on the commandline using:

./pokemon-showdown generate-team [optional format name] [optional seed]

The output will be in packed team format (which can be pasted into
a teambuilder import box).

The seed-passing should make it significantly more straightforward to
debug team generation weirdness.
2017-07-25 02:59:59 -04:00
Guangcong Luo
3b4d8b3ff0 Split random-teams.js out of scripts.js
Random team generation scripts are no longer in scripts.js, but instead
in a new file random-teams.js.

The scripts are now also no longer run from inside battles, but in a
new team generator object. This makes it easier for external scripts
to generate random teams by running Dex.generateTeam(format).
2017-07-25 02:59:59 -04:00
Guangcong Luo
a86762e4ea Fix in-battle clauses 2017-07-23 22:20:42 -07:00
Guangcong Luo
f38de6d775 Remove padStart shim
The padStart shim is currently unused and commented out. If we ever do
need it, we should increase the minimum Node version to 8.0.
2017-07-23 22:17:07 -07:00
Guangcong Luo
6c1a60df2e Fix limit rules in ruleTable team validation 2017-07-20 19:35:02 -05:00
Guangcong Luo
2b1d7b2cc3 Properly fix crash in /learn 2017-07-20 16:33:40 -05:00
Guangcong Luo
d79e348ebc Refactor banlistTable -> ruleTable
PS's rule table has been renamed from banlistTable, and works a bit
differently now. It's a Map instead of an object now, and the keys
work a bit differently.

The original banlistTable was designed to store bans, and later
additions shoved rules and then unbans in there. The new table is
designed to support all of these.
2017-07-20 12:50:41 -05:00
Konrad Borowski
212b99ed90 Remove Object.values shim (#3787)
It's not correct as far ES2017 specification is concerned, and Showdown
requires Node.js 7 anyway
2017-07-16 17:39:53 -05:00
asgdf
6dc5c877e3 Fix comment typos (#3757) 2017-07-10 16:57:07 +09:00
Guangcong Luo
58a1af0f0f Rename supplementaryBanlist -> customBanlist
It's shorter and clearer.
2017-07-04 09:36:37 +09:00
Guangcong Luo
3f6f9e61a5 Fix supplementary banlists
They're coded as nullable and are better treated that way.
2017-07-04 09:36:37 +09:00
Marty-D
3bf0ffdc97 Gen III: Fix Ingrain 2017-06-29 18:38:36 -04:00
Guangcong Luo
83f70fcf3a Export PRNG from sim/ 2017-06-22 20:57:51 -07:00
Quinton Lee
e3b964a65d Show correct rulesets in custom format battles (#3674)
Also add more format documentation
2017-06-22 15:25:31 -07:00
Quinton Lee
5ab919d858 Refactor supplementary banlists into custom formats (#3671) 2017-06-22 03:10:15 -07:00
Quinton Lee
ec10d30996 eslint: Lint sim/ directory (#3670) 2017-06-21 20:00:17 -07:00
Marty-D
d60c007f3d Update move flag descriptions 2017-06-17 09:36:52 -04:00
Guangcong Luo
cf7607cb90 Move cache tables out of Dex.data
Template/Item/Move/Ability caches are now direct properties of Dex,
instead of being inside Dex.data.
2017-06-13 21:45:53 -05:00
Guangcong Luo
00448ac865 TypeScript: Update for latest nightly
The latest nightly of TypeScript changes how the checks work, and I'm
tracking it because it also fixes several major bugs in --checkJs.
2017-06-11 12:03:38 -05:00
Caleb Young
9dab8e50e1 Implement DPP damage formula (#3583) 2017-06-11 10:18:34 -05:00
asgdf
f22963c718 Fix Last Will crash (#3561)
By moving BeforeFaint right before the faint message, so the move is done
by then.
2017-05-28 17:24:17 +09:00
urkerab
f24d7cbadb Move Illusion-breaking out of the battle engine (#3549) 2017-05-24 20:36:17 -04:00
asgdf
8a33238544 Fix statuses still being effective after being removed that turn (#3538) 2017-05-24 23:55:35 +09:00
urkerab
d212b9f128 Move, Ability and Item effects should inherit the name (#3547) 2017-05-24 23:12:38 +09:00
Guangcong Luo
cd3ac06987 Fix Hail/Sandstorm damage regression
(Also add a test for it since this isn't even the first time this
exact regression has happened.)
2017-05-18 06:29:25 -05:00
Guangcong Luo
109b2cfe1d Slightly refactor teamsize 2017-05-18 05:38:14 -05:00
QuiteQuiet
1be924f6e8 Send team size at the start of battles (#3512) 2017-05-18 05:09:38 -05:00
Guangcong Luo
149ca3759c Add classes for data
Having classes for data will make it better for documenting and make
for overall nicer code that's easier to statically analyze.
2017-05-17 04:10:01 -05:00
Guangcong Luo
fe5fa7889e Fix various TypeScript-related errors
Now that typescript@next fixes the major issue plaguing us, we can
start working on the other issues!
2017-05-17 04:10:01 -05:00
urkerab
b12d9cbf04 Give Natures a Generation (#3528) 2017-05-14 07:22:42 -05:00
urkerab
8ca39d65fc Properly report a near miss for an alias (#3532) 2017-05-14 07:22:20 -05:00
Charlie Kobayashi
78ed58d0c4 Dex: fix dataSearch (#3525)
Use the result's name first instead of inexact search term if search is found.
2017-05-12 17:12:07 -05:00
Charlie Kobayashi
196364adca Effect: don't override inherited properties from moreData (#3524)
- caused weather effects passed in through ``moreData`` to be marked as simply ``"Effect"``
    - as a result, sandstorm and hail will damage Rock/Ground/Steel and Ice types  respectively
- this fix makes ``Effect`` inherit the ``effectType`` from ``moreData`` if it doesn't exist in the primary ``data`` variable passed into the constructor
2017-05-12 14:23:05 -05:00
urkerab
59583ee113 Include aliases when searching the dex (#3475) 2017-05-09 23:58:32 -05:00
Guangcong Luo
e34c77930a Start creating classes for getEffect data
Currently, getEffect/getTemplate/getMove/etc return bare objects.
Refactoring their returns into classes will allow TypeScript to type
check them.
2017-05-09 16:00:11 -05:00
Guangcong Luo
a75282ea97 Fix crash in /weakness 2017-05-08 19:06:54 -05:00
Guangcong Luo
22186f1903 Improve TypeScript typing
sim/dex.js and sim/prng.js are now valid strict TypeScript! Also they
have slightly less "any" use than before.
2017-05-08 02:58:55 -05:00
Quinton Lee
fa1b45f7ab Support supplementary rulesets in battles (#3330) 2017-05-05 20:13:08 -05:00
Guangcong Luo
9e180e4fc1 Remove MockBattle
No MockBattle feature needs to be kept out of sim/...
2017-05-05 16:57:18 -05:00
Guangcong Luo
6dd58b40d3 Refactor simulator into new sim/ directory
This is a surprisingly minor refactor considering how many files it
touches, but most of this is only renames.

In terms of file renames:
- `tools.js` is now `sim/dex.js`
- `battle-engine.js` is now `sim/index.js` and its three classes are
  in `sim/battle.js`, `sim/side.js`, and `sim/pokemon.js`
- `prng.js` is now `sim/prng.js`

In terms of variable renames:
- `Tools` is now `Dex`
- `BattleEngine` is now `Sim`
- `BattleEngine.Battle` is now `Sim.Battle`
- `BattleEngine.BattleSide` is now `Sim.Side`
- `BattleEngine.BattlePokemon` is now `Sim.Pokemon`
2017-05-05 16:48:38 -05:00