[Bug] Fix Grip Claw sometimes stealing from the wrong enemy (#2766)
* Fix Grip Claw stealing from the wrong enemy * Document held item transfer modifiers
This commit is contained in:
parent
dad065cbae
commit
126174efe4
|
@ -2116,14 +2116,38 @@ export class SwitchEffectTransferModifier extends PokemonHeldItemModifier {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class for held items that steal other Pokemon's items.
|
||||
* @see {@linkcode TurnHeldItemTransferModifier}
|
||||
* @see {@linkcode ContactHeldItemTransferChanceModifier}
|
||||
*/
|
||||
export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier {
|
||||
constructor(type: ModifierType, pokemonId: integer, stackCount?: integer) {
|
||||
super(type, pokemonId, stackCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the targets to transfer items from when this applies.
|
||||
* @param args\[0\] the {@linkcode Pokemon} holding this item
|
||||
* @returns the opponents of the source {@linkcode Pokemon}
|
||||
*/
|
||||
getTargets(args: any[]): Pokemon[] {
|
||||
const pokemon = args[0];
|
||||
|
||||
return pokemon instanceof Pokemon
|
||||
? pokemon.getOpponents()
|
||||
: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Steals an item from a set of target Pokemon.
|
||||
* This prioritizes high-tier held items when selecting the item to steal.
|
||||
* @param args \[0\] The {@linkcode Pokemon} holding this item
|
||||
* @returns true if an item was stolen; false otherwise.
|
||||
*/
|
||||
apply(args: any[]): boolean {
|
||||
const pokemon = args[0] as Pokemon;
|
||||
const opponents = pokemon.getOpponents();
|
||||
const opponents = this.getTargets(args);
|
||||
|
||||
if (!opponents.length) {
|
||||
return false;
|
||||
|
@ -2180,6 +2204,11 @@ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier {
|
|||
abstract getTransferMessage(pokemon: Pokemon, targetPokemon: Pokemon, item: ModifierTypes.ModifierType): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier for held items that steal items from the enemy at the end of
|
||||
* each turn.
|
||||
* @see {@linkcode modifierTypes[MINI_BLACK_HOLE]}
|
||||
*/
|
||||
export class TurnHeldItemTransferModifier extends HeldItemTransferModifier {
|
||||
constructor(type: ModifierType, pokemonId: integer, stackCount?: integer) {
|
||||
super(type, pokemonId, stackCount);
|
||||
|
@ -2210,6 +2239,12 @@ export class TurnHeldItemTransferModifier extends HeldItemTransferModifier {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifier for held items that add a chance to steal items from the target of a
|
||||
* successful attack.
|
||||
* @see {@linkcode modifierTypes[GRIP_CLAW]}
|
||||
* @see {@linkcode HeldItemTransferModifier}
|
||||
*/
|
||||
export class ContactHeldItemTransferChanceModifier extends HeldItemTransferModifier {
|
||||
private chance: number;
|
||||
|
||||
|
@ -2219,6 +2254,20 @@ export class ContactHeldItemTransferChanceModifier extends HeldItemTransferModif
|
|||
this.chance = chancePercent / 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the target to steal items from when this applies.
|
||||
* @param args\[0\] The {@linkcode Pokemon} holding this item
|
||||
* @param args\[1\] The {@linkcode Pokemon} the holder is targeting with an attack
|
||||
* @returns The target (args[1]) stored in array format for use in {@linkcode HeldItemTransferModifier.apply}
|
||||
*/
|
||||
getTargets(args: any[]): Pokemon[] {
|
||||
const target = args[1];
|
||||
|
||||
return target instanceof Pokemon
|
||||
? [ target ]
|
||||
: [];
|
||||
}
|
||||
|
||||
matchType(modifier: Modifier): boolean {
|
||||
return modifier instanceof ContactHeldItemTransferChanceModifier;
|
||||
}
|
||||
|
|
|
@ -2966,7 +2966,7 @@ export class MoveEffectPhase extends PokemonPhase {
|
|||
})).then(() => {
|
||||
applyPostAttackAbAttrs(PostAttackAbAttr, user, target, this.move.getMove(), hitResult).then(() => {
|
||||
if (this.move.getMove() instanceof AttackMove) {
|
||||
this.scene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target.getFieldIndex());
|
||||
this.scene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import Phase from "phaser";
|
||||
import GameManager from "#app/test/utils/gameManager";
|
||||
import * as overrides from "#app/overrides";
|
||||
import { Moves } from "#app/enums/moves.js";
|
||||
import { Species } from "#app/enums/species.js";
|
||||
import { BerryType } from "#app/enums/berry-type.js";
|
||||
import { Abilities } from "#app/enums/abilities.js";
|
||||
import { getMovePosition } from "../utils/gameManagerUtils";
|
||||
import { CommandPhase, MoveEndPhase, SelectTargetPhase } from "#app/phases.js";
|
||||
import { BattlerIndex } from "#app/battle.js";
|
||||
import { allMoves } from "#app/data/move.js";
|
||||
|
||||
const TIMEOUT = 20 * 1000; // 20 seconds
|
||||
|
||||
describe("Items - Grip Claw", () => {
|
||||
let phaserGame: Phaser.Game;
|
||||
let game: GameManager;
|
||||
|
||||
beforeAll(() => {
|
||||
phaserGame = new Phase.Game({
|
||||
type: Phaser.HEADLESS,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
game.phaseInterceptor.restoreOg();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
game = new GameManager(phaserGame);
|
||||
|
||||
vi.spyOn(overrides, "DOUBLE_BATTLE_OVERRIDE", "get").mockReturnValue(true);
|
||||
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.POPULATION_BOMB, Moves.SPLASH ]);
|
||||
vi.spyOn(overrides, "STARTING_HELD_ITEMS_OVERRIDE", "get").mockReturnValue([{name: "GRIP_CLAW", count: 5}, {name: "MULTI_LENS", count: 3}]);
|
||||
vi.spyOn(overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.SNORLAX);
|
||||
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.KLUTZ);
|
||||
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([ Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH ]);
|
||||
vi.spyOn(overrides, "OPP_HELD_ITEMS_OVERRIDE", "get").mockReturnValue([
|
||||
{name: "BERRY", type: BerryType.SITRUS, count: 2},
|
||||
{name: "BERRY", type: BerryType.LUM, count: 2}
|
||||
]);
|
||||
vi.spyOn(overrides, "STARTING_LEVEL_OVERRIDE", "get").mockReturnValue(100);
|
||||
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(100);
|
||||
|
||||
vi.spyOn(allMoves[Moves.POPULATION_BOMB], "accuracy", "get").mockReturnValue(100);
|
||||
});
|
||||
|
||||
it(
|
||||
"should only steal items from the attack target",
|
||||
async () => {
|
||||
await game.startBattle([Species.PANSEAR, Species.ROWLET, Species.PANPOUR, Species.PANSAGE, Species.CHARMANDER, Species.SQUIRTLE]);
|
||||
|
||||
const playerPokemon = game.scene.getPlayerField();
|
||||
playerPokemon.forEach(p => expect(p).toBeDefined());
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyField();
|
||||
enemyPokemon.forEach(p => expect(p).toBeDefined());
|
||||
|
||||
const enemyHeldItemCt = enemyPokemon.map(p => p.getHeldItems.length);
|
||||
|
||||
game.doAttack(getMovePosition(game.scene, 0, Moves.POPULATION_BOMB));
|
||||
|
||||
await game.phaseInterceptor.to(SelectTargetPhase, false);
|
||||
game.doSelectTarget(BattlerIndex.ENEMY);
|
||||
|
||||
await game.phaseInterceptor.to(CommandPhase, false);
|
||||
game.doAttack(getMovePosition(game.scene, 1, Moves.SPLASH));
|
||||
|
||||
await game.phaseInterceptor.to(MoveEndPhase, false);
|
||||
|
||||
expect(enemyPokemon[1].getHeldItems.length).toBe(enemyHeldItemCt[1]);
|
||||
}, TIMEOUT
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue