Refactor Field Effect Setters, Add Functionality

This commit is contained in:
xsn34kzx 2024-11-04 23:06:35 -05:00
parent 7a0c88e661
commit 756add30bd
11 changed files with 59 additions and 27 deletions

View File

@ -848,7 +848,7 @@ export class PostDefendTerrainChangeAbAttr extends PostDefendAbAttr {
if (simulated) { if (simulated) {
return pokemon.scene.arena.terrain?.terrainType !== (this.terrainType || undefined); return pokemon.scene.arena.terrain?.terrainType !== (this.terrainType || undefined);
} else { } else {
return pokemon.scene.arena.trySetTerrain(this.terrainType, true); return pokemon.scene.arena.trySetTerrain(this.terrainType, pokemon);
} }
} }
@ -1031,7 +1031,7 @@ export class PostDefendWeatherChangeAbAttr extends PostDefendAbAttr {
if (simulated) { if (simulated) {
return pokemon.scene.arena.weather?.weatherType !== this.weatherType; return pokemon.scene.arena.weather?.weatherType !== this.weatherType;
} }
return pokemon.scene.arena.trySetWeather(this.weatherType, true); return pokemon.scene.arena.trySetWeather(this.weatherType, pokemon);
} }
return false; return false;
@ -2294,7 +2294,7 @@ export class PostSummonWeatherChangeAbAttr extends PostSummonAbAttr {
if (simulated) { if (simulated) {
return pokemon.scene.arena.weather?.weatherType !== this.weatherType; return pokemon.scene.arena.weather?.weatherType !== this.weatherType;
} else { } else {
return pokemon.scene.arena.trySetWeather(this.weatherType, true); return pokemon.scene.arena.trySetWeather(this.weatherType, pokemon);
} }
} }
@ -2315,7 +2315,7 @@ export class PostSummonTerrainChangeAbAttr extends PostSummonAbAttr {
if (simulated) { if (simulated) {
return pokemon.scene.arena.terrain?.terrainType !== this.terrainType; return pokemon.scene.arena.terrain?.terrainType !== this.terrainType;
} else { } else {
return pokemon.scene.arena.trySetTerrain(this.terrainType, true); return pokemon.scene.arena.trySetTerrain(this.terrainType, pokemon);
} }
} }
} }
@ -2658,7 +2658,7 @@ export class PreSwitchOutClearWeatherAbAttr extends PreSwitchOutAbAttr {
} }
if (turnOffWeather) { if (turnOffWeather) {
pokemon.scene.arena.trySetWeather(WeatherType.NONE, false); pokemon.scene.arena.trySetWeather(WeatherType.NONE, pokemon);
return true; return true;
} }
@ -3768,7 +3768,7 @@ export class PostBiomeChangeWeatherChangeAbAttr extends PostBiomeChangeAbAttr {
if (simulated) { if (simulated) {
return pokemon.scene.arena.weather?.weatherType !== this.weatherType; return pokemon.scene.arena.weather?.weatherType !== this.weatherType;
} else { } else {
return pokemon.scene.arena.trySetWeather(this.weatherType, true); return pokemon.scene.arena.trySetWeather(this.weatherType, pokemon);
} }
} }
@ -3789,7 +3789,7 @@ export class PostBiomeChangeTerrainChangeAbAttr extends PostBiomeChangeAbAttr {
if (simulated) { if (simulated) {
return pokemon.scene.arena.terrain?.terrainType !== this.terrainType; return pokemon.scene.arena.terrain?.terrainType !== this.terrainType;
} else { } else {
return pokemon.scene.arena.trySetTerrain(this.terrainType, true); return pokemon.scene.arena.trySetTerrain(this.terrainType, pokemon);
} }
} }
} }
@ -4190,7 +4190,7 @@ export class PostFaintClearWeatherAbAttr extends PostFaintAbAttr {
} }
if (turnOffWeather) { if (turnOffWeather) {
pokemon.scene.arena.trySetWeather(WeatherType.NONE, false); pokemon.scene.arena.trySetWeather(WeatherType.NONE);
return true; return true;
} }

View File

