Fixed several bugs related to accessing and visualizing held items

This commit is contained in:
Wlowscha 2025-06-19 22:29:46 +02:00
parent 1e9239720d
commit f26cb11e0b
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
13 changed files with 44 additions and 21 deletions

View File

@ -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();
}

View File

@ -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,
);
};
}

View File

@ -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();
}
/**

View File

@ -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;
}

View File

@ -38,7 +38,7 @@ export class BaseStatTotalHeldItem extends HeldItem {
});
}
get icon(): string {
get iconName(): string {
return "berry_juice";
}

View File

@ -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}

View File

@ -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";
}
/**

View File

@ -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";
}
/**

View File

@ -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();

View File

@ -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) {

View File

@ -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);

View File

@ -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;
};

View File

@ -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);