From 422eeb5d075ab96c61aa6f050d52a086522d0337 Mon Sep 17 00:00:00 2001 From: lucfd <83493765+lucfd@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:33:35 -0400 Subject: [PATCH] Implemented Stench (#190) * implemented stench * cleaned up code * removed redundant lines * Implemented Payback * refactored, increased PostAttackApplyBattlerTagAbAttr robustness * removed payback code * Update src/data/ability.ts --------- Co-authored-by: Samuel H --- src/data/ability.ts | 31 +++++++++++++++++++++++++++++-- src/data/move.ts | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index ef6e2a16b..7a4f53e77 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -9,7 +9,7 @@ import { BattlerTag } from "./battler-tags"; import { BattlerTagType } from "./enums/battler-tag-type"; import { StatusEffect, getStatusEffectDescriptor, getStatusEffectHealText } from "./status-effect"; import { Gender } from "./gender"; -import Move, { AttackMove, MoveCategory, MoveFlags, MoveTarget, RecoilAttr, StatusMoveTypeImmunityAttr, allMoves } from "./move"; +import Move, { AttackMove, MoveCategory, MoveFlags, MoveTarget, RecoilAttr, StatusMoveTypeImmunityAttr, FlinchAttr, allMoves } from "./move"; import { ArenaTagType } from "./enums/arena-tag-type"; import { Stat } from "./pokemon-stat"; import { PokemonHeldItemModifier } from "../modifier/modifier"; @@ -996,6 +996,32 @@ export class PostAttackContactApplyStatusEffectAbAttr extends PostAttackApplySta } } +export class PostAttackApplyBattlerTagAbAttr extends PostAttackAbAttr { + private contactRequired: boolean; + private chance: (user: Pokemon, target: Pokemon, move: PokemonMove) => integer; + private effects: BattlerTagType[]; + + + constructor(contactRequired: boolean, chance: (user: Pokemon, target: Pokemon, move: PokemonMove) => integer, ...effects: BattlerTagType[]) { + super(); + + this.contactRequired = contactRequired; + this.chance = chance; + this.effects = effects; + } + + applyPostAttack(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: PokemonMove, hitResult: HitResult, args: any[]): boolean { + if (pokemon != attacker && (!this.contactRequired || move.getMove().checkFlag(MoveFlags.MAKES_CONTACT, attacker, pokemon)) && pokemon.randSeedInt(100) < this.chance(attacker, pokemon, move) && !pokemon.status) { + const effect = this.effects.length === 1 ? this.effects[0] : this.effects[pokemon.randSeedInt(this.effects.length)]; + + + return attacker.addTag(effect); + } + + return false; + } +} + export class PostDefendStealHeldItemAbAttr extends PostDefendAbAttr { private condition: PokemonDefendCondition; @@ -2290,7 +2316,8 @@ export const allAbilities = [ new Ability(Abilities.NONE, "-", "", 3) ]; export function initAbilities() { allAbilities.push( - new Ability(Abilities.STENCH, "Stench (N)", "By releasing stench when attacking, this Pokémon may cause the target to flinch.", 3), + new Ability(Abilities.STENCH, "Stench", "By releasing stench when attacking, this Pokémon may cause the target to flinch.", 3) + .attr(PostAttackApplyBattlerTagAbAttr, false, (user, target, move) => !move.getMove().findAttr(attr => attr instanceof FlinchAttr) ? 10 : 0, BattlerTagType.FLINCHED), new Ability(Abilities.DRIZZLE, "Drizzle", "The Pokémon makes it rain when it enters a battle.", 3) .attr(PostSummonWeatherChangeAbAttr, WeatherType.RAIN) .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.RAIN), diff --git a/src/data/move.ts b/src/data/move.ts index e0d94dd9e..be559db8c 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1804,6 +1804,7 @@ export class FirstAttackDoublePowerAttr extends VariablePowerAttr { } } + export class TurnDamagedDoublePowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (user.turnData.attacksReceived.find(r => r.damage && r.sourceId === target.id)) {