mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-07 07:59:26 +02:00
* Changing remaining Modifiers to Consumables, and renaming ModifierType to Reward * Renamed modifier files and moved them into items folder * Using rewards in most places * Removed consumables in favor of using rewards directly * Renamed RewardTier to RarityTier * Reward ids, function to match rewards * Getting reward tiers from player pool still * Messing around with parameters of Reward.apply() * Always requiring player pokemon in rewards * Fixing some functions in select-reward-phase and battle-scene * Fixed various post-merge issues * Fixed most localization strings (accidentally broken by replacing modifierType with reward) * Fixed tests for select reward phase * Using Pokemon.hasSpecies() * Zero weight for trainer items rewards which are already max stack * Cleaning up SelectRewardPhase, held item rewards behave the same as any PokemonReward * Cleaned up some functions * Introduced RewardCategoryId, distributed RewardIds * Utility `is` functions for rewards * Minor fixes * Moved `HeldItemEffect` to its own file * rmade some todo comments * Adding a big comment * Added tsdocs and removed `RewardClass` * undid breaking changes * added TODO * Moved matchingRewards function to reward-utils.ts * Added RewardGenerator classes for mints and tera shards * Introducing default rarity tiers for trainer items and rewards * RewardFunc now can return RewardGenerator * Moved pool reward functions to their own file, plus other utility files * Fixed WeightedModifier to work with the new RewardFunc * Fixed wrong type import * Shifting trainer item and reward ids to avoid overlaps * Added some types * Updated comment in reward.ts * Added strong typing ot item maps * added type safety to held item name map --------- Co-authored-by: Bertie690 <taylormw163@gmail.com> Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
299 lines
11 KiB
TypeScript
299 lines
11 KiB
TypeScript
import type { BattleScene } from "#app/battle-scene";
|
|
import { allSpecies } from "#data/data-lists";
|
|
import { HeldItemId } from "#enums/held-item-id";
|
|
import { SpeciesId } from "#enums/species-id";
|
|
import { PlayerPokemon } from "#field/pokemon";
|
|
import {
|
|
Achv,
|
|
AchvTier,
|
|
achvs,
|
|
DamageAchv,
|
|
HealAchv,
|
|
HeldItemAchv,
|
|
LevelAchv,
|
|
MoneyAchv,
|
|
RibbonAchv,
|
|
} from "#system/achv";
|
|
import { GameManager } from "#test/test-utils/game-manager";
|
|
import { NumberHolder } from "#utils/common";
|
|
import Phaser from "phaser";
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
describe("check some Achievement related stuff", () => {
|
|
it("should check Achievement creation", () => {
|
|
const ach = new MoneyAchv("", "Achievement", 1000, null!, 100);
|
|
expect(ach.name).toBe("Achievement");
|
|
});
|
|
});
|
|
|
|
describe("Achv", () => {
|
|
let achv: Achv;
|
|
|
|
beforeEach(() => {
|
|
achv = new Achv("", "Test Achievement", "This is a test achievement", "test_icon", 10);
|
|
});
|
|
|
|
it("should have the correct name", () => {
|
|
expect(achv.getDescription()).toBe("This is a test achievement");
|
|
});
|
|
|
|
it("should have the correct icon image", () => {
|
|
expect(achv.getIconImage()).toBe("test_icon");
|
|
});
|
|
|
|
it("should set the achievement as secret", () => {
|
|
achv.setSecret();
|
|
expect(achv.secret).toBe(true);
|
|
expect(achv.hasParent).toBe(false);
|
|
|
|
achv.setSecret(true);
|
|
expect(achv.secret).toBe(true);
|
|
expect(achv.hasParent).toBe(true);
|
|
|
|
achv.setSecret(false);
|
|
expect(achv.secret).toBe(true);
|
|
expect(achv.hasParent).toBe(false);
|
|
});
|
|
|
|
it("should return the correct tier based on the score", () => {
|
|
const achv1 = new Achv("", "Test Achievement 1", "Test Description", "test_icon", 10);
|
|
const achv2 = new Achv("", "Test Achievement 2", "Test Description", "test_icon", 25);
|
|
const achv3 = new Achv("", "Test Achievement 3", "Test Description", "test_icon", 50);
|
|
const achv4 = new Achv("", "Test Achievement 4", "Test Description", "test_icon", 75);
|
|
const achv5 = new Achv("", "Test Achievement 5", "Test Description", "test_icon", 100);
|
|
|
|
expect(achv1.getTier()).toBe(AchvTier.COMMON);
|
|
expect(achv2.getTier()).toBe(AchvTier.GREAT);
|
|
expect(achv3.getTier()).toBe(AchvTier.ULTRA);
|
|
expect(achv4.getTier()).toBe(AchvTier.ROGUE);
|
|
expect(achv5.getTier()).toBe(AchvTier.MASTER);
|
|
});
|
|
|
|
it("should validate the achievement based on the condition function", () => {
|
|
const conditionFunc = vi.fn((args: any[]) => args[0] === 10);
|
|
const achv = new Achv("", "Test Achievement", "Test Description", "test_icon", 10, conditionFunc);
|
|
|
|
expect(achv.validate([5])).toBe(false);
|
|
expect(achv.validate([10])).toBe(true);
|
|
expect(conditionFunc).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|
|
|
|
describe("MoneyAchv", () => {
|
|
let phaserGame: Phaser.Game;
|
|
let game: GameManager;
|
|
let scene: BattleScene;
|
|
|
|
beforeAll(() => {
|
|
phaserGame = new Phaser.Game({
|
|
type: Phaser.HEADLESS,
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
game.phaseInterceptor.restoreOg();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
game = new GameManager(phaserGame);
|
|
scene = game.scene;
|
|
});
|
|
|
|
it("should create an instance of MoneyAchv", () => {
|
|
const moneyAchv = new MoneyAchv("", "Test Money Achievement", 10000, "money_icon", 10);
|
|
expect(moneyAchv).toBeInstanceOf(MoneyAchv);
|
|
expect(moneyAchv instanceof Achv).toBe(true);
|
|
});
|
|
|
|
it("should validate the achievement based on the money amount", () => {
|
|
const moneyAchv = new MoneyAchv("", "Test Money Achievement", 10000, "money_icon", 10);
|
|
scene.money = 5000;
|
|
|
|
expect(moneyAchv.validate([])).toBe(false);
|
|
|
|
scene.money = 15000;
|
|
expect(moneyAchv.validate([])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("RibbonAchv", () => {
|
|
let phaserGame: Phaser.Game;
|
|
let game: GameManager;
|
|
let scene: BattleScene;
|
|
|
|
beforeAll(() => {
|
|
phaserGame = new Phaser.Game({
|
|
type: Phaser.HEADLESS,
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
game.phaseInterceptor.restoreOg();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
game = new GameManager(phaserGame);
|
|
scene = game.scene;
|
|
});
|
|
|
|
it("should create an instance of RibbonAchv", () => {
|
|
const ribbonAchv = new RibbonAchv("", "Test Ribbon Achievement", 10, "ribbon_icon", 10);
|
|
expect(ribbonAchv).toBeInstanceOf(RibbonAchv);
|
|
expect(ribbonAchv instanceof Achv).toBe(true);
|
|
});
|
|
|
|
it("should validate the achievement based on the ribbon amount", () => {
|
|
const ribbonAchv = new RibbonAchv("", "Test Ribbon Achievement", 10, "ribbon_icon", 10);
|
|
scene.gameData.gameStats.ribbonsOwned = 5;
|
|
|
|
expect(ribbonAchv.validate([])).toBe(false);
|
|
|
|
scene.gameData.gameStats.ribbonsOwned = 15;
|
|
expect(ribbonAchv.validate([])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("DamageAchv", () => {
|
|
it("should create an instance of DamageAchv", () => {
|
|
const damageAchv = new DamageAchv("", "Test Damage Achievement", 250, "damage_icon", 10);
|
|
expect(damageAchv).toBeInstanceOf(DamageAchv);
|
|
expect(damageAchv instanceof Achv).toBe(true);
|
|
});
|
|
|
|
it("should validate the achievement based on the damage amount", () => {
|
|
const damageAchv = new DamageAchv("", "Test Damage Achievement", 250, "damage_icon", 10);
|
|
const numberHolder = new NumberHolder(200);
|
|
|
|
expect(damageAchv.validate([numberHolder])).toBe(false);
|
|
|
|
numberHolder.value = 300;
|
|
expect(damageAchv.validate([numberHolder])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("HealAchv", () => {
|
|
it("should create an instance of HealAchv", () => {
|
|
const healAchv = new HealAchv("", "Test Heal Achievement", 250, "heal_icon", 10);
|
|
expect(healAchv).toBeInstanceOf(HealAchv);
|
|
expect(healAchv instanceof Achv).toBe(true);
|
|
});
|
|
|
|
it("should validate the achievement based on the heal amount", () => {
|
|
const healAchv = new HealAchv("", "Test Heal Achievement", 250, "heal_icon", 10);
|
|
const numberHolder = new NumberHolder(200);
|
|
|
|
expect(healAchv.validate([numberHolder])).toBe(false);
|
|
|
|
numberHolder.value = 300;
|
|
expect(healAchv.validate([numberHolder])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("LevelAchv", () => {
|
|
it("should create an instance of LevelAchv", () => {
|
|
const levelAchv = new LevelAchv("", "Test Level Achievement", 100, "level_icon", 10);
|
|
expect(levelAchv).toBeInstanceOf(LevelAchv);
|
|
expect(levelAchv instanceof Achv).toBe(true);
|
|
});
|
|
|
|
it("should validate the achievement based on the level", () => {
|
|
const levelAchv = new LevelAchv("", "Test Level Achievement", 100, "level_icon", 10);
|
|
const integerHolder = new NumberHolder(50);
|
|
|
|
expect(levelAchv.validate([integerHolder])).toBe(false);
|
|
|
|
integerHolder.value = 150;
|
|
expect(levelAchv.validate([integerHolder])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("HeldItemAchv", () => {
|
|
it("should create an instance of ModifierAchv", () => {
|
|
const heldItemAchv = new HeldItemAchv(
|
|
"",
|
|
"Test Held Item Achievement",
|
|
"Test Description",
|
|
"modifier_icon",
|
|
10,
|
|
() => true,
|
|
);
|
|
expect(heldItemAchv).toBeInstanceOf(HeldItemAchv);
|
|
expect(heldItemAchv instanceof Achv).toBe(true);
|
|
});
|
|
|
|
it("should validate the mini black hole achievement", () => {
|
|
const heldItemAchv = achvs.MINI_BLACK_HOLE;
|
|
const pokemon = new PlayerPokemon(allSpecies[SpeciesId.BULBASAUR], 1);
|
|
expect(heldItemAchv.validate([pokemon])).toBe(false);
|
|
pokemon.heldItemManager.add(HeldItemId.MINI_BLACK_HOLE);
|
|
expect(heldItemAchv.validate([pokemon])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("achvs", () => {
|
|
it("should contain the predefined achievements", () => {
|
|
expect(achvs._10K_MONEY).toBeInstanceOf(MoneyAchv);
|
|
expect(achvs._100K_MONEY).toBeInstanceOf(MoneyAchv);
|
|
expect(achvs._1M_MONEY).toBeInstanceOf(MoneyAchv);
|
|
expect(achvs._10M_MONEY).toBeInstanceOf(MoneyAchv);
|
|
expect(achvs._250_DMG).toBeInstanceOf(DamageAchv);
|
|
expect(achvs._1000_DMG).toBeInstanceOf(DamageAchv);
|
|
expect(achvs._2500_DMG).toBeInstanceOf(DamageAchv);
|
|
expect(achvs._10000_DMG).toBeInstanceOf(DamageAchv);
|
|
expect(achvs._250_HEAL).toBeInstanceOf(HealAchv);
|
|
expect(achvs._1000_HEAL).toBeInstanceOf(HealAchv);
|
|
expect(achvs._2500_HEAL).toBeInstanceOf(HealAchv);
|
|
expect(achvs._10000_HEAL).toBeInstanceOf(HealAchv);
|
|
expect(achvs.LV_100).toBeInstanceOf(LevelAchv);
|
|
expect(achvs.LV_250).toBeInstanceOf(LevelAchv);
|
|
expect(achvs.LV_1000).toBeInstanceOf(LevelAchv);
|
|
expect(achvs._10_RIBBONS).toBeInstanceOf(RibbonAchv);
|
|
expect(achvs._25_RIBBONS).toBeInstanceOf(RibbonAchv);
|
|
expect(achvs._50_RIBBONS).toBeInstanceOf(RibbonAchv);
|
|
expect(achvs._75_RIBBONS).toBeInstanceOf(RibbonAchv);
|
|
expect(achvs._100_RIBBONS).toBeInstanceOf(RibbonAchv);
|
|
expect(achvs.TRANSFER_MAX_STAT_STAGE).toBeInstanceOf(Achv);
|
|
expect(achvs.MAX_FRIENDSHIP).toBeInstanceOf(Achv);
|
|
expect(achvs.MEGA_EVOLVE).toBeInstanceOf(Achv);
|
|
expect(achvs.GIGANTAMAX).toBeInstanceOf(Achv);
|
|
expect(achvs.TERASTALLIZE).toBeInstanceOf(Achv);
|
|
expect(achvs.STELLAR_TERASTALLIZE).toBeInstanceOf(Achv);
|
|
expect(achvs.SPLICE).toBeInstanceOf(Achv);
|
|
expect(achvs.MINI_BLACK_HOLE).toBeInstanceOf(HeldItemAchv);
|
|
expect(achvs.CATCH_MYTHICAL).toBeInstanceOf(Achv);
|
|
expect(achvs.CATCH_SUB_LEGENDARY).toBeInstanceOf(Achv);
|
|
expect(achvs.CATCH_LEGENDARY).toBeInstanceOf(Achv);
|
|
expect(achvs.SEE_SHINY).toBeInstanceOf(Achv);
|
|
expect(achvs.SHINY_PARTY).toBeInstanceOf(Achv);
|
|
expect(achvs.HATCH_MYTHICAL).toBeInstanceOf(Achv);
|
|
expect(achvs.HATCH_SUB_LEGENDARY).toBeInstanceOf(Achv);
|
|
expect(achvs.HATCH_LEGENDARY).toBeInstanceOf(Achv);
|
|
expect(achvs.HATCH_SHINY).toBeInstanceOf(Achv);
|
|
expect(achvs.HIDDEN_ABILITY).toBeInstanceOf(Achv);
|
|
expect(achvs.PERFECT_IVS).toBeInstanceOf(Achv);
|
|
expect(achvs.CLASSIC_VICTORY).toBeInstanceOf(Achv);
|
|
});
|
|
|
|
it("should initialize the achievements with IDs and parent IDs", () => {
|
|
expect(achvs._10K_MONEY.id).toBe("_10K_MONEY");
|
|
expect(achvs._10K_MONEY.hasParent).toBe(undefined);
|
|
expect(achvs._100K_MONEY.id).toBe("_100K_MONEY");
|
|
expect(achvs._100K_MONEY.hasParent).toBe(true);
|
|
expect(achvs._100K_MONEY.parentId).toBe("_10K_MONEY");
|
|
expect(achvs._1M_MONEY.id).toBe("_1M_MONEY");
|
|
expect(achvs._1M_MONEY.hasParent).toBe(true);
|
|
expect(achvs._1M_MONEY.parentId).toBe("_100K_MONEY");
|
|
expect(achvs._10M_MONEY.id).toBe("_10M_MONEY");
|
|
expect(achvs._10M_MONEY.hasParent).toBe(true);
|
|
expect(achvs._10M_MONEY.parentId).toBe("_1M_MONEY");
|
|
expect(achvs.LV_100.id).toBe("LV_100");
|
|
expect(achvs.LV_100.hasParent).toBe(false);
|
|
expect(achvs.LV_250.id).toBe("LV_250");
|
|
expect(achvs.LV_250.hasParent).toBe(true);
|
|
expect(achvs.LV_250.parentId).toBe("LV_100");
|
|
expect(achvs.LV_1000.id).toBe("LV_1000");
|
|
expect(achvs.LV_1000.hasParent).toBe(true);
|
|
expect(achvs.LV_1000.parentId).toBe("LV_250");
|
|
});
|
|
});
|