This commit is contained in:
Bertie690 2025-08-04 19:44:11 -04:00 committed by GitHub
commit da5dd43d75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 757 additions and 875 deletions

View File

@ -1945,19 +1945,34 @@ export class AddSubstituteAttr extends MoveEffectAttr {
* @see {@linkcode apply}
*/
export class HealAttr extends MoveEffectAttr {
/** The percentage of {@linkcode Stat.HP} to heal */
private healRatio: number;
/** Should an animation be shown? */
private showAnim: boolean;
/** The percentage of {@linkcode Stat.HP} to heal; default `1` */
protected healRatio = 1
/** Whether to display a healing animation upon healing the target; default `false` */
private showAnim = false
constructor(healRatio?: number, showAnim?: boolean, selfTarget?: boolean) {
super(selfTarget === undefined || selfTarget);
/**
* Whether the move should fail if the target is at full HP.
* @todo Remove post move failure rework
*/
private failOnFullHp = true;
this.healRatio = healRatio || 1;
this.showAnim = !!showAnim;
constructor(
healRatio = 1,
showAnim = false,
selfTarget = true,
failOnFullHp = true
) {
super(selfTarget);
this.healRatio = healRatio;
this.showAnim = showAnim
this.failOnFullHp = failOnFullHp
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (!super.apply(user, target, move, args)) {
return false;
}
this.addHealPhase(this.selfTarget ? user : target, this.healRatio);
return true;
}
@ -1966,15 +1981,74 @@ export class HealAttr extends MoveEffectAttr {
* Creates a new {@linkcode PokemonHealPhase}.
* This heals the target and shows the appropriate message.
*/
addHealPhase(target: Pokemon, healRatio: number) {
protected addHealPhase(target: Pokemon, healRatio: number) {
globalScene.phaseManager.unshiftNew("PokemonHealPhase", target.getBattlerIndex(),
toDmgValue(target.getMaxHp() * healRatio), i18next.t("moveTriggers:healHp", { pokemonName: getPokemonNameWithAffix(target) }), true, !this.showAnim);
}
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number {
override getTargetBenefitScore(user: Pokemon, target: Pokemon, _move: Move): number {
const score = ((1 - (this.selfTarget ? user : target).getHpRatio()) * 20) - this.healRatio * 10;
return Math.round(score / (1 - this.healRatio / 2));
}
override getCondition(): MoveConditionFunc {
return (user, target) => !(this.failOnFullHp && (this.selfTarget ? user : target).isFullHp());
}
override getFailedText(user: Pokemon, target: Pokemon): string | undefined {
const healedPokemon = (this.selfTarget ? user : target);
if (healedPokemon.isFullHp()) {
return i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(healedPokemon),
})
}
}
}
/**
* Attribute for moves with variable healing amounts.
* Heals the target by an amount depending on the return value of {@linkcode healFunc}.
*
* Used for:
* - {@linkcode MoveId.MOONLIGHT} and variants
* - {@linkcode MoveId.SHORE_UP}
* - {@linkcode MoveId.FLORAL_HEALING}
* - {@linkcode MoveId.SWALLOW}
*/
export class VariableHealAttr extends HealAttr {
constructor(
/** A function yielding the amount of HP to heal. */
private healFunc: (user: Pokemon, target: Pokemon, _move: Move) => number,
showAnim = false,
selfTarget = true,
) {
super(1, showAnim, selfTarget);
this.healFunc = healFunc;
}
apply(user: Pokemon, target: Pokemon, move: Move, _args: any[]): boolean {
this.healRatio = this.healFunc(user, target, move)
return super.apply(user, target, move, _args);
}
}
/**
* Heals the target only if it is an ally.
* Used for {@linkcode MoveId.POLLEN_PUFF}.
*/
export class HealOnAllyAttr extends HealAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (user.getAlly() === target) {
super.apply(user, target, move, args);
return true;
}
return false;
}
override getCondition(): MoveConditionFunc {
return (user, target, _move) => user.getAlly() !== target || super.getCondition()(user, target, _move)
}
}
/**
@ -2109,7 +2183,6 @@ export class SacrificialFullRestoreAttr extends SacrificialAttr {
false,
false,
true,
false,
this.restorePP),
true);
@ -2157,112 +2230,6 @@ export class IgnoreWeatherTypeDebuffAttr extends MoveAttr {
}
}
export abstract class WeatherHealAttr extends HealAttr {
constructor() {
super(0.5);
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
let healRatio = 0.5;
if (!globalScene.arena.weather?.isEffectSuppressed()) {
const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE;
healRatio = this.getWeatherHealRatio(weatherType);
}
this.addHealPhase(user, healRatio);
return true;
}
abstract getWeatherHealRatio(weatherType: WeatherType): number;
}
export class PlantHealAttr extends WeatherHealAttr {
getWeatherHealRatio(weatherType: WeatherType): number {
switch (weatherType) {
case WeatherType.SUNNY:
case WeatherType.HARSH_SUN:
return 2 / 3;
case WeatherType.RAIN:
case WeatherType.SANDSTORM:
case WeatherType.HAIL:
case WeatherType.SNOW:
case WeatherType.FOG:
case WeatherType.HEAVY_RAIN:
return 0.25;
default:
return 0.5;
}
}
}
export class SandHealAttr extends WeatherHealAttr {
getWeatherHealRatio(weatherType: WeatherType): number {
switch (weatherType) {
case WeatherType.SANDSTORM:
return 2 / 3;
default:
return 0.5;
}
}
}
/**
* Heals the target or the user by either {@linkcode normalHealRatio} or {@linkcode boostedHealRatio}
* depending on the evaluation of {@linkcode condition}
* @extends HealAttr
* @see {@linkcode apply}
*/
export class BoostHealAttr extends HealAttr {
/** Healing received when {@linkcode condition} is false */
private normalHealRatio: number;
/** Healing received when {@linkcode condition} is true */
private boostedHealRatio: number;
/** The lambda expression to check against when boosting the healing value */
private condition?: MoveConditionFunc;
constructor(normalHealRatio: number = 0.5, boostedHealRatio: number = 2 / 3, showAnim?: boolean, selfTarget?: boolean, condition?: MoveConditionFunc) {
super(normalHealRatio, showAnim, selfTarget);
this.normalHealRatio = normalHealRatio;
this.boostedHealRatio = boostedHealRatio;
this.condition = condition;
}
/**
* @param user {@linkcode Pokemon} using the move
* @param target {@linkcode Pokemon} target of the move
* @param move {@linkcode Move} with this attribute
* @param args N/A
* @returns true if the move was successful
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const healRatio: number = (this.condition ? this.condition(user, target, move) : false) ? this.boostedHealRatio : this.normalHealRatio;
this.addHealPhase(target, healRatio);
return true;
}
}
/**
* Heals the target only if it is the ally
* @extends HealAttr
* @see {@linkcode apply}
*/
export class HealOnAllyAttr extends HealAttr {
/**
* @param user {@linkcode Pokemon} using the move
* @param target {@linkcode Pokemon} target of the move
* @param move {@linkcode Move} with this attribute
* @param args N/A
* @returns true if the function succeeds
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (user.getAlly() === target) {
super.apply(user, target, move, args);
return true;
}
return false;
}
}
/**
* Heals user as a side effect of a move that hits a target.
* Healing is based on {@linkcode healRatio} * the amount of damage dealt or a stat of the target.
@ -4406,36 +4373,6 @@ export class SpitUpPowerAttr extends VariablePowerAttr {
}
}
/**
* Attribute used to apply Swallow's healing, which scales with Stockpile stacks.
* Does NOT remove stockpiled stacks.
*/
export class SwallowHealAttr extends HealAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const stockpilingTag = user.getTag(StockpilingTag);
if (stockpilingTag && stockpilingTag.stockpiledCount > 0) {
const stockpiled = stockpilingTag.stockpiledCount;
let healRatio: number;
if (stockpiled === 1) {
healRatio = 0.25;
} else if (stockpiled === 2) {
healRatio = 0.50;
} else { // stockpiled >= 3
healRatio = 1.00;
}
if (healRatio) {
this.addHealPhase(user, healRatio);
return true;
}
}
return false;
}
}
const hasStockpileStacksCondition: MoveConditionFunc = (user) => {
const hasStockpilingTag = user.getTag(StockpilingTag);
return !!hasStockpilingTag && hasStockpilingTag.stockpiledCount > 0;
@ -8088,6 +8025,53 @@ const attackedByItemMessageFunc = (user: Pokemon, target: Pokemon, move: Move) =
return message;
};
const sunnyHealRatioFunc = (): number => {
if (globalScene.arena.weather?.isEffectSuppressed()) {
return 1 / 2;
}
switch (globalScene.arena.getWeatherType()) {
case WeatherType.SUNNY:
case WeatherType.HARSH_SUN:
return 2 / 3;
case WeatherType.RAIN:
case WeatherType.SANDSTORM:
case WeatherType.HAIL:
case WeatherType.SNOW:
case WeatherType.HEAVY_RAIN:
case WeatherType.FOG:
return 1 / 4;
case WeatherType.STRONG_WINDS:
default:
return 1 / 2;
}
}
const shoreUpHealRatioFunc = (): number => {
if (globalScene.arena.weather?.isEffectSuppressed()) {
return 1 / 2;
}
return globalScene.arena.getWeatherType() === WeatherType.SANDSTORM ? 2 / 3 : 1 / 2;
}
const swallowHealFunc = (user: Pokemon): number => {
const tag = user.getTag(StockpilingTag);
if (!tag || tag.stockpiledCount <= 0) {
return 0;
}
switch (tag.stockpiledCount) {
case 1:
return 0.25
case 2:
return 0.5
case 3:
default: // in case we ever get more stacks
return 1;
}
}
export class MoveCondition {
protected func: MoveConditionFunc;
@ -8299,15 +8283,12 @@ const MoveAttrs = Object.freeze({
SacrificialAttrOnHit,
HalfSacrificialAttr,
AddSubstituteAttr,
HealAttr,
PartyStatusCureAttr,
FlameBurstAttr,
SacrificialFullRestoreAttr,
IgnoreWeatherTypeDebuffAttr,
WeatherHealAttr,
PlantHealAttr,
SandHealAttr,
BoostHealAttr,
HealAttr,
VariableHealAttr,
HealOnAllyAttr,
HitHealAttr,
IncrementMovePriorityAttr,
@ -8371,7 +8352,6 @@ const MoveAttrs = Object.freeze({
PresentPowerAttr,
WaterShurikenPowerAttr,
SpitUpPowerAttr,
SwallowHealAttr,
MultiHitPowerIncrementAttr,
LastMoveDoublePowerAttr,
CombinedPledgePowerAttr,
@ -9222,13 +9202,13 @@ export function initMoves() {
.attr(StatStageChangeAttr, [ Stat.ATK ], 1, true),
new AttackMove(MoveId.VITAL_THROW, PokemonType.FIGHTING, MoveCategory.PHYSICAL, 70, -1, 10, -1, -1, 2),
new SelfStatusMove(MoveId.MORNING_SUN, PokemonType.NORMAL, -1, 5, -1, 0, 2)
.attr(PlantHealAttr)
.attr(VariableHealAttr, sunnyHealRatioFunc)
.triageMove(),
new SelfStatusMove(MoveId.SYNTHESIS, PokemonType.GRASS, -1, 5, -1, 0, 2)
.attr(PlantHealAttr)
.attr(VariableHealAttr, sunnyHealRatioFunc)
.triageMove(),
new SelfStatusMove(MoveId.MOONLIGHT, PokemonType.FAIRY, -1, 5, -1, 0, 2)
.attr(PlantHealAttr)
.attr(VariableHealAttr, sunnyHealRatioFunc)
.triageMove(),
new AttackMove(MoveId.HIDDEN_POWER, PokemonType.NORMAL, MoveCategory.SPECIAL, 60, 100, 15, -1, 0, 2)
.attr(HiddenPowerTypeAttr),
@ -9288,12 +9268,12 @@ export function initMoves() {
.condition(user => (user.getTag(StockpilingTag)?.stockpiledCount ?? 0) < 3)
.attr(AddBattlerTagAttr, BattlerTagType.STOCKPILING, true),
new AttackMove(MoveId.SPIT_UP, PokemonType.NORMAL, MoveCategory.SPECIAL, -1, 100, 10, -1, 0, 3)
.condition(hasStockpileStacksCondition)
.attr(SpitUpPowerAttr, 100)
.condition(hasStockpileStacksCondition)
.attr(RemoveBattlerTagAttr, [ BattlerTagType.STOCKPILING ], true),
new SelfStatusMove(MoveId.SWALLOW, PokemonType.NORMAL, -1, 10, -1, 0, 3)
.attr(VariableHealAttr, swallowHealFunc)
.condition(hasStockpileStacksCondition)
.attr(SwallowHealAttr)
.attr(RemoveBattlerTagAttr, [ BattlerTagType.STOCKPILING ], true)
.triageMove(),
new AttackMove(MoveId.HEAT_WAVE, PokemonType.FIRE, MoveCategory.SPECIAL, 95, 90, 10, 10, 0, 3)
@ -10555,7 +10535,7 @@ export function initMoves() {
.unimplemented(),
/* End Unused */
new SelfStatusMove(MoveId.SHORE_UP, PokemonType.GROUND, -1, 5, -1, 0, 7)
.attr(SandHealAttr)
.attr(VariableHealAttr, shoreUpHealRatioFunc)
.triageMove(),
new AttackMove(MoveId.FIRST_IMPRESSION, PokemonType.BUG, MoveCategory.PHYSICAL, 90, 100, 10, -1, 2, 7)
.condition(new FirstMoveCondition()),
@ -10575,7 +10555,7 @@ export function initMoves() {
.attr(StatStageChangeAttr, [ Stat.SPD ], -1, true)
.punchingMove(),
new StatusMove(MoveId.FLORAL_HEALING, PokemonType.FAIRY, -1, 10, -1, 0, 7)
.attr(BoostHealAttr, 0.5, 2 / 3, true, false, (user, target, move) => globalScene.arena.terrain?.terrainType === TerrainType.GRASSY)
.attr(VariableHealAttr, () => globalScene.arena.terrain?.terrainType === TerrainType.GRASSY ? 2 / 3 : 1 / 2, true, false)
.triageMove()
.reflectable(),
new AttackMove(MoveId.HIGH_HORSEPOWER, PokemonType.GROUND, MoveCategory.PHYSICAL, 95, 95, 10, -1, 0, 7),
@ -11067,10 +11047,11 @@ export function initMoves() {
.attr(HealStatusEffectAttr, false, StatusEffect.FREEZE)
.attr(StatusEffectAttr, StatusEffect.BURN),
new StatusMove(MoveId.JUNGLE_HEALING, PokemonType.GRASS, -1, 10, -1, 0, 8)
.attr(HealAttr, 0.25, true, false)
.attr(HealAttr, 0.25, true, false, false)
.attr(HealStatusEffectAttr, false, getNonVolatileStatusEffects())
.target(MoveTarget.USER_AND_ALLIES)
.triageMove(),
.triageMove()
.edgeCase(), // TODO: Review if jungle healing fails if HP cannot be restored and status cannot be cured
new AttackMove(MoveId.WICKED_BLOW, PokemonType.DARK, MoveCategory.PHYSICAL, 75, 100, 5, -1, 0, 8)
.attr(CritOnlyAttr)
.punchingMove(),
@ -11172,10 +11153,11 @@ export function initMoves() {
.windMove()
.target(MoveTarget.ALL_NEAR_ENEMIES),
new StatusMove(MoveId.LUNAR_BLESSING, PokemonType.PSYCHIC, -1, 5, -1, 0, 8)
.attr(HealAttr, 0.25, true, false)
.attr(HealAttr, 0.25, true, false, false)
.attr(HealStatusEffectAttr, false, getNonVolatileStatusEffects())
.target(MoveTarget.USER_AND_ALLIES)
.triageMove(),
.triageMove()
.edgeCase(), // TODO: Review if lunar blessing fails if HP cannot be restored and status cannot be cured
new SelfStatusMove(MoveId.TAKE_HEART, PokemonType.PSYCHIC, -1, 10, -1, 0, 8)
.attr(StatStageChangeAttr, [ Stat.SPATK, Stat.SPDEF ], 1, true)
.attr(HealStatusEffectAttr, true, [ StatusEffect.PARALYSIS, StatusEffect.POISON, StatusEffect.TOXIC, StatusEffect.BURN, StatusEffect.SLEEP ]),

View File

@ -24,11 +24,11 @@ import { NoCritTag, WeakenMoveScreenTag } from "#data/arena-tag";
import {
AutotomizedTag,
BattlerTag,
type BattlerTagTypeMap,
CritBoostTag,
EncoreTag,
ExposedTag,
GroundedTag,
type GrudgeTag,
getBattlerTag,
HighestStatBoostTag,
MoveRestrictionBattlerTag,
@ -1640,6 +1640,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
return this.getMaxHp() - this.hp;
}
// TODO: Why does this default to `false`?
getHpRatio(precise = false): number {
return precise ? this.hp / this.getMaxHp() : Math.round((this.hp / this.getMaxHp()) * 100) / 100;
}
@ -4237,14 +4238,8 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
return false;
}
/**@overload */
getTag(tagType: BattlerTagType.GRUDGE): GrudgeTag | undefined;
/** @overload */
getTag(tagType: BattlerTagType.SUBSTITUTE): SubstituteTag | undefined;
/** @overload */
getTag(tagType: BattlerTagType): BattlerTag | undefined;
getTag<T extends BattlerTagType>(tagType: T): BattlerTagTypeMap[T] | undefined;
/** @overload */
getTag<T extends BattlerTag>(tagType: Constructor<T>): T | undefined;

View File

@ -1933,7 +1933,6 @@ export class PokemonInstantReviveModifier extends PokemonHeldItemModifier {
* @returns always `true`
*/
override apply(pokemon: Pokemon): boolean {
// Restore the Pokemon to half HP
globalScene.phaseManager.unshiftNew(
"PokemonHealPhase",
pokemon.getBattlerIndex(),
@ -1948,6 +1947,7 @@ export class PokemonInstantReviveModifier extends PokemonHeldItemModifier {
);
// Remove the Pokemon's FAINT status
// TODO: Remove call to `resetStatus` once StatusEffect.FAINT is canned
pokemon.resetStatus(true, false, true, false);
// Reapply Commander on the Pokemon's side of the field, if applicable
@ -3549,24 +3549,26 @@ export class EnemyTurnHealModifier extends EnemyPersistentModifier {
* @returns `true` if the {@linkcode Pokemon} was healed
*/
override apply(enemyPokemon: Pokemon): boolean {
if (!enemyPokemon.isFullHp()) {
globalScene.phaseManager.unshiftNew(
"PokemonHealPhase",
enemyPokemon.getBattlerIndex(),
Math.max(Math.floor(enemyPokemon.getMaxHp() / (100 / this.healPercent)) * this.stackCount, 1),
i18next.t("modifier:enemyTurnHealApply", {
pokemonNameWithAffix: getPokemonNameWithAffix(enemyPokemon),
}),
true,
false,
false,
false,
true,
);
return true;
if (enemyPokemon.isFullHp()) {
return false;
}
return false;
// Prevent healing to full from healing tokens
const healAmt = Math.min(
enemyPokemon.getMaxHp() - 1,
toDmgValue((enemyPokemon.getMaxHp() * this.stackCount * this.healPercent) / 100),
);
globalScene.phaseManager.unshiftNew(
"PokemonHealPhase",
enemyPokemon.getBattlerIndex(),
healAmt,
i18next.t("modifier:enemyTurnHealApply", {
pokemonNameWithAffix: getPokemonNameWithAffix(enemyPokemon),
}),
true,
);
return true;
}
getMaxStackCount(): number {

View File

@ -1,12 +1,10 @@
import { globalScene } from "#app/global-scene";
import { getPokemonNameWithAffix } from "#app/messages";
import type { HealBlockTag } from "#data/battler-tags";
import { getStatusEffectHealText } from "#data/status-effect";
import type { BattlerIndex } from "#enums/battler-index";
import { BattlerTagType } from "#enums/battler-tag-type";
import { HitResult } from "#enums/hit-result";
import { CommonAnim } from "#enums/move-anims-common";
import { StatusEffect } from "#enums/status-effect";
import { HealingBoosterModifier } from "#modifiers/modifier";
import { CommonAnimPhase } from "#phases/common-anim-phase";
import { HealAchv } from "#system/achv";
@ -15,13 +13,16 @@ import i18next from "i18next";
export class PokemonHealPhase extends CommonAnimPhase {
public readonly phaseName = "PokemonHealPhase";
/** The base amount of HP to heal. */
private hpHealed: number;
/** The message to display upon healing the target, or `null` to show no message. */
private message: string | null;
/** Whether to show a message and quit out early upon healing a Pokemon already at full hp. */
private showFullHpMessage: boolean;
private skipAnim: boolean;
private revive: boolean;
private healStatus: boolean;
private preventFullHeal: boolean;
private fullRestorePP: boolean;
constructor(
@ -32,7 +33,6 @@ export class PokemonHealPhase extends CommonAnimPhase {
skipAnim = false,
revive = false,
healStatus = false,
preventFullHeal = false,
fullRestorePP = false,
) {
super(battlerIndex, undefined, CommonAnim.HEALTH_UP);
@ -43,12 +43,11 @@ export class PokemonHealPhase extends CommonAnimPhase {
this.skipAnim = skipAnim;
this.revive = revive;
this.healStatus = healStatus;
this.preventFullHeal = preventFullHeal;
this.fullRestorePP = fullRestorePP;
}
start() {
if (!this.skipAnim && (this.revive || this.getPokemon().hp) && !this.getPokemon().isFullHp()) {
if (!this.skipAnim && !this.getPokemon().isFullHp()) {
super.start();
} else {
this.end();
@ -58,78 +57,72 @@ export class PokemonHealPhase extends CommonAnimPhase {
end() {
const pokemon = this.getPokemon();
if (!pokemon.isOnField() || (!this.revive && !pokemon.isActive())) {
return super.end();
// Prevent healing off-field pokemon
if (!pokemon.isActive(true)) {
super.end();
return;
}
const hasMessage = !!this.message;
const healOrDamage = !pokemon.isFullHp() || this.hpHealed < 0;
const healBlock = pokemon.getTag(BattlerTagType.HEAL_BLOCK) as HealBlockTag;
let lastStatusEffect = StatusEffect.NONE;
// Check for heal block, ending the phase early if healing was prevented
const healBlock = pokemon.getTag(BattlerTagType.HEAL_BLOCK);
if (healBlock && this.hpHealed > 0) {
globalScene.phaseManager.queueMessage(healBlock.onActivation(pokemon));
this.message = null;
return super.end();
}
if (healOrDamage) {
const hpRestoreMultiplier = new NumberHolder(1);
if (!this.revive) {
globalScene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier);
}
const healAmount = new NumberHolder(Math.floor(this.hpHealed * hpRestoreMultiplier.value));
if (healAmount.value < 0) {
pokemon.damageAndUpdate(healAmount.value * -1, { result: HitResult.INDIRECT });
healAmount.value = 0;
}
// Prevent healing to full if specified (in case of healing tokens so Sturdy doesn't cause a softlock)
if (this.preventFullHeal && pokemon.hp + healAmount.value >= pokemon.getMaxHp()) {
healAmount.value = pokemon.getMaxHp() - pokemon.hp - 1;
}
healAmount.value = pokemon.heal(healAmount.value);
if (healAmount.value) {
globalScene.damageNumberHandler.add(pokemon, healAmount.value, HitResult.HEAL);
}
if (pokemon.isPlayer()) {
globalScene.validateAchvs(HealAchv, healAmount);
if (healAmount.value > globalScene.gameData.gameStats.highestHeal) {
globalScene.gameData.gameStats.highestHeal = healAmount.value;
}
}
if (this.healStatus && !this.revive && pokemon.status) {
lastStatusEffect = pokemon.status.effect;
pokemon.resetStatus();
}
if (this.fullRestorePP) {
for (const move of this.getPokemon().getMoveset()) {
if (move) {
move.ppUsed = 0;
}
}
}
pokemon.updateInfo().then(() => super.end());
} else if (this.healStatus && !this.revive && pokemon.status) {
lastStatusEffect = pokemon.status.effect;
pokemon.resetStatus();
pokemon.updateInfo().then(() => super.end());
} else if (this.showFullHpMessage) {
this.message = i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(pokemon),
});
super.end();
return;
}
// If we would heal the user past full HP, don't.
if (this.hpHealed >= 0 && pokemon.isFullHp()) {
if (this.showFullHpMessage) {
globalScene.phaseManager.queueMessage(
i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(pokemon),
}),
);
}
super.end();
return;
}
// Apply the effect of healing charms for non-revival items
const hpRestoreMultiplier = new NumberHolder(1);
globalScene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier);
let healAmount = Math.floor(this.hpHealed * hpRestoreMultiplier.value);
// If Liquid Ooze is active, damage the user for the healing amount, then return.
// TODO: Refactor liquid ooze to not use a heal phase to do damage
if (healAmount < 0) {
pokemon.damageAndUpdate(-healAmount, { result: HitResult.INDIRECT });
pokemon.updateInfo().then(() => super.end());
return;
}
// Heal the pokemon (capping at max HP), then show damage numbers and
// do achievement validation
healAmount = pokemon.heal(healAmount);
globalScene.damageNumberHandler.add(pokemon, healAmount, HitResult.HEAL);
if (pokemon.isPlayer()) {
globalScene.validateAchvs(HealAchv, healAmount);
globalScene.gameData.gameStats.highestHeal = Math.max(globalScene.gameData.gameStats.highestHeal, healAmount);
}
// Cure status as applicable
// TODO: This should not be the job of the healing phase
if (this.healStatus && pokemon.status) {
globalScene.phaseManager.queueMessage(
getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon)),
);
pokemon.resetStatus();
}
this.showMessage();
pokemon.updateInfo().then(() => super.end());
}
private showMessage(): void {
if (this.message) {
globalScene.phaseManager.queueMessage(this.message);
}
if (this.healStatus && lastStatusEffect && !hasMessage) {
globalScene.phaseManager.queueMessage(
getStatusEffectHealText(lastStatusEffect, getPokemonNameWithAffix(pokemon)),
);
}
if (!healOrDamage && !lastStatusEffect) {
super.end();
}
}
}

View File

@ -2,7 +2,6 @@ import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import { DamageAnimPhase } from "#phases/damage-anim-phase";
import { TurnEndPhase } from "#phases/turn-end-phase";
import { GameManager } from "#test/test-utils/game-manager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
@ -54,7 +53,7 @@ describe("Items - Leftovers", () => {
const leadHpAfterDamage = leadPokemon.hp;
// Check if leftovers heal us
await game.phaseInterceptor.to(TurnEndPhase);
await game.toNextTurn();
expect(leadPokemon.hp).toBeGreaterThan(leadHpAfterDamage);
});
});

View File

@ -5,8 +5,11 @@ import { SpeciesId } from "#enums/species-id";
import { GameManager } from "#test/test-utils/game-manager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { MoveResult } from "#enums/move-result";
import { getPokemonNameWithAffix } from "#app/messages";
import i18next from "i18next";
describe("Moves - Pollen Puff", () => {
describe("Move - Pollen Puff", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
@ -23,42 +26,80 @@ describe("Moves - Pollen Puff", () => {
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([MoveId.POLLEN_PUFF])
.ability(AbilityId.BALL_FETCH)
.battleStyle("single")
.criticalHits(false)
.enemyLevel(100)
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH);
});
it("should not heal more than once when the user has a source of multi-hit", async () => {
game.override.battleStyle("double").moveset([MoveId.POLLEN_PUFF, MoveId.ENDURE]).ability(AbilityId.PARENTAL_BOND);
it("should damage an enemy when used, or heal an ally for 50% max HP", async () => {
game.override.battleStyle("double").ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.OMANYTE]);
const [_, rightPokemon] = game.scene.getPlayerField();
const [_, omantye, karp1] = game.scene.getField();
omantye.hp = 1;
rightPokemon.damageAndUpdate(rightPokemon.hp - 1);
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2);
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY);
await game.toNextTurn();
game.move.select(MoveId.POLLEN_PUFF, 0, BattlerIndex.PLAYER_2);
game.move.select(MoveId.ENDURE, 1);
expect(karp1.hp).toBeLessThan(karp1.getMaxHp());
expect(omantye.hp).toBeCloseTo(0.5 * omantye.getMaxHp() + 1, 1);
expect(game.phaseInterceptor.log).toContain("PokemonHealPhase");
});
await game.phaseInterceptor.to("BerryPhase");
it.todo("should display message & count as failed when hitting a full HP ally", async () => {
game.override.battleStyle("double").ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.OMANYTE]);
// Pollen Puff heals with a ratio of 0.5, as long as Pollen Puff triggers only once the pokemon will always be <= (0.5 * Max HP) + 1
expect(rightPokemon.hp).toBeLessThanOrEqual(0.5 * rightPokemon.getMaxHp() + 1);
const [bulbasaur, omantye] = game.scene.getPlayerField();
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2);
game.move.use(MoveId.SPLASH, BattlerIndex.PLAYER_2);
await game.toEndOfTurn();
// move failed without unshifting a phase
expect(omantye.hp).toBe(omantye.getMaxHp());
expect(bulbasaur.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
expect(game.textInterceptor.logs).toContain(
i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(omantye),
}),
);
expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase");
});
it("should not heal more than once if the user has a source of multi-hit", async () => {
game.override.battleStyle("double").ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.OMANYTE]);
const [bulbasaur, omantye] = game.scene.getPlayerField();
omantye.hp = 1;
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2);
game.move.use(MoveId.SPLASH, BattlerIndex.PLAYER_2);
await game.toEndOfTurn();
expect(bulbasaur.turnData.hitCount).toBe(1);
expect(omantye.hp).toBeLessThanOrEqual(0.5 * omantye.getMaxHp() + 1);
expect(
game.phaseInterceptor.log.filter(l => l === "PokemonHealPhase"),
game.phaseInterceptor.log.join("\n"),
).toHaveLength(1);
});
it("should damage an enemy multiple times when the user has a source of multi-hit", async () => {
game.override.moveset([MoveId.POLLEN_PUFF]).ability(AbilityId.PARENTAL_BOND).enemyLevel(100);
game.override.ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.MAGIKARP]);
const target = game.scene.getEnemyPokemon()!;
game.move.select(MoveId.POLLEN_PUFF);
await game.phaseInterceptor.to("BerryPhase");
game.move.use(MoveId.POLLEN_PUFF);
await game.toEndOfTurn();
const target = game.field.getEnemyPokemon();
expect(target.battleData.hitCount).toBe(2);
});
});

View File

@ -0,0 +1,148 @@
import { getPokemonNameWithAffix } from "#app/messages";
import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id";
import { MoveResult } from "#enums/move-result";
import { SpeciesId } from "#enums/species-id";
import { WeatherType } from "#enums/weather-type";
import { GameManager } from "#test/test-utils/game-manager";
import { getEnumValues } from "#utils/enums";
import { toTitleCase } from "#utils/strings";
import i18next from "i18next";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Moves - Recovery Moves - ", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.ability(AbilityId.MAGIC_GUARD) // prevents passive weather damage
.battleStyle("single")
.criticalHits(false)
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH)
.startingLevel(100)
.enemyLevel(100);
});
describe.each<{ name: string; move: MoveId }>([
{ name: "Recover", move: MoveId.RECOVER },
{ name: "Soft-Boiled", move: MoveId.SOFT_BOILED },
{ name: "Milk Drink", move: MoveId.MILK_DRINK },
{ name: "Slack Off", move: MoveId.SLACK_OFF },
{ name: "Roost", move: MoveId.ROOST },
{ name: "Weather-based Healing Moves", move: MoveId.SYNTHESIS },
{ name: "Shore Up", move: MoveId.SHORE_UP },
])("$name", ({ move }) => {
it("should heal 50% of the user's maximum HP", async () => {
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(move);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.5, 1);
expect(game.phaseInterceptor.log).toContain("PokemonHealPhase");
});
it("should fail if used at full HP", async () => {
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
game.move.use(move);
await game.toEndOfTurn();
const blissey = game.field.getPlayerPokemon();
expect(blissey.hp).toBe(blissey.getMaxHp());
expect(game.textInterceptor.logs).toContain(
i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(blissey),
}),
);
expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase");
expect(blissey.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
});
});
describe("Weather-based Healing Moves", () => {
it.each([
{ name: "Harsh Sunlight", weather: WeatherType.SUNNY },
{ name: "Extremely Harsh Sunlight", weather: WeatherType.HARSH_SUN },
])("should heal 66% of the user's maximum HP under $name", async ({ weather }) => {
game.override.weather(weather);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.MOONLIGHT);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.66, 1);
});
const nonSunWTs = getEnumValues(WeatherType)
.filter(
wt => ![WeatherType.SUNNY, WeatherType.HARSH_SUN, WeatherType.NONE, WeatherType.STRONG_WINDS].includes(wt),
)
.map(wt => ({
name: toTitleCase(WeatherType[wt]),
weather: wt,
}));
it.each(nonSunWTs)("should heal 25% of the user's maximum HP under $name", async ({ weather }) => {
game.override.weather(weather);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.MOONLIGHT);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.25, 1);
});
it("should heal 50% of the user's maximum HP under strong winds", async () => {
game.override.ability(AbilityId.DELTA_STREAM);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.MOONLIGHT);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.5, 1);
});
});
describe("Shore Up", () => {
it("should heal 66% of the user's maximum HP in a sandstorm", async () => {
game.override.weather(WeatherType.SANDSTORM);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.SHORE_UP);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.66, 1);
});
});
});

