From f26cb11e0b7dda9333c72d09e0ca435f8df4499b Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Thu, 19 Jun 2025 22:29:46 +0200 Subject: [PATCH] Fixed several bugs related to accessing and visualizing held items --- src/battle-scene.ts | 5 ++++- src/data/trainers/trainer-config.ts | 12 +++++++++++- src/field/pokemon.ts | 4 ++-- src/items/held-item-pool.ts | 7 +++++-- src/items/held-items/base-stat-total.ts | 2 +- src/items/held-items/berry.ts | 8 ++++---- src/items/held-items/instant-revive.ts | 2 +- src/items/held-items/reset-negative-stat-stage.ts | 2 +- src/loading-scene.ts | 2 ++ src/modifier/modifier-type.ts | 14 ++++++++++---- src/phases/select-modifier-phase.ts | 3 +-- src/ui/modifier-select-ui-handler.ts | 1 + src/ui/summary-ui-handler.ts | 3 +-- 13 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index aff124aef73..f196fc930a9 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -2906,7 +2906,10 @@ export default class BattleScene extends SceneBase { } this.updateParty(player ? this.getPlayerParty() : this.getEnemyParty(), true); - (player ? this.modifierBar : this.enemyModifierBar).updateModifiers(modifiers); + + const pokemonA = player ? this.getPlayerParty()[0] : this.getEnemyParty()[0]; + + (player ? this.modifierBar : this.enemyModifierBar).updateModifiers(modifiers, pokemonA); if (!player) { this.updateUIPositions(); } diff --git a/src/data/trainers/trainer-config.ts b/src/data/trainers/trainer-config.ts index 6786aa00ef7..5b892eb9015 100644 --- a/src/data/trainers/trainer-config.ts +++ b/src/data/trainers/trainer-config.ts @@ -1004,6 +1004,7 @@ export function getRandomPartyMemberFunc( undefined, false, undefined, + undefined, postProcess, ); }; @@ -1028,7 +1029,16 @@ function getSpeciesFilterRandomPartyMemberFunc( .getTrainerSpeciesForLevel(level, true, strength, waveIndex), ); - return globalScene.addEnemyPokemon(species, level, trainerSlot, undefined, false, undefined, postProcess); + return globalScene.addEnemyPokemon( + species, + level, + trainerSlot, + undefined, + false, + undefined, + undefined, + postProcess, + ); }; } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 2861a09d80a..19ad009e884 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -339,6 +339,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.exp = dataSource?.exp || getLevelTotalExp(this.level, species.growthRate); this.levelExp = dataSource?.levelExp || 0; + this.heldItemManager = new PokemonItemManager(); + if (dataSource) { this.id = dataSource.id; this.hp = dataSource.hp; @@ -444,8 +446,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (!dataSource) { this.calculateStats(); } - - this.heldItemManager = new PokemonItemManager(); } /** diff --git a/src/items/held-item-pool.ts b/src/items/held-item-pool.ts index 7041abbf579..56403891d21 100644 --- a/src/items/held-item-pool.ts +++ b/src/items/held-item-pool.ts @@ -2,7 +2,7 @@ import type { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; import type Pokemon from "#app/field/pokemon"; import { coerceArray, getEnumValues, randSeedFloat, randSeedInt } from "#app/utils/common"; import { BerryType } from "#enums/berry-type"; -import { HeldItemCategoryId, HeldItemId, isCategoryId } from "#enums/held-item-id"; +import { HeldItemCategoryId, HeldItemId, HeldItemNames, isCategoryId } from "#enums/held-item-id"; import { HeldItemPoolType } from "#enums/modifier-pool-type"; import type { PokemonType } from "#enums/pokemon-type"; import { RewardTier } from "#enums/reward-tier"; @@ -246,8 +246,11 @@ function getPoolWeights(pool: HeldItemPool, pokemon: Pokemon): number[] { return pool.map(p => { let weight = typeof p.weight === "function" ? p.weight(coerceArray(pokemon)) : p.weight; - if (typeof p.entry === "number") { + if (typeof p.entry === "number" && !isCategoryId(p.entry)) { const itemId = p.entry as HeldItemId; + console.log("ITEM ID: ", itemId, HeldItemNames[itemId]); + console.log(allHeldItems[itemId]); + if (pokemon.heldItemManager.getStack(itemId) >= allHeldItems[itemId].getMaxStackCount()) { weight = 0; } diff --git a/src/items/held-items/base-stat-total.ts b/src/items/held-items/base-stat-total.ts index f5c57c6a685..4524441e64f 100644 --- a/src/items/held-items/base-stat-total.ts +++ b/src/items/held-items/base-stat-total.ts @@ -38,7 +38,7 @@ export class BaseStatTotalHeldItem extends HeldItem { }); } - get icon(): string { + get iconName(): string { return "berry_juice"; } diff --git a/src/items/held-items/berry.ts b/src/items/held-items/berry.ts index e3f6dfd0962..d9d1f17ddfc 100644 --- a/src/items/held-items/berry.ts +++ b/src/items/held-items/berry.ts @@ -1,4 +1,4 @@ -import { getBerryEffectDescription, getBerryEffectFunc, getBerryName } from "#app/data/berry"; +import { getBerryEffectDescription, getBerryEffectFunc, getBerryName, getBerryPredicate } from "#app/data/berry"; import { BerryUsedEvent } from "#app/events/battle-scene"; import type Pokemon from "#app/field/pokemon"; import { globalScene } from "#app/global-scene"; @@ -60,9 +60,9 @@ export class BerryHeldItem extends ConsumableHeldItem { * @param pokemon The {@linkcode Pokemon} that holds the berry * @returns `true` if {@linkcode BerryModifier} should be applied */ - // override shouldApply(pokemon: Pokemon): boolean { - // return !this.consumed && super.shouldApply(pokemon) && getBerryPredicate(this.berryType)(pokemon); - // } + shouldApply(pokemon: Pokemon): boolean { + return getBerryPredicate(this.berryType)(pokemon); + } /** * Applies {@linkcode BerryHeldItem} diff --git a/src/items/held-items/instant-revive.ts b/src/items/held-items/instant-revive.ts index 62e0874f995..4290e2ede34 100644 --- a/src/items/held-items/instant-revive.ts +++ b/src/items/held-items/instant-revive.ts @@ -29,7 +29,7 @@ export class InstantReviveHeldItem extends ConsumableHeldItem { return i18next.t("modifierType:ModifierType.REVIVER_SEED.description"); } - get icon(): string { + get iconName(): string { return "reviver_seed"; } /** diff --git a/src/items/held-items/reset-negative-stat-stage.ts b/src/items/held-items/reset-negative-stat-stage.ts index c07deee8420..5c28c235d44 100644 --- a/src/items/held-items/reset-negative-stat-stage.ts +++ b/src/items/held-items/reset-negative-stat-stage.ts @@ -29,7 +29,7 @@ export class ResetNegativeStatStageHeldItem extends ConsumableHeldItem { return i18next.t("modifierType:ModifierType.WHITE_HERB.description"); } - get icon(): string { + get iconName(): string { return "white_herb"; } /** diff --git a/src/loading-scene.ts b/src/loading-scene.ts index bd8ccf852a6..f6bb11314d1 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -24,6 +24,7 @@ import { timedEventManager } from "./global-event-manager"; import { initHeldItems } from "./items/all-held-items"; import { initModifierPools } from "./modifier/init-modifier-pools"; import { initModifierTypes } from "./modifier/modifier-type"; +import { initHeldItemPools } from "./items/init-held-item-pools"; export class LoadingScene extends SceneBase { public static readonly KEY = "loading"; @@ -368,6 +369,7 @@ export class LoadingScene extends SceneBase { initModifierTypes(); initModifierPools(); + initHeldItemPools(); initAchievements(); initVouchers(); diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 0c5afe6d98e..bb926ba789a 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -354,12 +354,12 @@ export class HeldItemReward extends PokemonModifierType { return allHeldItems[this.itemId].name; } - get description(): string { - return allHeldItems[this.itemId].name; + getDescription(): string { + return allHeldItems[this.itemId].description; } - get icon(): string { - return allHeldItems[this.itemId].name; + getIcon(): string { + return allHeldItems[this.itemId].iconName; } apply(pokemon: Pokemon) { @@ -2070,6 +2070,11 @@ function getModifierTypeOptionWithRetry( ++r < retryCount && existingOptions.filter(o => o.type.name === candidate?.type.name || o.type.group === candidate?.type.group).length ) { + console.log("Retry count:", r); + console.log(candidate?.type.group); + console.log(candidate?.type.name); + console.log(existingOptions.filter(o => o.type.name === candidate?.type.name).length); + console.log(existingOptions.filter(o => o.type.group === candidate?.type.group).length); candidate = getNewModifierTypeOption( party, ModifierPoolType.PLAYER, @@ -2255,6 +2260,7 @@ function determineTier( retryCount = 0, allowLuckUpgrades = true, ): RewardTier { + const pool = getModifierPoolForType(ModifierPoolType.PLAYER); if (tier === undefined) { const tierValue = randSeedInt(1024); if (!upgradeCount) { diff --git a/src/phases/select-modifier-phase.ts b/src/phases/select-modifier-phase.ts index 93040b15584..e6d159e5da9 100644 --- a/src/phases/select-modifier-phase.ts +++ b/src/phases/select-modifier-phase.ts @@ -170,8 +170,7 @@ export class SelectModifierPhase extends BattlePhase { if (modifierType instanceof PokemonModifierType) { if (modifierType instanceof HeldItemReward) { this.openGiveHeldItemMenu(modifierType, modifierSelectCallback); - } - if (modifierType instanceof FusePokemonModifierType) { + } else if (modifierType instanceof FusePokemonModifierType) { this.openFusionMenu(modifierType, cost, modifierSelectCallback); } else { this.openModifierMenu(modifierType, cost, modifierSelectCallback); diff --git a/src/ui/modifier-select-ui-handler.ts b/src/ui/modifier-select-ui-handler.ts index 13f98fe42e5..24ddbdaef05 100644 --- a/src/ui/modifier-select-ui-handler.ts +++ b/src/ui/modifier-select-ui-handler.ts @@ -779,6 +779,7 @@ class ModifierOption extends Phaser.GameObjects.Container { this.add(this.itemContainer); const getItem = () => { + console.log("SHOWING ICON", this.modifierTypeOption.type?.name, this.modifierTypeOption.type?.getIcon()); const item = globalScene.add.sprite(0, 0, "items", this.modifierTypeOption.type?.getIcon()); return item; }; diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index 2846bff8ee2..17ccfdc5118 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -1035,9 +1035,8 @@ export default class SummaryUiHandler extends UiHandler { const heldItems = this.pokemon?.getHeldItems().sort(heldItemSortFunc); heldItems?.forEach((itemKey, i) => { - const stack = this.pokemon?.heldItemManager.getStack(itemKey); const heldItem = allHeldItems[itemKey]; - const icon = heldItem.createSummaryIcon(stack); + const icon = heldItem.createSummaryIcon(this.pokemon); console.log(icon); icon.setPosition((i % 17) * 12 + 3, 14 * Math.floor(i / 17) + 15);