From e39f9e6de5f190d2d560bb7a9550906ae96d1310 Mon Sep 17 00:00:00 2001 From: shayebeadlingkl Date: Thu, 9 May 2024 14:55:57 -0400 Subject: [PATCH] implements grudge, alters faint to not clear summondata until post faint phase --- src/data/battler-tags.ts | 52 ++++++++++++++++++++++++++++-- src/data/enums/battler-tag-type.ts | 1 + src/data/move.ts | 2 +- src/field/pokemon.ts | 1 - src/phases.ts | 1 + 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index ba00b0906..bb0a35349 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -1,12 +1,12 @@ import { CommonAnim, CommonBattleAnim } from "./battle-anims"; -import { CommonAnimPhase, MoveEffectPhase, MovePhase, PokemonHealPhase, ShowAbilityPhase, StatChangePhase } from "../phases"; +import { CommonAnimPhase, FaintPhase, MoveEffectPhase, MovePhase, PokemonHealPhase, ShowAbilityPhase, StatChangePhase } from "../phases"; import { getPokemonMessage, getPokemonPrefix } from "../messages"; -import Pokemon, { MoveResult, HitResult } from "../field/pokemon"; +import Pokemon, { MoveResult, HitResult, PokemonMove } from "../field/pokemon"; import { Stat, getStatName } from "./pokemon-stat"; import { StatusEffect } from "./status-effect"; import * as Utils from "../utils"; import { Moves } from "./enums/moves"; -import { ChargeAttr, MoveFlags, allMoves } from "./move"; +import { ChargeAttr, MoveCategory, MoveFlags, allMoves } from "./move"; import { Type } from "./type"; import { BlockNonDirectDamageAbAttr, FlinchEffectAbAttr, ReverseDrainAbAttr, applyAbAttrs } from "./ability"; import { Abilities } from "./enums/abilities"; @@ -1249,6 +1249,50 @@ export class CursedTag extends BattlerTag { } } +export class GrudgeTag extends BattlerTag { + private sourceIndex: integer; + + constructor(sourceId: integer) { + super(BattlerTagType.GRUDGE, BattlerTagLapseType.PRE_MOVE, 2, Moves.GRUDGE, sourceId); + } + + /** + * When given a battler tag or json representing one, load the data for it. + * @param {BattlerTag | any} source A battler tag + */ + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.sourceIndex = source.sourceIndex; + } + + onAdd(pokemon: Pokemon): void { + super.onAdd(pokemon); + + pokemon.scene.queueMessage(getPokemonMessage(pokemon, " wants its target to bear a grudge!")); + this.sourceIndex = pokemon.scene.getPokemonById(this.sourceId).getBattlerIndex(); + } + + onRemove(pokemon: Pokemon): void { + super.onRemove(pokemon); + + const effectPhase = pokemon.scene.getCurrentPhase(); + if (effectPhase instanceof FaintPhase && pokemon.turnData?.attacksReceived?.length) { + const attackMoveResult = pokemon.turnData.attacksReceived[0]; + const defeatSource = pokemon.scene.getPokemonById(attackMoveResult.sourceId); + if (defeatSource?.isOnField()) { + const faintingMove = defeatSource.getMoveset().find((move: PokemonMove) => move.moveId === attackMoveResult.move) + faintingMove.usePp(faintingMove.getMovePp()) + defeatSource.scene.queueMessage(getPokemonMessage(defeatSource, `'s ${faintingMove.getName()} lost all of its PP due to the grudge!`)); + } + } + } + + lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { + + return super.lapse(pokemon, lapseType); + } +} + export function getBattlerTag(tagType: BattlerTagType, turnCount: integer, sourceMove: Moves, sourceId: integer): BattlerTag { switch (tagType) { case BattlerTagType.RECHARGING: @@ -1354,6 +1398,8 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: integer, sourc return new SaltCuredTag(sourceId); case BattlerTagType.CURSED: return new CursedTag(sourceId); + case BattlerTagType.GRUDGE: + return new GrudgeTag(sourceId); case BattlerTagType.CHARGED: return new TypeBoostTag(tagType, sourceMove, Type.ELECTRIC, 2, true); case BattlerTagType.MAGNET_RISEN: diff --git a/src/data/enums/battler-tag-type.ts b/src/data/enums/battler-tag-type.ts index d18ccf1c5..8c42528a6 100644 --- a/src/data/enums/battler-tag-type.ts +++ b/src/data/enums/battler-tag-type.ts @@ -53,6 +53,7 @@ export enum BattlerTagType { IGNORE_FLYING = "IGNORE_FLYING", SALT_CURED = "SALT_CURED", CURSED = "CURSED", + GRUDGE = "GRUDGE", CHARGED = "CHARGED", GROUNDED = "GROUNDED", MAGNET_RISEN = "MAGNET_RISEN" diff --git a/src/data/move.ts b/src/data/move.ts index 99c4457a5..91952ef2d 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -4838,7 +4838,7 @@ export function initMoves() { .attr(HealStatusEffectAttr, true, StatusEffect.PARALYSIS, StatusEffect.POISON, StatusEffect.TOXIC, StatusEffect.BURN) .condition((user, target, move) => user.status && (user.status.effect === StatusEffect.PARALYSIS || user.status.effect === StatusEffect.POISON || user.status.effect === StatusEffect.TOXIC || user.status.effect === StatusEffect.BURN)), new SelfStatusMove(Moves.GRUDGE, Type.GHOST, -1, 5, -1, 0, 3) - .unimplemented(), + .attr(AddBattlerTagAttr, BattlerTagType.GRUDGE, true, true, 1, 1), new SelfStatusMove(Moves.SNATCH, Type.DARK, -1, 10, -1, 4, 3) .unimplemented(), new AttackMove(Moves.SECRET_POWER, Type.NORMAL, MoveCategory.PHYSICAL, 70, 100, 20, 30, 0, 3) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 88329a2c2..c1aa750f3 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1531,7 +1531,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.hp = this.hp - damage; if (this.isFainted()) { this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), preventEndure)); - this.resetSummonData(); } return damage; diff --git a/src/phases.ts b/src/phases.ts index 25b0c3b75..a419fa8b2 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -3195,6 +3195,7 @@ export class FaintPhase extends PokemonPhase { } pokemon.lapseTags(BattlerTagLapseType.FAINT); + pokemon.resetSummonData(); this.scene.getField(true).filter(p => p !== pokemon).forEach(p => p.removeTagsBySourceId(pokemon.id)); pokemon.faintCry(() => {