mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-23 07:49:36 +02:00
Add type inference to ArenaTag.apply
This commit is contained in:
parent
08da3ed936
commit
27d1a57090
@ -36,7 +36,7 @@ export abstract class ArenaTag {
|
|||||||
public side: ArenaTagSide = ArenaTagSide.BOTH
|
public side: ArenaTagSide = ArenaTagSide.BOTH
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
apply(arena: Arena, simulated: boolean, ...args: unknown[]): boolean {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,12 +126,12 @@ export class MistTag extends ArenaTag {
|
|||||||
* Cancels the lowering of stats
|
* Cancels the lowering of stats
|
||||||
* @param arena the {@linkcode Arena} containing this effect
|
* @param arena the {@linkcode Arena} containing this effect
|
||||||
* @param simulated `true` if the effect should be applied quietly
|
* @param simulated `true` if the effect should be applied quietly
|
||||||
* @param args `[0]` a {@linkcode Utils.BooleanHolder | BooleanHolder} whose value is set to `true`
|
* @param cancelled a {@linkcode Utils.BooleanHolder | BooleanHolder} whose value is set to `true`
|
||||||
* to flag the stat reduction as cancelled
|
* to flag the stat reduction as cancelled
|
||||||
* @returns `true` if a stat reduction was cancelled; `false` otherwise
|
* @returns `true` if a stat reduction was cancelled; `false` otherwise
|
||||||
*/
|
*/
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
override apply(arena: Arena, simulated: boolean, cancelled: Utils.BooleanHolder): boolean {
|
||||||
(args[0] as Utils.BooleanHolder).value = true;
|
cancelled.value = true;
|
||||||
|
|
||||||
if (!simulated) {
|
if (!simulated) {
|
||||||
arena.scene.queueMessage(i18next.t("arenaTag:mistApply"));
|
arena.scene.queueMessage(i18next.t("arenaTag:mistApply"));
|
||||||
@ -169,15 +169,13 @@ export class WeakenMoveScreenTag extends ArenaTag {
|
|||||||
*
|
*
|
||||||
* @param arena the {@linkcode Arena} where the move is applied.
|
* @param arena the {@linkcode Arena} where the move is applied.
|
||||||
* @param simulated n/a
|
* @param simulated n/a
|
||||||
* @param args the arguments for this tag's application:
|
* @param moveCategory the attacking move's {@linkcode MoveCategory}.
|
||||||
* - `[0]` The attacking move's {@linkcode MoveCategory}.
|
* @param damageMultiplier A {@linkcode Utils.NumberHolder | NumberHolder} containing the damage multiplier
|
||||||
* - `[1]` A boolean indicating whether it is a double battle.
|
|
||||||
* - `[2]` A {@linkcode Utils.NumberHolder | NumberHolder} containing the damage multiplier
|
|
||||||
* @returns `true` if the attacking move was weakened; `false` otherwise.
|
* @returns `true` if the attacking move was weakened; `false` otherwise.
|
||||||
*/
|
*/
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
override apply(arena: Arena, simulated: boolean, moveCategory: MoveCategory, damageMultiplier: Utils.NumberHolder): boolean {
|
||||||
if (this.weakenedCategories.includes((args[0] as MoveCategory))) {
|
if (this.weakenedCategories.includes(moveCategory)) {
|
||||||
(args[2] as Utils.NumberHolder).value = (args[1] as boolean) ? 2732 / 4096 : 0.5;
|
damageMultiplier.value = arena.scene.currentBattle.double ? 2732 / 4096 : 0.5;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -269,32 +267,25 @@ export class ConditionalProtectTag extends ArenaTag {
|
|||||||
* - `[2]` the defending {@linkcode Pokemon}
|
* - `[2]` the defending {@linkcode Pokemon}
|
||||||
* - `[3]` the {@linkcode Moves | identifier} for the move being used
|
* - `[3]` the {@linkcode Moves | identifier} for the move being used
|
||||||
* - `[4]` a {@linkcode Utils.BooleanHolder | BooleanHolder} used to flag if a protection effect supercedes effects that ignore protection
|
* - `[4]` a {@linkcode Utils.BooleanHolder | BooleanHolder} used to flag if a protection effect supercedes effects that ignore protection
|
||||||
* @returns
|
* @returns `true` if this tag protected against the attack; `false` otherwise
|
||||||
*/
|
*/
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
override apply(arena: Arena, simulated: boolean, isProtected: Utils.BooleanHolder, attacker: Pokemon, defender: Pokemon,
|
||||||
const [ cancelled, user, target, moveId, ignoresBypass ] = args;
|
moveId: Moves, ignoresProtectBypass: Utils.BooleanHolder): boolean {
|
||||||
|
|
||||||
if (cancelled instanceof Utils.BooleanHolder
|
if ((this.side === ArenaTagSide.PLAYER) === defender.isPlayer()
|
||||||
&& user instanceof Pokemon
|
&& this.protectConditionFunc(arena, moveId)) {
|
||||||
&& target instanceof Pokemon
|
if (!isProtected.value) {
|
||||||
&& typeof moveId === "number"
|
isProtected.value = true;
|
||||||
&& ignoresBypass instanceof Utils.BooleanHolder) {
|
if (!simulated) {
|
||||||
|
attacker.stopMultiHit(defender);
|
||||||
|
|
||||||
if ((this.side === ArenaTagSide.PLAYER) === target.isPlayer()
|
new CommonBattleAnim(CommonAnim.PROTECT, defender).play(arena.scene);
|
||||||
&& this.protectConditionFunc(arena, moveId)) {
|
arena.scene.queueMessage(i18next.t("arenaTag:conditionalProtectApply", { moveName: super.getMoveName(), pokemonNameWithAffix: getPokemonNameWithAffix(defender) }));
|
||||||
if (!cancelled.value) {
|
|
||||||
cancelled.value = true;
|
|
||||||
if (!simulated) {
|
|
||||||
user.stopMultiHit(target);
|
|
||||||
|
|
||||||
new CommonBattleAnim(CommonAnim.PROTECT, target).play(arena.scene);
|
|
||||||
arena.scene.queueMessage(i18next.t("arenaTag:conditionalProtectApply", { moveName: super.getMoveName(), pokemonNameWithAffix: getPokemonNameWithAffix(target) }));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoresBypass.value = ignoresBypass.value || this.ignoresBypass;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignoresProtectBypass.value = ignoresProtectBypass.value || this.ignoresBypass;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -515,17 +506,15 @@ export class WeakenMoveTypeTag extends ArenaTag {
|
|||||||
* Reduces an attack's power by 0.33x if it matches this tag's weakened type.
|
* Reduces an attack's power by 0.33x if it matches this tag's weakened type.
|
||||||
* @param arena n/a
|
* @param arena n/a
|
||||||
* @param simulated n/a
|
* @param simulated n/a
|
||||||
* @param args the arguments for this tag's application:
|
* @param type the attack's {@linkcode Type}
|
||||||
* - `[0]` the attack's {@linkcode Type}
|
* @param power a {@linkcode Utils.NumberHolder | NumberHolder} containing the attack's power
|
||||||
* - `[1]` a {@linkcode Utils.NumberHolder | NumberHolder} containing the attack's power
|
|
||||||
* @returns `true` if the attack's power was reduced; `false` otherwise.
|
* @returns `true` if the attack's power was reduced; `false` otherwise.
|
||||||
*/
|
*/
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
override apply(arena: Arena, simulated: boolean, type: Type, power: Utils.NumberHolder): boolean {
|
||||||
if ((args[0] as Type) === this.weakenedType) {
|
if (type === this.weakenedType) {
|
||||||
(args[1] as Utils.NumberHolder).value *= 0.33;
|
power.value *= 0.33;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -587,13 +576,11 @@ export class IonDelugeTag extends ArenaTag {
|
|||||||
* Converts Normal-type moves to Electric type
|
* Converts Normal-type moves to Electric type
|
||||||
* @param arena n/a
|
* @param arena n/a
|
||||||
* @param simulated n/a
|
* @param simulated n/a
|
||||||
* @param args
|
* @param moveType a {@linkcode Utils.NumberHolder | NumberHolder} containing a move's {@linkcode Type}
|
||||||
* - `[0]` {@linkcode Utils.NumberHolder} A container with a move's {@linkcode Type}
|
|
||||||
* @returns `true` if the given move type changed; `false` otherwise.
|
* @returns `true` if the given move type changed; `false` otherwise.
|
||||||
*/
|
*/
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
override apply(arena: Arena, simulated: boolean, moveType: Utils.NumberHolder): boolean {
|
||||||
const moveType = args[0];
|
if (moveType.value === Type.NORMAL) {
|
||||||
if (moveType instanceof Utils.NumberHolder && moveType.value === Type.NORMAL) {
|
|
||||||
moveType.value = Type.ELECTRIC;
|
moveType.value = Type.ELECTRIC;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -632,8 +619,7 @@ export class ArenaTrapTag extends ArenaTag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
override apply(arena: Arena, simulated: boolean, pokemon: Pokemon): boolean {
|
||||||
const pokemon = args[0] as Pokemon;
|
|
||||||
if (this.sourceId === pokemon.id || (this.side === ArenaTagSide.PLAYER) !== pokemon.isPlayer()) {
|
if (this.sourceId === pokemon.id || (this.side === ArenaTagSide.PLAYER) !== pokemon.isPlayer()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -920,8 +906,15 @@ export class TrickRoomTag extends ArenaTag {
|
|||||||
super(ArenaTagType.TRICK_ROOM, turnCount, Moves.TRICK_ROOM, sourceId);
|
super(ArenaTagType.TRICK_ROOM, turnCount, Moves.TRICK_ROOM, sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
/**
|
||||||
const speedReversed = args[0] as Utils.BooleanHolder;
|
* Reverses Speed-based turn order for all Pokemon on the field
|
||||||
|
* @param arena n/a
|
||||||
|
* @param simulated n/a
|
||||||
|
* @param speedReversed a {@linkcode Utils.BooleanHolder | BooleanHolder} used to flag if Speed-based
|
||||||
|
* turn order should be reversed.
|
||||||
|
* @returns `true` if turn order is successfully reversed; `false` otherwise
|
||||||
|
*/
|
||||||
|
override apply(arena: Arena, simulated: boolean, speedReversed: Utils.BooleanHolder): boolean {
|
||||||
speedReversed.value = !speedReversed.value;
|
speedReversed.value = !speedReversed.value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1152,8 +1145,7 @@ class WaterFirePledgeTag extends ArenaTag {
|
|||||||
arena.scene.queueMessage(i18next.t(`arenaTag:waterFirePledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`));
|
arena.scene.queueMessage(i18next.t(`arenaTag:waterFirePledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply(arena: Arena, simulated: boolean, args: any[]): boolean {
|
override apply(arena: Arena, simulated: boolean, moveChance: Utils.NumberHolder): boolean {
|
||||||
const moveChance = args[0] as Utils.NumberHolder;
|
|
||||||
moveChance.value *= 2;
|
moveChance.value *= 2;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2605,7 +2605,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
|
|
||||||
/** Reduces damage if this Pokemon has a relevant screen (e.g. Light Screen for special attacks) */
|
/** Reduces damage if this Pokemon has a relevant screen (e.g. Light Screen for special attacks) */
|
||||||
const screenMultiplier = new Utils.NumberHolder(1);
|
const screenMultiplier = new Utils.NumberHolder(1);
|
||||||
this.scene.arena.applyTagsForSide(WeakenMoveScreenTag, defendingSide, simulated, move.category, this.scene.currentBattle.double, screenMultiplier);
|
this.scene.arena.applyTagsForSide(WeakenMoveScreenTag, defendingSide, simulated, moveCategory, screenMultiplier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For each {@linkcode HitsTagAttr} the move has, doubles the damage of the move if:
|
* For each {@linkcode HitsTagAttr} the move has, doubles the damage of the move if:
|
||||||
|
Loading…
Reference in New Issue
Block a user