pokemon-showdown/data/mods/gen5/conditions.ts
Guangcong Luo f9fdc73133
Support per-pokemon Residual handlers in Side/Field conditions (#8222)
For side conditions, `onStart`/`onRestart`/`onResidual`/`onEnd`
have been renamed `onSideStart`/`onSideRestart`/`onSideResidual`/`onSideEnd`,
with the `onResidualOrder` properties renamed `onSideResidualOrder`.

For field conditions, `onStart`/`onRestart`/`onResidual`/`onEnd`
have been renamed `onFieldStart`/`onFieldRestart`/`onFieldResidual`/`onFieldEnd`,
with the `onResidualOrder` properties renamed `onFieldResidualOrder`.

(The `onField` and `onSide` part helps make it clear to the type system
that the first argument is a Field or Side, not a Pokemon.)

Side and field conditions can now use `onResidual` to tick separately
on each pokemon in Speed order. `onResidualOrder` (the per-pokemon
tick) can be timed separate from `onSideResidualOrder` (the
per-condition tick), allowing conditions to end at a different priority
than they tick per-pokemon.

Relatedly, `onTeamPreview` and `onStart` in formats now need to be
`onFieldTeamPreview` and `onFieldStart`.

Unrelatedly, `effectData` has been renamed `effectState`, and the
corresponding state containers (`pokemon.statusData`,
`pokemon.speciesData`, `pokemon.itemData`, `pokemon.abilityData`,
`field.weatherData`, `field.terrainData`) have been similarly renamed. I
renamed the types a while ago, but I was holding off renaming the fields
because it would be a breaking change. But this is a breaking change
anyway, so we might as well do it now.

Note: `onResidual` will tick even on `onSideEnd` turns, although
`onSideResidual` won't. When refactoring weather, remember to
check `this.state.duration` so you don't deal weather damage on the
ending turn.

Intended as a better fix for #8216
2021-04-25 10:55:54 -07:00

57 lines
1.6 KiB
TypeScript

export const Conditions: {[k: string]: ModdedConditionData} = {
slp: {
inherit: true,
onSwitchIn(target) {
this.effectState.time = this.effectState.startTime;
},
},
partiallytrapped: {
inherit: true,
onStart(pokemon, source) {
this.add('-activate', pokemon, 'move: ' + this.effectState.sourceEffect, '[of] ' + source);
this.effectState.boundDivisor = source.hasItem('bindingband') ? 8 : 16;
},
onResidual(pokemon) {
const trapper = this.effectState.source;
if (trapper && (!trapper.isActive || trapper.hp <= 0 || !trapper.activeTurns)) {
delete pokemon.volatiles['partiallytrapped'];
return;
}
this.damage(pokemon.baseMaxhp / this.effectState.boundDivisor);
},
},
stall: {
// Protect, Detect, Endure counter
duration: 2,
counterMax: 256,
onStart() {
this.effectState.counter = 2;
},
onStallMove() {
// this.effectState.counter should never be undefined here.
// However, just in case, use 1 if it is undefined.
const counter = this.effectState.counter || 1;
if (counter >= 256) {
// 2^32 - special-cased because Battle.random(n) can't handle n > 2^16 - 1
return (this.random() * 4294967296 < 1);
}
this.debug("Success chance: " + Math.round(100 / counter) + "%");
return this.randomChance(1, counter);
},
onRestart() {
if (this.effectState.counter < (this.effect as Condition).counterMax!) {
this.effectState.counter *= 2;
}
this.effectState.duration = 2;
},
},
gem: {
duration: 1,
affectsFainted: true,
onBasePower(basePower, user, target, move) {
this.debug('Gem Boost');
return this.chainModify(1.5);
},
},
};