View File

@ -1,13 +1,12 @@
import { AbilityId } from "#enums/ability-id";
import { BattlerIndex } from "#enums/battler-index";
import { BattlerTagType } from "#enums/battler-tag-type";
import { MoveId } from "#enums/move-id";
import { PokemonType } from "#enums/pokemon-type";
import { SpeciesId } from "#enums/species-id";
import { MoveEffectPhase } from "#phases/move-effect-phase";
import { TurnEndPhase } from "#phases/turn-end-phase";
import { GameManager } from "#test/test-utils/game-manager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, test } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Moves - Roost", () => {
let phaserGame: Phaser.Game;
@ -27,219 +26,105 @@ describe("Moves - Roost", () => {
game = new GameManager(phaserGame);
game.override
.battleStyle("single")
.enemySpecies(SpeciesId.RELICANTH)
.enemySpecies(SpeciesId.SHUCKLE)
.ability(AbilityId.BALL_FETCH)
.startingLevel(100)
.enemyLevel(100)
.enemyMoveset(MoveId.EARTHQUAKE)
.moveset([MoveId.ROOST, MoveId.BURN_UP, MoveId.DOUBLE_SHOCK]);
.enemyMoveset(MoveId.SPLASH);
});
/**
* Roost's behavior should be defined as:
* The pokemon loses its flying type for a turn. If the pokemon was ungroundd solely due to being a flying type, it will be grounded until end of turn.
* 1. Pure Flying type pokemon -> become normal type until end of turn
* 2. Dual Flying/X type pokemon -> become type X until end of turn
* 3. Pokemon that use burn up into roost (ex. Moltres) -> become flying due to burn up, then typeless until end of turn after using roost
* 4. If a pokemon is afflicted with Forest's Curse or Trick or treat, dual type pokemon will become 3 type pokemon after the flying type is regained
* Pure flying types become (Grass or Ghost) and then back to flying/ (Grass or Ghost),
* and pokemon post Burn up become ()
* 5. If a pokemon is also ungrounded due to other reasons (such as levitate), it will stay ungrounded post roost, despite not being flying type.
* 6. Non flying types using roost (such as dunsparce) are already grounded, so this move will only heal and have no other effects.
*/
test("Non flying type uses roost -> no type change, took damage", async () => {
await game.classicMode.startBattle([SpeciesId.DUNSPARCE]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerPokemonStartingHP = playerPokemon.hp;
game.move.select(MoveId.ROOST);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
// Should only be normal type, and NOT flying type
let playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes[0] === PokemonType.NORMAL).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeTruthy();
await game.phaseInterceptor.to(TurnEndPhase);
// Lose HP, still normal type
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.hp).toBeLessThan(playerPokemonStartingHP);
expect(playerPokemonTypes[0] === PokemonType.NORMAL).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeTruthy();
});
test("Pure flying type -> becomes normal after roost and takes damage from ground moves -> regains flying", async () => {
await game.classicMode.startBattle([SpeciesId.TORNADUS]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerPokemonStartingHP = playerPokemon.hp;
game.move.select(MoveId.ROOST);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
// Should only be normal type, and NOT flying type
let playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes[0] === PokemonType.NORMAL).toBeTruthy();
expect(playerPokemonTypes[0] === PokemonType.FLYING).toBeFalsy();
expect(playerPokemon.isGrounded()).toBeTruthy();
await game.phaseInterceptor.to(TurnEndPhase);
// Should have lost HP and is now back to being pure flying
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.hp).toBeLessThan(playerPokemonStartingHP);
expect(playerPokemonTypes[0] === PokemonType.NORMAL).toBeFalsy();
expect(playerPokemonTypes[0] === PokemonType.FLYING).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeFalsy();
});
test("Dual X/flying type -> becomes type X after roost and takes damage from ground moves -> regains flying", async () => {
it("should remove the user's Flying type until end of turn", async () => {
await game.classicMode.startBattle([SpeciesId.HAWLUCHA]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerPokemonStartingHP = playerPokemon.hp;
game.move.select(MoveId.ROOST);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
// Should only be pure fighting type and grounded
let playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes[0] === PokemonType.FIGHTING).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeTruthy();
const hawlucha = game.field.getPlayerPokemon();
hawlucha.hp = 1;
await game.phaseInterceptor.to(TurnEndPhase);
game.move.use(MoveId.ROOST);
await game.phaseInterceptor.to("MoveEffectPhase");
// Should have lost HP and is now back to being fighting/flying
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.hp).toBeLessThan(playerPokemonStartingHP);
expect(playerPokemonTypes[0] === PokemonType.FIGHTING).toBeTruthy();
expect(playerPokemonTypes[1] === PokemonType.FLYING).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeFalsy();
// Should lose flying type temporarily
expect(hawlucha.getTag(BattlerTagType.ROOSTED)).toBeDefined();
expect(hawlucha).toHaveTypes([PokemonType.FIGHTING]);
expect(hawlucha.isGrounded()).toBe(true);
await game.toEndOfTurn();
// Should have changed back to fighting/flying
expect(hawlucha).toHaveTypes([PokemonType.FIGHTING, PokemonType.FLYING]);
expect(hawlucha.isGrounded()).toBe(false);
});
test("Pokemon with levitate after using roost should lose flying type but still be unaffected by ground moves", async () => {
game.override.starterForms({ [SpeciesId.ROTOM]: 4 });
await game.classicMode.startBattle([SpeciesId.ROTOM]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerPokemonStartingHP = playerPokemon.hp;
game.move.select(MoveId.ROOST);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
it("should preserve types of non-Flying type Pokemon", async () => {
await game.classicMode.startBattle([SpeciesId.MEW]);
// Should only be pure eletric type and grounded
let playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes[0] === PokemonType.ELECTRIC).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeFalsy();
const mew = game.field.getPlayerPokemon();
mew.hp = 1;
await game.phaseInterceptor.to(TurnEndPhase);
game.move.use(MoveId.ROOST);
await game.toEndOfTurn(false);
// Should have lost HP and is now back to being electric/flying
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.hp).toBe(playerPokemonStartingHP);
expect(playerPokemonTypes[0] === PokemonType.ELECTRIC).toBeTruthy();
expect(playerPokemonTypes[1] === PokemonType.FLYING).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeFalsy();
// Should remain psychic type
expect(mew).toHaveTypes([PokemonType.PSYCHIC]);
expect(mew.isGrounded()).toBe(true);
});
test("A fire/flying type that uses burn up, then roost should be typeless until end of turn", async () => {
await game.classicMode.startBattle([SpeciesId.MOLTRES]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerPokemonStartingHP = playerPokemon.hp;
game.move.select(MoveId.BURN_UP);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
it("should not remove the user's Tera Type", async () => {
await game.classicMode.startBattle([SpeciesId.PIDGEOT]);
// Should only be pure flying type after burn up
let playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes[0] === PokemonType.FLYING).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
const pidgeot = game.field.getPlayerPokemon();
pidgeot.hp = 1;
pidgeot.teraType = PokemonType.FLYING;
await game.phaseInterceptor.to(TurnEndPhase);
game.move.select(MoveId.ROOST);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
game.move.use(MoveId.ROOST, BattlerIndex.PLAYER, undefined, true);
await game.toEndOfTurn(false);
// Should only be typeless type after roost and is grounded
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.getTag(BattlerTagType.ROOSTED)).toBeDefined();
expect(playerPokemonTypes[0] === PokemonType.UNKNOWN).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeTruthy();
await game.phaseInterceptor.to(TurnEndPhase);
// Should go back to being pure flying and have taken damage from earthquake, and is ungrounded again
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.hp).toBeLessThan(playerPokemonStartingHP);
expect(playerPokemonTypes[0] === PokemonType.FLYING).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeFalsy();
// Should remain flying type
expect(pidgeot).toHaveTypes([PokemonType.FLYING], { args: [true] });
expect(pidgeot.isGrounded()).toBe(false);
});
test("An electric/flying type that uses double shock, then roost should be typeless until end of turn", async () => {
game.override.enemySpecies(SpeciesId.ZEKROM);
await game.classicMode.startBattle([SpeciesId.ZAPDOS]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerPokemonStartingHP = playerPokemon.hp;
game.move.select(MoveId.DOUBLE_SHOCK);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
it("should convert pure Flying types into normal types", async () => {
await game.classicMode.startBattle([SpeciesId.TORNADUS]);
// Should only be pure flying type after burn up
let playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes[0] === PokemonType.FLYING).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
const tornadus = game.field.getPlayerPokemon();
tornadus.hp = 1;
await game.phaseInterceptor.to(TurnEndPhase);
game.move.select(MoveId.ROOST);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase);
game.move.use(MoveId.ROOST);
await game.toEndOfTurn(false);
// Should only be typeless type after roost and is grounded
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.getTag(BattlerTagType.ROOSTED)).toBeDefined();
expect(playerPokemonTypes[0] === PokemonType.UNKNOWN).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeTruthy();
await game.phaseInterceptor.to(TurnEndPhase);
// Should go back to being pure flying and have taken damage from earthquake, and is ungrounded again
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemon.hp).toBeLessThan(playerPokemonStartingHP);
expect(playerPokemonTypes[0] === PokemonType.FLYING).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeFalsy();
// Should only be normal type, and NOT flying type
expect(tornadus).toHaveTypes([PokemonType.NORMAL]);
expect(tornadus.isGrounded()).toBe(true);
});
test("Dual Type Pokemon afflicted with Forests Curse/Trick or Treat and post roost will become dual type and then become 3 type at end of turn", async () => {
game.override.enemyMoveset([
MoveId.TRICK_OR_TREAT,
MoveId.TRICK_OR_TREAT,
MoveId.TRICK_OR_TREAT,
MoveId.TRICK_OR_TREAT,
]);
await game.classicMode.startBattle([SpeciesId.MOLTRES]);
const playerPokemon = game.scene.getPlayerPokemon()!;
game.move.select(MoveId.ROOST);
await game.phaseInterceptor.to(MoveEffectPhase);
it.each<{ name: string; move: MoveId; species: SpeciesId }>([
{ name: "Burn Up", move: MoveId.BURN_UP, species: SpeciesId.MOLTRES },
{ name: "Double Shock", move: MoveId.DOUBLE_SHOCK, species: SpeciesId.ZAPDOS },
])("should render user typeless when roosting after using $name", async ({ move, species }) => {
await game.classicMode.startBattle([species]);
let playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes[0] === PokemonType.FIRE).toBeTruthy();
expect(playerPokemonTypes.length === 1).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeTruthy();
const player = game.field.getPlayerPokemon();
player.hp = 1;
await game.phaseInterceptor.to(TurnEndPhase);
game.move.use(move);
await game.toNextTurn();
// Should be fire/flying/ghost
playerPokemonTypes = playerPokemon.getTypes();
expect(playerPokemonTypes.filter(type => type === PokemonType.FLYING)).toHaveLength(1);
expect(playerPokemonTypes.filter(type => type === PokemonType.FIRE)).toHaveLength(1);
expect(playerPokemonTypes.filter(type => type === PokemonType.GHOST)).toHaveLength(1);
expect(playerPokemonTypes.length === 3).toBeTruthy();
expect(playerPokemon.isGrounded()).toBeFalsy();
// Should be pure flying type
expect(player).toHaveTypes([PokemonType.FLYING]);
expect(player.isGrounded()).toBe(false);
game.move.use(MoveId.ROOST);
await game.phaseInterceptor.to("MoveEffectPhase");
// Should be typeless
expect(player.getTag(BattlerTagType.ROOSTED)).toBeDefined();
expect(player).toHaveTypes([PokemonType.UNKNOWN]);
expect(player.isGrounded()).toBe(true);
await game.toEndOfTurn();
// Should go back to being pure flying
expect(player).toHaveTypes([PokemonType.FLYING]);
expect(player.isGrounded()).toBe(false);
});
});

