mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-11 01:49:29 +02:00
Added noneReward
This commit is contained in:
parent
9dfbee9bb9
commit
6a097ebb5e
47
scripts/create-test/boilerplates/reward.ts
Normal file
47
scripts/create-test/boilerplates/reward.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { AbilityId } from "#enums/ability-id";
|
||||
import { MoveId } from "#enums/move-id";
|
||||
import { RewardId } from "#enums/reward-id";
|
||||
import { SpeciesId } from "#enums/species-id";
|
||||
import { BerryHeldItem } from "#items/berry";
|
||||
import { HeldItemReward } from "#items/reward";
|
||||
import { GameManager } from "#test/test-utils/game-manager";
|
||||
import { generateRewardForTest } from "#test/test-utils/reward-test-utils";
|
||||
import Phaser from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
describe("{{description}}", () => {
|
||||
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
|
||||
.ability(AbilityId.BALL_FETCH)
|
||||
.battleStyle("single")
|
||||
.criticalHits(false)
|
||||
.enemySpecies(SpeciesId.MAGIKARP)
|
||||
.enemyAbility(AbilityId.BALL_FETCH)
|
||||
.enemyMoveset(MoveId.SPLASH)
|
||||
.startingLevel(100)
|
||||
.enemyLevel(100);
|
||||
});
|
||||
|
||||
it("should do XYZ when applied", async () => {
|
||||
await game.classicMode.startBattle([SpeciesId.FEEBAS]);
|
||||
|
||||
const reward = generateRewardForTest(RewardId.BERRY);
|
||||
expect(reward).toBeInstanceOf(HeldItemReward);
|
||||
game.scene.applyReward(reward, []);
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
@ -12,16 +12,16 @@ export type WeightedRewardWeightFunc = (party: Pokemon[], rerollCount?: number)
|
||||
|
||||
export type RewardPoolId = RewardId | HeldItemId | TrainerItemId;
|
||||
|
||||
type allRewardsInstanceMap = {
|
||||
type allRewardGenerators = {
|
||||
[k in keyof allRewardsType as allRewardsType[k] extends RewardGenerator ? k : never]: allRewardsType[k];
|
||||
};
|
||||
|
||||
type RewardGeneratorArgMap = {
|
||||
[k in keyof allRewardsInstanceMap]: Exclude<Parameters<allRewardsInstanceMap[k]["generateReward"]>[0], undefined>;
|
||||
[k in keyof allRewardGenerators]: Exclude<Parameters<allRewardGenerators[k]["generateReward"]>[0], undefined>;
|
||||
};
|
||||
|
||||
/** Union type containing all {@linkcode RewardId}s corresponding to valid {@linkcode RewardGenerator}s. */
|
||||
type RewardGeneratorId = keyof allRewardsInstanceMap;
|
||||
type RewardGeneratorId = keyof allRewardGenerators;
|
||||
|
||||
type RewardGeneratorSpecs<T extends RewardGeneratorId = RewardGeneratorId> = {
|
||||
id: T;
|
||||
|
@ -86,7 +86,7 @@ import { applyHeldItems } from "#items/all-held-items";
|
||||
import { type ApplyTrainerItemsParams, applyTrainerItems } from "#items/apply-trainer-items";
|
||||
import type { HeldItemConfiguration } from "#items/held-item-data-types";
|
||||
import { assignEnemyHeldItemsForWave, assignItemsFromConfiguration } from "#items/held-item-pool";
|
||||
import type { Reward } from "#items/reward";
|
||||
import type { MatchExact, Reward } from "#items/reward";
|
||||
import { getRewardPoolForType } from "#items/reward-pool-utils";
|
||||
import { type EnemyAttackStatusEffectChanceTrainerItem, TrainerItemEffect } from "#items/trainer-item";
|
||||
import {
|
||||
@ -2636,15 +2636,17 @@ export class BattleScene extends SceneBase {
|
||||
applyTrainerItems(effect, this.trainerItems, params);
|
||||
}
|
||||
|
||||
applyReward<T extends Reward>(reward: T, params: Parameters<T["apply"]>[0], playSound?: boolean): boolean {
|
||||
applyReward<T extends Reward>(
|
||||
reward: T,
|
||||
params: MatchExact<Parameters<T["apply"]>[0]>,
|
||||
playSound?: boolean,
|
||||
): boolean {
|
||||
const soundName = reward.soundName;
|
||||
|
||||
if (playSound && !this.sound.get(soundName)) {
|
||||
this.playSound(soundName);
|
||||
}
|
||||
|
||||
// TODO: fix later
|
||||
// @ts-expect-error
|
||||
if (!reward.shouldApply(params)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ export const RewardId = {
|
||||
MEMORY_MUSHROOM: 0x2B03,
|
||||
DNA_SPLICERS: 0x2B04,
|
||||
|
||||
HELD_ITEM: 0x2C01,
|
||||
HELD_ITEM: 0x2C01, // TODO: Remove?
|
||||
SPECIES_STAT_BOOSTER: 0x2C02,
|
||||
RARE_SPECIES_STAT_BOOSTER: 0x2C03,
|
||||
BASE_STAT_BOOSTER: 0x2C04,
|
||||
|
@ -18,6 +18,7 @@ import {
|
||||
FusePokemonReward,
|
||||
LapsingTrainerItemReward,
|
||||
MintRewardGenerator,
|
||||
NoneReward,
|
||||
PokemonAllMovePpRestoreReward,
|
||||
PokemonHpRestoreReward,
|
||||
PokemonLevelIncrementReward,
|
||||
@ -34,6 +35,8 @@ import {
|
||||
|
||||
// TODO: Move to `reward-utils.ts` and un-exportt
|
||||
export const allRewards = {
|
||||
[RewardId.NONE]: new NoneReward(),
|
||||
|
||||
// Pokeball rewards
|
||||
[RewardId.POKEBALL]: new AddPokeballReward("pb", PokeballType.POKEBALL, 5, RewardId.POKEBALL),
|
||||
[RewardId.GREAT_BALL]: new AddPokeballReward("gb", PokeballType.GREAT_BALL, 5, RewardId.GREAT_BALL),
|
||||
@ -171,8 +174,6 @@ export const allRewards = {
|
||||
|
||||
[RewardId.BERRY]: new BerryRewardGenerator(),
|
||||
|
||||
// [RewardId.MINI_BLACK_HOLE] = new HeldItemReward(HeldItemId.MINI_BLACK_HOLE),
|
||||
|
||||
// Trainer items
|
||||
|
||||
[RewardId.LURE]: new LapsingTrainerItemReward(TrainerItemId.LURE, RewardId.LURE),
|
||||
@ -182,7 +183,6 @@ export const allRewards = {
|
||||
[RewardId.TEMP_STAT_STAGE_BOOSTER]: new TempStatStageBoosterRewardGenerator(),
|
||||
|
||||
[RewardId.DIRE_HIT]: new LapsingTrainerItemReward(TrainerItemId.DIRE_HIT, RewardId.TEMP_STAT_STAGE_BOOSTER),
|
||||
// [RewardId.GOLDEN_POKEBALL]: new TrainerItemReward(TrainerItemId.GOLDEN_POKEBALL),
|
||||
} as const satisfies {
|
||||
[k in RewardId]: RewardFunc;
|
||||
};
|
||||
|
@ -93,7 +93,7 @@ import i18next from "i18next";
|
||||
* Type helper to exactly match objects and nothing else.
|
||||
* @todo merge with `Exact` later on
|
||||
*/
|
||||
type MatchExact<T> = T extends object ? Exact<T> : T;
|
||||
export type MatchExact<T> = T extends object ? Exact<T> : T;
|
||||
|
||||
export abstract class Reward {
|
||||
// TODO: If all we care about for categorization is the reward's ID's _category_, why not do it there?
|
||||
@ -369,6 +369,7 @@ export class HeldItemReward extends PokemonReward {
|
||||
}
|
||||
|
||||
export class TrainerItemReward extends Reward {
|
||||
// TODO: This should not be public
|
||||
public itemId: TrainerItemId;
|
||||
constructor(itemId: TrainerItemId, group?: string, soundName?: string) {
|
||||
super("", "", group, soundName);
|
||||
@ -1528,3 +1529,7 @@ export class RewardOption {
|
||||
this.cost = Math.min(Math.round(cost), Number.MAX_SAFE_INTEGER);
|
||||
}
|
||||
}
|
||||
|
||||
export class NoneReward extends Reward {
|
||||
override apply(): void {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user