implement partingshot to pass tests - TODO figure out dup msg queue

This commit is contained in:
DustinLin 2024-08-15 13:55:08 -04:00
parent 07201ad8f4
commit 91976fc0c2
2 changed files with 54 additions and 11 deletions

View File

@ -4877,6 +4877,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
// Check if the move category is not STATUS or if the switch out condition is not met
if (!this.getSwitchOutCondition()(user, target, move)) {
console.log("switching out condition is false in the apply");
return resolve(false);
}
@ -4885,6 +4886,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
const switchOutTarget = this.user ? user : target;
if (switchOutTarget instanceof PlayerPokemon) {
switchOutTarget.leaveField(!this.batonPass);
console.log("switching out , what isgoing on here");
if (switchOutTarget.hp > 0) {
user.scene.prependToPhase(new SwitchPhase(user.scene, switchOutTarget.getFieldIndex(), true, true), MoveEndPhase);
@ -4977,6 +4979,47 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
}
}
/**
* Attr used by parting shot, it is a combo of ForceSwitchOut and StatChange with a special getCondition()
*/
export class PartingShotAttr extends ForceSwitchOutAttr {
private statChange: StatChangeAttr;
private canLowerStats: boolean;
constructor(user?: boolean, batonPass?: boolean) {
super(user, batonPass);
this.statChange = new StatChangeAttr([ BattleStat.ATK, BattleStat.SPATK ], -1, false, null, true, true, MoveEffectTrigger.PRE_APPLY);
this.canLowerStats = true;
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
// apply stat change, conditionally apply switch-out
this.statChange.apply(user, target, move, args);
if (this.canLowerStats) {
return super.apply(user, target, move, args);
} else {
return new Promise(resolve => {
resolve(false);
});
}
}
getCondition(): MoveConditionFunc {
return (user, target, move) => {
// conditions on if move should fail or not don't depend on if user is able to switch
// getCondition() is called before move is applied: move will only switch out if canLowerStats
if (target.hasAbility(Abilities.CLEAR_BODY, true, false) ||
(target.summonData.battleStats[0] === -6 && target.summonData.battleStats[2] === -6) || target.scene.arena.findTagsOnSide(t => t.tagType === ArenaTagType.MIST, ArenaTagSide.ENEMY).length > 0
) {
this.canLowerStats = false;
} else {
this.canLowerStats = true;
}
return true;
};
}
}
export class RemoveTypeAttr extends MoveEffectAttr {
private removedType: Type;
@ -7760,9 +7803,9 @@ export function initMoves() {
.soundBased()
.target(MoveTarget.ALL_NEAR_ENEMIES),
new StatusMove(Moves.PARTING_SHOT, Type.DARK, 100, 20, -1, 0, 6)
.attr(StatChangeAttr, [ BattleStat.ATK, BattleStat.SPATK ], -1, false, null, true, true, MoveEffectTrigger.PRE_APPLY)
.attr(ForceSwitchOutAttr, true, false)
.attr(PartingShotAttr, true, false)
.soundBased(),
new StatusMove(Moves.TOPSY_TURVY, Type.DARK, -1, 20, -1, 0, 6)
.attr(InvertStatsAttr),
new AttackMove(Moves.DRAINING_KISS, Type.FAIRY, MoveCategory.SPECIAL, 50, 100, 10, -1, 0, 6)

View File

@ -4,7 +4,7 @@ import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, test, it } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, test } from "vitest";
import GameManager from "../utils/gameManager";
import { getMovePosition } from "../utils/gameManagerUtils";
import { BattleStat } from "#app/data/battle-stat";
@ -77,8 +77,8 @@ describe("Moves - Parting Shot", () => {
}, TIMEOUT
);
it.skip( // TODO: fix this bug to pass the test!
"Parting shot should fail if target is -6/-6 de-buffed",
test(
"Parting shot should not switch out if target is -6/-6 de-buffed",
async () => {
game.override.moveset([Moves.PARTING_SHOT, Moves.MEMENTO, Moves.SPLASH]);
await game.startBattle([Species.MEOWTH, Species.MEOWTH, Species.MEOWTH, Species.MURKROW, Species.ABRA]);
@ -120,7 +120,7 @@ describe("Moves - Parting Shot", () => {
}, TIMEOUT
);
it.skip( // TODO: fix this bug to pass the test!
test(
"Parting shot shouldn't allow switch out when mist is active",
async () => {
game.override
@ -138,11 +138,11 @@ describe("Moves - Parting Shot", () => {
const battleStatsOpponent = enemyPokemon.summonData.battleStats;
expect(battleStatsOpponent[BattleStat.ATK]).toBe(0);
expect(battleStatsOpponent[BattleStat.SPATK]).toBe(0);
expect(game.scene.getPlayerField()[0].species.speciesId).toBe(Species.MURKROW);
expect(game.scene.getPlayerField()[0].species.speciesId).toBe(Species.SNORLAX);
}, TIMEOUT
);
it.skip( // TODO: fix this bug to pass the test!
test(
"Parting shot shouldn't allow switch out against clear body ability",
async () => {
game.override
@ -159,11 +159,11 @@ describe("Moves - Parting Shot", () => {
const battleStatsOpponent = enemyPokemon.summonData.battleStats;
expect(battleStatsOpponent[BattleStat.ATK]).toBe(0);
expect(battleStatsOpponent[BattleStat.SPATK]).toBe(0);
expect(game.scene.getPlayerField()[0].species.speciesId).toBe(Species.MURKROW);
expect(game.scene.getPlayerField()[0].species.speciesId).toBe(Species.SNORLAX);
}, TIMEOUT
);
it.skip( // TODO: fix this bug to pass the test!
test(
"Parting shot should de-buff and not fail if no party available to switch - party size 1",
async () => {
await game.startBattle([Species.MURKROW]);
@ -181,7 +181,7 @@ describe("Moves - Parting Shot", () => {
}, TIMEOUT
);
it.skip( // TODO: fix this bug to pass the test!
test(
"Parting shot regularly not fail if no party available to switch - party fainted",
async () => {
await game.startBattle([Species.MURKROW, Species.MEOWTH]);