mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-09 00:49:27 +02:00
Moved getPartyBerries() utility function
This commit is contained in:
parent
e034d7e04e
commit
b8324e85f7
@ -16,11 +16,11 @@ import type { MysteryEncounterSpriteConfig } from "#field/mystery-encounter-intr
|
||||
import type { Pokemon } from "#field/pokemon";
|
||||
import { EnemyPokemon } from "#field/pokemon";
|
||||
import type { HeldItemConfiguration, PokemonItemMap } from "#items/held-item-data-types";
|
||||
import { getPartyBerries } from "#items/item-utility";
|
||||
import { PokemonMove } from "#moves/pokemon-move";
|
||||
import { queueEncounterMessage } from "#mystery-encounters/encounter-dialogue-utils";
|
||||
import type { EnemyPartyConfig } from "#mystery-encounters/encounter-phase-utils";
|
||||
import {
|
||||
getPartyBerries,
|
||||
initBattleWithEnemyConfig,
|
||||
leaveEncounterWithoutBattle,
|
||||
setEncounterRewards,
|
||||
|
@ -12,11 +12,11 @@ import { PokeballType } from "#enums/pokeball";
|
||||
import { Stat } from "#enums/stat";
|
||||
import type { EnemyPokemon, Pokemon } from "#field/pokemon";
|
||||
import type { PokemonItemMap } from "#items/held-item-data-types";
|
||||
import { getPartyBerries } from "#items/item-utility";
|
||||
import { PokemonMove } from "#moves/pokemon-move";
|
||||
import { queueEncounterMessage } from "#mystery-encounters/encounter-dialogue-utils";
|
||||
import type { EnemyPartyConfig } from "#mystery-encounters/encounter-phase-utils";
|
||||
import {
|
||||
getPartyBerries,
|
||||
getRandomEncounterSpecies,
|
||||
initBattleWithEnemyConfig,
|
||||
leaveEncounterWithoutBattle,
|
||||
|
@ -5,7 +5,7 @@ import { globalScene } from "#app/global-scene";
|
||||
import { getPokemonNameWithAffix } from "#app/messages";
|
||||
import { BiomePoolTier, biomeLinks } from "#balance/biomes";
|
||||
import { initMoveAnim, loadMoveAnimAssets } from "#data/battle-anims";
|
||||
import { allHeldItems, modifierTypes } from "#data/data-lists";
|
||||
import { modifierTypes } from "#data/data-lists";
|
||||
import type { IEggOptions } from "#data/egg";
|
||||
import { Egg } from "#data/egg";
|
||||
import type { Gender } from "#data/gender";
|
||||
@ -17,7 +17,6 @@ import type { AiType } from "#enums/ai-type";
|
||||
import type { BattlerTagType } from "#enums/battler-tag-type";
|
||||
import { BiomeId } from "#enums/biome-id";
|
||||
import { FieldPosition } from "#enums/field-position";
|
||||
import { HeldItemCategoryId, type HeldItemId, isItemInCategory } from "#enums/held-item-id";
|
||||
import { ModifierPoolType } from "#enums/modifier-pool-type";
|
||||
import type { MoveId } from "#enums/move-id";
|
||||
import { MysteryEncounterMode } from "#enums/mystery-encounter-mode";
|
||||
@ -31,7 +30,7 @@ import { UiMode } from "#enums/ui-mode";
|
||||
import type { PlayerPokemon, Pokemon } from "#field/pokemon";
|
||||
import { EnemyPokemon } from "#field/pokemon";
|
||||
import { Trainer } from "#field/trainer";
|
||||
import type { HeldItemConfiguration, PokemonItemMap } from "#items/held-item-data-types";
|
||||
import type { HeldItemConfiguration } from "#items/held-item-data-types";
|
||||
import type { CustomModifierSettings, ModifierType } from "#modifiers/modifier-type";
|
||||
import { getPartyLuckValue, ModifierTypeGenerator, ModifierTypeOption } from "#modifiers/modifier-type";
|
||||
import { PokemonMove } from "#moves/pokemon-move";
|
||||
@ -1294,29 +1293,3 @@ export function calculateRareSpawnAggregateStats(luckValue: number) {
|
||||
|
||||
console.log(stats);
|
||||
}
|
||||
|
||||
// Iterate over the party until an item is successfully given
|
||||
export function assignItemToFirstFreePokemon(item: HeldItemId, party: Pokemon[]): void {
|
||||
for (const pokemon of party) {
|
||||
const stack = pokemon.heldItemManager.getStack(item);
|
||||
if (stack < allHeldItems[item].getMaxStackCount()) {
|
||||
pokemon.heldItemManager.add(item);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Creates an item map of berries to pokemon, storing each berry separately (splitting up stacks)
|
||||
export function getPartyBerries(): PokemonItemMap[] {
|
||||
const pokemonItems: PokemonItemMap[] = [];
|
||||
globalScene.getPlayerParty().forEach(pokemon => {
|
||||
const berries = pokemon.getHeldItems().filter(item => isItemInCategory(item, HeldItemCategoryId.BERRY));
|
||||
berries.forEach(berryId => {
|
||||
const berryStack = pokemon.heldItemManager.getStack(berryId);
|
||||
for (let i = 1; i <= berryStack; i++) {
|
||||
pokemonItems.push({ item: { id: berryId, stack: 1 }, pokemonId: pokemon.id });
|
||||
}
|
||||
});
|
||||
});
|
||||
return pokemonItems;
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { allHeldItems, allTrainerItems } from "#data/data-lists";
|
||||
import { FormChangeItem } from "#enums/form-change-item";
|
||||
import type { HeldItemId } from "#enums/held-item-id";
|
||||
import { HeldItemCategoryId, type HeldItemId, isItemInCategory } from "#enums/held-item-id";
|
||||
import type { TrainerItemId } from "#enums/trainer-item-id";
|
||||
import type { Pokemon } from "#field/pokemon";
|
||||
import i18next from "i18next";
|
||||
import type { PokemonItemMap } from "./held-item-data-types";
|
||||
|
||||
export function formChangeItemName(id: FormChangeItem) {
|
||||
return i18next.t(`modifierType:FormChangeItem.${FormChangeItem[id]}`);
|
||||
@ -43,3 +46,29 @@ export const formChangeItemSortFunc = (a: FormChangeItem, b: FormChangeItem): nu
|
||||
}
|
||||
return itemIdMatch;
|
||||
};
|
||||
|
||||
// Iterate over the party until an item is successfully given
|
||||
export function assignItemToFirstFreePokemon(item: HeldItemId, party: Pokemon[]): void {
|
||||
for (const pokemon of party) {
|
||||
const stack = pokemon.heldItemManager.getStack(item);
|
||||
if (stack < allHeldItems[item].getMaxStackCount()) {
|
||||
pokemon.heldItemManager.add(item);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Creates an item map of berries to pokemon, storing each berry separately (splitting up stacks)
|
||||
export function getPartyBerries(): PokemonItemMap[] {
|
||||
const pokemonItems: PokemonItemMap[] = [];
|
||||
globalScene.getPlayerParty().forEach(pokemon => {
|
||||
const berries = pokemon.getHeldItems().filter(item => isItemInCategory(item, HeldItemCategoryId.BERRY));
|
||||
berries.forEach(berryId => {
|
||||
const berryStack = pokemon.heldItemManager.getStack(berryId);
|
||||
for (let i = 1; i <= berryStack; i++) {
|
||||
pokemonItems.push({ item: { id: berryId, stack: 1 }, pokemonId: pokemon.id });
|
||||
}
|
||||
});
|
||||
});
|
||||
return pokemonItems;
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
|
||||
import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
||||
import { SpeciesId } from "#enums/species-id";
|
||||
import { UiMode } from "#enums/ui-mode";
|
||||
import type { HeldItemSpecs } from "#items/held-item-data-types";
|
||||
import { getPartyBerries } from "#items/item-utility";
|
||||
import { BerriesAboundEncounter } from "#mystery-encounters/berries-abound-encounter";
|
||||
import * as EncounterDialogueUtils from "#mystery-encounters/encounter-dialogue-utils";
|
||||
import * as EncounterPhaseUtils from "#mystery-encounters/encounter-phase-utils";
|
||||
@ -133,8 +135,8 @@ describe("Berries Abound - Mystery Encounter", () => {
|
||||
await game.phaseInterceptor.to(SelectRewardPhase, false);
|
||||
expect(scene.phaseManager.getCurrentPhase()?.constructor.name).toBe(SelectRewardPhase.name);
|
||||
|
||||
const berriesAfter = scene.findModifiers(m => m instanceof BerryModifier) as BerryModifier[];
|
||||
const berriesAfterCount = berriesAfter.reduce((a, b) => a + b.stackCount, 0);
|
||||
const berriesAfter = getPartyBerries();
|
||||
const berriesAfterCount = berriesAfter.reduce((a, b) => a + (b.item as HeldItemSpecs).stack, 0);
|
||||
|
||||
expect(numBerries).toBe(berriesAfterCount);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user