[Move] Fully Implement Secret Power (#4647)

* initial work

* move go

* biomes for damo

* more cleanup

* added effect for space

* test

* balance change 1

* i'm silly

* fixed effect cahnce

* secret power atr

* Apply suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* got tests to work + added final balance biomes

* added documentation

* Apply suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Update src/data/move.ts

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

---------

Co-authored-by: frutescens <info@laptop>
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
Mumble 2024-10-16 07:38:12 -07:00 committed by GitHub
parent c6ec01958c
commit 2caa09f246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 247 additions and 2 deletions

View File

@ -1024,7 +1024,7 @@ export class MoveEffectAttr extends MoveAttr {
applyAbAttrs(MoveEffectChanceMultiplierAbAttr, user, null, false, moveChance, move, target, selfEffect, showAbility); applyAbAttrs(MoveEffectChanceMultiplierAbAttr, user, null, false, moveChance, move, target, selfEffect, showAbility);
if (!move.hasAttr(FlinchAttr) || moveChance.value <= move.chance) { if ((!move.hasAttr(FlinchAttr) || moveChance.value <= move.chance) && !move.hasAttr(SecretPowerAttr)) {
const userSide = user.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; const userSide = user.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY;
user.scene.arena.applyTagsForSide(ArenaTagType.WATER_FIRE_PLEDGE, userSide, false, moveChance); user.scene.arena.applyTagsForSide(ArenaTagType.WATER_FIRE_PLEDGE, userSide, false, moveChance);
} }
@ -2875,6 +2875,162 @@ export class StatStageChangeAttr extends MoveEffectAttr {
} }
} }
/**
* Attribute used to determine the Biome/Terrain-based secondary effect of Secret Power
*/
export class SecretPowerAttr extends MoveEffectAttr {
constructor() {
super(false);
}
/**
* Used to determine if the move should apply a secondary effect based on Secret Power's 30% chance
* @returns `true` if the move's secondary effect should apply
*/
override canApply(user: Pokemon, target: Pokemon, move: Move, args?: any[]): boolean {
this.effectChanceOverride = move.chance;
const moveChance = this.getMoveChance(user, target, move, this.selfTarget);
if (moveChance < 0 || moveChance === 100 || user.randSeedInt(100) < moveChance) {
// effectChanceOverride used in the application of the actual secondary effect
this.effectChanceOverride = 100;
return true;
} else {
return false;
}
}
/**
* Used to apply the secondary effect to the target Pokemon
* @returns `true` if a secondary effect is successfully applied
*/
override apply(user: Pokemon, target: Pokemon, move: Move, args?: any[]): boolean | Promise<boolean> {
if (!super.apply(user, target, move, args)) {
return false;
}
let secondaryEffect: MoveEffectAttr;
const terrain = user.scene.arena.getTerrainType();
if (terrain !== TerrainType.NONE) {
secondaryEffect = this.determineTerrainEffect(terrain);
} else {
const biome = user.scene.arena.biomeType;
secondaryEffect = this.determineBiomeEffect(biome);
}
return secondaryEffect.apply(user, target, move, []);
}
/**
* Determines the secondary effect based on terrain.
* Takes precedence over biome-based effects.
* ```
* Electric Terrain | Paralysis
* Misty Terrain | SpAtk -1
* Grassy Terrain | Sleep
* Psychic Terrain | Speed -1
* ```
* @param terrain - {@linkcode TerrainType} The current terrain
* @returns the chosen secondary effect {@linkcode MoveEffectAttr}
*/
private determineTerrainEffect(terrain: TerrainType): MoveEffectAttr {
let secondaryEffect: MoveEffectAttr;
switch (terrain) {
case TerrainType.ELECTRIC:
default:
secondaryEffect = new StatusEffectAttr(StatusEffect.PARALYSIS, false);
break;
case TerrainType.MISTY:
secondaryEffect = new StatStageChangeAttr([ Stat.SPATK ], -1, false);
break;
case TerrainType.GRASSY:
secondaryEffect = new StatusEffectAttr(StatusEffect.SLEEP, false);
break;
case TerrainType.PSYCHIC:
secondaryEffect = new StatStageChangeAttr([ Stat.SPD ], -1, false);
break;
}
return secondaryEffect;
}
/**
* Determines the secondary effect based on biome
* ```
* Town, Metropolis, Slum, Dojo, Laboratory, Power Plant + Default | Paralysis
* Plains, Grass, Tall Grass, Forest, Jungle, Meadow | Sleep
* Swamp, Mountain, Temple, Ruins | Speed -1
* Ice Cave, Snowy Forest | Freeze
* Volcano | Burn
* Fairy Cave | SpAtk -1
* Desert, Construction Site, Beach, Island, Badlands | Accuracy -1
* Sea, Lake, Seabed | Atk -1
* Cave, Wasteland, Graveyard, Abyss, Space | Flinch
* End | Def -1
* ```
* @param biome - The current {@linkcode Biome} the battle is set in
* @returns the chosen secondary effect {@linkcode MoveEffectAttr}
*/
private determineBiomeEffect(biome: Biome): MoveEffectAttr {
let secondaryEffect: MoveEffectAttr;
switch (biome) {
case Biome.PLAINS:
case Biome.GRASS:
case Biome.TALL_GRASS:
case Biome.FOREST:
case Biome.JUNGLE:
case Biome.MEADOW:
secondaryEffect = new StatusEffectAttr(StatusEffect.SLEEP, false);
break;
case Biome.SWAMP:
case Biome.MOUNTAIN:
case Biome.TEMPLE:
case Biome.RUINS:
secondaryEffect = new StatStageChangeAttr([ Stat.SPD ], -1, false);
break;
case Biome.ICE_CAVE:
case Biome.SNOWY_FOREST:
secondaryEffect = new StatusEffectAttr(StatusEffect.FREEZE, false);
break;
case Biome.VOLCANO:
secondaryEffect = new StatusEffectAttr(StatusEffect.BURN, false);
break;
case Biome.FAIRY_CAVE:
secondaryEffect = new StatStageChangeAttr([ Stat.SPATK ], -1, false);
break;
case Biome.DESERT:
case Biome.CONSTRUCTION_SITE:
case Biome.BEACH:
case Biome.ISLAND:
case Biome.BADLANDS:
secondaryEffect = new StatStageChangeAttr([ Stat.ACC ], -1, false);
break;
case Biome.SEA:
case Biome.LAKE:
case Biome.SEABED:
secondaryEffect = new StatStageChangeAttr([ Stat.ATK ], -1, false);
break;
case Biome.CAVE:
case Biome.WASTELAND:
case Biome.GRAVEYARD:
case Biome.ABYSS:
case Biome.SPACE:
secondaryEffect = new AddBattlerTagAttr(BattlerTagType.FLINCHED, false, true);
break;
case Biome.END:
secondaryEffect = new StatStageChangeAttr([ Stat.DEF ], -1, false);
break;
case Biome.TOWN:
case Biome.METROPOLIS:
case Biome.SLUM:
case Biome.DOJO:
case Biome.FACTORY:
case Biome.LABORATORY:
case Biome.POWER_PLANT:
default:
secondaryEffect = new StatusEffectAttr(StatusEffect.PARALYSIS, false);
break;
}
return secondaryEffect;
}
}
export class PostVictoryStatStageChangeAttr extends MoveAttr { export class PostVictoryStatStageChangeAttr extends MoveAttr {
private stats: BattleStat[]; private stats: BattleStat[];
private stages: number; private stages: number;
@ -7898,7 +8054,7 @@ export function initMoves() {
.unimplemented(), .unimplemented(),
new AttackMove(Moves.SECRET_POWER, Type.NORMAL, MoveCategory.PHYSICAL, 70, 100, 20, 30, 0, 3) new AttackMove(Moves.SECRET_POWER, Type.NORMAL, MoveCategory.PHYSICAL, 70, 100, 20, 30, 0, 3)
.makesContact(false) .makesContact(false)
.partial(), // No effect implemented .attr(SecretPowerAttr),
new AttackMove(Moves.DIVE, Type.WATER, MoveCategory.PHYSICAL, 80, 100, 10, -1, 0, 3) new AttackMove(Moves.DIVE, Type.WATER, MoveCategory.PHYSICAL, 80, 100, 10, -1, 0, 3)
.attr(ChargeAttr, ChargeAnim.DIVE_CHARGING, i18next.t("moveTriggers:hidUnderwater", { pokemonName: "{USER}" }), BattlerTagType.UNDERWATER, true) .attr(ChargeAttr, ChargeAnim.DIVE_CHARGING, i18next.t("moveTriggers:hidUnderwater", { pokemonName: "{USER}" }), BattlerTagType.UNDERWATER, true)
.attr(GulpMissileTagAttr) .attr(GulpMissileTagAttr)

View File

@ -0,0 +1,89 @@
import { Abilities } from "#enums/abilities";
import { Biome } from "#enums/biome";
import { Moves } from "#enums/moves";
import { Stat } from "#enums/stat";
import { allMoves, SecretPowerAttr } from "#app/data/move";
import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { StatusEffect } from "#enums/status-effect";
import { BattlerIndex } from "#app/battle";
import { ArenaTagType } from "#enums/arena-tag-type";
import { ArenaTagSide } from "#app/data/arena-tag";
describe("Moves - Secret Power", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([ Moves.SECRET_POWER ])
.ability(Abilities.BALL_FETCH)
.battleType("single")
.disableCrits()
.enemySpecies(Species.MAGIKARP)
.enemyLevel(60)
.enemyAbility(Abilities.BALL_FETCH);
});
it("Secret Power checks for an active terrain first then looks at the biome for its secondary effect", async () => {
game.override
.startingBiome(Biome.VOLCANO)
.enemyMoveset([ Moves.SPLASH, Moves.MISTY_TERRAIN ]);
vi.spyOn(allMoves[Moves.SECRET_POWER], "chance", "get").mockReturnValue(100);
await game.classicMode.startBattle([ Species.FEEBAS ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
// No Terrain + Biome.VOLCANO --> Burn
game.move.select(Moves.SECRET_POWER);
await game.forceEnemyMove(Moves.SPLASH);
await game.phaseInterceptor.to("TurnEndPhase");
expect(enemyPokemon.status?.effect).toBe(StatusEffect.BURN);
// Misty Terrain --> SpAtk -1
game.move.select(Moves.SECRET_POWER);
await game.forceEnemyMove(Moves.MISTY_TERRAIN);
await game.phaseInterceptor.to("TurnEndPhase");
expect(enemyPokemon.getStatStage(Stat.SPATK)).toBe(-1);
});
it("the 'rainbow' effect of fire+water pledge does not double the chance of secret power's secondary effect",
async () => {
game.override
.moveset([ Moves.FIRE_PLEDGE, Moves.WATER_PLEDGE, Moves.SECRET_POWER, Moves.SPLASH ])
.enemyMoveset([ Moves.SPLASH ])
.battleType("double");
await game.classicMode.startBattle([ Species.BLASTOISE, Species.CHARIZARD ]);
const secretPowerAttr = allMoves[Moves.SECRET_POWER].getAttrs(SecretPowerAttr)[0];
vi.spyOn(secretPowerAttr, "getMoveChance");
game.move.select(Moves.WATER_PLEDGE, 0, BattlerIndex.ENEMY);
game.move.select(Moves.FIRE_PLEDGE, 1, BattlerIndex.ENEMY_2);
await game.phaseInterceptor.to("TurnEndPhase");
expect(game.scene.arena.getTagOnSide(ArenaTagType.WATER_FIRE_PLEDGE, ArenaTagSide.PLAYER)).toBeDefined();
game.move.select(Moves.SECRET_POWER, 0, BattlerIndex.ENEMY);
game.move.select(Moves.SPLASH, 1);
await game.phaseInterceptor.to("BerryPhase", false);
expect(secretPowerAttr.getMoveChance).toHaveLastReturnedWith(30);
}
);
});