diff --git a/src/data/ability.ts b/src/data/ability.ts index 0edbc172ad5..becdad32f34 100755 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -4228,6 +4228,10 @@ export class ReduceBerryUseThresholdAbAttr extends AbAttr { } } +/** + * Ability attribute used for abilites that change the ability owner's weight + * Used for Heavy Metal (doubling weight) and Light Metal (halving weight) + */ export class WeightMultiplierAbAttr extends AbAttr { private multiplier: integer; diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index 32b3d54f302..9e910430c09 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -2201,6 +2201,36 @@ export class TarShotTag extends BattlerTag { } } +/** + * Battler Tag that keeps track of how many times the user has Autotomized + * Each count of Autotomization reduces the weight by 100kg + */ +export class AutotomizedTag extends BattlerTag { + public autotomizeCount: number = 0; + constructor(sourceMove: Moves = Moves.AUTOTOMIZE) { + super(BattlerTagType.AUTOTOMIZED, BattlerTagLapseType.CUSTOM, 1, sourceMove); + } + + /** + * Adds an autotomize count to the Pokemon. Each stack reduces weight by 100kg + * If the Pokemon is over 0.1kg it also displays a message. + * @param pokemon The Pokemon that is being autotomized + */ + onAdd(pokemon: Pokemon): void { + const minWeight = 0.1; + if (pokemon.getWeight() > minWeight) { + pokemon.scene.queueMessage(i18next.t("battlerTags:autotomizeOnAdd", { + pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) + })); + } + this.autotomizeCount += 1; + } + + onOverlap(pokemon: Pokemon): void { + this.onAdd(pokemon); + } +} + export class SubstituteTag extends BattlerTag { /** The substitute's remaining HP. If HP is depleted, the Substitute fades. */ public hp: number; @@ -2488,6 +2518,8 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: number, source return new GorillaTacticsTag(); case BattlerTagType.SUBSTITUTE: return new SubstituteTag(sourceMove, sourceId); + case BattlerTagType.AUTOTOMIZED: + return new AutotomizedTag(); case BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON: return new MysteryEncounterPostSummonTag(); case BattlerTagType.NONE: diff --git a/src/data/move.ts b/src/data/move.ts index 1bfe20abc48..cb46fed0514 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -8071,7 +8071,7 @@ export function initMoves() { .attr(MovePowerMultiplierAttr, (user, target, move) => target.status && (target.status.effect === StatusEffect.POISON || target.status.effect === StatusEffect.TOXIC) ? 2 : 1), new SelfStatusMove(Moves.AUTOTOMIZE, Type.STEEL, -1, 15, -1, 0, 5) .attr(StatStageChangeAttr, [ Stat.SPD ], 2, true) - .partial(), + .attr(AddBattlerTagAttr, BattlerTagType.AUTOTOMIZED, true), new SelfStatusMove(Moves.RAGE_POWDER, Type.BUG, -1, 20, -1, 2, 5) .powderMove() .attr(AddBattlerTagAttr, BattlerTagType.CENTER_OF_ATTENTION, true), diff --git a/src/enums/battler-tag-type.ts b/src/enums/battler-tag-type.ts index f367b1b56c0..2805ad5bfed 100644 --- a/src/enums/battler-tag-type.ts +++ b/src/enums/battler-tag-type.ts @@ -79,5 +79,6 @@ export enum BattlerTagType { TAR_SHOT = "TAR_SHOT", BURNED_UP = "BURNED_UP", DOUBLE_SHOCKED = "DOUBLE_SHOCKED", + AUTOTOMIZED = "AUTOTOMIZED", MYSTERY_ENCOUNTER_POST_SUMMON = "MYSTERY_ENCOUNTER_POST_SUMMON", } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index cdafc960382..5ed12ded2d1 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -17,7 +17,7 @@ import { initMoveAnim, loadMoveAnimAssets } from "../data/battle-anims"; import { Status, StatusEffect, getRandomStatus } from "../data/status-effect"; import { pokemonEvolutions, pokemonPrevolutions, SpeciesFormEvolution, SpeciesEvolutionCondition, FusionSpeciesFormEvolution } from "../data/pokemon-evolutions"; import { reverseCompatibleTms, tmSpecies, tmPoolTiers } from "../data/tms"; -import { BattlerTag, BattlerTagLapseType, EncoreTag, GroundedTag, HighestStatBoostTag, SubstituteTag, TypeImmuneTag, getBattlerTag, SemiInvulnerableTag, TypeBoostTag, MoveRestrictionBattlerTag, ExposedTag, DragonCheerTag, CritBoostTag, TrappedTag, TarShotTag } from "../data/battler-tags"; +import { BattlerTag, BattlerTagLapseType, EncoreTag, GroundedTag, HighestStatBoostTag, SubstituteTag, TypeImmuneTag, getBattlerTag, SemiInvulnerableTag, TypeBoostTag, MoveRestrictionBattlerTag, ExposedTag, DragonCheerTag, CritBoostTag, TrappedTag, TarShotTag, AutotomizedTag } from "../data/battler-tags"; import { WeatherType } from "../data/weather"; import { ArenaTagSide, NoCritTag, WeakenMoveScreenTag } from "../data/arena-tag"; import { Ability, AbAttr, StatMultiplierAbAttr, BlockCritAbAttr, BonusCritAbAttr, BypassBurnDamageReductionAbAttr, FieldPriorityMoveImmunityAbAttr, IgnoreOpponentStatStagesAbAttr, MoveImmunityAbAttr, PreDefendFullHpEndureAbAttr, ReceivedMoveDamageMultiplierAbAttr, ReduceStatusEffectDurationAbAttr, 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 } from "../data/ability"; @@ -1393,11 +1393,23 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return false; } + /** + * Gets the weight of the Pokemon with subtractive modifiers (Autotomize) happening first + * and then multiplicative modifiers happening after (Heavy Metal and Light Metal) + * @returns the kg of the Pokemon (minimum of 0.1) + */ getWeight(): number { - const weight = new Utils.NumberHolder(this.species.weight); + const autotomizedTag = this.getTag(AutotomizedTag); + let weightRemoved = 0; + if (!Utils.isNullOrUndefined(autotomizedTag)) { + weightRemoved = 100 * autotomizedTag.autotomizeCount; + } + const minWeight = 0.1; + const weight = new Utils.NumberHolder(this.species.weight - weightRemoved); + // This will trigger the ability overlay so only call this function when necessary applyAbAttrs(WeightMultiplierAbAttr, this, null, false, weight); - return weight.value; + return Math.max(minWeight, weight.value); } /** diff --git a/src/locales/en/battler-tags.json b/src/locales/en/battler-tags.json index b31826b0244..6b513f3a832 100644 --- a/src/locales/en/battler-tags.json +++ b/src/locales/en/battler-tags.json @@ -73,5 +73,6 @@ "tarShotOnAdd": "{{pokemonNameWithAffix}} became weaker to fire!", "substituteOnAdd": "{{pokemonNameWithAffix}} put in a substitute!", "substituteOnHit": "The substitute took damage for {{pokemonNameWithAffix}}!", - "substituteOnRemove": "{{pokemonNameWithAffix}}'s substitute faded!" + "substituteOnRemove": "{{pokemonNameWithAffix}}'s substitute faded!", + "autotomizeOnAdd": "{{pokemonNameWIthAffix}} became nimble!" } diff --git a/src/phases/form-change-phase.ts b/src/phases/form-change-phase.ts index 33c1f8e8cef..1f18457146d 100644 --- a/src/phases/form-change-phase.ts +++ b/src/phases/form-change-phase.ts @@ -9,6 +9,7 @@ import PartyUiHandler from "../ui/party-ui-handler"; import { getPokemonNameWithAffix } from "../messages"; import { EndEvolutionPhase } from "./end-evolution-phase"; import { EvolutionPhase } from "./evolution-phase"; +import { BattlerTagType } from "#app/enums/battler-tag-type"; export class FormChangePhase extends EvolutionPhase { private formChange: SpeciesFormChange; @@ -157,6 +158,7 @@ export class FormChangePhase extends EvolutionPhase { } end(): void { + this.pokemon.findAndRemoveTags(t => t.tagType === BattlerTagType.AUTOTOMIZED); if (this.modal) { this.scene.ui.revertMode().then(() => { if (this.scene.ui.getMode() === Mode.PARTY) { diff --git a/src/phases/quiet-form-change-phase.ts b/src/phases/quiet-form-change-phase.ts index dde500e156a..c28cc28b592 100644 --- a/src/phases/quiet-form-change-phase.ts +++ b/src/phases/quiet-form-change-phase.ts @@ -3,6 +3,7 @@ import { SemiInvulnerableTag } from "#app/data/battler-tags"; import { SpeciesFormChange, getSpeciesFormChangeMessage } from "#app/data/pokemon-forms"; import { getTypeRgb } from "#app/data/type"; import { BattleSpec } from "#app/enums/battle-spec"; +import { BattlerTagType } from "#app/enums/battler-tag-type"; import Pokemon, { EnemyPokemon } from "#app/field/pokemon"; import { getPokemonNameWithAffix } from "#app/messages"; import { BattlePhase } from "./battle-phase"; @@ -113,6 +114,7 @@ export class QuietFormChangePhase extends BattlePhase { } end(): void { + this.pokemon.findAndRemoveTags(t => t.tagType === BattlerTagType.AUTOTOMIZED); if (this.pokemon.scene?.currentBattle.battleSpec === BattleSpec.FINAL_BOSS && this.pokemon instanceof EnemyPokemon) { this.scene.playBgm(); this.scene.unshiftPhase(new PokemonHealPhase(this.scene, this.pokemon.getBattlerIndex(), this.pokemon.getMaxHp(), null, false, false, false, true)); diff --git a/src/test/moves/autotomize.test.ts b/src/test/moves/autotomize.test.ts new file mode 100644 index 00000000000..4da246736f9 --- /dev/null +++ b/src/test/moves/autotomize.test.ts @@ -0,0 +1,98 @@ +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, it, expect } from "vitest"; + +describe("Moves - Autotomize", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + const TIMEOUT = 20 * 1000; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .moveset([Moves.AUTOTOMIZE, Moves.KINGS_SHIELD, Moves.FALSE_SWIPE]) + .battleType("single") + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.SPLASH); + }); + + it("Autotomize should reduce weight", async () => { + const baseDracozoltWeight = 190; + const oneAutotomizeDracozoltWeight = 90; + const twoAutotomizeDracozoltWeight = 0.1; + const threeAutotomizeDracozoltWeight = 0.1; + + await game.classicMode.startBattle([Species.DRACOZOLT]); + const playerPokemon = game.scene.getPlayerPokemon()!; + expect(playerPokemon.getWeight()).toBe(baseDracozoltWeight); + game.move.select(Moves.AUTOTOMIZE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(oneAutotomizeDracozoltWeight); + + game.move.select(Moves.AUTOTOMIZE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(twoAutotomizeDracozoltWeight); + + + game.move.select(Moves.AUTOTOMIZE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(threeAutotomizeDracozoltWeight); + }, TIMEOUT); + + it("Changing forms should revert weight", async () => { + const baseAegislashWeight = 53; + const autotomizeAegislashWeight = 0.1; + + await game.classicMode.startBattle([Species.AEGISLASH]); + const playerPokemon = game.scene.getPlayerPokemon()!; + + expect(playerPokemon.getWeight()).toBe(baseAegislashWeight); + game.move.select(Moves.AUTOTOMIZE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(autotomizeAegislashWeight); + game.move.select(Moves.FALSE_SWIPE); + await game.toNextTurn(); + + game.move.select(Moves.KINGS_SHIELD); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(baseAegislashWeight); + + + game.move.select(Moves.AUTOTOMIZE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(autotomizeAegislashWeight); + + game.move.select(Moves.FALSE_SWIPE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(baseAegislashWeight); + + game.move.select(Moves.AUTOTOMIZE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(autotomizeAegislashWeight); + }, TIMEOUT); + + it("Autotomize should interact with light metal correctly", async () => { + const baseLightGroudonWeight = 475; + const autotomizeLightGroudonWeight = 425; + game.override.ability(Abilities.LIGHT_METAL); + await game.classicMode.startBattle([Species.GROUDON]); + const playerPokemon = game.scene.getPlayerPokemon()!; + expect(playerPokemon.getWeight()).toBe(baseLightGroudonWeight); + game.move.select(Moves.AUTOTOMIZE); + await game.toNextTurn(); + expect(playerPokemon.getWeight()).toBe(autotomizeLightGroudonWeight); + }, TIMEOUT); +});