[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.
|
* Steals an item from a set of target Pokemon.
|
||||||
* This prioritizes high-tier held items when selecting the item to steal.
|
* This prioritizes high-tier held items when selecting the item to steal.
|
||||||
* @param pokemon The {@linkcode Pokemon} holding this item
|
* @param pokemon The {@linkcode Pokemon} holding this item
|
||||||
|
* @param target The {@linkcode Pokemon} to steal from (optional)
|
||||||
* @param _args N/A
|
* @param _args N/A
|
||||||
* @returns `true` if an item was stolen; false otherwise.
|
* @returns `true` if an item was stolen; false otherwise.
|
||||||
*/
|
*/
|
||||||
override apply(pokemon: Pokemon, ..._args: unknown[]): boolean {
|
override apply(pokemon: Pokemon, target?: Pokemon, ..._args: unknown[]): boolean {
|
||||||
const opponents = this.getTargets(pokemon);
|
const opponents = this.getTargets(pokemon, target);
|
||||||
|
|
||||||
if (!opponents.length) {
|
if (!opponents.length) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -3187,7 +3188,7 @@ export class TurnHeldItemTransferModifier extends HeldItemTransferModifier {
|
||||||
* @see {@linkcode HeldItemTransferModifier}
|
* @see {@linkcode HeldItemTransferModifier}
|
||||||
*/
|
*/
|
||||||
export class ContactHeldItemTransferChanceModifier extends HeldItemTransferModifier {
|
export class ContactHeldItemTransferChanceModifier extends HeldItemTransferModifier {
|
||||||
private chance: number;
|
public readonly chance: number;
|
||||||
|
|
||||||
constructor(type: ModifierType, pokemonId: number, chancePercent: number, stackCount?: number) {
|
constructor(type: ModifierType, pokemonId: number, chancePercent: number, stackCount?: number) {
|
||||||
super(type, pokemonId, stackCount);
|
super(type, pokemonId, stackCount);
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
import { BattlerIndex } from "#app/battle";
|
import { BattlerIndex } from "#app/battle";
|
||||||
import { allMoves } from "#app/data/move";
|
import Pokemon from "#app/field/pokemon";
|
||||||
import { Abilities } from "#app/enums/abilities";
|
import { ContactHeldItemTransferChanceModifier } from "#app/modifier/modifier";
|
||||||
import { BerryType } from "#app/enums/berry-type";
|
import { Abilities } from "#enums/abilities";
|
||||||
import { Moves } from "#app/enums/moves";
|
import { BerryType } from "#enums/berry-type";
|
||||||
import { Species } from "#app/enums/species";
|
import { Moves } from "#enums/moves";
|
||||||
import { MoveEndPhase } from "#app/phases/move-end-phase";
|
import { Species } from "#enums/species";
|
||||||
import GameManager from "#test/utils/gameManager";
|
import GameManager from "#test/utils/gameManager";
|
||||||
import Phase from "phaser";
|
import Phase from "phaser";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
// 20 seconds
|
|
||||||
|
|
||||||
describe("Items - Grip Claw", () => {
|
describe("Items - Grip Claw", () => {
|
||||||
let phaserGame: Phaser.Game;
|
let phaserGame: Phaser.Game;
|
||||||
let game: GameManager;
|
let game: GameManager;
|
||||||
|
@ -30,39 +28,85 @@ describe("Items - Grip Claw", () => {
|
||||||
|
|
||||||
game.override
|
game.override
|
||||||
.battleType("double")
|
.battleType("double")
|
||||||
.moveset([ Moves.POPULATION_BOMB, Moves.SPLASH ])
|
.moveset([ Moves.TACKLE, Moves.SPLASH, Moves.ATTRACT ])
|
||||||
.startingHeldItems([
|
.startingHeldItems([
|
||||||
{ name: "GRIP_CLAW", count: 5 }, // TODO: Find a way to mock the steal chance of grip claw
|
{ name: "GRIP_CLAW", count: 1 },
|
||||||
{ name: "MULTI_LENS", count: 3 },
|
|
||||||
])
|
])
|
||||||
.enemySpecies(Species.SNORLAX)
|
.enemySpecies(Species.SNORLAX)
|
||||||
.ability(Abilities.KLUTZ)
|
.enemyAbility(Abilities.UNNERVE)
|
||||||
|
.ability(Abilities.UNNERVE)
|
||||||
.enemyMoveset(Moves.SPLASH)
|
.enemyMoveset(Moves.SPLASH)
|
||||||
.enemyHeldItems([
|
.enemyHeldItems([
|
||||||
{ name: "BERRY", type: BerryType.SITRUS, count: 2 },
|
{ name: "BERRY", type: BerryType.SITRUS, count: 2 },
|
||||||
{ name: "BERRY", type: BerryType.LUM, count: 2 },
|
{ name: "BERRY", type: BerryType.LUM, count: 2 },
|
||||||
])
|
])
|
||||||
.startingLevel(100)
|
|
||||||
.enemyLevel(100);
|
.enemyLevel(100);
|
||||||
|
|
||||||
vi.spyOn(allMoves[Moves.POPULATION_BOMB], "accuracy", "get").mockReturnValue(100);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(
|
it("should steal items on contact and only from the attack target", async () => {
|
||||||
"should only steal items from the attack target",
|
await game.classicMode.startBattle([ Species.FEEBAS, Species.MILOTIC ]);
|
||||||
async () => {
|
|
||||||
await game.startBattle([ Species.PANSEAR, Species.ROWLET ]);
|
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 enemyPokemon = game.scene.getEnemyField();
|
||||||
|
|
||||||
const enemyHeldItemCt = enemyPokemon.map(p => p.getHeldItems.length);
|
const playerHeldItemCount = getHeldItemCount(playerPokemon);
|
||||||
|
const enemy1HeldItemCount = getHeldItemCount(enemyPokemon[0]);
|
||||||
|
const enemy2HeldItemCount = getHeldItemCount(enemyPokemon[1]);
|
||||||
|
expect(enemy2HeldItemCount).toBeGreaterThan(0);
|
||||||
|
|
||||||
game.move.select(Moves.POPULATION_BOMB, 0, BattlerIndex.ENEMY);
|
game.move.select(Moves.TACKLE, 0, BattlerIndex.ENEMY_2);
|
||||||
game.move.select(Moves.SPLASH, 1);
|
game.move.select(Moves.SPLASH, 1);
|
||||||
|
|
||||||
await game.phaseInterceptor.to(MoveEndPhase, false);
|
await game.phaseInterceptor.to("BerryPhase", false);
|
||||||
|
|
||||||
expect(enemyPokemon[1].getHeldItems.length).toBe(enemyHeldItemCt[1]);
|
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