@ -2641,7 +2641,7 @@ export class WeatherChangeAttr extends MoveEffectAttr {
} }
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
return user.scene.arena.trySetWeather(this.weatherType, true); return user.scene.arena.trySetWeather(this.weatherType, user);
} }
getCondition(): MoveConditionFunc { getCondition(): MoveConditionFunc {
@ -2660,7 +2660,7 @@ export class ClearWeatherAttr extends MoveEffectAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (user.scene.arena.weather?.weatherType === this.weatherType) { if (user.scene.arena.weather?.weatherType === this.weatherType) {
return user.scene.arena.trySetWeather(WeatherType.NONE, true); return user.scene.arena.trySetWeather(WeatherType.NONE, user);
} }
return false; return false;
@ -2677,7 +2677,7 @@ export class TerrainChangeAttr extends MoveEffectAttr {
} }
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
return user.scene.arena.trySetTerrain(this.terrainType, true, true); return user.scene.arena.trySetTerrain(this.terrainType, user, true);
} }
getCondition(): MoveConditionFunc { getCondition(): MoveConditionFunc {
@ -2696,7 +2696,7 @@ export class ClearTerrainAttr extends MoveEffectAttr {
} }
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
return user.scene.arena.trySetTerrain(TerrainType.NONE, true, true); return user.scene.arena.trySetTerrain(TerrainType.NONE, user, true);
} }
} }
@ -5998,7 +5998,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
export class ChillyReceptionAttr extends ForceSwitchOutAttr { export class ChillyReceptionAttr extends ForceSwitchOutAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
user.scene.arena.trySetWeather(WeatherType.SNOW, true); user.scene.arena.trySetWeather(WeatherType.SNOW, user);
return super.apply(user, target, move, args); return super.apply(user, target, move, args);
} }

View File

@ -115,7 +115,7 @@ export const FieryFalloutEncounter: MysteryEncounter =
// Load animations/sfx for Volcarona moves // Load animations/sfx for Volcarona moves
loadCustomMovesForEncounter(scene, [ Moves.FIRE_SPIN, Moves.QUIVER_DANCE ]); loadCustomMovesForEncounter(scene, [ Moves.FIRE_SPIN, Moves.QUIVER_DANCE ]);
scene.arena.trySetWeather(WeatherType.SUNNY, true); scene.arena.trySetWeather(WeatherType.SUNNY); // TODO: This breaks the duration
encounter.setDialogueToken("volcaronaName", getPokemonSpecies(Species.VOLCARONA).getName()); encounter.setDialogueToken("volcaronaName", getPokemonSpecies(Species.VOLCARONA).getName());

View File

@ -31,6 +31,7 @@ import { Abilities } from "#enums/abilities";
import { SpeciesFormChangeRevertWeatherFormTrigger, SpeciesFormChangeWeatherTrigger } from "#app/data/pokemon-forms"; import { SpeciesFormChangeRevertWeatherFormTrigger, SpeciesFormChangeWeatherTrigger } from "#app/data/pokemon-forms";
import { CommonAnimPhase } from "#app/phases/common-anim-phase"; import { CommonAnimPhase } from "#app/phases/common-anim-phase";
import { ShowAbilityPhase } from "#app/phases/show-ability-phase"; import { ShowAbilityPhase } from "#app/phases/show-ability-phase";
import { FieldEffectModifier } from "#app/modifier/modifier";
export class Arena { export class Arena {
public scene: BattleScene; public scene: BattleScene;
@ -253,7 +254,7 @@ export class Arena {
* @param hasPokemonSource boolean if the new weather is from a pokemon * @param hasPokemonSource boolean if the new weather is from a pokemon
* @returns true if new weather set, false if no weather provided or attempting to set the same weather as currently in use * @returns true if new weather set, false if no weather provided or attempting to set the same weather as currently in use
*/ */
trySetWeather(weather: WeatherType, hasPokemonSource: boolean): boolean { trySetWeather(weather: WeatherType, user?: Pokemon): boolean {
if (Overrides.WEATHER_OVERRIDE) { if (Overrides.WEATHER_OVERRIDE) {
return this.trySetWeatherOverride(Overrides.WEATHER_OVERRIDE); return this.trySetWeatherOverride(Overrides.WEATHER_OVERRIDE);
} }
@ -264,7 +265,14 @@ export class Arena {
const oldWeatherType = this.weather?.weatherType || WeatherType.NONE; const oldWeatherType = this.weather?.weatherType || WeatherType.NONE;
this.weather = weather ? new Weather(weather, hasPokemonSource ? 5 : 0) : null; const weatherDuration = new Utils.NumberHolder(0);
if (!Utils.isNullOrUndefined(user)) {
weatherDuration.value = 5;
this.scene.applyModifier(FieldEffectModifier, user.isPlayer(), user, weatherDuration);
}
this.weather = weather ? new Weather(weather, weatherDuration.value) : null;
this.eventTarget.dispatchEvent(new WeatherChangedEvent(oldWeatherType, this.weather?.weatherType!, this.weather?.turnsLeft!)); // TODO: is this bang correct? this.eventTarget.dispatchEvent(new WeatherChangedEvent(oldWeatherType, this.weather?.weatherType!, this.weather?.turnsLeft!)); // TODO: is this bang correct?
if (this.weather) { if (this.weather) {
@ -312,14 +320,21 @@ export class Arena {
}); });
} }
trySetTerrain(terrain: TerrainType, hasPokemonSource: boolean, ignoreAnim: boolean = false): boolean { trySetTerrain(terrain: TerrainType, user?: Pokemon, ignoreAnim: boolean = false): boolean {
if (this.terrain?.terrainType === (terrain || undefined)) { if (this.terrain?.terrainType === (terrain || undefined)) {
return false; return false;
} }
const oldTerrainType = this.terrain?.terrainType || TerrainType.NONE; const oldTerrainType = this.terrain?.terrainType || TerrainType.NONE;
this.terrain = terrain ? new Terrain(terrain, hasPokemonSource ? 5 : 0) : null; const terrainDuration = new Utils.NumberHolder(0);
if (!Utils.isNullOrUndefined(user)) {
terrainDuration.value = 5;
this.scene.applyModifier(FieldEffectModifier, user.isPlayer(), user, terrainDuration);
}
this.terrain = terrain ? new Terrain(terrain, terrainDuration.value) : null;
this.eventTarget.dispatchEvent(new TerrainChangedEvent(oldTerrainType, this.terrain?.terrainType!, this.terrain?.turnsLeft!)); // TODO: are those bangs correct? this.eventTarget.dispatchEvent(new TerrainChangedEvent(oldTerrainType, this.terrain?.terrainType!, this.terrain?.turnsLeft!)); // TODO: are those bangs correct?
if (this.terrain) { if (this.terrain) {
@ -683,9 +698,9 @@ export class Arena {
resetArenaEffects(): void { resetArenaEffects(): void {
// Don't reset weather if a Biome's permanent weather is active // Don't reset weather if a Biome's permanent weather is active
if (this.weather?.turnsLeft !== 0) { if (this.weather?.turnsLeft !== 0) {
this.trySetWeather(WeatherType.NONE, false); this.trySetWeather(WeatherType.NONE);
} }
this.trySetTerrain(TerrainType.NONE, false, true); this.trySetTerrain(TerrainType.NONE, undefined, true);
this.removeAllTags(); this.removeAllTags();
} }

View File

@ -11,7 +11,7 @@ import { Type } from "#app/data/type";
import Pokemon, { EnemyPokemon, PlayerPokemon, PokemonMove } from "#app/field/pokemon"; import Pokemon, { EnemyPokemon, PlayerPokemon, PokemonMove } from "#app/field/pokemon";
import { getPokemonNameWithAffix } from "#app/messages"; import { getPokemonNameWithAffix } from "#app/messages";
import { import {
AddPokeballModifier, AddVoucherModifier, AttackTypeBoosterModifier, BaseStatModifier, BerryModifier, BoostBugSpawnModifier, BypassSpeedChanceModifier, ContactHeldItemTransferChanceModifier, CritBoosterModifier, DamageMoneyRewardModifier, DoubleBattleChanceBoosterModifier, EnemyAttackStatusEffectChanceModifier, EnemyDamageBoosterModifier, EnemyDamageReducerModifier, EnemyEndureChanceModifier, EnemyFusionChanceModifier, EnemyStatusEffectHealChanceModifier, EnemyTurnHealModifier, EvolutionItemModifier, EvolutionStatBoosterModifier, EvoTrackerModifier, ExpBalanceModifier, ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, FlinchChanceModifier, FusePokemonModifier, GigantamaxAccessModifier, HealingBoosterModifier, HealShopCostModifier, HiddenAbilityRateBoosterModifier, HitHealModifier, IvScannerModifier, LevelIncrementBoosterModifier, LockModifierTiersModifier, MapModifier, MegaEvolutionAccessModifier, MoneyInterestModifier, MoneyMultiplierModifier, MoneyRewardModifier, MultipleParticipantExpBonusModifier, PokemonAllMovePpRestoreModifier, PokemonBaseStatFlatModifier, PokemonBaseStatTotalModifier, PokemonExpBoosterModifier, PokemonFormChangeItemModifier, PokemonFriendshipBoosterModifier, PokemonHeldItemModifier, PokemonHpRestoreModifier, PokemonIncrementingStatModifier, PokemonInstantReviveModifier, PokemonLevelIncrementModifier, PokemonMoveAccuracyBoosterModifier, PokemonMultiHitModifier, PokemonNatureChangeModifier, PokemonNatureWeightModifier, PokemonPpRestoreModifier, PokemonPpUpModifier, PokemonStatusHealModifier, PreserveBerryModifier, RememberMoveModifier, ResetNegativeStatStageModifier, ShinyRateBoosterModifier, SpeciesCritBoosterModifier, SpeciesStatBoosterModifier, SurviveDamageModifier, SwitchEffectTransferModifier, TempCritBoosterModifier, TempStatStageBoosterModifier, TerastallizeAccessModifier, TerastallizeModifier, TmModifier, TurnHealModifier, TurnHeldItemTransferModifier, TurnStatusEffectModifier, type EnemyPersistentModifier, type Modifier, type PersistentModifier, TempExtraModifierModifier AddPokeballModifier, AddVoucherModifier, AttackTypeBoosterModifier, BaseStatModifier, BerryModifier, BoostBugSpawnModifier, BypassSpeedChanceModifier, ContactHeldItemTransferChanceModifier, CritBoosterModifier, DamageMoneyRewardModifier, DoubleBattleChanceBoosterModifier, EnemyAttackStatusEffectChanceModifier, EnemyDamageBoosterModifier, EnemyDamageReducerModifier, EnemyEndureChanceModifier, EnemyFusionChanceModifier, EnemyStatusEffectHealChanceModifier, EnemyTurnHealModifier, EvolutionItemModifier, EvolutionStatBoosterModifier, EvoTrackerModifier, ExpBalanceModifier, ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, FlinchChanceModifier, FusePokemonModifier, GigantamaxAccessModifier, HealingBoosterModifier, HealShopCostModifier, HiddenAbilityRateBoosterModifier, HitHealModifier, IvScannerModifier, LevelIncrementBoosterModifier, LockModifierTiersModifier, MapModifier, MegaEvolutionAccessModifier, MoneyInterestModifier, MoneyMultiplierModifier, MoneyRewardModifier, MultipleParticipantExpBonusModifier, PokemonAllMovePpRestoreModifier, PokemonBaseStatFlatModifier, PokemonBaseStatTotalModifier, PokemonExpBoosterModifier, PokemonFormChangeItemModifier, PokemonFriendshipBoosterModifier, PokemonHeldItemModifier, PokemonHpRestoreModifier, PokemonIncrementingStatModifier, PokemonInstantReviveModifier, PokemonLevelIncrementModifier, PokemonMoveAccuracyBoosterModifier, PokemonMultiHitModifier, PokemonNatureChangeModifier, PokemonNatureWeightModifier, PokemonPpRestoreModifier, PokemonPpUpModifier, PokemonStatusHealModifier, PreserveBerryModifier, RememberMoveModifier, ResetNegativeStatStageModifier, ShinyRateBoosterModifier, SpeciesCritBoosterModifier, SpeciesStatBoosterModifier, SurviveDamageModifier, SwitchEffectTransferModifier, TempCritBoosterModifier, TempStatStageBoosterModifier, TerastallizeAccessModifier, TerastallizeModifier, TmModifier, TurnHealModifier, TurnHeldItemTransferModifier, TurnStatusEffectModifier, type EnemyPersistentModifier, type Modifier, type PersistentModifier, TempExtraModifierModifier, FieldEffectModifier
} from "#app/modifier/modifier"; } from "#app/modifier/modifier";
import { ModifierTier } from "#app/modifier/modifier-tier"; import { ModifierTier } from "#app/modifier/modifier-tier";
import Overrides from "#app/overrides"; import Overrides from "#app/overrides";
@ -1490,6 +1490,8 @@ export const modifierTypes = {
return new BerryModifierType(randBerryType); return new BerryModifierType(randBerryType);
}), }),
DOMAIN_EXPANDER: () => new ModifierType("modifierType:ModifierType.DOMAIN_EXPANDER", "domain_expander", (type, args) => new FieldEffectModifier(type, (args[0] as Pokemon).id)),
TM_COMMON: () => new TmModifierTypeGenerator(ModifierTier.COMMON), TM_COMMON: () => new TmModifierTypeGenerator(ModifierTier.COMMON),
TM_GREAT: () => new TmModifierTypeGenerator(ModifierTier.GREAT), TM_GREAT: () => new TmModifierTypeGenerator(ModifierTier.GREAT),
TM_ULTRA: () => new TmModifierTypeGenerator(ModifierTier.ULTRA), TM_ULTRA: () => new TmModifierTypeGenerator(ModifierTier.ULTRA),

View File

@ -1995,6 +1995,21 @@ export class ResetNegativeStatStageModifier extends PokemonHeldItemModifier {
} }
} }
export abstract class FieldEffectModifier extends PokemonHeldItemModifier {
constructor(type: ModifierType, pokemonId: number, stackCount?: number) {
super(type, pokemonId, stackCount);
}
override apply(_pokemon: Pokemon, fieldDuration: NumberHolder): boolean {
fieldDuration.value += 2 * this.stackCount;
return true;
}
override getMaxHeldItemCount(_pokemon?: Pokemon): number {
return 2;
}
}
export abstract class ConsumablePokemonModifier extends ConsumableModifier { export abstract class ConsumablePokemonModifier extends ConsumableModifier {
public pokemonId: number; public pokemonId: number;

View File

@ -541,7 +541,7 @@ export class EncounterPhase extends BattlePhase {
*/ */
trySetWeatherIfNewBiome(): void { trySetWeatherIfNewBiome(): void {
if (!this.loaded) { if (!this.loaded) {
this.scene.arena.trySetWeather(getRandomWeatherType(this.scene.arena), false); this.scene.arena.trySetWeather(getRandomWeatherType(this.scene.arena));
} }
} }
} }

View File

@ -44,6 +44,6 @@ export class NewBiomeEncounterPhase extends NextEncounterPhase {
* Set biome weather. * Set biome weather.
*/ */
trySetWeatherIfNewBiome(): void { trySetWeatherIfNewBiome(): void {
this.scene.arena.trySetWeather(getRandomWeatherType(this.scene.arena), false); this.scene.arena.trySetWeather(getRandomWeatherType(this.scene.arena));
} }
} }

View File

@ -52,12 +52,12 @@ export class TurnEndPhase extends FieldPhase {
this.scene.arena.lapseTags(); this.scene.arena.lapseTags();
if (this.scene.arena.weather && !this.scene.arena.weather.lapse()) { if (this.scene.arena.weather && !this.scene.arena.weather.lapse()) {
this.scene.arena.trySetWeather(WeatherType.NONE, false); this.scene.arena.trySetWeather(WeatherType.NONE);
this.scene.arena.triggerWeatherBasedFormChangesToNormal(); this.scene.arena.triggerWeatherBasedFormChangesToNormal();
} }
if (this.scene.arena.terrain && !this.scene.arena.terrain.lapse()) { if (this.scene.arena.terrain && !this.scene.arena.terrain.lapse()) {
this.scene.arena.trySetTerrain(TerrainType.NONE, false); this.scene.arena.trySetTerrain(TerrainType.NONE);
} }
this.end(); this.end();

View File

@ -172,7 +172,7 @@ describe("Abilities - Forecast", () => {
expect(castform.formIndex).toBe(SNOWY_FORM); expect(castform.formIndex).toBe(SNOWY_FORM);
game.scene.arena.trySetWeather(WeatherType.FOG, false); game.scene.arena.trySetWeather(WeatherType.FOG);
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);
game.move.select(Moves.SPLASH, 1); game.move.select(Moves.SPLASH, 1);
await game.phaseInterceptor.to("TurnStartPhase"); await game.phaseInterceptor.to("TurnStartPhase");

View File

@ -124,7 +124,7 @@ describe("Moves - Dive", () => {
await game.phaseInterceptor.to("TurnEndPhase"); await game.phaseInterceptor.to("TurnEndPhase");
await game.phaseInterceptor.to("TurnStartPhase", false); await game.phaseInterceptor.to("TurnStartPhase", false);
game.scene.arena.trySetWeather(WeatherType.HARSH_SUN, false); game.scene.arena.trySetWeather(WeatherType.HARSH_SUN);
await game.phaseInterceptor.to("MoveEndPhase"); await game.phaseInterceptor.to("MoveEndPhase");
expect(playerPokemon.getLastXMoves(1)[0].result).toBe(MoveResult.FAIL); expect(playerPokemon.getLastXMoves(1)[0].result).toBe(MoveResult.FAIL);