Merge branch 'pagefaultgames:beta' into freeze-dry-implementation

This commit is contained in:
geeilhan 2024-11-11 08:40:18 +01:00 committed by GitHub
commit cacd92636a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 645 additions and 242 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

View File

@ -1647,6 +1647,27 @@
"h": 25
}
},
{
"filename": "85-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 5,
"y": 3,
"w": 29,
"h": 25
},
"frame": {
"x": 55,
"y": 270,
"w": 29,
"h": 25
}
},
{
"filename": "22s",
"rotated": false,
@ -1731,6 +1752,27 @@
"h": 25
}
},
{
"filename": "85s-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 5,
"y": 3,
"w": 29,
"h": 25
},
"frame": {
"x": 56,
"y": 317,
"w": 29,
"h": 25
}
},
{
"filename": "9s",
"rotated": false,
@ -6456,6 +6498,27 @@
"h": 18
}
},
{
"filename": "84-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 9,
"y": 10,
"w": 21,
"h": 18
},
"frame": {
"x": 98,
"y": 712,
"w": 21,
"h": 18
}
},
{
"filename": "107",
"rotated": false,
@ -6519,6 +6582,27 @@
"h": 18
}
},
{
"filename": "84s-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 9,
"y": 10,
"w": 21,
"h": 18
},
"frame": {
"x": 96,
"y": 770,
"w": 21,
"h": 18
}
},
{
"filename": "88",
"rotated": false,

View File

@ -786,6 +786,27 @@
"h": 27
}
},
{
"filename": "154-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 8,
"y": 1,
"w": 23,
"h": 27
},
"frame": {
"x": 29,
"y": 147,
"w": 23,
"h": 27
}
},
{
"filename": "154s",
"rotated": false,
@ -807,6 +828,27 @@
"h": 27
}
},
{
"filename": "154s-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 8,
"y": 1,
"w": 23,
"h": 27
},
"frame": {
"x": 29,
"y": 174,
"w": 23,
"h": 27
}
},
{
"filename": "229-mega",
"rotated": false,

View File

@ -198,6 +198,27 @@
"h": 27
}
},
{
"filename": "257-f-mega",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 4,
"y": 2,
"w": 32,
"h": 27
},
"frame": {
"x": 0,
"y": 79,
"w": 32,
"h": 27
}
},
{
"filename": "257s-mega",
"rotated": false,
@ -219,6 +240,27 @@
"h": 27
}
},
{
"filename": "257s-f-mega",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 4,
"y": 2,
"w": 32,
"h": 27
},
"frame": {
"x": 0,
"y": 106,
"w": 32,
"h": 27
}
},
{
"filename": "323-mega",
"rotated": false,
@ -1248,6 +1290,27 @@
"h": 26
}
},
{
"filename": "257-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 7,
"y": 2,
"w": 25,
"h": 26
},
"frame": {
"x": 28,
"y": 556,
"w": 25,
"h": 26
}
},
{
"filename": "257s",
"rotated": false,
@ -1269,6 +1332,27 @@
"h": 26
}
},
{
"filename": "257s-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 7,
"y": 2,
"w": 25,
"h": 26
},
"frame": {
"x": 28,
"y": 582,
"w": 25,
"h": 26
}
},
{
"filename": "359-mega",
"rotated": false,
@ -1605,6 +1689,27 @@
"h": 25
}
},
{
"filename": "256-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 8,
"y": 3,
"w": 23,
"h": 25
},
"frame": {
"x": 98,
"y": 72,
"w": 23,
"h": 25
}
},
{
"filename": "282s-mega",
"rotated": false,
@ -5553,6 +5658,27 @@
"h": 19
}
},
{
"filename": "255-f",
"rotated": false,
"trimmed": true,
"sourceSize": {
"w": 40,
"h": 30
},
"spriteSourceSize": {
"x": 13,
"y": 9,
"w": 13,
"h": 19
},
"frame": {
"x": 204,
"y": 342,
"w": 13,
"h": 19
}
},
{
"filename": "307s",
"rotated": false,

View File

@ -2572,14 +2572,15 @@ export default class BattleScene extends SceneBase {
* The quantity to transfer is automatically capped at how much the recepient can take before reaching the maximum stack size for the item.
* A transfer that moves a quantity smaller than what is specified in the transferQuantity parameter is still considered successful.
* @param itemModifier {@linkcode PokemonHeldItemModifier} item to transfer (represents the whole stack)
* @param target {@linkcode Pokemon} pokemon recepient in this transfer
* @param playSound {boolean}
* @param transferQuantity {@linkcode integer} how many items of the stack to transfer. Optional, defaults to 1
* @param instant {boolean}
* @param ignoreUpdate {boolean}
* @returns true if the transfer was successful
* @param target {@linkcode Pokemon} recepient in this transfer
* @param playSound `true` to play a sound when transferring the item
* @param transferQuantity How many items of the stack to transfer. Optional, defaults to `1`
* @param instant ??? (Optional)
* @param ignoreUpdate ??? (Optional)
* @param itemLost If `true`, treat the item's current holder as losing the item (for now, this simply enables Unburden). Default is `true`.
* @returns `true` if the transfer was successful
*/
tryTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, playSound: boolean, transferQuantity: integer = 1, instant?: boolean, ignoreUpdate?: boolean): Promise<boolean> {
tryTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, playSound: boolean, transferQuantity: number = 1, instant?: boolean, ignoreUpdate?: boolean, itemLost: boolean = true): Promise<boolean> {
return new Promise(resolve => {
const source = itemModifier.pokemonId ? itemModifier.getPokemon(target.scene) : null;
const cancelled = new Utils.BooleanHolder(false);
@ -2612,14 +2613,14 @@ export default class BattleScene extends SceneBase {
if (!matchingModifier || this.removeModifier(matchingModifier, !target.isPlayer())) {
if (target.isPlayer()) {
this.addModifier(newItemModifier, ignoreUpdate, playSound, false, instant).then(() => {
if (source) {
if (source && itemLost) {
applyPostItemLostAbAttrs(PostItemLostAbAttr, source, false);
}
resolve(true);
});
} else {
this.addEnemyModifier(newItemModifier, ignoreUpdate, instant).then(() => {
if (source) {
if (source && itemLost) {
applyPostItemLostAbAttrs(PostItemLostAbAttr, source, false);
}
resolve(true);
@ -2791,7 +2792,15 @@ export default class BattleScene extends SceneBase {
});
}
removeModifier(modifier: PersistentModifier, enemy?: boolean): boolean {
/**
* Removes a currently owned item. If the item is stacked, the entire item stack
* gets removed. This function does NOT apply in-battle effects, such as Unburden.
* If in-battle effects are needed, use {@linkcode Pokemon.loseHeldItem} instead.
* @param modifier The item to be removed.
* @param enemy If `true`, remove an item owned by the enemy. If `false`, remove an item owned by the player. Default is `false`.
* @returns `true` if the item exists and was successfully removed, `false` otherwise.
*/
removeModifier(modifier: PersistentModifier, enemy: boolean = false): boolean {
const modifiers = !enemy ? this.modifiers : this.enemyModifiers;
const modifierIndex = modifiers.indexOf(modifier);
if (modifierIndex > -1) {

View File

@ -4152,7 +4152,7 @@ export class PostBattleLootAbAttr extends PostBattleAbAttr {
if (!simulated && postBattleLoot.length) {
const randItem = Utils.randSeedItem(postBattleLoot);
//@ts-ignore - TODO see below
if (pokemon.scene.tryTransferHeldItemModifier(randItem, pokemon, true, 1, true)) { // TODO: fix. This is a promise!?
if (pokemon.scene.tryTransferHeldItemModifier(randItem, pokemon, true, 1, true, undefined, false)) { // TODO: fix. This is a promise!?
postBattleLoot.splice(postBattleLoot.indexOf(randItem), 1);
pokemon.scene.queueMessage(i18next.t("abilityTriggers:postBattleLoot", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), itemName: randItem.type.name }));
return true;
@ -5616,7 +5616,9 @@ export function initAbilities() {
new Ability(Abilities.ANGER_POINT, 4)
.attr(PostDefendCritStatStageChangeAbAttr, Stat.ATK, 6),
new Ability(Abilities.UNBURDEN, 4)
.attr(PostItemLostApplyBattlerTagAbAttr, BattlerTagType.UNBURDEN),
.attr(PostItemLostApplyBattlerTagAbAttr, BattlerTagType.UNBURDEN)
.bypassFaint() // Allows reviver seed to activate Unburden
.edgeCase(), // Should not restore Unburden boost if Pokemon loses then regains Unburden ability
new Ability(Abilities.HEATPROOF, 4)
.attr(ReceivedTypeDamageMultiplierAbAttr, Type.FIRE, 0.5)
.attr(ReduceBurnDamageAbAttr, 0.5)

View File

@ -61,13 +61,13 @@ export function getBerryPredicate(berryType: BerryType): BerryPredicate {
}
}
export type BerryEffectFunc = (pokemon: Pokemon) => void;
export type BerryEffectFunc = (pokemon: Pokemon, berryOwner?: Pokemon) => void;
export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
switch (berryType) {
case BerryType.SITRUS:
case BerryType.ENIGMA:
return (pokemon: Pokemon) => {
return (pokemon: Pokemon, berryOwner?: Pokemon) => {
if (pokemon.battleData) {
pokemon.battleData.berriesEaten.push(berryType);
}
@ -75,10 +75,10 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, hpHealed);
pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(),
hpHealed.value, i18next.t("battle:hpHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), berryName: getBerryName(berryType) }), true));
applyPostItemLostAbAttrs(PostItemLostAbAttr, pokemon, false);
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
case BerryType.LUM:
return (pokemon: Pokemon) => {
return (pokemon: Pokemon, berryOwner?: Pokemon) => {
if (pokemon.battleData) {
pokemon.battleData.berriesEaten.push(berryType);
}
@ -87,14 +87,14 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
}
pokemon.resetStatus(true, true);
pokemon.updateInfo();
applyPostItemLostAbAttrs(PostItemLostAbAttr, pokemon, false);
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
case BerryType.LIECHI:
case BerryType.GANLON:
case BerryType.PETAYA:
case BerryType.APICOT:
case BerryType.SALAC:
return (pokemon: Pokemon) => {
return (pokemon: Pokemon, berryOwner?: Pokemon) => {
if (pokemon.battleData) {
pokemon.battleData.berriesEaten.push(berryType);
}
@ -103,18 +103,18 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
const statStages = new Utils.NumberHolder(1);
applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, statStages);
pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ stat ], statStages.value));
applyPostItemLostAbAttrs(PostItemLostAbAttr, pokemon, false);
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
case BerryType.LANSAT:
return (pokemon: Pokemon) => {
return (pokemon: Pokemon, berryOwner?: Pokemon) => {
if (pokemon.battleData) {
pokemon.battleData.berriesEaten.push(berryType);
}
pokemon.addTag(BattlerTagType.CRIT_BOOST);
applyPostItemLostAbAttrs(PostItemLostAbAttr, pokemon, false);
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
case BerryType.STARF:
return (pokemon: Pokemon) => {
return (pokemon: Pokemon, berryOwner?: Pokemon) => {
if (pokemon.battleData) {
pokemon.battleData.berriesEaten.push(berryType);
}
@ -122,10 +122,10 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
const stages = new Utils.NumberHolder(2);
applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, stages);
pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ randStat ], stages.value));
applyPostItemLostAbAttrs(PostItemLostAbAttr, pokemon, false);
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
};
case BerryType.LEPPA:
return (pokemon: Pokemon) => {
return (pokemon: Pokemon, berryOwner?: Pokemon) => {
if (pokemon.battleData) {
pokemon.battleData.berriesEaten.push(berryType);
}
@ -133,7 +133,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
if (ppRestoreMove !== undefined) {
ppRestoreMove!.ppUsed = Math.max(ppRestoreMove!.ppUsed - 10, 0);
pokemon.scene.queueMessage(i18next.t("battle:ppHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: ppRestoreMove!.getName(), berryName: getBerryName(berryType) }));
applyPostItemLostAbAttrs(PostItemLostAbAttr, pokemon, false);
applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false);
}
};
}

View File

@ -2417,9 +2417,8 @@ export class RemoveHeldItemAttr extends MoveEffectAttr {
const removedItem = heldItems[user.randSeedInt(heldItems.length)];
// Decrease item amount and update icon
!--removedItem.stackCount;
target.loseHeldItem(removedItem);
target.scene.updateModifiers(target.isPlayer());
applyPostItemLostAbAttrs(PostItemLostAbAttr, target, false);
if (this.berriesOnly) {
@ -2489,18 +2488,15 @@ export class EatBerryAttr extends MoveEffectAttr {
}
reduceBerryModifier(target: Pokemon) {
if (this.chosenBerry?.stackCount === 1) {
target.scene.removeModifier(this.chosenBerry, !target.isPlayer());
} else if (this.chosenBerry !== undefined && this.chosenBerry.stackCount > 1) {
this.chosenBerry.stackCount--;
if (this.chosenBerry) {
target.loseHeldItem(this.chosenBerry);
}
target.scene.updateModifiers(target.isPlayer());
}
eatBerry(consumer: Pokemon) {
getBerryEffectFunc(this.chosenBerry!.berryType)(consumer); // consumer eats the berry
eatBerry(consumer: Pokemon, berryOwner?: Pokemon) {
getBerryEffectFunc(this.chosenBerry!.berryType)(consumer, berryOwner); // consumer eats the berry
applyAbAttrs(HealFromBerryUseAbAttr, consumer, new Utils.BooleanHolder(false));
applyPostItemLostAbAttrs(PostItemLostAbAttr, consumer, false);
}
}
@ -2540,7 +2536,7 @@ export class StealEatBerryAttr extends EatBerryAttr {
const message = i18next.t("battle:stealEatBerry", { pokemonName: user.name, targetName: target.name, berryName: this.chosenBerry.type.name });
user.scene.queueMessage(message);
this.reduceBerryModifier(target);
this.eatBerry(user);
this.eatBerry(user, target);
return true;
}
}

View File

@ -477,12 +477,9 @@ export const BugTypeSuperfanEncounter: MysteryEncounter =
.withOptionPhase(async (scene: BattleScene) => {
const encounter = scene.currentBattle.mysteryEncounter!;
const modifier = encounter.misc.chosenModifier;
const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon;
// Remove the modifier if its stacks go to 0
modifier.stackCount -= 1;
if (modifier.stackCount === 0) {
scene.removeModifier(modifier);
}
chosenPokemon.loseHeldItem(modifier, false);
scene.updateModifiers(true, true);
const bugNet = generateModifierTypeOption(scene, modifierTypes.MYSTERY_ENCOUNTER_GOLDEN_BUG_NET)!;

View File

@ -8,7 +8,7 @@ import { applyModifierTypeToPlayerPokemon } from "#app/data/mystery-encounters/u
import { getPokemonSpecies } from "#app/data/pokemon-species";
import Pokemon, { PlayerPokemon } from "#app/field/pokemon";
import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/game-mode";
import { BerryModifier, HealingBoosterModifier, LevelIncrementBoosterModifier, MoneyMultiplierModifier, PokemonHeldItemModifier, PreserveBerryModifier } from "#app/modifier/modifier";
import { BerryModifier, HealingBoosterModifier, LevelIncrementBoosterModifier, MoneyMultiplierModifier, PokemonHeldItemModifier, PokemonInstantReviveModifier, PreserveBerryModifier } from "#app/modifier/modifier";
import { modifierTypes, PokemonHeldItemModifierType } from "#app/modifier/modifier-type";
import { ModifierRewardPhase } from "#app/phases/modifier-reward-phase";
import i18next from "#app/plugins/i18n";
@ -197,7 +197,8 @@ export const DelibirdyEncounter: MysteryEncounter =
})
.withOptionPhase(async (scene: BattleScene) => {
const encounter = scene.currentBattle.mysteryEncounter!;
const modifier: BerryModifier | HealingBoosterModifier = encounter.misc.chosenModifier;
const modifier: BerryModifier | PokemonInstantReviveModifier = encounter.misc.chosenModifier;
const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon;
// Give the player a Candy Jar if they gave a Berry, and a Berry Pouch for Reviver Seed
if (modifier instanceof BerryModifier) {
@ -228,11 +229,7 @@ export const DelibirdyEncounter: MysteryEncounter =
}
}
// Remove the modifier if its stacks go to 0
modifier.stackCount -= 1;
if (modifier.stackCount === 0) {
scene.removeModifier(modifier);
}
chosenPokemon.loseHeldItem(modifier, false);
leaveEncounterWithoutBattle(scene, true);
})
@ -292,6 +289,7 @@ export const DelibirdyEncounter: MysteryEncounter =
.withOptionPhase(async (scene: BattleScene) => {
const encounter = scene.currentBattle.mysteryEncounter!;
const modifier = encounter.misc.chosenModifier;
const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon;
// Check if the player has max stacks of Healing Charm already
const existing = scene.findModifier(m => m instanceof HealingBoosterModifier) as HealingBoosterModifier;
@ -306,11 +304,7 @@ export const DelibirdyEncounter: MysteryEncounter =
scene.unshiftPhase(new ModifierRewardPhase(scene, modifierTypes.HEALING_CHARM));
}
// Remove the modifier if its stacks go to 0
modifier.stackCount -= 1;
if (modifier.stackCount === 0) {
scene.removeModifier(modifier);
}
chosenPokemon.loseHeldItem(modifier, false);
leaveEncounterWithoutBattle(scene, true);
})

View File

@ -345,6 +345,7 @@ export const GlobalTradeSystemEncounter: MysteryEncounter =
// Pokemon and item selected
encounter.setDialogueToken("chosenItem", modifier.type.name);
encounter.misc.chosenModifier = modifier;
encounter.misc.chosenPokemon = pokemon;
return true;
},
};
@ -370,6 +371,7 @@ export const GlobalTradeSystemEncounter: MysteryEncounter =
const encounter = scene.currentBattle.mysteryEncounter!;
const modifier = encounter.misc.chosenModifier as PokemonHeldItemModifier;
const party = scene.getPlayerParty();
const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon;
// Check tier of the traded item, the received item will be one tier up
const type = modifier.type.withTierFromPool(ModifierPoolType.PLAYER, party);
@ -397,11 +399,7 @@ export const GlobalTradeSystemEncounter: MysteryEncounter =
encounter.setDialogueToken("itemName", item.type.name);
setEncounterRewards(scene, { guaranteedModifierTypeOptions: [ item ], fillRemaining: false });
// Remove the chosen modifier if its stacks go to 0
modifier.stackCount -= 1;
if (modifier.stackCount === 0) {
scene.removeModifier(modifier);
}
chosenPokemon.loseHeldItem(modifier, false);
await scene.updateModifiers(true, true);
// Generate a trainer name

View File

@ -363,6 +363,12 @@ export abstract class PokemonSpeciesForm {
}
switch (this.speciesId) {
case Species.DODUO:
case Species.DODRIO:
case Species.MEGANIUM:
case Species.TORCHIC:
case Species.COMBUSKEN:
case Species.BLAZIKEN:
case Species.HIPPOPOTAS:
case Species.HIPPOWDON:
case Species.UNFEZANT:

View File

@ -23,7 +23,7 @@ import { reverseCompatibleTms, tmSpecies, tmPoolTiers } from "#app/data/balance/
import { BattlerTag, BattlerTagLapseType, EncoreTag, GroundedTag, HighestStatBoostTag, SubstituteTag, TypeImmuneTag, getBattlerTag, SemiInvulnerableTag, TypeBoostTag, MoveRestrictionBattlerTag, ExposedTag, DragonCheerTag, CritBoostTag, TrappedTag, TarShotTag, AutotomizedTag, PowerTrickTag } from "../data/battler-tags";
import { WeatherType } from "#enums/weather-type";
import { ArenaTagSide, NoCritTag, WeakenMoveScreenTag } from "#app/data/arena-tag";
import { Ability, AbAttr, StatMultiplierAbAttr, BlockCritAbAttr, BonusCritAbAttr, BypassBurnDamageReductionAbAttr, FieldPriorityMoveImmunityAbAttr, IgnoreOpponentStatStagesAbAttr, MoveImmunityAbAttr, PreDefendFullHpEndureAbAttr, ReceivedMoveDamageMultiplierAbAttr, StabBoostAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, WeightMultiplierAbAttr, allAbilities, applyAbAttrs, applyStatMultiplierAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs, UnsuppressableAbilityAbAttr, SuppressFieldAbilitiesAbAttr, NoFusionAbilityAbAttr, MultCritAbAttr, IgnoreTypeImmunityAbAttr, DamageBoostAbAttr, IgnoreTypeStatusEffectImmunityAbAttr, ConditionalCritAbAttr, applyFieldStatMultiplierAbAttrs, FieldMultiplyStatAbAttr, AddSecondStrikeAbAttr, UserFieldStatusEffectImmunityAbAttr, UserFieldBattlerTagImmunityAbAttr, BattlerTagImmunityAbAttr, MoveTypeChangeAbAttr, FullHpResistTypeAbAttr, applyCheckTrappedAbAttrs, CheckTrappedAbAttr, PostSetStatusAbAttr, applyPostSetStatusAbAttrs, InfiltratorAbAttr, AlliedFieldDamageReductionAbAttr, PostDamageAbAttr, applyPostDamageAbAttrs, PostDamageForceSwitchAbAttr, CommanderAbAttr } from "#app/data/ability";
import { Ability, AbAttr, StatMultiplierAbAttr, BlockCritAbAttr, BonusCritAbAttr, BypassBurnDamageReductionAbAttr, FieldPriorityMoveImmunityAbAttr, IgnoreOpponentStatStagesAbAttr, MoveImmunityAbAttr, PreDefendFullHpEndureAbAttr, ReceivedMoveDamageMultiplierAbAttr, StabBoostAbAttr, StatusEffectImmunityAbAttr, TypeImmunityAbAttr, WeightMultiplierAbAttr, allAbilities, applyAbAttrs, applyStatMultiplierAbAttrs, applyPreApplyBattlerTagAbAttrs, applyPreAttackAbAttrs, applyPreDefendAbAttrs, applyPreSetStatusAbAttrs, UnsuppressableAbilityAbAttr, SuppressFieldAbilitiesAbAttr, NoFusionAbilityAbAttr, MultCritAbAttr, IgnoreTypeImmunityAbAttr, DamageBoostAbAttr, IgnoreTypeStatusEffectImmunityAbAttr, ConditionalCritAbAttr, applyFieldStatMultiplierAbAttrs, FieldMultiplyStatAbAttr, AddSecondStrikeAbAttr, UserFieldStatusEffectImmunityAbAttr, UserFieldBattlerTagImmunityAbAttr, BattlerTagImmunityAbAttr, MoveTypeChangeAbAttr, FullHpResistTypeAbAttr, applyCheckTrappedAbAttrs, CheckTrappedAbAttr, PostSetStatusAbAttr, applyPostSetStatusAbAttrs, InfiltratorAbAttr, AlliedFieldDamageReductionAbAttr, PostDamageAbAttr, applyPostDamageAbAttrs, PostDamageForceSwitchAbAttr, CommanderAbAttr, applyPostItemLostAbAttrs, PostItemLostAbAttr } from "#app/data/ability";
import PokemonData from "#app/system/pokemon-data";
import { BattlerIndex } from "#app/battle";
import { Mode } from "#app/ui/ui";
@ -442,7 +442,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
};
if (this.shiny) {
const populateVariantColors = (isBackSprite: boolean = false): Promise<void> => {
return new Promise(resolve => {
return new Promise(async resolve => {
const battleSpritePath = this.getBattleSpriteAtlasPath(isBackSprite, ignoreOverride).replace("variant/", "").replace(/_[1-3]$/, "");
let config = variantData;
const useExpSprite = this.scene.experimentalSprites && this.scene.hasExpSprite(this.getBattleSpriteKey(isBackSprite, ignoreOverride));
@ -451,7 +451,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
if (variantSet && variantSet[this.variant] === 1) {
const cacheKey = this.getBattleSpriteKey(isBackSprite);
if (!variantColorCache.hasOwnProperty(cacheKey)) {
this.populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath);
await this.populateVariantColorCache(cacheKey, useExpSprite, battleSpritePath);
}
}
resolve();
@ -483,10 +483,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* @param battleSpritePath the filename of the sprite
* @param optionalParams any additional params to log
*/
fallbackVariantColor(cacheKey: string, attemptedSpritePath: string, useExpSprite: boolean, battleSpritePath: string, ...optionalParams: any[]) {
async fallbackVariantColor(cacheKey: string, attemptedSpritePath: string, useExpSprite: boolean, battleSpritePath: string, ...optionalParams: any[]) {
console.warn(`Could not load ${attemptedSpritePath}!`, ...optionalParams);
if (useExpSprite) {
this.populateVariantColorCache(cacheKey, false, battleSpritePath);
await this.populateVariantColorCache(cacheKey, false, battleSpritePath);
}
}
@ -497,18 +497,20 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* @param useExpSprite should the experimental sprite be used
* @param battleSpritePath the filename of the sprite
*/
populateVariantColorCache(cacheKey: string, useExpSprite: boolean, battleSpritePath: string) {
async populateVariantColorCache(cacheKey: string, useExpSprite: boolean, battleSpritePath: string) {
const spritePath = `./images/pokemon/variant/${useExpSprite ? "exp/" : ""}${battleSpritePath}.json`;
this.scene.cachedFetch(spritePath).then(res => {
return this.scene.cachedFetch(spritePath).then(res => {
// Prevent the JSON from processing if it failed to load
if (!res.ok) {
return this.fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText);
}
return res.json();
}).catch(error => {
this.fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
return this.fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
}).then(c => {
variantColorCache[cacheKey] = c;
if (!isNullOrUndefined(c)) {
variantColorCache[cacheKey] = c;
}
});
}
@ -985,7 +987,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
if (this.status && this.status.effect === StatusEffect.PARALYSIS) {
ret >>= 1;
}
if (this.getTag(BattlerTagType.UNBURDEN) && !this.scene.getField(true).some(pokemon => pokemon !== this && pokemon.hasAbilityWithAttr(SuppressFieldAbilitiesAbAttr))) {
if (this.getTag(BattlerTagType.UNBURDEN) && this.hasAbility(Abilities.UNBURDEN)) {
ret *= 2;
}
break;
@ -4102,6 +4104,28 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
}
return false;
}
/**
* Reduces one of this Pokemon's held item stacks by 1, and removes the item if applicable.
* Does nothing if this Pokemon is somehow not the owner of the held item.
* @param heldItem The item stack to be reduced by 1.
* @param forBattle If `false`, do not trigger in-battle effects (such as Unburden) from losing the item. For example, set this to `false` if the Pokemon is giving away the held item for a Mystery Encounter. Default is `true`.
* @returns `true` if the item was removed successfully, `false` otherwise.
*/
public loseHeldItem(heldItem: PokemonHeldItemModifier, forBattle: boolean = true): boolean {
if (heldItem.pokemonId === -1 || heldItem.pokemonId === this.id) {
heldItem.stackCount--;
if (heldItem.stackCount <= 0) {
this.scene.removeModifier(heldItem, !this.isPlayer());
}
if (forBattle) {
applyPostItemLostAbAttrs(PostItemLostAbAttr, this, false);
}
return true;
} else {
return false;
}
}
}
export default interface Pokemon {
@ -4544,7 +4568,7 @@ export class PlayerPokemon extends Pokemon {
&& m.pokemonId === pokemon.id, true) as PokemonHeldItemModifier[];
const transferModifiers: Promise<boolean>[] = [];
for (const modifier of fusedPartyMemberHeldModifiers) {
transferModifiers.push(this.scene.tryTransferHeldItemModifier(modifier, this, false, modifier.getStackCount(), true, true));
transferModifiers.push(this.scene.tryTransferHeldItemModifier(modifier, this, false, modifier.getStackCount(), true, true, false));
}
Promise.allSettled(transferModifiers).then(() => {
this.scene.updateModifiers(true, true).then(() => {

View File

@ -31,11 +31,8 @@ export class BerryPhase extends FieldPhase {
for (const berryModifier of this.scene.applyModifiers(BerryModifier, pokemon.isPlayer(), pokemon)) {
if (berryModifier.consumed) {
if (!--berryModifier.stackCount) {
this.scene.removeModifier(berryModifier);
} else {
berryModifier.consumed = false;
}
berryModifier.consumed = false;
pokemon.loseHeldItem(berryModifier);
}
this.scene.eventTarget.dispatchEvent(new BerryUsedEvent(berryModifier)); // Announce a berry was used
}

View File

@ -55,21 +55,21 @@ export class FaintPhase extends PokemonPhase {
start() {
super.start();
const faintPokemon = this.getPokemon();
if (!isNullOrUndefined(this.destinyTag) && !isNullOrUndefined(this.source)) {
this.destinyTag.lapse(this.source, BattlerTagLapseType.CUSTOM);
}
if (!isNullOrUndefined(this.grudgeTag) && !isNullOrUndefined(this.source)) {
this.grudgeTag.lapse(this.getPokemon(), BattlerTagLapseType.CUSTOM, this.source);
this.grudgeTag.lapse(faintPokemon, BattlerTagLapseType.CUSTOM, this.source);
}
if (!this.preventEndure) {
const instantReviveModifier = this.scene.applyModifier(PokemonInstantReviveModifier, this.player, this.getPokemon()) as PokemonInstantReviveModifier;
const instantReviveModifier = this.scene.applyModifier(PokemonInstantReviveModifier, this.player, faintPokemon) as PokemonInstantReviveModifier;
if (instantReviveModifier) {
if (!--instantReviveModifier.stackCount) {
this.scene.removeModifier(instantReviveModifier);
}
faintPokemon.loseHeldItem(instantReviveModifier);
this.scene.updateModifiers(this.player);
return this.end();
}

View File

@ -103,7 +103,7 @@ export class SelectModifierPhase extends BattlePhase {
const itemModifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier
&& m.isTransferable && m.pokemonId === party[fromSlotIndex].id) as PokemonHeldItemModifier[];
const itemModifier = itemModifiers[itemIndex];
this.scene.tryTransferHeldItemModifier(itemModifier, party[toSlotIndex], true, itemQuantity);
this.scene.tryTransferHeldItemModifier(itemModifier, party[toSlotIndex], true, itemQuantity, undefined, undefined, false);
} else {
this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(this.scene.lockModifierTiers));
}

View File

@ -125,10 +125,7 @@ export class StatStageChangePhase extends PokemonPhase {
const whiteHerb = this.scene.applyModifier(ResetNegativeStatStageModifier, this.player, pokemon) as ResetNegativeStatStageModifier;
// If the White Herb was applied, consume it
if (whiteHerb) {
whiteHerb.stackCount--;
if (whiteHerb.stackCount <= 0) {
this.scene.removeModifier(whiteHerb);
}
pokemon.loseHeldItem(whiteHerb);
this.scene.updateModifiers(this.player);
}
}

View File

@ -111,7 +111,7 @@ export class SwitchSummonPhase extends SummonPhase {
const batonPassModifier = this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier
&& (m as SwitchEffectTransferModifier).pokemonId === this.lastPokemon.id) as SwitchEffectTransferModifier;
if (batonPassModifier && !this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === switchedInPokemon.id)) {
this.scene.tryTransferHeldItemModifier(batonPassModifier, switchedInPokemon, false);
this.scene.tryTransferHeldItemModifier(batonPassModifier, switchedInPokemon, false, undefined, undefined, undefined, false);
}
}
}

View File

@ -1,18 +1,35 @@
import { BattlerIndex } from "#app/battle";
import { PostItemLostAbAttr } from "#app/data/ability";
import { allMoves, StealHeldItemChanceAttr } from "#app/data/move";
import Pokemon from "#app/field/pokemon";
import type { ContactHeldItemTransferChanceModifier } from "#app/modifier/modifier";
import { Abilities } from "#enums/abilities";
import { BattlerTagType } from "#enums/battler-tag-type";
import { BerryType } from "#enums/berry-type";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import { Stat } from "#enums/stat";
import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { Stat } from "#enums/stat";
import { BerryType } from "#app/enums/berry-type";
import { allMoves, StealHeldItemChanceAttr } from "#app/data/move";
describe("Abilities - Unburden", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
/**
* Count the number of held items a Pokemon has, accounting for stacks of multiple items.
*/
function getHeldItemCount(pokemon: Pokemon): number {
const stackCounts = pokemon.getHeldItems().map(m => m.getStackCount());
if (stackCounts.length) {
return stackCounts.reduce((a, b) => a + b);
} else {
return 0;
}
}
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
@ -27,9 +44,9 @@ describe("Abilities - Unburden", () => {
game = new GameManager(phaserGame);
game.override
.battleType("single")
.starterSpecies(Species.TREECKO)
.startingLevel(1)
.moveset([ Moves.POPULATION_BOMB, Moves.KNOCK_OFF, Moves.PLUCK, Moves.THIEF ])
.ability(Abilities.UNBURDEN)
.moveset([ Moves.SPLASH, Moves.KNOCK_OFF, Moves.PLUCK, Moves.FALSE_SWIPE ])
.startingHeldItems([
{ name: "BERRY", count: 1, type: BerryType.SITRUS },
{ name: "BERRY", count: 2, type: BerryType.APICOT },
@ -37,209 +54,348 @@ describe("Abilities - Unburden", () => {
])
.enemySpecies(Species.NINJASK)
.enemyLevel(100)
.enemyMoveset([ Moves.FALSE_SWIPE ])
.enemyMoveset(Moves.SPLASH)
.enemyAbility(Abilities.UNBURDEN)
.enemyPassiveAbility(Abilities.NO_GUARD)
.enemyHeldItems([
{ name: "BERRY", type: BerryType.SITRUS, count: 1 },
{ name: "BERRY", type: BerryType.LUM, count: 1 },
]);
// For the various tests that use Thief, give it a 100% steal rate
vi.spyOn(allMoves[Moves.THIEF], "attrs", "get").mockReturnValue([ new StealHeldItemChanceAttr(1.0) ]);
});
it("should activate when a berry is eaten", async () => {
await game.classicMode.startBattle();
game.override.enemyMoveset(Moves.FALSE_SWIPE);
await game.classicMode.startBattle([ Species.TREECKO ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
playerPokemon.abilityIndex = 2;
const playerHeldItems = playerPokemon.getHeldItems().length;
const playerHeldItems = getHeldItemCount(playerPokemon);
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
game.move.select(Moves.FALSE_SWIPE);
// Player gets hit by False Swipe and eats its own Sitrus Berry
game.move.select(Moves.SPLASH);
await game.toNextTurn();
expect(playerPokemon.getHeldItems().length).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialPlayerSpeed * 2);
expect(getHeldItemCount(playerPokemon)).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
});
it("should activate when a berry is stolen", async () => {
await game.classicMode.startBattle();
it("should activate when a berry is eaten, even if Berry Pouch preserves the berry", async () => {
game.override.enemyMoveset(Moves.FALSE_SWIPE)
.startingModifier([{ name: "BERRY_POUCH", count: 5850 }]);
await game.classicMode.startBattle([ Species.TREECKO ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerHeldItems = getHeldItemCount(playerPokemon);
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
// Player gets hit by False Swipe and eats its own Sitrus Berry
game.move.select(Moves.SPLASH);
await game.toNextTurn();
expect(getHeldItemCount(playerPokemon)).toBe(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
});
it("should activate for the target, and not the stealer, when a berry is stolen", async () => {
await game.classicMode.startBattle([ Species.TREECKO ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
const enemyPokemon = game.scene.getEnemyPokemon()!;
const enemyHeldItemCt = enemyPokemon.getHeldItems().length;
const enemyHeldItemCt = getHeldItemCount(enemyPokemon);
const initialEnemySpeed = enemyPokemon.getStat(Stat.SPD);
// Player uses Pluck and eats the opponent's berry
game.move.select(Moves.PLUCK);
await game.toNextTurn();
expect(enemyPokemon.getHeldItems().length).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialEnemySpeed * 2);
expect(getHeldItemCount(enemyPokemon)).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBe(initialEnemySpeed * 2);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed);
});
it("should activate when an item is knocked off", async () => {
await game.classicMode.startBattle();
await game.classicMode.startBattle([ Species.TREECKO ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
const enemyHeldItemCt = enemyPokemon.getHeldItems().length;
const enemyHeldItemCt = getHeldItemCount(enemyPokemon);
const initialEnemySpeed = enemyPokemon.getStat(Stat.SPD);
// Player uses Knock Off and removes the opponent's item
game.move.select(Moves.KNOCK_OFF);
await game.toNextTurn();
expect(enemyPokemon.getHeldItems().length).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialEnemySpeed * 2);
expect(getHeldItemCount(enemyPokemon)).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBe(initialEnemySpeed * 2);
});
it("should activate when an item is stolen via attacking ability", async () => {
game.override
.ability(Abilities.MAGICIAN)
.startingHeldItems([
{ name: "MULTI_LENS", count: 3 },
]);
await game.classicMode.startBattle();
.startingHeldItems([]); // Remove player's full stacks of held items so it can steal opponent's held items
await game.classicMode.startBattle([ Species.TREECKO ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
const enemyHeldItemCt = enemyPokemon.getHeldItems().length;
const enemyHeldItemCt = getHeldItemCount(enemyPokemon);
const initialEnemySpeed = enemyPokemon.getStat(Stat.SPD);
game.move.select(Moves.POPULATION_BOMB);
// Player steals the opponent's item via ability Magician
game.move.select(Moves.FALSE_SWIPE);
await game.toNextTurn();
expect(enemyPokemon.getHeldItems().length).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialEnemySpeed * 2);
expect(getHeldItemCount(enemyPokemon)).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBe(initialEnemySpeed * 2);
});
it("should activate when an item is stolen via defending ability", async () => {
game.override
.startingLevel(45)
.enemyAbility(Abilities.PICKPOCKET)
.startingHeldItems([
{ name: "MULTI_LENS", count: 3 },
{ name: "SOUL_DEW", count: 1 },
{ name: "LUCKY_EGG", count: 1 },
]);
await game.classicMode.startBattle();
.enemyHeldItems([]); // Remove opponent's full stacks of held items so it can steal player's held items
await game.classicMode.startBattle([ Species.TREECKO ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
playerPokemon.abilityIndex = 2;
const playerHeldItems = playerPokemon.getHeldItems().length;
const playerHeldItems = getHeldItemCount(playerPokemon);
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
game.move.select(Moves.POPULATION_BOMB);
// Player's item gets stolen via ability Pickpocket
game.move.select(Moves.FALSE_SWIPE);
await game.toNextTurn();
expect(playerPokemon.getHeldItems().length).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialPlayerSpeed * 2);
expect(getHeldItemCount(playerPokemon)).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
});
it("should activate when an item is stolen via move", async () => {
vi.spyOn(allMoves[Moves.THIEF], "attrs", "get").mockReturnValue([ new StealHeldItemChanceAttr(1.0) ]); // give Thief 100% steal rate
game.override.startingHeldItems([
{ name: "MULTI_LENS", count: 3 },
]);
await game.classicMode.startBattle();
game.override.moveset(Moves.THIEF)
.startingHeldItems([]); // Remove player's full stacks of held items so it can steal opponent's held items
await game.classicMode.startBattle([ Species.TREECKO ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
const enemyHeldItemCt = enemyPokemon.getHeldItems().length;
const enemyHeldItemCt = getHeldItemCount(enemyPokemon);
const initialEnemySpeed = enemyPokemon.getStat(Stat.SPD);
// Player uses Thief and steals the opponent's item
game.move.select(Moves.THIEF);
await game.toNextTurn();
expect(enemyPokemon.getHeldItems().length).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialEnemySpeed * 2);
expect(getHeldItemCount(enemyPokemon)).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBe(initialEnemySpeed * 2);
});
it("should activate when an item is stolen via grip claw", async () => {
game.override
.startingLevel(5)
.startingHeldItems([
{ name: "GRIP_CLAW", count: 5 },
{ name: "MULTI_LENS", count: 3 },
])
.enemyHeldItems([
{ name: "SOUL_DEW", count: 1 },
{ name: "LUCKY_EGG", count: 1 },
{ name: "LEFTOVERS", count: 1 },
{ name: "GRIP_CLAW", count: 1 },
{ name: "MULTI_LENS", count: 1 },
{ name: "BERRY", type: BerryType.SITRUS, count: 1 },
{ name: "BERRY", type: BerryType.LUM, count: 1 },
]);
await game.classicMode.startBattle();
const enemyPokemon = game.scene.getEnemyPokemon()!;
const enemyHeldItemCt = enemyPokemon.getHeldItems().length;
const initialEnemySpeed = enemyPokemon.getStat(Stat.SPD);
while (enemyPokemon.getHeldItems().length === enemyHeldItemCt) {
game.move.select(Moves.POPULATION_BOMB);
await game.toNextTurn();
}
expect(enemyPokemon.getHeldItems().length).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialEnemySpeed * 2);
});
it("should not activate when a neutralizing ability is present", async () => {
game.override.enemyAbility(Abilities.NEUTRALIZING_GAS);
await game.classicMode.startBattle();
await game.classicMode.startBattle([ Species.TREECKO ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerHeldItems = playerPokemon.getHeldItems().length;
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
const gripClaw = playerPokemon.getHeldItems()[0] as ContactHeldItemTransferChanceModifier;
vi.spyOn(gripClaw, "chance", "get").mockReturnValue(100);
const enemyPokemon = game.scene.getEnemyPokemon()!;
const enemyHeldItemCt = getHeldItemCount(enemyPokemon);
const initialEnemySpeed = enemyPokemon.getStat(Stat.SPD);
// Player steals the opponent's item using Grip Claw
game.move.select(Moves.FALSE_SWIPE);
await game.toNextTurn();
expect(playerPokemon.getHeldItems().length).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialPlayerSpeed);
expect(getHeldItemCount(enemyPokemon)).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBe(initialEnemySpeed * 2);
});
it("should not activate when a neutralizing ability is present", async () => {
game.override.enemyAbility(Abilities.NEUTRALIZING_GAS)
.enemyMoveset(Moves.FALSE_SWIPE);
await game.classicMode.startBattle([ Species.TREECKO ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerHeldItems = getHeldItemCount(playerPokemon);
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
// Player gets hit by False Swipe and eats Sitrus Berry, which should not trigger Unburden
game.move.select(Moves.SPLASH);
await game.toNextTurn();
expect(getHeldItemCount(playerPokemon)).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed);
expect(playerPokemon.getTag(BattlerTagType.UNBURDEN)).toBeUndefined();
});
it("should activate when a move that consumes a berry is used", async () => {
game.override.enemyMoveset([ Moves.STUFF_CHEEKS ]);
await game.classicMode.startBattle();
game.override.moveset(Moves.STUFF_CHEEKS);
await game.classicMode.startBattle([ Species.TREECKO ]);
const enemyPokemon = game.scene.getEnemyPokemon()!;
const enemyHeldItemCt = enemyPokemon.getHeldItems().length;
const initialEnemySpeed = enemyPokemon.getStat(Stat.SPD);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerHeldItemCt = getHeldItemCount(playerPokemon);
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
// Player uses Stuff Cheeks and eats its own berry
// Caution: Do not test this using opponent, there is a known issue where opponent can randomly generate with Salac Berry
game.move.select(Moves.STUFF_CHEEKS);
await game.toNextTurn();
expect(enemyPokemon.getHeldItems().length).toBeLessThan(enemyHeldItemCt);
expect(enemyPokemon.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialEnemySpeed * 2);
expect(getHeldItemCount(playerPokemon)).toBeLessThan(playerHeldItemCt);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
});
it("should deactivate when a neutralizing gas user enters the field", async () => {
it("should deactivate temporarily when a neutralizing gas user is on the field", async () => {
game.override
.battleType("double")
.moveset([ Moves.SPLASH ]);
.ability(Abilities.NONE); // Disable ability override so that we can properly set abilities below
await game.classicMode.startBattle([ Species.TREECKO, Species.MEOWTH, Species.WEEZING ]);
const playerPokemon = game.scene.getPlayerParty();
const treecko = playerPokemon[0];
const weezing = playerPokemon[2];
treecko.abilityIndex = 2;
weezing.abilityIndex = 1;
const playerHeldItems = treecko.getHeldItems().length;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [ treecko, _meowth, weezing ] = game.scene.getPlayerParty();
treecko.abilityIndex = 2; // Treecko has Unburden
weezing.abilityIndex = 1; // Weezing has Neutralizing Gas
const playerHeldItems = getHeldItemCount(treecko);
const initialPlayerSpeed = treecko.getStat(Stat.SPD);
// Turn 1: Treecko gets hit by False Swipe and eats Sitrus Berry, activating Unburden
game.move.select(Moves.SPLASH);
game.move.select(Moves.SPLASH);
game.move.select(Moves.SPLASH, 1);
await game.forceEnemyMove(Moves.FALSE_SWIPE, 0);
await game.forceEnemyMove(Moves.FALSE_SWIPE, 0);
await game.phaseInterceptor.to("TurnEndPhase");
expect(treecko.getHeldItems().length).toBeLessThan(playerHeldItems);
expect(treecko.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialPlayerSpeed * 2);
expect(getHeldItemCount(treecko)).toBeLessThan(playerHeldItems);
expect(treecko.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
// Turn 2: Switch Meowth to Weezing, activating Neutralizing Gas
await game.toNextTurn();
game.move.select(Moves.SPLASH);
game.doSwitchPokemon(2);
await game.phaseInterceptor.to("TurnEndPhase");
expect(treecko.getHeldItems().length).toBeLessThan(playerHeldItems);
expect(treecko.getEffectiveStat(Stat.SPD)).toBeCloseTo(initialPlayerSpeed);
expect(getHeldItemCount(treecko)).toBeLessThan(playerHeldItems);
expect(treecko.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed);
// Turn 3: Switch Weezing to Meowth, deactivating Neutralizing Gas
await game.toNextTurn();
game.move.select(Moves.SPLASH);
game.doSwitchPokemon(2);
await game.phaseInterceptor.to("TurnEndPhase");
expect(getHeldItemCount(treecko)).toBeLessThan(playerHeldItems);
expect(treecko.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
});
it("should not activate when passing a baton to a teammate switching in", async () => {
game.override.startingHeldItems([{ name: "BATON" }])
.moveset(Moves.BATON_PASS);
await game.classicMode.startBattle([ Species.TREECKO, Species.PURRLOIN ]);
const [ treecko, purrloin ] = game.scene.getPlayerParty();
const initialTreeckoSpeed = treecko.getStat(Stat.SPD);
const initialPurrloinSpeed = purrloin.getStat(Stat.SPD);
const unburdenAttr = treecko.getAbilityAttrs(PostItemLostAbAttr)[0];
vi.spyOn(unburdenAttr, "applyPostItemLost");
// Player uses Baton Pass, which also passes the Baton item
game.move.select(Moves.BATON_PASS);
game.doSelectPartyPokemon(1);
await game.toNextTurn();
expect(getHeldItemCount(treecko)).toBe(0);
expect(getHeldItemCount(purrloin)).toBe(1);
expect(treecko.getEffectiveStat(Stat.SPD)).toBe(initialTreeckoSpeed);
expect(purrloin.getEffectiveStat(Stat.SPD)).toBe(initialPurrloinSpeed);
expect(unburdenAttr.applyPostItemLost).not.toHaveBeenCalled();
});
it("should not speed up a Pokemon after it loses the ability Unburden", async () => {
game.override.enemyMoveset([ Moves.FALSE_SWIPE, Moves.WORRY_SEED ]);
await game.classicMode.startBattle([ Species.PURRLOIN ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerHeldItems = getHeldItemCount(playerPokemon);
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
// Turn 1: Get hit by False Swipe and eat Sitrus Berry, activating Unburden
game.move.select(Moves.SPLASH);
await game.forceEnemyMove(Moves.FALSE_SWIPE);
await game.toNextTurn();
expect(getHeldItemCount(playerPokemon)).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
// Turn 2: Get hit by Worry Seed, deactivating Unburden
game.move.select(Moves.SPLASH);
await game.forceEnemyMove(Moves.WORRY_SEED);
await game.toNextTurn();
expect(getHeldItemCount(playerPokemon)).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed);
});
it("should activate when a reviver seed is used", async () => {
game.override.startingHeldItems([{ name: "REVIVER_SEED" }])
.enemyMoveset([ Moves.WING_ATTACK ]);
await game.classicMode.startBattle([ Species.TREECKO ]);
const playerPokemon = game.scene.getPlayerPokemon()!;
const playerHeldItems = getHeldItemCount(playerPokemon);
const initialPlayerSpeed = playerPokemon.getStat(Stat.SPD);
// Turn 1: Get hit by Wing Attack and faint, activating Reviver Seed
game.move.select(Moves.SPLASH);
await game.toNextTurn();
expect(getHeldItemCount(playerPokemon)).toBeLessThan(playerHeldItems);
expect(playerPokemon.getEffectiveStat(Stat.SPD)).toBe(initialPlayerSpeed * 2);
});
// test for `.bypassFaint()` - singles
it("shouldn't persist when revived normally if activated while fainting", async () => {
game.override.enemyMoveset([ Moves.SPLASH, Moves.THIEF ]);
await game.classicMode.startBattle([ Species.TREECKO, Species.FEEBAS ]);
const treecko = game.scene.getPlayerPokemon()!;
const treeckoInitialHeldItems = getHeldItemCount(treecko);
const initialSpeed = treecko.getStat(Stat.SPD);
game.move.select(Moves.SPLASH);
await game.forceEnemyMove(Moves.THIEF);
game.doSelectPartyPokemon(1);
await game.toNextTurn();
game.doRevivePokemon(1);
game.doSwitchPokemon(1);
await game.forceEnemyMove(Moves.SPLASH);
await game.toNextTurn();
expect(game.scene.getPlayerPokemon()!).toBe(treecko);
expect(getHeldItemCount(treecko)).toBeLessThan(treeckoInitialHeldItems);
expect(treecko.getEffectiveStat(Stat.SPD)).toBe(initialSpeed);
});
// test for `.bypassFaint()` - doubles
it("shouldn't persist when revived by revival blessing if activated while fainting", async () => {
game.override
.battleType("double")
.enemyMoveset([ Moves.SPLASH, Moves.THIEF ])
.moveset([ Moves.SPLASH, Moves.REVIVAL_BLESSING ])
.startingHeldItems([{ name: "WIDE_LENS" }]);
await game.classicMode.startBattle([ Species.TREECKO, Species.FEEBAS, Species.MILOTIC ]);
const treecko = game.scene.getPlayerField()[0];
const treeckoInitialHeldItems = getHeldItemCount(treecko);
const initialSpeed = treecko.getStat(Stat.SPD);
game.move.select(Moves.SPLASH);
game.move.select(Moves.REVIVAL_BLESSING, 1);
await game.forceEnemyMove(Moves.THIEF, BattlerIndex.PLAYER);
await game.forceEnemyMove(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2 ]);
game.doSelectPartyPokemon(0, "MoveEffectPhase");
await game.toNextTurn();
expect(game.scene.getPlayerField()[0]).toBe(treecko);
expect(getHeldItemCount(treecko)).toBeLessThan(treeckoInitialHeldItems);
expect(treecko.getEffectiveStat(Stat.SPD)).toBe(initialSpeed);
});
});

View File

@ -1,14 +1,8 @@
import { BattlerIndex } from "#app/battle";
import { Status } from "#app/data/status-effect";
import { DamagePhase } from "#app/phases/damage-phase";
import { SwitchSummonPhase } from "#app/phases/switch-summon-phase";
import { Mode } from "#app/ui/ui";
import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import { Stat } from "#enums/stat";
import { StatusEffect } from "#enums/status-effect";
import { SwitchType } from "#enums/switch-type";
import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
@ -34,78 +28,60 @@ describe("Abilities - ZEN MODE", () => {
game = new GameManager(phaserGame);
game.override
.battleType("single")
.enemySpecies(Species.RATTATA)
.enemyAbility(Abilities.HYDRATION)
.disableCrits()
.enemySpecies(Species.MAGIKARP)
.enemyAbility(Abilities.BALL_FETCH)
.enemyLevel(5)
.ability(Abilities.ZEN_MODE)
.startingLevel(100)
.moveset(Moves.SPLASH)
.enemyMoveset(Moves.TACKLE);
.enemyMoveset(Moves.SEISMIC_TOSS);
});
it("shouldn't change form when taking damage if not dropping below 50% HP", async () => {
await game.classicMode.startBattle([ Species.DARMANITAN ]);
const player = game.scene.getPlayerPokemon()!;
player.stats[Stat.HP] = 100;
player.hp = 100;
expect(player.formIndex).toBe(baseForm);
const darmanitan = game.scene.getPlayerPokemon()!;
expect(darmanitan.formIndex).toBe(baseForm);
game.move.select(Moves.SPLASH);
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("BerryPhase");
await game.toNextTurn();
expect(player.hp).toBeLessThan(100);
expect(player.formIndex).toBe(baseForm);
expect(darmanitan.getHpRatio()).toBeLessThan(1);
expect(darmanitan.getHpRatio()).toBeGreaterThan(0.5);
expect(darmanitan.formIndex).toBe(baseForm);
});
it("should change form when falling below 50% HP", async () => {
await game.classicMode.startBattle([ Species.DARMANITAN ]);
const player = game.scene.getPlayerPokemon()!;
player.stats[Stat.HP] = 1000;
player.hp = 100;
expect(player.formIndex).toBe(baseForm);
const darmanitan = game.scene.getPlayerPokemon()!;
darmanitan.hp = (darmanitan.getMaxHp() / 2) + 1;
expect(darmanitan.formIndex).toBe(baseForm);
game.move.select(Moves.SPLASH);
await game.toNextTurn();
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to("QuietFormChangePhase");
await game.phaseInterceptor.to("TurnInitPhase", false);
expect(player.hp).not.toBe(100);
expect(player.formIndex).toBe(zenForm);
expect(darmanitan.getHpRatio()).toBeLessThan(0.5);
expect(darmanitan.formIndex).toBe(zenForm);
});
it("should stay zen mode when fainted", async () => {
await game.classicMode.startBattle([ Species.DARMANITAN, Species.CHARIZARD ]);
const player = game.scene.getPlayerPokemon()!;
player.stats[Stat.HP] = 1000;
player.hp = 100;
expect(player.formIndex).toBe(baseForm);
const darmanitan = game.scene.getPlayerPokemon()!;
darmanitan.hp = (darmanitan.getMaxHp() / 2) + 1;
expect(darmanitan.formIndex).toBe(baseForm);
game.move.select(Moves.SPLASH);
await game.toNextTurn();
await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]);
await game.phaseInterceptor.to(DamagePhase, false);
const damagePhase = game.scene.getCurrentPhase() as DamagePhase;
damagePhase.updateAmount(80);
await game.phaseInterceptor.to("QuietFormChangePhase");
expect(darmanitan.getHpRatio()).toBeLessThan(0.5);
expect(darmanitan.formIndex).toBe(zenForm);
expect(player.hp).not.toBe(100);
expect(player.formIndex).toBe(zenForm);
await game.killPokemon(player);
expect(player.isFainted()).toBe(true);
await game.phaseInterceptor.to("TurnStartPhase");
game.onNextPrompt("SwitchPhase", Mode.PARTY, () => {
game.scene.unshiftPhase(new SwitchSummonPhase(game.scene, SwitchType.SWITCH, 0, 1, false));
game.scene.ui.setMode(Mode.MESSAGE);
});
game.onNextPrompt("SwitchPhase", Mode.MESSAGE, () => {
game.endPhase();
});
await game.phaseInterceptor.to("PostSummonPhase");
game.move.select(Moves.SPLASH);
await game.killPokemon(darmanitan);
game.doSelectPartyPokemon(1);
await game.toNextTurn();
expect(darmanitan.isFainted()).toBe(true);
expect(game.scene.getPlayerParty()[1].formIndex).toBe(zenForm);
});
@ -117,7 +93,8 @@ describe("Abilities - ZEN MODE", () => {
await game.classicMode.startBattle([ Species.MAGIKARP, Species.DARMANITAN ]);
const darmanitan = game.scene.getPlayerParty().find((p) => p.species.speciesId === Species.DARMANITAN)!;
const darmanitan = game.scene.getPlayerParty()[1];
darmanitan.hp = 1;
expect(darmanitan.formIndex).toBe(zenForm);
darmanitan.hp = 0;
@ -126,9 +103,7 @@ describe("Abilities - ZEN MODE", () => {
game.move.select(Moves.SPLASH);
await game.doKillOpponents();
await game.phaseInterceptor.to("TurnEndPhase");
game.doSelectModifier();
await game.phaseInterceptor.to("QuietFormChangePhase");
await game.toNextWave();
expect(darmanitan.formIndex).toBe(baseForm);
});