Gens 3-4: Fix Knock Off state being reset on switch out
Some checks are pending
Node.js CI / build (18.x) (push) Waiting to run

This commit is contained in:
Karthik99999 2025-10-14 18:12:18 -07:00
parent f1adacf0ee
commit dc48d8234e
5 changed files with 14 additions and 11 deletions

View File

@ -190,7 +190,7 @@ export const Abilities: import('../../../sim/dex-abilities').ModdedAbilityDataTa
inherit: true,
onStart(pokemon) {
const target = pokemon.side.randomFoe();
if (target?.item && !target.itemState.knockedOff) {
if (target?.item && !target.itemKnockedOff) {
this.add('-item', '', target.getItem().name, '[from] ability: Frisk', `[of] ${pokemon}`);
}
},
@ -542,7 +542,7 @@ export const Abilities: import('../../../sim/dex-abilities').ModdedAbilityDataTa
inherit: true,
condition: {
onModifySpe(spe, pokemon) {
if ((!pokemon.item || pokemon.itemState.knockedOff) && !pokemon.ignoringAbility()) {
if ((!pokemon.item || pokemon.itemKnockedOff) && !pokemon.ignoringAbility()) {
return this.chainModify(2);
}
},

View File

@ -905,11 +905,11 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
knockoff: {
inherit: true,
onAfterHit(target, source, move) {
if (!target.item || target.itemState.knockedOff) return;
if (!target.item || target.itemKnockedOff) return;
if (target.ability === 'multitype') return;
const item = target.getItem();
if (this.runEvent('TakeItem', target, source, move, item)) {
target.itemState.knockedOff = true;
target.itemKnockedOff = true;
this.add('-enditem', target, item.name, '[from] move: Knock Off', `[of] ${source}`);
this.hint("In Gens 3-4, Knock Off only makes the target's item unusable; it cannot obtain a new item.", true);
}

View File

@ -115,7 +115,7 @@ export const Scripts: ModdedBattleScriptsData = {
},
setItem(item, source, effect) {
if (!this.hp || !this.isActive) return false;
if (this.itemState.knockedOff) return false;
if (this.itemKnockedOff) return false;
if (typeof item === 'string') item = this.battle.dex.items.get(item);
const effectid = this.battle.effect ? this.battle.effect.id : '';

View File

@ -15364,6 +15364,7 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = {
if (pokemon.item || !pokemon.lastItem) return false;
const item = pokemon.lastItem;
pokemon.lastItem = '';
pokemon.itemKnockedOff = false; // Gens 3-4 only
this.add('-item', pokemon, this.dex.items.get(item), '[from] move: Recycle');
pokemon.setItem(item, source, move);
},

View File

@ -123,6 +123,8 @@ export class Pokemon {
lastItem: ID;
usedItemThisTurn: boolean;
ateBerry: boolean;
// Gens 3-4 only
itemKnockedOff: boolean;
trapped: boolean | "hidden";
maybeTrapped: boolean;
@ -419,6 +421,7 @@ export class Pokemon {
this.lastItem = '';
this.usedItemThisTurn = false;
this.ateBerry = false;
this.itemKnockedOff = false;
this.trapped = false;
this.maybeTrapped = false;
@ -865,7 +868,7 @@ export class Pokemon {
ignoringItem(isFling = false) {
if (this.getItem().isPrimalOrb) return false;
if (this.itemState.knockedOff) return true; // Gen 3-4
if (this.itemKnockedOff) return true; // Gen 3-4
if (this.battle.gen >= 5 && !this.isActive) return true;
if (this.volatiles['embargo'] || this.battle.field.pseudoWeather['magicroom']) return true;
// check Fling first to avoid infinite recursion
@ -1736,7 +1739,7 @@ export class Pokemon {
}
eatItem(force?: boolean, source?: Pokemon, sourceEffect?: Effect) {
if (!this.item || this.itemState.knockedOff) return false;
if (!this.item || this.itemKnockedOff) return false;
if ((!this.hp && this.item !== 'jabocaberry' && this.item !== 'rowapberry') || !this.isActive) return false;
if (!sourceEffect && this.battle.effect) sourceEffect = this.battle.effect;
@ -1780,7 +1783,7 @@ export class Pokemon {
useItem(source?: Pokemon, sourceEffect?: Effect) {
if ((!this.hp && !this.getItem().isGem) || !this.isActive) return false;
if (!this.item || this.itemState.knockedOff) return false;
if (!this.item || this.itemKnockedOff) return false;
if (!sourceEffect && this.battle.effect) sourceEffect = this.battle.effect;
if (!source && this.battle.event?.target) source = this.battle.event.target;
@ -1819,7 +1822,7 @@ export class Pokemon {
}
takeItem(source?: Pokemon) {
if (!this.item || this.itemState.knockedOff) return false;
if (!this.item || this.itemKnockedOff) return false;
if (!source) source = this;
if (this.battle.gen === 4) {
if (toID(this.ability) === 'multitype') return false;
@ -1840,8 +1843,7 @@ export class Pokemon {
setItem(item: string | Item, source?: Pokemon, effect?: Effect) {
if (!this.hp || !this.isActive) return false;
if (this.itemState.knockedOff && !(effect?.id === 'recycle')) return false;
delete this.itemState.knockedOff;
if (this.itemKnockedOff) return false;
if (typeof item === 'string') item = this.battle.dex.items.get(item);
const effectid = this.battle.effect ? this.battle.effect.id : '';