View File

@ -1,201 +0,0 @@
import { StockpilingTag } from "#data/battler-tags";
import { allMoves } from "#data/data-lists";
import { AbilityId } from "#enums/ability-id";
import { BattlerTagType } from "#enums/battler-tag-type";
import { MoveId } from "#enums/move-id";
import { MoveResult } from "#enums/move-result";
import { SpeciesId } from "#enums/species-id";
import { Stat } from "#enums/stat";
import type { Move } from "#moves/move";
import { MovePhase } from "#phases/move-phase";
import { TurnInitPhase } from "#phases/turn-init-phase";
import { GameManager } from "#test/test-utils/game-manager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Moves - Spit Up", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
let spitUp: Move;
beforeAll(() => {
phaserGame = new Phaser.Game({ type: Phaser.HEADLESS });
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
spitUp = allMoves[MoveId.SPIT_UP];
game = new GameManager(phaserGame);
game.override
.battleStyle("single")
.enemySpecies(SpeciesId.RATTATA)
.enemyMoveset(MoveId.SPLASH)
.enemyAbility(AbilityId.NONE)
.enemyLevel(2000)
.moveset(MoveId.SPIT_UP)
.ability(AbilityId.NONE);
vi.spyOn(spitUp, "calculateBattlePower");
});
describe("consumes all stockpile stacks to deal damage (scaling with stacks)", () => {
it("1 stack -> 100 power", async () => {
const stacksToSetup = 1;
const expectedPower = 100;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
game.move.select(MoveId.SPIT_UP);
await game.phaseInterceptor.to(TurnInitPhase);
expect(spitUp.calculateBattlePower).toHaveBeenCalledOnce();
expect(spitUp.calculateBattlePower).toHaveReturnedWith(expectedPower);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("2 stacks -> 200 power", async () => {
const stacksToSetup = 2;
const expectedPower = 200;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
game.move.select(MoveId.SPIT_UP);
await game.phaseInterceptor.to(TurnInitPhase);
expect(spitUp.calculateBattlePower).toHaveBeenCalledOnce();
expect(spitUp.calculateBattlePower).toHaveReturnedWith(expectedPower);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("3 stacks -> 300 power", async () => {
const stacksToSetup = 3;
const expectedPower = 300;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
game.move.select(MoveId.SPIT_UP);
await game.phaseInterceptor.to(TurnInitPhase);
expect(spitUp.calculateBattlePower).toHaveBeenCalledOnce();
expect(spitUp.calculateBattlePower).toHaveReturnedWith(expectedPower);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
});
it("fails without stacks", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeUndefined();
game.move.select(MoveId.SPIT_UP);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject({
move: MoveId.SPIT_UP,
result: MoveResult.FAIL,
targets: [game.scene.getEnemyPokemon()!.getBattlerIndex()],
});
expect(spitUp.calculateBattlePower).not.toHaveBeenCalled();
});
describe("restores stat boosts granted by stacks", () => {
it("decreases stats based on stored values (both boosts equal)", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
game.move.select(MoveId.SPIT_UP);
await game.phaseInterceptor.to(MovePhase);
expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(1);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject({
move: MoveId.SPIT_UP,
result: MoveResult.SUCCESS,
targets: [game.scene.getEnemyPokemon()!.getBattlerIndex()],
});
expect(spitUp.calculateBattlePower).toHaveBeenCalledOnce();
expect(pokemon.getStatStage(Stat.DEF)).toBe(0);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(0);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("decreases stats based on stored values (different boosts)", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
// for the sake of simplicity (and because other tests cover the setup), set boost amounts directly
stockpilingTag.statChangeCounts = {
[Stat.DEF]: -1,
[Stat.SPDEF]: 2,
};
game.move.select(MoveId.SPIT_UP);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject({
move: MoveId.SPIT_UP,
result: MoveResult.SUCCESS,
targets: [game.scene.getEnemyPokemon()!.getBattlerIndex()],
});
expect(spitUp.calculateBattlePower).toHaveBeenCalledOnce();
expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(-2);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
});
});

View File

@ -0,0 +1,237 @@
import { StockpilingTag } from "#app/data/battler-tags";
import { allMoves } from "#app/data/data-lists";
import { BattlerTagType } from "#app/enums/battler-tag-type";
import { getPokemonNameWithAffix } from "#app/messages";
import { AbilityId } from "#enums/ability-id";
import { BattlerIndex } from "#enums/battler-index";
import { MoveId } from "#enums/move-id";
import { MoveResult } from "#enums/move-result";
import { SpeciesId } from "#enums/species-id";
import { Stat } from "#enums/stat";
import { GameManager } from "#test/test-utils/game-manager";
import i18next from "i18next";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, type MockInstance, vi } from "vitest";
describe("Moves - Swallow & Spit Up - ", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.battleStyle("single")
.enemySpecies(SpeciesId.RATTATA)
.enemyMoveset(MoveId.SPLASH)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyLevel(100)
.startingLevel(100)
.ability(AbilityId.BALL_FETCH);
});
describe("Swallow", () => {
it.each<{ stackCount: number; healPercent: number }>([
{ stackCount: 1, healPercent: 25 },
{ stackCount: 2, healPercent: 50 },
{ stackCount: 3, healPercent: 100 },
])(
"should heal the user by $healPercent% max HP when consuming $stackCount stockpile stacks",
async ({ stackCount, healPercent }) => {
await game.classicMode.startBattle([SpeciesId.SWALOT]);
const swalot = game.field.getPlayerPokemon();
swalot.hp = 1;
for (let i = 0; i < stackCount; i++) {
swalot.addTag(BattlerTagType.STOCKPILING);
}
const stockpilingTag = swalot.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stackCount);
game.move.use(MoveId.SWALLOW);
await game.toEndOfTurn();
expect(swalot.getHpRatio()).toBeCloseTo(healPercent / 100, 1);
expect(swalot.getTag(StockpilingTag)).toBeUndefined();
},
);
it("should fail without Stockpile stacks", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const player = game.field.getPlayerPokemon();
player.hp = 1;
const stockpilingTag = player.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeUndefined();
game.move.use(MoveId.SWALLOW);
await game.toEndOfTurn();
expect(player.getLastXMoves()[0]).toMatchObject({
move: MoveId.SWALLOW,
result: MoveResult.FAIL,
});
});
// TODO: Does this consume stacks or not?
it.todo("should fail and display message at full HP, consuming stacks", async () => {
await game.classicMode.startBattle([SpeciesId.SWALOT]);
const swalot = game.field.getPlayerPokemon();
swalot.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = swalot.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
game.move.use(MoveId.SWALLOW);
await game.toEndOfTurn();
expect(swalot.getLastXMoves()[0]).toMatchObject({
move: MoveId.SWALLOW,
result: MoveResult.FAIL,
});
expect(game.textInterceptor.logs).toContain(
i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(swalot),
}),
);
expect(stockpilingTag).toBeDefined();
});
});
describe("Spit Up", () => {
let spitUpSpy: MockInstance;
beforeEach(() => {
spitUpSpy = vi.spyOn(allMoves[MoveId.SPIT_UP], "calculateBattlePower");
});
it.each<{ stackCount: number; power: number }>([
{ stackCount: 1, power: 100 },
{ stackCount: 2, power: 200 },
{ stackCount: 3, power: 300 },
])("should have $power base power when consuming $stackCount stockpile stacks", async ({ stackCount, power }) => {
await game.classicMode.startBattle([SpeciesId.SWALOT]);
const swalot = game.field.getPlayerPokemon();
for (let i = 0; i < stackCount; i++) {
swalot.addTag(BattlerTagType.STOCKPILING);
}
const stockpilingTag = swalot.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stackCount);
game.move.use(MoveId.SPIT_UP);
await game.toEndOfTurn();
expect(spitUpSpy).toHaveReturnedWith(power);
expect(swalot.getTag(StockpilingTag)).toBeUndefined();
});
it("should fail without Stockpile stacks", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const player = game.field.getPlayerPokemon();
const stockpilingTag = player.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeUndefined();
game.move.use(MoveId.SPIT_UP);
await game.toEndOfTurn();
expect(player.getLastXMoves()[0]).toMatchObject({
move: MoveId.SPIT_UP,
result: MoveResult.FAIL,
});
});
});
describe("Stockpile stack removal", () => {
it("should undo stat boosts when losing stacks", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const player = game.field.getPlayerPokemon();
player.hp = 1;
game.move.use(MoveId.STOCKPILE);
await game.toNextTurn();
const stockpilingTag = player.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(player.getStatStage(Stat.DEF)).toBe(1);
expect(player.getStatStage(Stat.SPDEF)).toBe(1);
// remove the prior stat boosts from the log
game.phaseInterceptor.clearLogs();
game.move.use(MoveId.SWALLOW);
await game.move.forceEnemyMove(MoveId.ACID_SPRAY);
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.toEndOfTurn();
expect(player.getStatStage(Stat.DEF)).toBe(0);
expect(player.getStatStage(Stat.SPDEF)).toBe(-2); // +1 --> -1 --> -2
expect(game.phaseInterceptor.log.filter(l => l === "StatStageChangePhase")).toHaveLength(3);
});
it("should double stat drops when gaining Simple", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const player = game.field.getPlayerPokemon();
game.move.use(MoveId.STOCKPILE);
await game.move.forceEnemyMove(MoveId.SIMPLE_BEAM);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.toNextTurn();
expect(player.getStatStage(Stat.DEF)).toBe(1);
expect(player.getStatStage(Stat.SPDEF)).toBe(1);
expect(player.hasAbility(AbilityId.SIMPLE)).toBe(true);
game.move.use(MoveId.SPIT_UP);
await game.move.forceEnemyMove(MoveId.SPLASH);
await game.toEndOfTurn();
// should have fallen by 2 stages from Simple
expect(player.getStatStage(Stat.DEF)).toBe(-1);
expect(player.getStatStage(Stat.SPDEF)).toBe(-1);
});
it("should invert stat drops when gaining Contrary", async () => {
game.override.enemyAbility(AbilityId.CONTRARY);
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const player = game.field.getPlayerPokemon();
game.move.use(MoveId.STOCKPILE);
await game.move.forceEnemyMove(MoveId.ENTRAINMENT);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.toEndOfTurn();
expect(player.getStatStage(Stat.DEF)).toBe(1);
expect(player.getStatStage(Stat.SPDEF)).toBe(1);
expect(player.hasAbility(AbilityId.CONTRARY)).toBe(true);
game.move.use(MoveId.SPIT_UP);
await game.move.forceEnemyMove(MoveId.SPLASH);
await game.toEndOfTurn();
// should have risen 1 stage from Contrary
expect(player.getStatStage(Stat.DEF)).toBe(2);
expect(player.getStatStage(Stat.SPDEF)).toBe(2);
});
});
});

View File

@ -1,204 +0,0 @@
import { StockpilingTag } from "#data/battler-tags";
import { AbilityId } from "#enums/ability-id";
import { BattlerTagType } from "#enums/battler-tag-type";
import { MoveId } from "#enums/move-id";
import { MoveResult } from "#enums/move-result";
import { SpeciesId } from "#enums/species-id";
import { Stat } from "#enums/stat";
import { MovePhase } from "#phases/move-phase";
import { TurnInitPhase } from "#phases/turn-init-phase";
import { GameManager } from "#test/test-utils/game-manager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Moves - Swallow", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({ type: Phaser.HEADLESS });
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.battleStyle("single")
.enemySpecies(SpeciesId.RATTATA)
.enemyMoveset(MoveId.SPLASH)
.enemyAbility(AbilityId.NONE)
.enemyLevel(2000)
.moveset(MoveId.SWALLOW)
.ability(AbilityId.NONE);
});
describe("consumes all stockpile stacks to heal (scaling with stacks)", () => {
it("1 stack -> 25% heal", async () => {
const stacksToSetup = 1;
const expectedHeal = 25;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 1;
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
vi.spyOn(pokemon, "heal");
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expectedHeal);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("2 stacks -> 50% heal", async () => {
const stacksToSetup = 2;
const expectedHeal = 50;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 1;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
vi.spyOn(pokemon, "heal");
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expectedHeal);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("3 stacks -> 100% heal", async () => {
const stacksToSetup = 3;
const expectedHeal = 100;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 0.0001;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
vi.spyOn(pokemon, "heal");
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expect.closeTo(expectedHeal));
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
});
it("fails without stacks", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeUndefined();
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject({
move: MoveId.SWALLOW,
result: MoveResult.FAIL,
targets: [pokemon.getBattlerIndex()],
});
});
describe("restores stat stage boosts granted by stacks", () => {
it("decreases stats based on stored values (both boosts equal)", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(MovePhase);
expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(1);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject({
move: MoveId.SWALLOW,
result: MoveResult.SUCCESS,
targets: [pokemon.getBattlerIndex()],
});
expect(pokemon.getStatStage(Stat.DEF)).toBe(0);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(0);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("lower stat stages based on stored values (different boosts)", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
// for the sake of simplicity (and because other tests cover the setup), set boost amounts directly
stockpilingTag.statChangeCounts = {
[Stat.DEF]: -1,
[Stat.SPDEF]: 2,
};
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject({
move: MoveId.SWALLOW,
result: MoveResult.SUCCESS,
targets: [pokemon.getBattlerIndex()],
});
expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(-2);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
});
});

View File

@ -371,9 +371,12 @@ export class GameManager {
console.log("==================[New Turn]==================");
}
/** Transition to the {@linkcode TurnEndPhase | end of the current turn}. */
async toEndOfTurn() {
await this.phaseInterceptor.to("TurnEndPhase");
/**
* Transition to the {@linkcode TurnEndPhase | end of the current turn}.
* @param endTurn - Whether to run the TurnEndPhase or not; default `true`
*/
async toEndOfTurn(endTurn = true) {
await this.phaseInterceptor.to("TurnEndPhase", endTurn);
console.log("==================[End of Turn]==================");
}

View File

@ -36,6 +36,7 @@ import { NewBiomeEncounterPhase } from "#phases/new-biome-encounter-phase";
import { NextEncounterPhase } from "#phases/next-encounter-phase";
import { PartyExpPhase } from "#phases/party-exp-phase";
import { PartyHealPhase } from "#phases/party-heal-phase";
import { PokemonHealPhase } from "#phases/pokemon-heal-phase";
import { PokemonTransformPhase } from "#phases/pokemon-transform-phase";
import { PositionalTagPhase } from "#phases/positional-tag-phase";
import { PostGameOverPhase } from "#phases/post-game-over-phase";
@ -146,6 +147,7 @@ export class PhaseInterceptor {
[PositionalTagPhase, this.startPhase],
[PokemonTransformPhase, this.startPhase],
[MysteryEncounterPhase, this.startPhase],
[PokemonHealPhase, this.startPhase],
[MysteryEncounterOptionSelectedPhase, this.startPhase],
[MysteryEncounterBattlePhase, this.startPhase],
[MysteryEncounterRewardsPhase, this.startPhase],