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.
Latest research (http://www.smogon.com/forums/posts/7625046/) shows that although Z-Synthesis bypasses Heal Block, using Z-Copycat to copy Synthesis does not. (Z-Copycat on a damaging move does of course turn into a damaging Z-Move.)
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.
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!
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).
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.
* Random Battle: Add possibility for Fly-Z or Bounce-Z
This involves adding Fly to some Flying Pokemon without a good Flying
STAB. (This also makes sure Fly is not their only STAB, and only exists
with setup.)
* Update scripts.js
Armaldo is far too slow to utilize Swords Dance well, and only works on
dedicated Rain teams (which are very uncommon in Randoms).
Update item selection for Substitute and Reversal in combination.
* Magnet Pull Magnzone now gets HP Fire 100% of the time
* Change Ditto's IVs to allow players to know it's Hidden Power at Team
Preview
* Dittos are now Sassy to give a better download matchup in the case of
a 'double down" - mirror matchup remains unchanged
* Removed weather restriction on Chlorophyll to bump up Venusaur usage
* Removed unused weather abilities
Also updated the link to the VR thread in the BSS format description
Eevee only gets Celebrate from an Event, and thus Umbreon cannot have its HA or Egg Move (Wish) on a set that also has Celebrate.
Also fixes several items being left out of the item clause (Thanks Urkerab and DragonWhale)
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`
Previously, `moveid` would contain the specific type of hidden power such as `'hiddenpowerfire'`, but the switch statement would check for `'hiddenpower'`, and thus Hidden Power would never be rejected.
* Random Battle: Improve HP evs
This lets Zygarde-10% activate Power Construct in two subs, and also simplifies some unnecessarily complex code.
* Fix formatting (#19)
* Update scripts.js
It can't sub down to exactly half if it's got lefties, so don't give it less HP for no reason.
The regressions affected information handling
- Seeds used for random teams were no longer being logged.
- The seed used for generating p2's team was also used for the battle itself.
Dancer Petal Dance shouldn't lock. This is a horrible hack but it fixes
the problem. A real fix would involve refactoring basically all locking
moves. Which I guess I should do one day...
Fixes#2974
This doesn't fix the biggest issue with Dancer (Petal Dance locking),
but it does fix every other Dancer issue, by moving it from useMove
to runMove.
This also adds improved comments on runMove and useMove.
This removes the 'deterministic test' tools by preventing action at a
distance (namely, preventing the modification of the `init` method in
`Battle` during tests). This action at a distance is incredibly
confusing.
All this action at a distance did was discard any parameters that were
passed to `Battle` that weren't the first three (which was probably a
mistake by the original author) and also hard code `this.seed` and
`this.startingSeed` in `Battle`.
This functionality has now been moved to the `PRNG` class, so instead
users should pass a `PRNG` to `Battle` as the 5th constructor argument.
Users can also pass one as the third argument to `common.createBattle`
or use `common.createBattleWithPRNG` with the PRNG as the first
argument.
The PRNG is just an encapsulation of the pseudo-random algorithm in a
class. It is stateful, so make sure to take a `clone()` of the PRNG if
you want to re-use it.
With the Gale Wings nerf, it appreciates being able to use one additional
super-heavy priority attack before Brave Bird takes it below Gale Wings
range.
Priority Z-moves exist (namely, Gale Wings Supersonic Skystrike).
Quick Guard now partially protects against priority Z-moves.
Psychic Terrain now fully protects against priority Z-moves.
In case of boosts, the attacking animation would play 1st, stealing the
boosts last, instead of the other way around.
This approach was chosen since Spectral Thief is the only move that
steals boosts this way, for now
Encore and Disable now fail when used against Z-moves.
Encore and Disable now no longer prevent Z-moves from being used.
Instruct now repeats the selected target location.
Instruct Pursuit now repeats the switched out target location, if
activated.
This refactor also simplifies some previously unnecessarily-complicated
code.
With the buffs to the healing berries that confuse if a Pokemon has a
conflicting nature, it is now possible for Linoone to use them as a
substitute for Sitrus Berry, if it has Gluttony as its ability.
In Random Battles, natures are always neutral, so the any of the berries
will serve this purpose.
- Z-Moves are always single-target, even if based on spread moves.
- Z-Moves cannot be selected if the base move has no PP.
- Z-Moves can be selected if the base move is disabled.