Skip to content

Commit

Permalink
Merge branch 'beta' into refactor/api-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
flx-sta authored Oct 21, 2024
2 parents af32e42 + f779760 commit 93d805e
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/data/arena-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ export class ArenaTrapTag extends ArenaTag {
* @returns `true` if this hazard affects the given Pokemon; `false` otherwise.
*/
override apply(arena: Arena, simulated: boolean, pokemon: Pokemon): boolean {
if (this.sourceId === pokemon.id || (this.side === ArenaTagSide.PLAYER) !== pokemon.isPlayer()) {
if ((this.side === ArenaTagSide.PLAYER) !== pokemon.isPlayer()) {
return false;
}

Expand Down
15 changes: 11 additions & 4 deletions src/field/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3982,10 +3982,14 @@ export class PlayerPokemon extends Pokemon {
if (Overrides.SHINY_OVERRIDE) {
this.shiny = true;
this.initShinySparkle();
if (Overrides.VARIANT_OVERRIDE) {
this.variant = Overrides.VARIANT_OVERRIDE;
}
} else if (Overrides.SHINY_OVERRIDE === false) {
this.shiny = false;
}

if (Overrides.VARIANT_OVERRIDE !== null && this.shiny) {
this.variant = Overrides.VARIANT_OVERRIDE;
}

if (!dataSource) {
if (this.scene.gameMode.isDaily) {
this.generateAndPopulateMoveset();
Expand Down Expand Up @@ -4474,10 +4478,13 @@ export class EnemyPokemon extends Pokemon {
if (Overrides.OPP_SHINY_OVERRIDE) {
this.shiny = true;
this.initShinySparkle();
} else if (Overrides.OPP_SHINY_OVERRIDE === false) {
this.shiny = false;
}

if (this.shiny) {
this.variant = this.generateVariant();
if (Overrides.OPP_VARIANT_OVERRIDE) {
if (Overrides.OPP_VARIANT_OVERRIDE !== null) {
this.variant = Overrides.OPP_VARIANT_OVERRIDE;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class DefaultOverrides {
readonly STATUS_OVERRIDE: StatusEffect = StatusEffect.NONE;
readonly GENDER_OVERRIDE: Gender | null = null;
readonly MOVESET_OVERRIDE: Moves | Array<Moves> = [];
readonly SHINY_OVERRIDE: boolean = false;
readonly VARIANT_OVERRIDE: Variant = 0;
readonly SHINY_OVERRIDE: boolean | null = null;
readonly VARIANT_OVERRIDE: Variant | null = null;

// --------------------------
// OPPONENT / ENEMY OVERRIDES
Expand All @@ -134,8 +134,8 @@ class DefaultOverrides {
readonly OPP_STATUS_OVERRIDE: StatusEffect = StatusEffect.NONE;
readonly OPP_GENDER_OVERRIDE: Gender | null = null;
readonly OPP_MOVESET_OVERRIDE: Moves | Array<Moves> = [];
readonly OPP_SHINY_OVERRIDE: boolean = false;
readonly OPP_VARIANT_OVERRIDE: Variant = 0;
readonly OPP_SHINY_OVERRIDE: boolean | null = null;
readonly OPP_VARIANT_OVERRIDE: Variant | null = null;
readonly OPP_IVS_OVERRIDE: number | number[] = [];
readonly OPP_FORM_OVERRIDES: Partial<Record<Species, number>> = {};
/**
Expand Down
13 changes: 8 additions & 5 deletions src/phases/learn-move-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase {
pokemon.setMove(index, this.moveId);
initMoveAnim(this.scene, this.moveId).then(() => {
loadMoveAnimAssets(this.scene, [ this.moveId ], true);
this.scene.playSound("level_up_fanfare"); // Sound loaded into game as is
});
this.scene.ui.setMode(this.messageMode);
const learnMoveText = i18next.t("battle:learnMove", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: move.name });
textMessage = textMessage ? textMessage + "$" + learnMoveText : learnMoveText;
await this.scene.ui.showTextPromise(textMessage, this.messageMode === Mode.EVOLUTION_SCENE ? 1000 : undefined, true);
this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeMoveLearnedTrigger, true);
this.end();
if (textMessage) {
await this.scene.ui.showTextPromise(textMessage);
}
this.scene.playSound("level_up_fanfare"); // Sound loaded into game as is
this.scene.ui.showText(learnMoveText, null, () => {
this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeMoveLearnedTrigger, true);
this.end();
}, this.messageMode === Mode.EVOLUTION_SCENE ? 1000 : undefined, true);
}
}
55 changes: 29 additions & 26 deletions src/test/moves/toxic_spikes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";

const TIMEOUT = 20 * 1000;

describe("Moves - Toxic Spikes", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
Expand All @@ -34,10 +32,10 @@ describe("Moves - Toxic Spikes", () => {
.enemyAbility(Abilities.BALL_FETCH)
.ability(Abilities.BALL_FETCH)
.enemyMoveset(Moves.SPLASH)
.moveset([ Moves.TOXIC_SPIKES, Moves.SPLASH, Moves.ROAR ]);
.moveset([ Moves.TOXIC_SPIKES, Moves.SPLASH, Moves.ROAR, Moves.COURT_CHANGE ]);
});

it("should not affect the opponent if they do not switch", async() => {
it("should not affect the opponent if they do not switch", async () => {
await game.classicMode.runToSummon([ Species.MIGHTYENA, Species.POOCHYENA ]);

const enemy = game.scene.getEnemyField()[0];
Expand All @@ -51,9 +49,9 @@ describe("Moves - Toxic Spikes", () => {

expect(enemy.hp).toBe(enemy.getMaxHp());
expect(enemy.status?.effect).toBeUndefined();
}, TIMEOUT);
});

it("should poison the opponent if they switch into 1 layer", async() => {
it("should poison the opponent if they switch into 1 layer", async () => {
await game.classicMode.runToSummon([ Species.MIGHTYENA ]);

game.move.select(Moves.TOXIC_SPIKES);
Expand All @@ -65,9 +63,9 @@ describe("Moves - Toxic Spikes", () => {

expect(enemy.hp).toBeLessThan(enemy.getMaxHp());
expect(enemy.status?.effect).toBe(StatusEffect.POISON);
}, TIMEOUT);
});

it("should badly poison the opponent if they switch into 2 layers", async() => {
it("should badly poison the opponent if they switch into 2 layers", async () => {
await game.classicMode.runToSummon([ Species.MIGHTYENA ]);

game.move.select(Moves.TOXIC_SPIKES);
Expand All @@ -80,27 +78,32 @@ describe("Moves - Toxic Spikes", () => {
const enemy = game.scene.getEnemyField()[0];
expect(enemy.hp).toBeLessThan(enemy.getMaxHp());
expect(enemy.status?.effect).toBe(StatusEffect.TOXIC);
}, TIMEOUT);
});

it("should be removed if a grounded poison pokemon switches in", async() => {
game.override.enemySpecies(Species.GRIMER);
await game.classicMode.runToSummon([ Species.MIGHTYENA ]);
it("should be removed if a grounded poison pokemon switches in", async () => {
await game.classicMode.runToSummon([ Species.MUK, Species.PIDGEY ]);

game.move.select(Moves.TOXIC_SPIKES);
await game.phaseInterceptor.to("TurnEndPhase");
game.move.select(Moves.TOXIC_SPIKES);
await game.phaseInterceptor.to("TurnEndPhase");
game.move.select(Moves.ROAR);
await game.phaseInterceptor.to("TurnEndPhase");
const muk = game.scene.getPlayerPokemon()!;

const enemy = game.scene.getEnemyField()[0];
expect(enemy.hp).toBe(enemy.getMaxHp());
expect(enemy.status?.effect).toBeUndefined();
game.move.select(Moves.TOXIC_SPIKES);
await game.toNextTurn();
// also make sure the toxic spikes are removed even if the pokemon
// that set them up is the one switching in (https://github.com/pagefaultgames/pokerogue/issues/935)
game.move.select(Moves.COURT_CHANGE);
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.toNextTurn();
game.move.select(Moves.SPLASH);
await game.toNextTurn();

expect(muk.isFullHp()).toBe(true);
expect(muk.status?.effect).toBeUndefined();
expect(game.scene.arena.tags.length).toBe(0);
}, TIMEOUT);
});

it("shouldn't create multiple layers per use in doubles", async() => {
it("shouldn't create multiple layers per use in doubles", async () => {
await game.classicMode.runToSummon([ Species.MIGHTYENA, Species.POOCHYENA ]);

game.move.select(Moves.TOXIC_SPIKES);
Expand All @@ -109,9 +112,9 @@ describe("Moves - Toxic Spikes", () => {
const arenaTags = (game.scene.arena.getTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.ENEMY) as ArenaTrapTag);
expect(arenaTags.tagType).toBe(ArenaTagType.TOXIC_SPIKES);
expect(arenaTags.layers).toBe(1);
}, TIMEOUT);
});

it("should persist through reload", async() => {
it("should persist through reload", async () => {
game.override.startingWave(1);
const scene = game.scene;
const gameData = new GameData(scene);
Expand All @@ -132,5 +135,5 @@ describe("Moves - Toxic Spikes", () => {

expect(sessionData.arena.tags).toEqual(recoveredData.arena.tags);
localStorage.removeItem("sessionTestData");
}, TIMEOUT);
});
});
6 changes: 5 additions & 1 deletion src/test/utils/helpers/challengeModeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class ChallengeModeHelper extends GameManagerHelper {
async runToSummon(species?: Species[]) {
await this.game.runToTitle();

if (this.game.override.disableShinies) {
this.game.override.shiny(false).enemyShiny(false);
}

this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => {
this.game.scene.gameMode.challenges = this.challenges;
const starters = generateStarter(this.game.scene, species);
Expand All @@ -47,7 +51,7 @@ export class ChallengeModeHelper extends GameManagerHelper {
});

await this.game.phaseInterceptor.run(EncounterPhase);
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) {
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0 && this.game.override.removeEnemyStartingItems) {
this.game.removeEnemyHeldItems();
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/test/utils/helpers/classicModeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ export class ClassicModeHelper extends GameManagerHelper {
* @param species - Optional array of species to summon.
* @returns A promise that resolves when the summon phase is reached.
*/
async runToSummon(species?: Species[]) {
async runToSummon(species?: Species[]): Promise<void> {
await this.game.runToTitle();

if (this.game.override.disableShinies) {
this.game.override.shiny(false).enemyShiny(false);
}

this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => {
this.game.scene.gameMode = getGameMode(GameModes.CLASSIC);
const starters = generateStarter(this.game.scene, species);
Expand All @@ -32,7 +36,7 @@ export class ClassicModeHelper extends GameManagerHelper {
});

await this.game.phaseInterceptor.run(EncounterPhase);
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) {
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0 && this.game.override.removeEnemyStartingItems) {
this.game.removeEnemyHeldItems();
}
}
Expand All @@ -42,7 +46,7 @@ export class ClassicModeHelper extends GameManagerHelper {
* @param species - Optional array of species to start the battle with.
* @returns A promise that resolves when the battle is started.
*/
async startBattle(species?: Species[]) {
async startBattle(species?: Species[]): Promise<void> {
await this.runToSummon(species);

if (this.game.scene.battleStyle === BattleStyle.SWITCH) {
Expand Down
6 changes: 5 additions & 1 deletion src/test/utils/helpers/dailyModeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class DailyModeHelper extends GameManagerHelper {
async runToSummon() {
await this.game.runToTitle();

if (this.game.override.disableShinies) {
this.game.override.shiny(false).enemyShiny(false);
}

this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => {
const titlePhase = new TitlePhase(this.game.scene);
titlePhase.initDailyRun();
Expand All @@ -33,7 +37,7 @@ export class DailyModeHelper extends GameManagerHelper {

await this.game.phaseInterceptor.to(EncounterPhase);

if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) {
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0 && this.game.override.removeEnemyStartingItems) {
this.game.removeEnemyHeldItems();
}
}
Expand Down
42 changes: 37 additions & 5 deletions src/test/utils/helpers/overridesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
* Helper to handle overrides in tests
*/
export class OverridesHelper extends GameManagerHelper {
/** If `true`, removes the starting items from enemies at the start of each test; default `true` */
public removeEnemyStartingItems: boolean = true;
/** If `true`, sets the shiny overrides to disable shinies at the start of each test; default `true` */
public disableShinies: boolean = true;

/**
* Override the starting biome
* @warning Any event listeners that are attached to [NewArenaEvent](events\battle-scene.ts) may need to be handled down the line
Expand Down Expand Up @@ -368,23 +373,50 @@ export class OverridesHelper extends GameManagerHelper {

/**
* Override player shininess
* @param shininess Whether the player's Pokemon should be shiny.
* @param shininess - `true` or `false` to force the player's pokemon to be shiny or not shiny,
* `null` to disable the override and re-enable RNG shinies.
*/
shinyLevel(shininess: boolean): this {
shiny(shininess: boolean | null): this {
vi.spyOn(Overrides, "SHINY_OVERRIDE", "get").mockReturnValue(shininess);
this.log(`Set player Pokemon as ${shininess ? "" : "not "}shiny!`);
if (shininess === null) {
this.log("Disabled player Pokemon shiny override!");
} else {
this.log(`Set player Pokemon to be ${shininess ? "" : "not "}shiny!`);
}
return this;
}

/**
* Override player shiny variant
* @param variant The player's shiny variant.
* @param variant - The player's shiny variant.
*/
variantLevel(variant: Variant): this {
shinyVariant(variant: Variant): this {
vi.spyOn(Overrides, "VARIANT_OVERRIDE", "get").mockReturnValue(variant);
this.log(`Set player Pokemon's shiny variant to ${variant}!`);
return this;
}

/**
* Override enemy shininess
* @param shininess - `true` or `false` to force the enemy's pokemon to be shiny or not shiny,
* `null` to disable the override and re-enable RNG shinies.
* @param variant - (Optional) The enemy's shiny {@linkcode Variant}.
*/
enemyShiny(shininess: boolean | null, variant?: Variant): this {
vi.spyOn(Overrides, "OPP_SHINY_OVERRIDE", "get").mockReturnValue(shininess);
if (shininess === null) {
this.log("Disabled enemy Pokemon shiny override!");
} else {
this.log(`Set enemy Pokemon to be ${shininess ? "" : "not "}shiny!`);
}

if (variant !== undefined) {
vi.spyOn(Overrides, "OPP_VARIANT_OVERRIDE", "get").mockReturnValue(variant);
this.log(`Set enemy shiny variant to be ${variant}!`);
}
return this;
}

/**
* Override the enemy (Pokemon) to have the given amount of health segments
* @param healthSegments the number of segments to give
Expand Down

0 comments on commit 93d805e

Please sign in to comment.