Commit Graph

175 Commits

Author SHA1 Message Date
Marty-D
85525e9463 Gen I: Put PP underflow before hit checks 2018-08-25 21:14:47 -04:00
Marty-D
5271a3c44f Gen I: Fix PP underflow for binding moves 2018-08-25 15:07:50 -04:00
MacChaeger
82c792f82c Update to TypeScript 3.0.1 (#4710) 2018-08-07 03:27:28 +09:00
MacChaeger
8eb5caa103 Gens 1 & 2: Support Inverse mod (#4617) 2018-04-22 14:00:41 -05:00
MacChaeger
711a0d4ce4 Check semi-invulnerability before immunities (#4574) 2018-04-14 10:27:45 -04:00
Quinton Lee
acd812c71e Typescript gens 1-4 (#4556) 2018-04-11 22:11:25 -05: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
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
Marty-D
6c898b0828
Gen I: Correct secondary chances
Since there are no 100% secondary effects in this gen, there's actually no difference between this implementation and the previous one, but for the sake of custom moves this is the way the rolls really work.
2018-02-13 22:01:42 +00:00
urkerab
99d682ca26 Change lastMove from a string to a Move (#4298) 2018-01-03 11:54:35 -06:00
Kris Johnson
238ac1fdd7 Refactor old gens to for...of (#4274) 2017-12-23 21:46:04 -06:00
urkerab
0aef595177 Fix this unnecessary reference to battle (#4221) 2017-12-07 14:29:11 -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
XnadrojX
024c2ce7ac Gen I-II: Fix accuracy calculations and BrightPowder (#3926) 2017-11-30 21:12:59 -05:00
Guangcong Luo
9cb81bf67b Correct spelling of "offense"
(Just a small change while making some changes to `ofe`)
2017-11-17 19:33:47 -06: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
c7335a3904 Gen I & Stadium: Fix secondary rolls 2017-08-30 09:52:32 -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
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
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
Guangcong Luo
d7f180954f Comment out unused Gen 1 setupType 2017-02-23 05:24:45 -06:00
xCrystal
2abd1dbef5 Gen 1 Random Battles: Improve movesets and balance (#3210) 2017-02-22 16:46:32 -06:00
xCrystal
64e742ab9d Gen I: Fix three minor bugs (#3222)
Fix being put to sleep not clearing recharge condition

Fix Supersonic clearing last stored damage

Fix Substitute HP
- In RBY, a Substitute is only knocked out when its HP underflows, but remains alive at 0 HP. Therefore, it's effectively as if the Substitute had 1 more HP than the amount of HP lost in order to set it up.
2017-02-14 21:10:15 -05:00
Guernouille
9c1c4b64e6 Gen I: Fix Challenge Cup DVs (#3059)
SpA and SpD use the same DV, and HP DV is calculated using the 4 other DVs.
In-game, the DV range is [0;15], each point giving 2 points in the stats, so to simulate that we make every DV a multiple of 2 in the [0;30] range.
2017-01-02 14:35:36 -05:00
Guangcong Luo
bf4e3df3b8 Deprecate decision.targetSide/targetPosition
These are no longer used; we now only use targetLoc.
2016-12-26 17:12:40 -05:00
Guangcong Luo
9f4613ea1e Don't use tradeback moves in Gen 1 CC 2016-12-23 12:59:08 -08:00
Ivo Julca
b684db5a81
Gen 1: Improve comments and refactor out volatile data for trap PP rollover 2016-09-17 15:51:05 -05:00
Guangcong Luo
2a90611718 Optimize Gen 1 boostBy 2016-08-18 16:15:09 -05:00
Marty-D
6953200e62 Gen I: Fix boosting resulting in a neutral stat stage 2016-08-18 16:10:15 -04:00
Marty-D
fc86e0ef0a Prevent confusion damage from being a critical hit 2016-05-05 23:44:58 -04:00
Ivo Julca
0281176fd1 Remove usage of Array|Object methods implemented by Sugar.js
Adds a dependency to shim Object.values until it's natively available.
2016-03-09 16:55:34 -05:00
Guangcong Luo
cc7ccd2efe Stop unnecessarily calling update()
pokemon.update() used to be called after pretty much everything, but
now that we've refactored pretty much everything out of it, it's no
longer necessary for most of the situations we call it for.

It currently only updates pokemon.speed, so I've renamed it updateSpeed
for clarity.

We now only update pokemon.speed on switch-in, right before the
residual event, and at the beginning of every turn. This gives
something like a 30% speed-up.
2016-02-17 01:07:22 -06:00
Marty-D
635123c5e2 Gen I: Fix partial-trapping PP display 2016-01-31 15:54:06 -05:00
Konrad Borowski
81f602b8d8 Always use trailing comma for multiline objects 2016-01-01 00:20:07 +01:00
Guangcong Luo
94a67eb243 Fix inaccurate PP use tracking in gen 1 2015-12-19 04:12:31 -05:00
Juanma Serrano
7a8b033bf5 Gen 1 RandBat: Fix teams having 5 mons sometimes
Very small chance that happened in very specific scenarios.
2015-12-17 16:24:56 +01:00
r0730
4dcc422a07 Gen 1: Reduce occurrence of extremely weak team
You won't get more UU if you already have handicapMons, however if you get a lot UU first, you could still get handicapMons.
This fix make sure you wont get handicapMons once you have at least 2 NU/worse (which is already bad enough)
2015-11-18 18:11:34 +08:00
r0730
680a3f3d04 prevent getting >1 handicapMons
NU is worse than UU, so if UU pokemons will be skipped, NU should certainly be skipped as well.
2015-11-14 23:18:24 +08:00
Marty-D
be670b0a68 Gen I: Fix Random Battle set generator
Previously, it would reject every move until there were 4 left in the pool.
2015-11-09 23:13:56 -05:00
Ivo Julca
04c64c143e Cleanup: remove several unused variables 2015-11-07 17:34:21 -05:00
Ivo Julca
90973d5c0c Style fixes
- Cut down excessive spacing
- Add braces to missing conditionals
2015-11-07 17:08:09 -05:00
Ivo Julca
2c2a3bdf58 Fix misplaced cases in random sets generators 2015-11-07 16:50:51 -05:00
Juanma Serrano
c4ac8d6e2f Use strict mode and let and const instead of var
This commit also fixes some duplicated variable declarations.
2015-11-06 21:56:52 -05:00
Juanma Serrano
9cace281b5 Gen 1: Remove Rage accuracy bug, it's not real
Read: http://www.smogon.com/forums/threads/gen-1-and-tradebacks-dev-post-bugs-here.3524844/page-9#post-6416886
2015-09-16 11:55:12 +02:00
Guangcong Luo
5d3cd8263c More updates to Endless Battle Clause
- Gen 1 PP overflow makes a Pokemon stale
- Staleness warnings now specify the staleness source
- Half-staleness also warns, if another pokemon is already stale

Warning on half-staleness helps remind people who seem to think
they've beaten Endless Battle Clause after 5-ish turns, when it
takes 10-20 turns for some staleness verdics, especially if
there's a lot of switching going on.
2015-07-24 03:33:28 -04:00
Ivo Julca
15b925f7e4 RBY-GSC Randbats: Fix high incidence of later gen Pokémon 2015-07-16 13:33:42 -05:00
Ivo Julca
baadd0a92f Overhaul old-gen random team builders
Mainly follow-up for 1deedc595, but also fixes a few bugs.
- BW/GSC/RBY - randomSet: fixed and renamed slot argument.
- BW - randomTeam: crashlogger relative path was set incorrectly.
- BW - randomTeam: PotD Magikarp and Delibird used outdated randomBattleMoves data format.
- RBY - randomTeam: builder was too reject-happy regarding weaknesses (counters prematurely updated).

An improvement of 130% more op/s is observed for RBY randomCCTeam,
with no significative performance regression for randomTeam in any gen.
2015-07-16 12:03:14 -05:00
Marty-D
0f7f238a10 Gen I: Prevent Cosplay Pikachu from appearing in Challenge Cup 2015-07-08 20:27:09 -04:00
Ivo Julca
f18eef39ca Fix Travis build 2015-06-12 03:41:22 -05:00
The Immortal
a4a09021b2 Gen 1: Fix Wrap deducting extra PP
It currently deducts an extra PP on a switch. According to the comment,
PP is not deducted earlier, which is why it was being deducted here.
But this is incorrect. PP is deducted earlier on a switch.
2015-06-09 19:12:43 +04:00