[Beta][P2] Fix Grip Claw (#4614)
* [Beta][P2] Fix Grip Claw * Add test for Grip Claw * [test] improve grip claw's test readability * PR feedback --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
parent
d8c914c768
commit
deb2035610
|
@ -3084,11 +3084,12 @@ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier {
|
|||
* Steals an item from a set of target Pokemon.
|
||||
* This prioritizes high-tier held items when selecting the item to steal.
|
||||
* @param pokemon The {@linkcode Pokemon} holding this item
|
||||
* @param target The {@linkcode Pokemon} to steal from (optional)
|
||||
* @param _args N/A
|
||||
* @returns `true` if an item was stolen; false otherwise.
|
||||
*/
|
||||
override apply(pokemon: Pokemon, ..._args: unknown[]): boolean {
|
||||
const opponents = this.getTargets(pokemon);
|
||||
override apply(pokemon: Pokemon, target?: Pokemon, ..._args: unknown[]): boolean {
|
||||
const opponents = this.getTargets(pokemon, target);
|
||||
|
||||
if (!opponents.length) {
|
||||
return false;
|
||||
|
@ -3187,7 +3188,7 @@ export class TurnHeldItemTransferModifier extends HeldItemTransferModifier {
|
|||
* @see {@linkcode HeldItemTransferModifier}
|
||||
*/
|
||||
export class ContactHeldItemTransferChanceModifier extends HeldItemTransferModifier {
|
||||
private chance: number;
|
||||
public readonly chance: number;
|
||||
|
||||
constructor(type: ModifierType, pokemonId: number, chancePercent: number, stackCount?: number) {
|
||||
super(type, pokemonId, stackCount);
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
import { BattlerIndex } from "#app/battle";
|
||||
import { allMoves } from "#app/data/move";
|
||||
import { Abilities } from "#app/enums/abilities";
|
||||
import { BerryType } from "#app/enums/berry-type";
|
||||
import { Moves } from "#app/enums/moves";
|
||||
import { Species } from "#app/enums/species";
|
||||
import { MoveEndPhase } from "#app/phases/move-end-phase";
|
||||
import Pokemon from "#app/field/pokemon";
|
||||
import { ContactHeldItemTransferChanceModifier } from "#app/modifier/modifier";
|
||||
import { Abilities } from "#enums/abilities";
|
||||
import { BerryType } from "#enums/berry-type";
|
||||
import { Moves } from "#enums/moves";
|
||||
import { Species } from "#enums/species";
|
||||
import GameManager from "#test/utils/gameManager";
|
||||
import Phase from "phaser";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// 20 seconds
|
||||
|
||||
describe("Items - Grip Claw", () => {
|
||||
let phaserGame: Phaser.Game;
|
||||
let game: GameManager;
|
||||
|
@ -30,39 +28,85 @@ describe("Items - Grip Claw", () => {
|
|||
|
||||
game.override
|
||||
.battleType("double")
|
||||
.moveset([ Moves.POPULATION_BOMB, Moves.SPLASH ])
|
||||
.moveset([ Moves.TACKLE, Moves.SPLASH, Moves.ATTRACT ])
|
||||
.startingHeldItems([
|
||||
{ name: "GRIP_CLAW", count: 5 }, // TODO: Find a way to mock the steal chance of grip claw
|
||||
{ name: "MULTI_LENS", count: 3 },
|
||||
{ name: "GRIP_CLAW", count: 1 },
|
||||
])
|
||||
.enemySpecies(Species.SNORLAX)
|
||||
.ability(Abilities.KLUTZ)
|
||||
.enemyAbility(Abilities.UNNERVE)
|
||||
.ability(Abilities.UNNERVE)
|
||||
.enemyMoveset(Moves.SPLASH)
|
||||
.enemyHeldItems([
|
||||
{ name: "BERRY", type: BerryType.SITRUS, count: 2 },
|
||||
{ name: "BERRY", type: BerryType.LUM, count: 2 },
|
||||
])
|
||||
.startingLevel(100)
|
||||
.enemyLevel(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 ]);
|
||||
it("should steal items on contact and only from the attack target", async () => {
|
||||
await game.classicMode.startBattle([ Species.FEEBAS, Species.MILOTIC ]);
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyField();
|
||||
const [ playerPokemon, ] = game.scene.getPlayerField();
|
||||
|
||||
const enemyHeldItemCt = enemyPokemon.map(p => p.getHeldItems.length);
|
||||
const gripClaw = playerPokemon.getHeldItems()[0] as ContactHeldItemTransferChanceModifier;
|
||||
vi.spyOn(gripClaw, "chance", "get").mockReturnValue(100);
|
||||
|
||||
game.move.select(Moves.POPULATION_BOMB, 0, BattlerIndex.ENEMY);
|
||||
game.move.select(Moves.SPLASH, 1);
|
||||
const enemyPokemon = game.scene.getEnemyField();
|
||||
|
||||
await game.phaseInterceptor.to(MoveEndPhase, false);
|
||||
const playerHeldItemCount = getHeldItemCount(playerPokemon);
|
||||
const enemy1HeldItemCount = getHeldItemCount(enemyPokemon[0]);
|
||||
const enemy2HeldItemCount = getHeldItemCount(enemyPokemon[1]);
|
||||
expect(enemy2HeldItemCount).toBeGreaterThan(0);
|
||||
|
||||
expect(enemyPokemon[1].getHeldItems.length).toBe(enemyHeldItemCt[1]);
|
||||
}
|
||||
);
|
||||
game.move.select(Moves.TACKLE, 0, BattlerIndex.ENEMY_2);
|
||||
game.move.select(Moves.SPLASH, 1);
|
||||
|
||||
await game.phaseInterceptor.to("BerryPhase", false);
|
||||
|
||||
const playerHeldItemCountAfter = getHeldItemCount(playerPokemon);
|
||||
const enemy1HeldItemCountsAfter = getHeldItemCount(enemyPokemon[0]);
|
||||
const enemy2HeldItemCountsAfter = getHeldItemCount(enemyPokemon[1]);
|
||||
|
||||
expect(playerHeldItemCountAfter).toBe(playerHeldItemCount + 1);
|
||||
expect(enemy1HeldItemCountsAfter).toBe(enemy1HeldItemCount);
|
||||
expect(enemy2HeldItemCountsAfter).toBe(enemy2HeldItemCount - 1);
|
||||
});
|
||||
|
||||
it("should not steal items when using a targetted, non attack move", async () => {
|
||||
await game.classicMode.startBattle([ Species.FEEBAS, Species.MILOTIC ]);
|
||||
|
||||
const [ playerPokemon, ] = game.scene.getPlayerField();
|
||||
|
||||
const gripClaw = playerPokemon.getHeldItems()[0] as ContactHeldItemTransferChanceModifier;
|
||||
vi.spyOn(gripClaw, "chance", "get").mockReturnValue(100);
|
||||
|
||||
const enemyPokemon = game.scene.getEnemyField();
|
||||
|
||||
const playerHeldItemCount = getHeldItemCount(playerPokemon);
|
||||
const enemy1HeldItemCount = getHeldItemCount(enemyPokemon[0]);
|
||||
const enemy2HeldItemCount = getHeldItemCount(enemyPokemon[1]);
|
||||
expect(enemy2HeldItemCount).toBeGreaterThan(0);
|
||||
|
||||
game.move.select(Moves.ATTRACT, 0, BattlerIndex.ENEMY_2);
|
||||
game.move.select(Moves.SPLASH, 1);
|
||||
|
||||
await game.phaseInterceptor.to("BerryPhase", false);
|
||||
|
||||
const playerHeldItemCountAfter = getHeldItemCount(playerPokemon);
|
||||
const enemy1HeldItemCountsAfter = getHeldItemCount(enemyPokemon[0]);
|
||||
const enemy2HeldItemCountsAfter = getHeldItemCount(enemyPokemon[1]);
|
||||
|
||||
expect(playerHeldItemCountAfter).toBe(playerHeldItemCount);
|
||||
expect(enemy1HeldItemCountsAfter).toBe(enemy1HeldItemCount);
|
||||
expect(enemy2HeldItemCountsAfter).toBe(enemy2HeldItemCount);
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* Gets the total number of items a Pokemon holds
|
||||
*/
|
||||
function getHeldItemCount(pokemon: Pokemon) {
|
||||
return pokemon.getHeldItems().reduce((currentTotal, item) => currentTotal + item.getStackCount(), 0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue