[P1 Bug] Fix infinite recursion from abilities disabled by Sheer Force (#4631)

This commit is contained in:
PigeonBar 2024-10-10 11:28:26 -04:00 committed by GitHub
parent f180b6070e
commit ca3cc3c9c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View File

@ -1417,10 +1417,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* @returns {boolean} Whether the ability is present and active
*/
hasAbility(ability: Abilities, canApply: boolean = true, ignoreOverride?: boolean): boolean {
if ((!canApply || this.canApplyAbility()) && this.getAbility(ignoreOverride).id === ability) {
if (this.getAbility(ignoreOverride).id === ability && (!canApply || this.canApplyAbility())) {
return true;
}
if (this.hasPassive() && (!canApply || this.canApplyAbility(true)) && this.getPassiveAbility().id === ability) {
if (this.getPassiveAbility().id === ability && this.hasPassive() && (!canApply || this.canApplyAbility(true))) {
return true;
}
return false;

View File

@ -9,6 +9,7 @@ import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { allMoves } from "#app/data/move";
describe("Abilities - Sheer Force", () => {
@ -174,5 +175,31 @@ describe("Abilities - Sheer Force", () => {
}, 20000);
it("Two Pokemon with abilities disabled by Sheer Force hitting each other should not cause a crash", async () => {
const moveToUse = Moves.CRUNCH;
game.override.enemyAbility(Abilities.COLOR_CHANGE)
.ability(Abilities.COLOR_CHANGE)
.moveset(moveToUse)
.enemyMoveset(moveToUse);
await game.classicMode.startBattle([
Species.PIDGEOT
]);
const pidgeot = game.scene.getParty()[0];
const onix = game.scene.getEnemyParty()[0];
pidgeot.stats[Stat.DEF] = 10000;
onix.stats[Stat.DEF] = 10000;
game.move.select(moveToUse);
await game.toNextTurn();
// Check that both Pokemon's Color Change activated
const expectedTypes = [ allMoves[moveToUse].type ];
expect(pidgeot.getTypes()).toStrictEqual(expectedTypes);
expect(onix.getTypes()).toStrictEqual(expectedTypes);
});
//TODO King's Rock Interaction Unit Test
});