Apply suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
Mumble 2024-10-15 17:43:08 -07:00 committed by GitHub
parent b33dcb9635
commit 78ba14fb3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 17 deletions

View File

@ -2885,17 +2885,14 @@ export class SecretPowerAttr extends MoveEffectAttr {
/** /**
* Used to determine if the move should apply a secondary effect based on Secret Power's 30% chance * Used to determine if the move should apply a secondary effect based on Secret Power's 30% chance
* @param user * @returns `true` if the move's secondary effect should apply
* @param target
* @param move
* @param args
* @returns `true` if the move should | `false` if the roll fails and the move should not
*/ */
override canApply(user: Pokemon, target: Pokemon, move: Move, args?: any[]): boolean { override canApply(user: Pokemon, target: Pokemon, move: Move, args?: any[]): boolean {
this.effectChanceOverride = move.chance; this.effectChanceOverride = move.chance;
const moveChance = this.getMoveChance(user, target, move, this.selfTarget); const moveChance = this.getMoveChance(user, target, move, this.selfTarget);
if (moveChance < 0 || moveChance === 100 || user.randSeedInt(100) < moveChance) { if (moveChance < 0 || moveChance === 100 || user.randSeedInt(100) < moveChance) {
this.effectChanceOverride = 100; // effectChanceOverride used in the application of the actual secondary effect // effectChanceOverride used in the application of the actual secondary effect
this.effectChanceOverride = 100;
return true; return true;
} else { } else {
return false; return false;
@ -2908,9 +2905,9 @@ export class SecretPowerAttr extends MoveEffectAttr {
* @param target * @param target
* @param move * @param move
* @param args * @param args
* @returns `true` if a secondary effect is successfully applied | 'false' if not * @returns `true` if a secondary effect is successfully applied
*/ */
override apply(user: Pokemon, target: Pokemon, move: Move, args?: any[] | undefined): boolean | Promise<boolean> { override apply(user: Pokemon, target: Pokemon, move: Move, args?: any[]): boolean | Promise<boolean> {
if (!super.apply(user, target, move, args)) { if (!super.apply(user, target, move, args)) {
return false; return false;
} }
@ -2922,23 +2919,26 @@ export class SecretPowerAttr extends MoveEffectAttr {
const biome = user.scene.arena.biomeType; const biome = user.scene.arena.biomeType;
secondaryEffect = this.determineBiomeEffect(biome); secondaryEffect = this.determineBiomeEffect(biome);
} }
return secondaryEffect!.apply(user, target, move, []); return secondaryEffect.apply(user, target, move, []);
} }
/** /**
* Determines the secondary effect based on terrain * Determines the secondary effect based on terrain.
* Takes precedence over biome * Takes precedence over biome-based effects.
* ```
* Electric Terrain | Paralysis * Electric Terrain | Paralysis
* Misty Terrain | SpAtk -1 * Misty Terrain | SpAtk -1
* Grassy Terrain | Sleep * Grassy Terrain | Sleep
* Psychic Terrain | Speed -1 * Psychic Terrain | Speed -1
* @param terrain {@linkcode TerrainType}the current terrain * ```
* @param terrain - {@linkcode TerrainType} The current terrain
* @returns the chosen secondary effect {@linkcode MoveEffectAttr} * @returns the chosen secondary effect {@linkcode MoveEffectAttr}
*/ */
private determineTerrainEffect(terrain: TerrainType): MoveEffectAttr { private determineTerrainEffect(terrain: TerrainType): MoveEffectAttr {
let secondaryEffect: MoveEffectAttr; let secondaryEffect: MoveEffectAttr;
switch (terrain) { switch (terrain) {
case TerrainType.ELECTRIC: case TerrainType.ELECTRIC:
default:
secondaryEffect = new StatusEffectAttr(StatusEffect.PARALYSIS, false); secondaryEffect = new StatusEffectAttr(StatusEffect.PARALYSIS, false);
break; break;
case TerrainType.MISTY: case TerrainType.MISTY:
@ -2951,11 +2951,12 @@ export class SecretPowerAttr extends MoveEffectAttr {
secondaryEffect = new StatStageChangeAttr([ Stat.SPD ], -1, false); secondaryEffect = new StatStageChangeAttr([ Stat.SPD ], -1, false);
break; break;
} }
return secondaryEffect!; return secondaryEffect;
} }
/** /**
* Determines the secondary effect based on biome * Determines the secondary effect based on biome
* ```
* Town, Metropolis, Slum, Dojo, Laboratory, Power Plant + Default | Paralysis * Town, Metropolis, Slum, Dojo, Laboratory, Power Plant + Default | Paralysis
* Plains, Grass, Tall Grass, Forest, Jungle, Meadow | Sleep * Plains, Grass, Tall Grass, Forest, Jungle, Meadow | Sleep
* Swamp, Mountain, Temple, Ruins | Speed -1 * Swamp, Mountain, Temple, Ruins | Speed -1
@ -2966,7 +2967,8 @@ export class SecretPowerAttr extends MoveEffectAttr {
* Sea, Lake, Seabed | Atk -1 * Sea, Lake, Seabed | Atk -1
* Cave, Wasteland, Graveyard, Abyss, Space | Flinch * Cave, Wasteland, Graveyard, Abyss, Space | Flinch
* End | Def -1 * End | Def -1
* @param biome {@linkcode Biome} the current biome the battle is set in * ```
* @param biome - The current {@linkcode Biome} the battle is set in
* @returns the chosen secondary effect {@linkcode MoveEffectAttr} * @returns the chosen secondary effect {@linkcode MoveEffectAttr}
*/ */
private determineBiomeEffect(biome: Biome): MoveEffectAttr { private determineBiomeEffect(biome: Biome): MoveEffectAttr {

View File

@ -1,5 +1,5 @@
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { Biome } from "#app/enums/biome"; import { Biome } from "#enums/biome";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Stat } from "#enums/stat"; import { Stat } from "#enums/stat";
import { allMoves, SecretPowerAttr } from "#app/data/move"; import { allMoves, SecretPowerAttr } from "#app/data/move";
@ -7,9 +7,9 @@ import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { StatusEffect } from "#app/enums/status-effect"; import { StatusEffect } from "#enums/status-effect";
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { ArenaTagType } from "#app/enums/arena-tag-type"; import { ArenaTagType } from "#enums/arena-tag-type";
import { ArenaTagSide } from "#app/data/arena-tag"; import { ArenaTagSide } from "#app/data/arena-tag";
describe("Moves - Secret Power", () => { describe("Moves - Secret Power", () => {