From 86877dc3139a37198c2ef2d366344557ff10ad0c Mon Sep 17 00:00:00 2001 From: Jakub Hanko <60473007+JakubHanko@users.noreply.github.com> Date: Mon, 13 May 2024 16:04:25 +0200 Subject: [PATCH] Code cleanup --- src/data/battler-tags.ts | 16 +++++++++++----- src/data/enums/battler-tag-type.ts | 3 ++- src/data/move.ts | 20 +++++++++++++------- src/field/pokemon.ts | 12 +++++------- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index 1314b644a..7b6fb5b5b 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -1104,8 +1104,8 @@ export class ExposedTag extends BattlerTag { public immuneType: Type; public allowedTypes: Type[]; - constructor(tagType: BattlerTagType, sourceMove: Moves, type: Type, allowedTypes: Type[], length: number) { - super(tagType, BattlerTagLapseType.TURN_END, length, sourceMove); + constructor(tagType: BattlerTagType, sourceMove: Moves, type: Type, allowedTypes: Type[]) { + super(tagType, BattlerTagLapseType.TURN_END, 1, sourceMove); this.immuneType = type; this.allowedTypes = allowedTypes; } @@ -1119,8 +1119,14 @@ export class ExposedTag extends BattlerTag { this.immuneType = source.type as Type; this.allowedTypes = source.allowedTypes as Type[]; } + lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { - return true; + return lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); + } + + ignoreImmunity(pokemon: Pokemon, moveType: Type): boolean { + return pokemon.getTypes(true, true).includes(this.immuneType) + && this.allowedTypes.includes(moveType); } } @@ -1383,9 +1389,9 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: integer, sourc case BattlerTagType.MAGNET_RISEN: return new MagnetRisenTag(tagType, sourceMove); case BattlerTagType.ODOR_SLEUTH: - return new ExposedTag(tagType, sourceMove, Type.GHOST, [ Type.NORMAL, Type.FIGHTING ], turnCount); + return new ExposedTag(tagType, sourceMove, Type.GHOST, [ Type.NORMAL, Type.FIGHTING ]); case BattlerTagType.MIRACLE_EYE: - return new ExposedTag(tagType, sourceMove, Type.DARK, [ Type.PSYCHIC ], turnCount); + return new ExposedTag(tagType, sourceMove, Type.DARK, [ Type.PSYCHIC ]); case BattlerTagType.NONE: default: return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId); diff --git a/src/data/enums/battler-tag-type.ts b/src/data/enums/battler-tag-type.ts index e06e4283e..dcf7cb228 100644 --- a/src/data/enums/battler-tag-type.ts +++ b/src/data/enums/battler-tag-type.ts @@ -56,5 +56,6 @@ export enum BattlerTagType { CHARGED = "CHARGED", GROUNDED = "GROUNDED", MAGNET_RISEN = "MAGNET_RISEN", - ODOR_SLEUTH = "ODOR_SLEUTH" + ODOR_SLEUTH = "ODOR_SLEUTH", + MIRACLE_EYE = "MIRACLE_EYE" } diff --git a/src/data/move.ts b/src/data/move.ts index 2e8bb4ec4..cecbe99ae 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -2,7 +2,7 @@ import { Moves } from "./enums/moves"; import { ChargeAnim, MoveChargeAnim, initMoveAnim, loadMoveAnimAssets } from "./battle-anims"; import { BattleEndPhase, MovePhase, NewBattlePhase, PartyStatusCurePhase, PokemonHealPhase, StatChangePhase, SwitchSummonPhase } from "../phases"; import { BattleStat, getBattleStatName } from "./battle-stat"; -import { EncoreTag, ExposedTag } from "./battler-tags"; +import { BattlerTag, EncoreTag, ExposedTag } from "./battler-tags"; import { BattlerTagType } from "./enums/battler-tag-type"; import { getPokemonMessage } from "../messages"; import Pokemon, { AttackMoveResult, EnemyPokemon, HitResult, MoveResult, PlayerPokemon, PokemonMove, TurnMove } from "../field/pokemon"; @@ -1776,12 +1776,21 @@ export class ResetStatsAttr extends MoveEffectAttr { } export class ExposedAttr extends MoveEffectAttr { + private tagType: BattlerTagType; + + constructor(tagType: BattlerTagType) { + super(); + + this.tagType = tagType; + } + apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!super.apply(user, target, move, args)) return false; target.summonData.battleStats[BattleStat.EVA] = 0; target.updateInfo(); + target.addTag(this.tagType, 20, move.id, user.id); target.scene.queueMessage(`${getPokemonMessage(user, " identified\n")}${getPokemonMessage(target, "!")}`); @@ -4671,8 +4680,7 @@ export function initMoves() { .attr(StatusEffectAttr, StatusEffect.PARALYSIS) .ballBombMove(), new StatusMove(Moves.FORESIGHT, Type.NORMAL, -1, 40, -1, 0, 2) - .attr(ExposedAttr) - .attr(AddBattlerTagAttr, BattlerTagType.ODOR_SLEUTH, false, false, 20), + .attr(ExposedAttr, BattlerTagType.ODOR_SLEUTH), new SelfStatusMove(Moves.DESTINY_BOND, Type.GHOST, -1, 5, -1, 0, 2) .ignoresProtect() .condition(failOnBossCondition) @@ -5022,8 +5030,7 @@ export function initMoves() { .attr(StatChangeAttr, BattleStat.SPATK, -2, true) .attr(HealStatusEffectAttr, true, StatusEffect.FREEZE), new StatusMove(Moves.ODOR_SLEUTH, Type.NORMAL, -1, 40, -1, 0, 3) - .attr(ExposedAttr) - .attr(AddBattlerTagAttr, BattlerTagType.ODOR_SLEUTH, false, false, 20), + .attr(ExposedAttr, BattlerTagType.ODOR_SLEUTH), new AttackMove(Moves.ROCK_TOMB, Type.ROCK, MoveCategory.PHYSICAL, 60, 95, 15, 100, 0, 3) .attr(StatChangeAttr, BattleStat.SPD, -1) .makesContact(false), @@ -5131,8 +5138,7 @@ export function initMoves() { .attr(AddArenaTagAttr, ArenaTagType.GRAVITY, 5) .target(MoveTarget.BOTH_SIDES), new StatusMove(Moves.MIRACLE_EYE, Type.PSYCHIC, -1, 40, -1, 0, 4) - .attr(ExposedAttr) - .attr(AddBattlerTagAttr, BattlerTagType.MIRACLE_EYE, false, false, 20), + .attr(ExposedAttr, BattlerTagType.MIRACLE_EYE), new AttackMove(Moves.WAKE_UP_SLAP, Type.FIGHTING, MoveCategory.PHYSICAL, 70, 100, 10, -1, 0, 4) .attr(MovePowerMultiplierAttr, (user, target, move) => target.status?.effect === StatusEffect.SLEEP ? 2 : 1) .attr(HealStatusEffectAttr, false, StatusEffect.SLEEP), diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 9ffeb12fe..3520d7e35 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -965,6 +965,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { applyAbAttrs(IgnoreTypeImmunityAbAttr, source, ignoreImmunity, moveType, defType); if (ignoreImmunity.value) return 1; + + const exposedTags = this.getTags(ExposedTag) as ExposedTag[]; + if (exposedTags.some(t => t.ignoreImmunity(this, moveType))) { + return 1; + } } return getTypeDamageMultiplier(moveType, defType); @@ -1445,13 +1450,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (types.find(t => move.isTypeImmune(t))) typeMultiplier.value = 0; - if ((this.getTags(ExposedTag) as ExposedTag[]).some(t => { - return t.allowedTypes.includes(move.type) - && this.getTypes(true, true).includes(t.immuneType); - })) { - typeMultiplier.value = 1; - } - switch (moveCategory) { case MoveCategory.PHYSICAL: case MoveCategory.SPECIAL: