From 4ac7f7005acd42a194dbefd375104e174f691639 Mon Sep 17 00:00:00 2001 From: new name Date: Mon, 2 Sep 2024 02:13:47 -0400 Subject: [PATCH] electric terrain --- src/data/battler-tags.ts | 8 ++++++-- src/data/move.ts | 8 +------- src/field/pokemon.ts | 30 +++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index 92df6fc294f..6aa82e3a7dd 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -7,7 +7,7 @@ import * as Utils from "../utils"; import { ChargeAttr, MoveFlags, allMoves } from "./move"; import { Type } from "./type"; import { BlockNonDirectDamageAbAttr, FlinchEffectAbAttr, ReverseDrainAbAttr, applyAbAttrs } from "./ability"; -import { TerrainType } from "./terrain"; +import { getTerrainName, TerrainType } from "./terrain"; import { WeatherType } from "./weather"; import { BattleStat } from "./battle-stat"; import { allAbilities } from "./ability"; @@ -839,7 +839,11 @@ export class DrowsyTag extends BattlerTag { } canAdd(pokemon: Pokemon): boolean { - return pokemon.scene.arena.terrain?.terrainType !== TerrainType.ELECTRIC || !pokemon.isGrounded(); + const isElectricTerrainProtected = (pokemon.scene.arena.terrain?.terrainType === TerrainType.ELECTRIC && pokemon.isGrounded()); + if (isElectricTerrainProtected) { + pokemon.scene.queueMessage(i18next.t("terrain:defaultBlockMessage", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), terrainName: getTerrainName(TerrainType.ELECTRIC) })); + } + return !isElectricTerrainProtected; } onAdd(pokemon: Pokemon): void { diff --git a/src/data/move.ts b/src/data/move.ts index 1dc715f264a..5bfba140386 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1954,14 +1954,8 @@ export class StatusEffectAttr extends MoveEffectAttr { } } - if (user !== target && target.scene.arena.getTagOnSide(ArenaTagType.SAFEGUARD, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY)) { - if (move.category === MoveCategory.STATUS) { - user.scene.queueMessage(i18next.t("moveTriggers:safeguard", { targetName: getPokemonNameWithAffix(target)})); - } - return false; - } if ((!pokemon.status || (pokemon.status.effect === this.effect && moveChance < 0)) - && pokemon.trySetStatus(this.effect, true, user, this.cureTurn)) { + && pokemon.checkIfCanSetStatus(this.effect, false, false, user) && pokemon.trySetStatus(this.effect, true, user, this.cureTurn, null)) { applyPostAttackAbAttrs(ConfusionOnStatusEffectAbAttr, user, target, move, null, false, this.effect); return true; } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 8594d5b769b..d4413a22de0 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -34,7 +34,7 @@ import { DexAttr, StarterDataEntry, StarterMoveset } from "../system/game-data"; import { QuantizerCelebi, argbFromRgba, rgbaFromArgb } from "@material/material-color-utilities"; import { Nature, getNatureStatMultiplier } from "../data/nature"; import { SpeciesFormChange, SpeciesFormChangeActiveTrigger, SpeciesFormChangeMoveLearnedTrigger, SpeciesFormChangePostMoveTrigger, SpeciesFormChangeStatusEffectTrigger } from "../data/pokemon-forms"; -import { TerrainType } from "../data/terrain"; +import { getTerrainName, TerrainType } from "../data/terrain"; import { TrainerSlot } from "../data/trainer-config"; import Overrides from "#app/overrides"; import i18next from "i18next"; @@ -2775,7 +2775,15 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.gender !== Gender.GENDERLESS && pokemon.gender === (this.gender === Gender.MALE ? Gender.FEMALE : Gender.MALE); } - canSetStatus(effect: StatusEffect | undefined, quiet: boolean = false, overrideStatus: boolean = false, sourcePokemon: Pokemon | null = null): boolean { + /** + * Checks if it is possible for a pokemon to be afflicted with the given status + * @param effect {@linkcode StatusEffect} the status effect being checked. + * @param quiet a boolean value that is sometimes used as the asPhase boolean which causes unshifting the phase. + * @param overrideStatus a boolean value to determine whether a status should be overriden. If true, the pokemon cannot be statused essentially + * @param sourcePokemon {@linkcode Pokemon} The pokemon causing the status. The target pokemon is 'this'. + * @returns true if the pokemon can be affected by the status, false if not. + */ + checkIfCanSetStatus(effect: StatusEffect | undefined, quiet: boolean = false, overrideStatus: boolean = false, sourcePokemon: Pokemon | null = null): boolean { if (effect !== StatusEffect.FAINT) { if (overrideStatus ? this.status?.effect === effect : this.status) { return false; @@ -2827,6 +2835,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { break; case StatusEffect.SLEEP: if (this.isGrounded() && this.scene.arena.terrain?.terrainType === TerrainType.ELECTRIC) { + if (!quiet) { + this.scene.queueMessage(i18next.t("terrain:defaultBlockMessage", { pokemonNameWithAffix: getPokemonNameWithAffix(this), terrainName: getTerrainName(TerrainType.ELECTRIC) })); + } return false; } break; @@ -2841,6 +2852,19 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } break; } + return true; + } + + /** + * Checks if it is possible for a pokemon to be afflicted with the given status + * @param effect {@linkcode StatusEffect} the status effect being checked. + * @param quiet a boolean value that is sometimes used as the asPhase boolean which in this case affects that. + * @param overrideStatus a boolean value to determine whether a status should be overriden. If true, the pokemon cannot be statused essentially + * @param sourcePokemon {@linkcode Pokemon} The pokemon causing the status. The target pokemon is 'this'. + * @returns true if the pokemon can be affected by the status, false if not. + */ + canSetStatus(effect: StatusEffect | undefined, quiet: boolean = false, overrideStatus: boolean = false, sourcePokemon: Pokemon | null = null): boolean { + const canSetStatus = this.checkIfCanSetStatus(effect, quiet, overrideStatus, sourcePokemon); const cancelled = new Utils.BooleanHolder(false); applyPreSetStatusAbAttrs(StatusEffectImmunityAbAttr, this, effect, cancelled, quiet); @@ -2852,7 +2876,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return false; } - return true; + return canSetStatus; } trySetStatus(effect: StatusEffect | undefined, asPhase: boolean = false, sourcePokemon: Pokemon | null = null, cureTurn: integer | null = 0, sourceText: string | null = null): boolean {