Changed BattleScene.removeModifier and pokemon.loseHeldItem

This commit is contained in:
Wlowscha 2025-06-09 10:42:55 +02:00
parent 565d75225a
commit c41ae99365
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
3 changed files with 12 additions and 18 deletions

View File

@ -33,7 +33,6 @@ import {
PokemonFormChangeItemModifier, PokemonFormChangeItemModifier,
PokemonHeldItemModifier, PokemonHeldItemModifier,
PokemonHpRestoreModifier, PokemonHpRestoreModifier,
PokemonIncrementingStatModifier,
RememberMoveModifier, RememberMoveModifier,
} from "./modifier/modifier"; } from "./modifier/modifier";
import { PokeballType } from "#enums/pokeball"; import { PokeballType } from "#enums/pokeball";
@ -169,6 +168,7 @@ import { ModifierBar } from "./modifier/modifier-bar";
import { applyHeldItems } from "./items/all-held-items"; import { applyHeldItems } from "./items/all-held-items";
import { ITEM_EFFECT } from "./items/held-item"; import { ITEM_EFFECT } from "./items/held-item";
import { PhaseManager } from "./phase-manager"; import { PhaseManager } from "./phase-manager";
import { HeldItemId } from "#enums/held-item-id";
const DEBUG_RNG = false; const DEBUG_RNG = false;
@ -3019,12 +3019,6 @@ export default class BattleScene extends SceneBase {
const modifierIndex = modifiers.indexOf(modifier); const modifierIndex = modifiers.indexOf(modifier);
if (modifierIndex > -1) { if (modifierIndex > -1) {
modifiers.splice(modifierIndex, 1); modifiers.splice(modifierIndex, 1);
if (modifier instanceof PokemonFormChangeItemModifier) {
const pokemon = this.getPokemonById(modifier.pokemonId);
if (pokemon) {
modifier.apply(pokemon, false);
}
}
return true; return true;
} }
@ -3177,6 +3171,7 @@ export default class BattleScene extends SceneBase {
} else { } else {
matchingFormChange = matchingFormChangeOpts[0]; matchingFormChange = matchingFormChangeOpts[0];
} }
if (matchingFormChange) { if (matchingFormChange) {
let phase: Phase; let phase: Phase;
if (pokemon.isPlayer() && !matchingFormChange.quiet) { if (pokemon.isPlayer() && !matchingFormChange.quiet) {
@ -3374,9 +3369,9 @@ export default class BattleScene extends SceneBase {
const participated = participantIds.has(pId); const participated = participantIds.has(pId);
if (participated && pokemonDefeated) { if (participated && pokemonDefeated) {
partyMember.addFriendship(FRIENDSHIP_GAIN_FROM_BATTLE); partyMember.addFriendship(FRIENDSHIP_GAIN_FROM_BATTLE);
const machoBraceModifier = partyMember.getHeldItems().find(m => m instanceof PokemonIncrementingStatModifier); const hasMachoBrace = partyMember.heldItemManager.hasItem(HeldItemId.MACHO_BRACE);
if (machoBraceModifier && machoBraceModifier.stackCount < machoBraceModifier.getMaxStackCount()) { if (hasMachoBrace) {
machoBraceModifier.stackCount++; partyMember.heldItemManager.add(HeldItemId.MACHO_BRACE);
this.updateModifiers(true, true); this.updateModifiers(true, true);
partyMember.updateInfo(); partyMember.updateInfo();
} }

View File

@ -59,10 +59,10 @@ export class PokemonItemManager {
} }
} }
remove(itemType: HeldItemId, removeStack = 1) { remove(itemType: HeldItemId, removeStack = 1, all = false) {
this.heldItems[itemType].stack -= removeStack; this.heldItems[itemType].stack -= removeStack;
if (this.heldItems[itemType].stack <= 0) { if (all || this.heldItems[itemType].stack <= 0) {
delete this.heldItems[itemType]; delete this.heldItems[itemType];
} }
} }

View File

@ -242,6 +242,7 @@ import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader";
import { PokemonItemManager } from "./pokemon-held-item-manager"; import { PokemonItemManager } from "./pokemon-held-item-manager";
import { applyHeldItems } from "#app/items/all-held-items"; import { applyHeldItems } from "#app/items/all-held-items";
import { ITEM_EFFECT } from "#app/items/held-item"; import { ITEM_EFFECT } from "#app/items/held-item";
import type { HeldItemId } from "#enums/held-item-id";
export enum LearnMoveSituation { export enum LearnMoveSituation {
MISC, MISC,
@ -5462,15 +5463,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* @param forBattle If `false`, do not trigger in-battle effects (such as Unburden) from losing the item. For example, set this to `false` if the Pokemon is giving away the held item for a Mystery Encounter. Default is `true`. * @param forBattle If `false`, do not trigger in-battle effects (such as Unburden) from losing the item. For example, set this to `false` if the Pokemon is giving away the held item for a Mystery Encounter. Default is `true`.
* @returns `true` if the item was removed successfully, `false` otherwise. * @returns `true` if the item was removed successfully, `false` otherwise.
*/ */
public loseHeldItem(heldItem: PokemonHeldItemModifier, forBattle = true): boolean { public loseHeldItem(heldItemId: HeldItemId, forBattle = true): boolean {
if (heldItem.pokemonId !== -1 && heldItem.pokemonId !== this.id) { if (!this.heldItemManager.hasItem(heldItemId)) {
return false; return false;
} }
heldItem.stackCount--; this.heldItemManager.remove(heldItemId);
if (heldItem.stackCount <= 0) {
globalScene.removeModifier(heldItem, this.isEnemy());
}
if (forBattle) { if (forBattle) {
applyPostItemLostAbAttrs(PostItemLostAbAttr, this, false); applyPostItemLostAbAttrs(PostItemLostAbAttr, this, false);
} }