From 62f6ea27cbcc2dff2cb016657af80cfb7c9d328c Mon Sep 17 00:00:00 2001 From: shayebeadlingkl Date: Sat, 11 May 2024 13:56:25 -0400 Subject: [PATCH] working properly to block weather damage --- src/data/weather.ts | 11 +++++++++++ src/modifier/modifier-type.ts | 2 +- src/modifier/modifier.ts | 12 +++++++----- src/phases.ts | 17 ++++++++++++----- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/data/weather.ts b/src/data/weather.ts index 1409920a1..74318f1a7 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -179,6 +179,17 @@ export function getWeatherDamageMessage(weatherType: WeatherType, pokemon: Pokem return null; } +export function getWeatherImmunityMessage(weatherType: WeatherType, pokemon: Pokemon): string { + switch (weatherType) { + case WeatherType.SANDSTORM: + return getPokemonMessage(pokemon, ' is not affected by\nsandstorm due to its Safety Goggles!'); + case WeatherType.HAIL: + return getPokemonMessage(pokemon, ' is not affected by\nhail due to its Safety Goggles!'); + } + + return null; +} + export function getWeatherClearMessage(weatherType: WeatherType): string { switch (weatherType) { case WeatherType.SUNNY: diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 142b37444..00fabf17c 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -923,7 +923,7 @@ export const modifierTypes = { (type, _args) => new Modifiers.PreserveBerryModifier(type)), SAFETY_GOGGLES: () => new ModifierType('Safety Goggles', 'Prevents damage from weather and powder', - (type, _args) => new Modifiers.WeatherChipImmunityModifier(type), "safety_goggles"), + (type, _args) => new Modifiers.WeatherDamageImmunityModifier(type), "safety_goggles"), FOCUS_BAND: () => new PokemonHeldItemModifierType('Focus Band', 'Adds a 10% chance to survive with 1 HP after being damaged enough to faint', (type, args) => new Modifiers.SurviveDamageModifier(type, (args[0] as Pokemon).id)), diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 100f2a528..9059a3621 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -918,17 +918,17 @@ export class PreserveBerryModifier extends PersistentModifier { } } -export class WeatherChipImmunityModifier extends PersistentModifier { +export class WeatherDamageImmunityModifier extends PersistentModifier { constructor(type: ModifierType, stackCount?: integer) { super(type, stackCount); } match(modifier: Modifier) { - return modifier instanceof WeatherChipImmunityModifier; + return modifier instanceof WeatherDamageImmunityModifier; } clone() { - return new WeatherChipImmunityModifier(this.type, this.stackCount); + return new WeatherDamageImmunityModifier(this.type, this.stackCount); } shouldApply(args: any[]): boolean { @@ -936,8 +936,10 @@ export class WeatherChipImmunityModifier extends PersistentModifier { } apply(args: any[]): boolean { - if (!(args[1] as Utils.BooleanHolder).value) - (args[1] as Utils.BooleanHolder).value = (args[0] as Pokemon).randSeedInt(this.getMaxStackCount(null)) < this.getStackCount(); + const pokemon = args[0] as Pokemon; + if (pokemon.isPlayer()) { + (args[1] as Utils.BooleanHolder).value = true; + } return true; } diff --git a/src/phases.ts b/src/phases.ts index d8ce55e95..44d2d6980 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -6,7 +6,7 @@ import { allMoves, applyMoveAttrs, BypassSleepAttr, ChargeAttr, applyFilteredMov import { Mode } from './ui/ui'; import { Command } from "./ui/command-ui-handler"; import { Stat } from "./data/pokemon-stat"; -import { BerryModifier, ContactHeldItemTransferChanceModifier, EnemyAttackStatusEffectChanceModifier, EnemyPersistentModifier, EnemyStatusEffectHealChanceModifier, EnemyTurnHealModifier, ExpBalanceModifier, ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, FlinchChanceModifier, FusePokemonModifier, HealingBoosterModifier, HitHealModifier, LapsingPersistentModifier, MapModifier, Modifier, MultipleParticipantExpBonusModifier, PersistentModifier, PokemonExpBoosterModifier, PokemonHeldItemModifier, PokemonInstantReviveModifier, SwitchEffectTransferModifier, TempBattleStatBoosterModifier, TurnHealModifier, TurnHeldItemTransferModifier, MoneyMultiplierModifier, MoneyInterestModifier, IvScannerModifier, LapsingPokemonHeldItemModifier, PokemonMultiHitModifier, PokemonMoveAccuracyBoosterModifier, overrideModifiers, overrideHeldItems } from "./modifier/modifier"; +import { BerryModifier, ContactHeldItemTransferChanceModifier, EnemyAttackStatusEffectChanceModifier, EnemyPersistentModifier, EnemyStatusEffectHealChanceModifier, EnemyTurnHealModifier, ExpBalanceModifier, ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, FlinchChanceModifier, FusePokemonModifier, HealingBoosterModifier, HitHealModifier, LapsingPersistentModifier, MapModifier, Modifier, MultipleParticipantExpBonusModifier, PersistentModifier, PokemonExpBoosterModifier, PokemonHeldItemModifier, PokemonInstantReviveModifier, SwitchEffectTransferModifier, TempBattleStatBoosterModifier, TurnHealModifier, TurnHeldItemTransferModifier, MoneyMultiplierModifier, MoneyInterestModifier, IvScannerModifier, LapsingPokemonHeldItemModifier, PokemonMultiHitModifier, PokemonMoveAccuracyBoosterModifier, overrideModifiers, overrideHeldItems, WeatherDamageImmunityModifier } from "./modifier/modifier"; import PartyUiHandler, { PartyOption, PartyUiMode } from "./ui/party-ui-handler"; import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor, PokeballType } from "./data/pokeball"; import { CommonAnim, CommonBattleAnim, MoveAnim, initMoveAnim, loadMoveAnimAssets } from "./data/battle-anims"; @@ -26,7 +26,7 @@ import { BattlerTagType } from "./data/enums/battler-tag-type"; import { getPokemonMessage, getPokemonPrefix } from "./messages"; import { Starter } from "./ui/starter-select-ui-handler"; import { Gender } from "./data/gender"; -import { Weather, WeatherType, getRandomWeatherType, getTerrainBlockMessage, getWeatherDamageMessage, getWeatherLapseMessage } from "./data/weather"; +import { Weather, WeatherType, getRandomWeatherType, getTerrainBlockMessage, getWeatherDamageMessage, getWeatherImmunityMessage, getWeatherLapseMessage } from "./data/weather"; import { TempBattleStat } from "./data/temp-battle-stat"; import { ArenaTagSide, ArenaTrapTag, MistTag, TrickRoomTag } from "./data/arena-tag"; import { ArenaTagType } from "./data/enums/arena-tag-type"; @@ -2905,10 +2905,17 @@ export class WeatherEffectPhase extends CommonAnimPhase { if (cancelled.value) return; - const damage = Math.ceil(pokemon.getMaxHp() / 16); + const goggles = new Utils.BooleanHolder(false); + this.scene.applyModifiers(WeatherDamageImmunityModifier, pokemon.isPlayer(), pokemon, goggles); - this.scene.queueMessage(getWeatherDamageMessage(this.weather.weatherType, pokemon)); - pokemon.damageAndUpdate(damage, HitResult.EFFECTIVE, false, false, true); + if (goggles.value) { + this.scene.queueMessage(getWeatherImmunityMessage(this.weather.weatherType, pokemon)); + } else { + const damage = Math.ceil(pokemon.getMaxHp() / 16); + + this.scene.queueMessage(getWeatherDamageMessage(this.weather.weatherType, pokemon)); + pokemon.damageAndUpdate(damage, HitResult.EFFECTIVE, false, false, true); + } }; this.executeForAll((pokemon: Pokemon) => {