Commit Graph

245 Commits

Author SHA1 Message Date
NoahWhite1115
ee6532d0ce Fix Illusion to display Users level instead of Illusions level (#4764) 2018-07-20 15:27:53 +09:00
Guangcong Luo
7ec8bb7bcb Rename getData to getRequestData
Part of an ongoing effort to get rid of ridiculously vague
function/variable names.
2018-07-20 14:40:40 +09:00
Quinton Lee
58b20d99eb Dex: Support custom rules altering complex bans (#4738)
Also adds some tests for custom rules
2018-07-03 17:22:28 -07:00
Quinton Lee
ed01c527ba
Validator: allow custom rules to unban unreleased items and moves 2018-07-03 11:29:38 -05:00
Marty-D
538ac5ca55 Fix protection interaction with Z-Powered Z-Moves 2018-06-30 16:34:35 -04:00
Marty-D
f259d43987 Fix Nightmare removal properly 2018-06-09 18:17:58 -04:00
Marty-D
e3416dd54a
Fix some formechange bugs
- Allows Rayquaza to visibly Mega Evolve with no item again
- There's no reason to do complete forme changes in Gen 1 or 2
2018-06-09 15:28:57 +00:00
Marty-D
691ce185b0 Add Shiny Zygarde event 2018-05-31 22:02:02 -04:00
MacChaeger
b082705569 Transform should ignore Roost's effects (#4698) 2018-05-28 13:17:06 -04:00
MacChaeger
df20e45f92 Camomons: Fix permanent forme changes causing apparentType to desync (#4693) 2018-05-26 21:11:58 -05:00
MacChaeger
22ad90d3ff Camomons: Modify the template unless the Pokemon is transforming (#4688) 2018-05-25 19:27:47 -04:00
MacChaeger
1aaeca908f Fix transforming into Arceus/Silvally (#4687) 2018-05-23 19:55:59 -04:00
MacChaeger
08ba5bc831 Make formeChange handle relevant messages and ability changes (#4654) 2018-05-23 19:55:05 -04:00
MacChaeger
a85932f75b Actually fix Camomons (#4685) 2018-05-22 00:54:14 -05:00
MacChaeger
1be208916a Improve Stomping Tantrum interaction with Protect (#4680) 2018-05-21 22:39:30 -04:00
MacChaeger
68783537ca Fix type display in camomons after switching out (#4683) 2018-05-21 21:27:07 -05:00
MacChaeger
e3174ebc02 Fix type display in Gen 7 metas (#4655) 2018-05-21 17:27:23 -05:00
MacChaeger
a4a3d31b7c Properly support Pokemon with no ability (#4678) 2018-05-20 22:13:24 -05:00
Ivo Julca
c3e752c87f Fix leak of trapped status if no healthy Pokémon can switch in
Only request data needs this fix, as choice validation is already safe from this issue.
2018-05-19 15:09:41 -05:00
MacChaeger
dbb3d1a053 Fix failure messages of nonstandard healing moves (again) (#4675) 2018-05-18 15:47:46 -05:00
Marty-D
b450fce65e
Fix Shell Bell damage tracker 2018-05-14 13:34:54 +00:00
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