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,
PokemonHeldItemModifier,
PokemonHpRestoreModifier,
PokemonIncrementingStatModifier,
RememberMoveModifier,
} from "./modifier/modifier";
import { PokeballType } from "#enums/pokeball";
@ -169,6 +168,7 @@ import { ModifierBar } from "./modifier/modifier-bar";
import { applyHeldItems } from "./items/all-held-items";
import { ITEM_EFFECT } from "./items/held-item";
import { PhaseManager } from "./phase-manager";
import { HeldItemId } from "#enums/held-item-id";
const DEBUG_RNG = false;
@ -3019,12 +3019,6 @@ export default class BattleScene extends SceneBase {
const modifierIndex = modifiers.indexOf(modifier);
if (modifierIndex > -1) {
modifiers.splice(modifierIndex, 1);
if (modifier instanceof PokemonFormChangeItemModifier) {
const pokemon = this.getPokemonById(modifier.pokemonId);
if (pokemon) {
modifier.apply(pokemon, false);
}
}
return true;
}
@ -3177,6 +3171,7 @@ export default class BattleScene extends SceneBase {
} else {
matchingFormChange = matchingFormChangeOpts[0];
}
if (matchingFormChange) {
let phase: Phase;
if (pokemon.isPlayer() && !matchingFormChange.quiet) {
@ -3374,9 +3369,9 @@ export default class BattleScene extends SceneBase {
const participated = participantIds.has(pId);
if (participated && pokemonDefeated) {
partyMember.addFriendship(FRIENDSHIP_GAIN_FROM_BATTLE);
const machoBraceModifier = partyMember.getHeldItems().find(m => m instanceof PokemonIncrementingStatModifier);
if (machoBraceModifier && machoBraceModifier.stackCount < machoBraceModifier.getMaxStackCount()) {
machoBraceModifier.stackCount++;
const hasMachoBrace = partyMember.heldItemManager.hasItem(HeldItemId.MACHO_BRACE);
if (hasMachoBrace) {
partyMember.heldItemManager.add(HeldItemId.MACHO_BRACE);
this.updateModifiers(true, true);
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;
if (this.heldItems[itemType].stack <= 0) {
if (all || this.heldItems[itemType].stack <= 0) {
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 { applyHeldItems } from "#app/items/all-held-items";
import { ITEM_EFFECT } from "#app/items/held-item";
import type { HeldItemId } from "#enums/held-item-id";
export enum LearnMoveSituation {
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`.
* @returns `true` if the item was removed successfully, `false` otherwise.
*/
public loseHeldItem(heldItem: PokemonHeldItemModifier, forBattle = true): boolean {
if (heldItem.pokemonId !== -1 && heldItem.pokemonId !== this.id) {
public loseHeldItem(heldItemId: HeldItemId, forBattle = true): boolean {
if (!this.heldItemManager.hasItem(heldItemId)) {
return false;
}
heldItem.stackCount--;
if (heldItem.stackCount <= 0) {
globalScene.removeModifier(heldItem, this.isEnemy());
}
this.heldItemManager.remove(heldItemId);
if (forBattle) {
applyPostItemLostAbAttrs(PostItemLostAbAttr, this, false);
}