mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-19 22:09:27 +02:00
Moved getSecondaryChanceMultiplier to FlinchChanceModifier and revised Serene Grace tests
This commit is contained in:
parent
3cc4425aa2
commit
5c2922c22b
@ -726,22 +726,6 @@ export abstract class PokemonHeldItemModifier extends PersistentModifier {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Applies to items with chance of activating secondary effects ie Kings Rock
|
|
||||||
getSecondaryChanceMultiplier(pokemon: Pokemon): number {
|
|
||||||
// Temporary quickfix to stop game from freezing when the opponet uses u-turn while holding on to king's rock
|
|
||||||
if (!pokemon.getLastXMoves()[0]) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
const sheerForceAffected = allMoves[pokemon.getLastXMoves()[0].move].chance >= 0 && pokemon.hasAbility(Abilities.SHEER_FORCE);
|
|
||||||
|
|
||||||
if (sheerForceAffected) {
|
|
||||||
return 0;
|
|
||||||
} else if (pokemon.hasAbility(Abilities.SERENE_GRACE)) {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
getMaxStackCount(scene: BattleScene, forThreshold?: boolean): number {
|
getMaxStackCount(scene: BattleScene, forThreshold?: boolean): number {
|
||||||
const pokemon = this.getPokemon(scene);
|
const pokemon = this.getPokemon(scene);
|
||||||
if (!pokemon) {
|
if (!pokemon) {
|
||||||
@ -1615,8 +1599,11 @@ export class BypassSpeedChanceModifier extends PokemonHeldItemModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class FlinchChanceModifier extends PokemonHeldItemModifier {
|
export class FlinchChanceModifier extends PokemonHeldItemModifier {
|
||||||
|
private chance: number;
|
||||||
constructor(type: ModifierType, pokemonId: number, stackCount?: number) {
|
constructor(type: ModifierType, pokemonId: number, stackCount?: number) {
|
||||||
super(type, pokemonId, stackCount);
|
super(type, pokemonId, stackCount);
|
||||||
|
|
||||||
|
this.chance = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
matchType(modifier: Modifier) {
|
matchType(modifier: Modifier) {
|
||||||
@ -1637,6 +1624,18 @@ export class FlinchChanceModifier extends PokemonHeldItemModifier {
|
|||||||
return super.shouldApply(pokemon, flinched) && !!flinched;
|
return super.shouldApply(pokemon, flinched) && !!flinched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for any chance modifying abilities
|
||||||
|
* @param pokemon
|
||||||
|
* @returns `2` if the pokemon involved has a Serene Grace-like ability | `1` if it does not
|
||||||
|
*/
|
||||||
|
getSecondaryChanceMultiplier(pokemon: Pokemon): number {
|
||||||
|
if (pokemon.hasAbility(Abilities.SERENE_GRACE)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies {@linkcode FlinchChanceModifier}
|
* Applies {@linkcode FlinchChanceModifier}
|
||||||
* @param pokemon the {@linkcode Pokemon} that holds the item
|
* @param pokemon the {@linkcode Pokemon} that holds the item
|
||||||
@ -1644,7 +1643,9 @@ export class FlinchChanceModifier extends PokemonHeldItemModifier {
|
|||||||
* @returns `true` if {@linkcode FlinchChanceModifier} has been applied
|
* @returns `true` if {@linkcode FlinchChanceModifier} has been applied
|
||||||
*/
|
*/
|
||||||
override apply(pokemon: Pokemon, flinched: BooleanHolder): boolean {
|
override apply(pokemon: Pokemon, flinched: BooleanHolder): boolean {
|
||||||
if (!flinched.value && pokemon.randSeedInt(10) < (this.getStackCount() * this.getSecondaryChanceMultiplier(pokemon))) {
|
// The check for pokemon.battleSummonData is to ensure that a crash doesn't occur when a Pokemon with King's Rock procs a flinch
|
||||||
|
const secondaryChanceMultiplier = pokemon.battleSummonData ? this.getSecondaryChanceMultiplier(pokemon) : 1;
|
||||||
|
if (!flinched.value && pokemon.randSeedInt(100) < (this.getStackCount() * secondaryChanceMultiplier * this.chance)) {
|
||||||
flinched.value = true;
|
flinched.value = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { BattlerIndex } from "#app/battle";
|
import { BattlerIndex } from "#app/battle";
|
||||||
import { applyAbAttrs, MoveEffectChanceMultiplierAbAttr } from "#app/data/ability";
|
|
||||||
import { Stat } from "#enums/stat";
|
|
||||||
import { MoveEffectPhase } from "#app/phases/move-effect-phase";
|
|
||||||
import * as Utils from "#app/utils";
|
|
||||||
import { Abilities } from "#enums/abilities";
|
import { Abilities } from "#enums/abilities";
|
||||||
import { Moves } from "#enums/moves";
|
import { Moves } from "#enums/moves";
|
||||||
import { Species } from "#enums/species";
|
import { Species } from "#enums/species";
|
||||||
import GameManager from "#test/utils/gameManager";
|
import GameManager from "#test/utils/gameManager";
|
||||||
import Phaser from "phaser";
|
import Phaser from "phaser";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
import { allMoves } from "#app/data/move";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { FlinchAttr } from "#app/data/move";
|
||||||
|
import { FlinchChanceModifier } from "#app/modifier/modifier";
|
||||||
|
|
||||||
|
|
||||||
describe("Abilities - Serene Grace", () => {
|
describe("Abilities - Serene Grace", () => {
|
||||||
@ -27,66 +26,42 @@ describe("Abilities - Serene Grace", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
game = new GameManager(phaserGame);
|
game = new GameManager(phaserGame);
|
||||||
const movesToUse = [ Moves.AIR_SLASH, Moves.TACKLE ];
|
game.override
|
||||||
game.override.battleType("single");
|
.ability(Abilities.SERENE_GRACE)
|
||||||
game.override.enemySpecies(Species.ONIX);
|
.moveset([ Moves.AIR_SLASH, Moves.TACKLE ])
|
||||||
game.override.startingLevel(100);
|
.enemyLevel(10)
|
||||||
game.override.moveset(movesToUse);
|
.enemyMoveset([ Moves.SPLASH ]);
|
||||||
game.override.enemyMoveset([ Moves.TACKLE, Moves.TACKLE, Moves.TACKLE, Moves.TACKLE ]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Move chance without Serene Grace", async () => {
|
it("Serene Grace should double the secondary effect chance of a move", async () => {
|
||||||
const moveToUse = Moves.AIR_SLASH;
|
await game.classicMode.startBattle([ Species.SHUCKLE ]);
|
||||||
await game.startBattle([
|
|
||||||
Species.PIDGEOT
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
const airSlashMove = allMoves[Moves.AIR_SLASH];
|
||||||
|
const airSlashFlinchAttr = airSlashMove.getAttrs(FlinchAttr)[0];
|
||||||
|
vi.spyOn(airSlashFlinchAttr, "getMoveChance");
|
||||||
|
|
||||||
game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000;
|
game.move.select(Moves.AIR_SLASH);
|
||||||
expect(game.scene.getPlayerParty()[0].formIndex).toBe(0);
|
|
||||||
|
|
||||||
game.move.select(moveToUse);
|
|
||||||
|
|
||||||
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
|
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
|
||||||
await game.phaseInterceptor.to(MoveEffectPhase, false);
|
await game.move.forceHit();
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
// Check chance of Air Slash without Serene Grace
|
expect(airSlashFlinchAttr.getMoveChance).toHaveLastReturnedWith(60);
|
||||||
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
|
});
|
||||||
const move = phase.move.getMove();
|
|
||||||
expect(move.id).toBe(Moves.AIR_SLASH);
|
|
||||||
|
|
||||||
const chance = new Utils.IntegerHolder(move.chance);
|
it("Serene Grace should double the chance of King Rock's activating", async () => {
|
||||||
console.log(move.chance + " Their ability is " + phase.getUserPokemon()!.getAbility().name);
|
game.override
|
||||||
applyAbAttrs(MoveEffectChanceMultiplierAbAttr, phase.getUserPokemon()!, null, false, chance, move, phase.getFirstTarget(), false);
|
.startingHeldItems([{ name: "KINGS_ROCK", count: 1 }]);
|
||||||
expect(chance.value).toBe(30);
|
|
||||||
|
|
||||||
}, 20000);
|
await game.classicMode.startBattle([ Species.SHUCKLE ]);
|
||||||
|
|
||||||
it("Move chance with Serene Grace", async () => {
|
const kingsRockInstance = game.scene.findModifier(m => m instanceof FlinchChanceModifier) as FlinchChanceModifier;
|
||||||
const moveToUse = Moves.AIR_SLASH;
|
vi.spyOn(kingsRockInstance, "getSecondaryChanceMultiplier");
|
||||||
game.override.ability(Abilities.SERENE_GRACE);
|
|
||||||
await game.startBattle([
|
|
||||||
Species.TOGEKISS
|
|
||||||
]);
|
|
||||||
|
|
||||||
game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000;
|
|
||||||
expect(game.scene.getPlayerParty()[0].formIndex).toBe(0);
|
|
||||||
|
|
||||||
game.move.select(moveToUse);
|
|
||||||
|
|
||||||
|
game.move.select(Moves.TACKLE);
|
||||||
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
|
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
|
||||||
await game.phaseInterceptor.to(MoveEffectPhase, false);
|
await game.move.forceHit();
|
||||||
|
await game.phaseInterceptor.to("BerryPhase");
|
||||||
|
|
||||||
// Check chance of Air Slash with Serene Grace
|
expect(kingsRockInstance.getSecondaryChanceMultiplier).toHaveLastReturnedWith(2);
|
||||||
const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
|
});
|
||||||
const move = phase.move.getMove();
|
|
||||||
expect(move.id).toBe(Moves.AIR_SLASH);
|
|
||||||
|
|
||||||
const chance = new Utils.IntegerHolder(move.chance);
|
|
||||||
applyAbAttrs(MoveEffectChanceMultiplierAbAttr, phase.getUserPokemon()!, null, false, chance, move, phase.getFirstTarget(), false);
|
|
||||||
expect(chance.value).toBe(60);
|
|
||||||
|
|
||||||
}, 20000);
|
|
||||||
|
|
||||||
//TODO King's Rock Interaction Unit Test
|
|
||||||
});
|
});
|
||||||
|
@ -152,6 +152,4 @@ describe("Abilities - Sheer Force", () => {
|
|||||||
await game.phaseInterceptor.to("TurnEndPhase");
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
expect(formKeyStart).toBe(playerPokemon?.getFormKey());
|
expect(formKeyStart).toBe(playerPokemon?.getFormKey());
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO King's Rock Interaction Unit Test
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user