From 5e71f4b26a9e7cc596b6b6a8f5dd5073b63faf1e Mon Sep 17 00:00:00 2001 From: PrabbyDD Date: Mon, 18 Nov 2024 16:31:15 -0800 Subject: [PATCH] adding changes for sticky web and other features of mirror armor --- src/battle.ts | 3 +++ src/data/ability.ts | 4 +-- src/data/arena-tag.ts | 2 +- src/overrides.ts | 2 +- src/phases/move-effect-phase.ts | 8 ++++++ src/phases/stat-stage-change-phase.ts | 36 ++++++++++++++++--------- src/test/abilities/mirror_armor.test.ts | 3 +-- 7 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/battle.ts b/src/battle.ts index f9533d41984..d5a71479d6f 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -84,6 +84,9 @@ export default class Battle { /** Primarily for double battles, keeps track of last enemy and player pokemon that triggered its ability or used a move */ public lastEnemyInvolved: number; public lastPlayerInvolved: number; + /* Specifically for mirror armor, keeps track of last enemy/player pokemon to sucessfully use sticky web */ + public lastEnemyIDUsingStickyWeb: integer; + public lastPlayerIDUsingStickyWeb: integer; public lastUsedPokeball: PokeballType | null = null; /** The number of times a Pokemon on the player's side has fainted this battle */ public playerFaints: number = 0; diff --git a/src/data/ability.ts b/src/data/ability.ts index af606053741..7da2822493e 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -2705,8 +2705,8 @@ export class PreStatStageChangeAbAttr extends AbAttr { } /** - * Reflect one or all {@linkcode BattleStat} reductions caused by other Pokémon's moves and Abilities. - * Currently only applies to Mirror Armor + * Reflect all {@linkcode BattleStat} reductions caused by other Pokémon's moves and Abilities. + * Currently only applies to Mirror Armor. */ // TODO: CODE INTERACTION WITH MAGIC BOUNCE AS WELL // TODO: CODE INTERACTION WITH STICKY WEB diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index 43de6e02dcb..d8b57aa9a70 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -910,7 +910,7 @@ class StickyWebTag extends ArenaTrapTag { if (!cancelled.value) { pokemon.scene.queueMessage(i18next.t("arenaTag:stickyWebActivateTrap", { pokemonName: pokemon.getNameToRender() })); const stages = new NumberHolder(-1); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, [ Stat.SPD ], stages.value)); + pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, [ Stat.SPD ], stages.value, true, false, true, null, false, true)); return true; } } diff --git a/src/overrides.ts b/src/overrides.ts index ba2cc0eb0ba..6760db79205 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -131,7 +131,7 @@ class DefaultOverrides { */ readonly OPP_FUSION_SPECIES_OVERRIDE: Species | integer = 0; readonly OPP_LEVEL_OVERRIDE: number = 0; - readonly OPP_ABILITY_OVERRIDE: Abilities = Abilities.z; + readonly OPP_ABILITY_OVERRIDE: Abilities = Abilities.NONE; readonly OPP_PASSIVE_ABILITY_OVERRIDE: Abilities = Abilities.NONE; readonly OPP_STATUS_OVERRIDE: StatusEffect = StatusEffect.NONE; readonly OPP_GENDER_OVERRIDE: Gender | null = null; diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index 320ff93f96f..3038e4a5df7 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -15,6 +15,7 @@ import i18next from "i18next"; import * as Utils from "#app/utils"; import { PokemonPhase } from "./pokemon-phase"; import { Type } from "#app/data/type"; +import { ArenaTagType } from "#app/enums/arena-tag-type"; export class MoveEffectPhase extends PokemonPhase { public move: PokemonMove; @@ -45,8 +46,15 @@ export class MoveEffectPhase extends PokemonPhase { /** If an enemy used this move, set this as last enemy that used move or ability */ if (!user?.isPlayer()) { + /** If the move used was sticky web AND it was successful, save the id of pokemon that used it */ + if (this.move.moveId === 564 && user !== undefined && !this.scene.arena.hasTag(ArenaTagType.STICKY_WEB)) { + this.scene.currentBattle.lastEnemyIDUsingStickyWeb = user.id; + } this.scene.currentBattle.lastEnemyInvolved = this.fieldIndex; } else { + if (this.move.moveId === 564 && user !== undefined && !this.scene.arena.hasTag(ArenaTagType.STICKY_WEB)) { + this.scene.currentBattle.lastPlayerIDUsingStickyWeb = user.id; + } this.scene.currentBattle.lastPlayerInvolved = this.fieldIndex; } diff --git a/src/phases/stat-stage-change-phase.ts b/src/phases/stat-stage-change-phase.ts index 33396cada59..877ee777073 100644 --- a/src/phases/stat-stage-change-phase.ts +++ b/src/phases/stat-stage-change-phase.ts @@ -23,9 +23,10 @@ export class StatStageChangePhase extends PokemonPhase { private canBeCopied: boolean; private onChange: StatStageChangeCallback | null; private comingFromMirrorArmorUser: boolean; + private comingFromStickyWeb: boolean; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, selfTarget: boolean, stats: BattleStat[], stages: integer, showMessage: boolean = true, ignoreAbilities: boolean = false, canBeCopied: boolean = true, onChange: StatStageChangeCallback | null = null, comingFromMirrorArmorUser: boolean = false) { + constructor(scene: BattleScene, battlerIndex: BattlerIndex, selfTarget: boolean, stats: BattleStat[], stages: integer, showMessage: boolean = true, ignoreAbilities: boolean = false, canBeCopied: boolean = true, onChange: StatStageChangeCallback | null = null, comingFromMirrorArmorUser: boolean = false, comingFromStickyWeb: boolean = false) { super(scene, battlerIndex); this.selfTarget = selfTarget; @@ -36,6 +37,7 @@ export class StatStageChangePhase extends PokemonPhase { this.canBeCopied = canBeCopied; this.onChange = onChange; this.comingFromMirrorArmorUser = comingFromMirrorArmorUser; + this.comingFromStickyWeb = comingFromStickyWeb; } start() { @@ -52,18 +54,29 @@ export class StatStageChangePhase extends PokemonPhase { const pokemon = this.getPokemon(); let opponentPokemon: Pokemon | undefined; - /** StickY web should be like - * if (stat loss due to switching in on sticky web) - * if (have mirror armor) - * if (enemy that used sticky web is in) - * apply -1 spd to that enemy - */ - - // Gets the position of last enemy or player pokemon that used ability or move, primarily for double battles involving Mirror Armor + /** Gets the position of last enemy or player pokemon that used ability or move, primarily for double battles involving Mirror Armor */ if (pokemon.isPlayer()) { - opponentPokemon = this.scene.getEnemyField()[this.scene.currentBattle.lastEnemyInvolved]; + /** If this SSCP is not from sticky web, then we find the opponent pokemon that last did something */ + if (!this.comingFromStickyWeb) { + opponentPokemon = this.scene.getEnemyField()[this.scene.currentBattle.lastEnemyInvolved]; + } else { + /** If this SSCP is from sticky web, then check if pokemon that last sucessfully used sticky web is on field */ + this.scene.getEnemyField().forEach((e) => { + if (e.id === this.scene.currentBattle.lastEnemyIDUsingStickyWeb) { + opponentPokemon = e; + } + }); + } } else { - opponentPokemon = this.scene.getPlayerField()[this.scene.currentBattle.lastPlayerInvolved]; + if (!this.comingFromStickyWeb) { + opponentPokemon = this.scene.getPlayerField()[this.scene.currentBattle.lastPlayerInvolved]; + } else { + this.scene.getPlayerField().forEach((p) => { + if (p.id === this.scene.currentBattle.lastPlayerIDUsingStickyWeb) { + opponentPokemon = p; + } + }); + } } if (!pokemon.isActive(true)) { @@ -90,7 +103,6 @@ export class StatStageChangePhase extends PokemonPhase { applyPreStatStageChangeAbAttrs(ProtectStatAbAttr, pokemon, stat, cancelled, simulate); // TODO: CODE INTERACTION WITH MAGIC BOUNCE AS WELL - // TODO: CODE INTERACTION WITH STICKY WEB /** Potential stat reflection due to Mirror Armor, does not apply to Octolock end of turn effect */ if (opponentPokemon !== undefined && !pokemon.findTag(t => t instanceof OctolockTag) && !this.comingFromMirrorArmorUser) { applyPreStatStageChangeAbAttrs(ReflectStatStageChangeAbAttr, pokemon, stat, cancelled, simulate, opponentPokemon, this.stages); diff --git a/src/test/abilities/mirror_armor.test.ts b/src/test/abilities/mirror_armor.test.ts index bb715d80e8e..336a6fc42cd 100644 --- a/src/test/abilities/mirror_armor.test.ts +++ b/src/test/abilities/mirror_armor.test.ts @@ -266,8 +266,7 @@ describe("Ability - Mirror Armor", () => { // expect(enemyPokemon.findTag(t => t instanceof TrappedTag)).toBeDefined(); // }); -//TODO: Implement test for sticky web -// TODO: IMPLEMENT TEST FOR MEMENTO +// TODO: Implement test for sticky web // TODO: IMPLEMENT TEST FOR LOOPING MIRROR ARMORS BETWEEN OPPONENT AND PLAYER // TODO: IMPLEMENT MAGIC GUARD INTERACITON TEST });