From df18dd885d01b93ac52117389e19dce58cb9f3e0 Mon Sep 17 00:00:00 2001 From: schmidtc1 <62030095+schmidtc1@users.noreply.github.com> Date: Tue, 2 Jul 2024 10:28:38 -0400 Subject: [PATCH] [Bug] Adjusts bug bite/pluck to remove berry pouch preservation on opponent berries (#2047) * Adjusts bug bite functionality when stealing from opponent with three berry pouches * Adjusts bug bite functionality when stealing from opponent with three berry pouches * Adjusts bug bite to remove berry pouch preservation on opponent berries * Remove Promise where unnecessary Leftover code removed from previous testing of the EatBerryAttr class. * Remove undefined check on chosenBerry Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> * Update StealEatBerryAttr if-clause readability Decrementing inside of an if-clause removed for readability. Changed to check: if count is 1, then remove modifier. * Localization of StealEatBerryAttr battle message * Fixes berry incrementing after improper adjustment to readability * Fixes berry decrementing after improper adjustment to readability * Update battle.ts * Update src/locales/fr/battle.ts Co-authored-by: Lugiad' * Update battle.ts properly Incorrectly added localization in previous commit * Remove unnecessary space * Update src/locales/ko/battle.ts I do not have experience with Korean, so this may need other review. Co-authored-by: Enoch * Rewrites EatBerryAttr to combine with StealEatBerryAttr * Removes excess lines * Revert and refactor StealEatBerry and EatBerryAttr * Refactor for early returns instead of nesting --------- Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com> Co-authored-by: Lugiad' Co-authored-by: Enoch --- src/data/move.ts | 97 ++++++++++++++++++------------------- src/locales/de/battle.ts | 1 + src/locales/en/battle.ts | 1 + src/locales/es/battle.ts | 1 + src/locales/fr/battle.ts | 1 + src/locales/it/battle.ts | 1 + src/locales/ko/battle.ts | 3 +- src/locales/pt_BR/battle.ts | 1 + src/locales/zh_CN/battle.ts | 1 + src/locales/zh_TW/battle.ts | 3 +- 10 files changed, 57 insertions(+), 53 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index c62d7e3b53f..9964665c12a 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1909,7 +1909,7 @@ export class RemoveHeldItemAttr extends MoveEffectAttr { } /** - * Attribute that causes targets of the move to eat a berry. If chosenBerry is not overridden, a random berry will be picked from the target's inventory. + * Attribute that causes targets of the move to eat a berry. Used for Teatime, Stuff Cheeks */ export class EatBerryAttr extends MoveEffectAttr { protected chosenBerry: BerryModifier; @@ -1918,42 +1918,29 @@ export class EatBerryAttr extends MoveEffectAttr { this.chosenBerry = undefined; } /** - * Causes the target to eat a berry. - * @param user {@linkcode Pokemon} Pokemon that used the move - * @param target {@linkcode Pokemon} Pokemon that will eat a berry - * @param move {@linkcode Move} The move being used - * @param args Unused - * @returns {boolean} true if the function succeeds - */ + * Causes the target to eat a berry. + * @param user {@linkcode Pokemon} Pokemon that used the move + * @param target {@linkcode Pokemon} Pokemon that will eat a berry + * @param move {@linkcode Move} The move being used + * @param args Unused + * @returns {boolean} true if the function succeeds + */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!super.apply(user, target, move, args)) { return false; } - if (this.chosenBerry === undefined) { // if no berry has been provided, pick a random berry from their inventory - const heldBerries = this.getTargetHeldBerries(target); - if (heldBerries.length <= 0) { - return false; - } - this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)]; + const heldBerries = this.getTargetHeldBerries(target); + if (heldBerries.length <= 0) { + return false; } - - getBerryEffectFunc(this.chosenBerry.berryType)(target); // target eats the berry - + this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)]; const preserve = new Utils.BooleanHolder(false); - target.scene.applyModifiers(PreserveBerryModifier, target.isPlayer(), target, preserve); - - if (!preserve.value) { // remove the eaten berry if not preserved - if (!--this.chosenBerry.stackCount) { - target.scene.removeModifier(this.chosenBerry, !target.isPlayer()); - } - target.scene.updateModifiers(target.isPlayer()); + target.scene.applyModifiers(PreserveBerryModifier, target.isPlayer(), target, preserve); // check for berry pouch preservation + if (!preserve.value) { + this.reduceBerryModifier(target); } - - this.chosenBerry = undefined; - - applyAbAttrs(HealFromBerryUseAbAttr, target, new Utils.BooleanHolder(false)); - + this.eatBerry(target); return true; } @@ -1962,7 +1949,21 @@ export class EatBerryAttr extends MoveEffectAttr { && (m as BerryModifier).pokemonId === target.id, target.isPlayer()) as BerryModifier[]; } + reduceBerryModifier(target: Pokemon) { + if (this.chosenBerry.stackCount === 1) { + target.scene.removeModifier(this.chosenBerry, !target.isPlayer()); + } else { + this.chosenBerry.stackCount--; + } + target.scene.updateModifiers(target.isPlayer()); + } + + eatBerry(consumer: Pokemon) { + getBerryEffectFunc(this.chosenBerry.berryType)(consumer); // consumer eats the berry + applyAbAttrs(HealFromBerryUseAbAttr, consumer, new Utils.BooleanHolder(false)); + } } + /** * Attribute used for moves that steal a random berry from the target. The user then eats the stolen berry. * Used for Pluck & Bug Bite. @@ -1972,36 +1973,30 @@ export class StealEatBerryAttr extends EatBerryAttr { super(); } /** - * User steals a random berry from the target and then eats it. - * @param {Pokemon} user Pokemon that used the move and will eat the stolen berry - * @param {Pokemon} target Pokemon that will have its berry stolen - * @param {Move} move Move being used - * @param {any[]} args Unused - * @returns {boolean} true if the function succeeds - */ + * User steals a random berry from the target and then eats it. + * @param {Pokemon} user Pokemon that used the move and will eat the stolen berry + * @param {Pokemon} target Pokemon that will have its berry stolen + * @param {Move} move Move being used + * @param {any[]} args Unused + * @returns {boolean} true if the function succeeds + */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const cancelled = new Utils.BooleanHolder(false); applyAbAttrs(BlockItemTheftAbAttr, target, cancelled); // check for abilities that block item theft if (cancelled.value === true) { return false; } - const heldBerries = this.getTargetHeldBerries(target).filter(i => i.getTransferrable(false)); - - if (heldBerries.length) { // if the target has berries, pick a random berry and steal it - this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)]; - - if (this.chosenBerry.stackCount === 1) { // remove modifier if its the last berry - target.scene.removeModifier(this.chosenBerry, !target.isPlayer()); - } - target.scene.updateModifiers(target.isPlayer()); - - user.scene.queueMessage(getPokemonMessage(user, ` stole and ate\n${target.name}'s ${this.chosenBerry.type.name}!`)); - return super.apply(user, user, move, args); + if (heldBerries.length <= 0) { + return false; } - - return false; + // if the target has berries, pick a random berry and steal it + this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)]; + 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); + return true; } } diff --git a/src/locales/de/battle.ts b/src/locales/de/battle.ts index 72acb7d073e..67c2cd9a6b0 100644 --- a/src/locales/de/battle.ts +++ b/src/locales/de/battle.ts @@ -65,6 +65,7 @@ export const battle: SimpleTranslationEntries = { "useMove": "{{pokemonNameWithAffix}} setzt {{moveName}} ein!", "drainMessage": "{{pokemonName}} wurde Energie abgesaugt", "regainHealth": "KP von {{pokemonName}} wurden wieder aufgefrischt!", + "stealEatBerry": "{{pokemonName}} stole and ate\n{{targetName}}'s {{berryName}}!", "fainted": "{{pokemonNameWithAffix}} wurde besiegt!", "statRose": "{{stats}} von {{pokemonNameWithAffix}} steigt!", "statSharplyRose": "{{stats}} von {{pokemonNameWithAffix}} steigt stark!", diff --git a/src/locales/en/battle.ts b/src/locales/en/battle.ts index 263a48e8f0a..d41ffc373dc 100644 --- a/src/locales/en/battle.ts +++ b/src/locales/en/battle.ts @@ -65,6 +65,7 @@ export const battle: SimpleTranslationEntries = { "useMove": "{{pokemonNameWithAffix}} used {{moveName}}!", "drainMessage": "{{pokemonName}} had its\nenergy drained!", "regainHealth": "{{pokemonName}} regained\nhealth!", + "stealEatBerry": "{{pokemonName}} stole and ate\n{{targetName}}'s {{berryName}}!", "fainted": "{{pokemonNameWithAffix}} fainted!", "statRose": "{{pokemonNameWithAffix}}'s {{stats}} rose!", "statSharplyRose": "{{pokemonNameWithAffix}}'s {{stats}} sharply rose!", diff --git a/src/locales/es/battle.ts b/src/locales/es/battle.ts index c1a85ffe267..7f5832d069d 100644 --- a/src/locales/es/battle.ts +++ b/src/locales/es/battle.ts @@ -65,6 +65,7 @@ export const battle: SimpleTranslationEntries = { "useMove": "¡{{pokemonNameWithAffix}} usó {{moveName}}!", "drainMessage": "¡{{pokemonName}} tuvo su\nenergía absorbida!", "regainHealth": "¡{{pokemonName}} recuperó\nPS!", + "stealEatBerry": "¡{{pokemonName}} robó la {{berryName}}\nde {{targetName}} y se la comió!", "fainted": "¡{{pokemonNameWithAffix}} se debilitó!", "statRose": "¡El {{stats}} de {{pokemonNameWithAffix}} ha subido!", "statSharplyRose": "¡El {{stats}} de {{pokemonNameWithAffix}} ha subido mucho!", diff --git a/src/locales/fr/battle.ts b/src/locales/fr/battle.ts index 3d86c5f84f1..539b7c99094 100644 --- a/src/locales/fr/battle.ts +++ b/src/locales/fr/battle.ts @@ -63,6 +63,7 @@ export const battle: SimpleTranslationEntries = { "wildPokemonWithAffix": "{{pokemonName}} sauvage", "foePokemonWithAffix": "{{pokemonName}} ennemi", "useMove": "{{pokemonNameWithAffix}} utilise\n{{moveName}} !", + "stealEatBerry": "{{pokemonName}} vole et mange\nla {{berryName}} de {{targetName}} !", "drainMessage": "L’énergie de {{pokemonName}}\nest drainée !", "regainHealth": "{{pokemonName}} récupère\ndes PV !", "fainted": "{{pokemonNameWithAffix}}\nest K.O. !", diff --git a/src/locales/it/battle.ts b/src/locales/it/battle.ts index 2052dc49cfc..d9af58893e5 100644 --- a/src/locales/it/battle.ts +++ b/src/locales/it/battle.ts @@ -60,6 +60,7 @@ export const battle: SimpleTranslationEntries = { "skipItemQuestion": "Sei sicuro di non voler prendere nessun oggetto?", "eggHatching": "Oh!", "ivScannerUseQuestion": "Vuoi usare lo scanner di IV su {{pokemonName}}?", + "stealEatBerry": "{{pokemonName}} stole and ate\n{{targetName}}'s {{berryName}}!", "wildPokemonWithAffix": "{{pokemonName}} selvatico", "foePokemonWithAffix": "{{pokemonName}} avversario", "useMove": "{{pokemonNameWithAffix}} usa {{moveName}}!", diff --git a/src/locales/ko/battle.ts b/src/locales/ko/battle.ts index bf32bbe08e7..e9bfb7cb307 100644 --- a/src/locales/ko/battle.ts +++ b/src/locales/ko/battle.ts @@ -64,6 +64,7 @@ export const battle: SimpleTranslationEntries = { "foePokemonWithAffix": "상대 {{pokemonName}}", "useMove": "{{pokemonNameWithAffix}}의 {{moveName}}!", "drainMessage": "{{pokemonName}}[[로]]부터\n체력을 흡수했다!", + "stealEatBerry": "{{pokemonName}}[[가]]\n{{targetName}}의 {{berryName}}[[를]] 빼앗아 먹었다!", "regainHealth": "{{pokemonName}}[[는]]\n체력을 회복했다!", "fainted": "{{pokemonNameWithAffix}}[[는]] 쓰러졌다!", "statRose": "{{pokemonNameWithAffix}}의\n{{stats}}[[가]] 올라갔다!", @@ -131,5 +132,5 @@ export const battle: SimpleTranslationEntries = { "battlerTagsSaltCuredOnAdd": "{{pokemonNameWithAffix}}[[는]]\n소금에 절여졌다!", "battlerTagsSaltCuredLapse": "{{pokemonNameWithAffix}}[[는]] 소금절이의\n데미지를 입고 있다.", "battlerTagsCursedOnAdd": "{{pokemonNameWithAffix}}[[는]]\n자신의 체력을 깎아서\n{{pokemonName}}에게 저주를 걸었다!", - "battlerTagsCursedLapse": "{{pokemonNameWithAffix}}[[는]]\n저주받고 있다!" + "battlerTagsCursedLapse": "{{pokemonNameWithAffix}}[[는]]\n저주받고 있다!", } as const; diff --git a/src/locales/pt_BR/battle.ts b/src/locales/pt_BR/battle.ts index e5ec5cb9917..15f1d83c3c9 100644 --- a/src/locales/pt_BR/battle.ts +++ b/src/locales/pt_BR/battle.ts @@ -65,6 +65,7 @@ export const battle: SimpleTranslationEntries = { "useMove": "{{pokemonNameWithAffix}} usou {{moveName}}!", "drainMessage": "{{pokemonName}} teve sua\nenergia drenada!", "regainHealth": "{{pokemonName}} recuperou\npontos de saúde!", + "stealEatBerry": "{{pokemonName}} stole and ate\n{{targetName}}'s {{berryName}}!", "fainted": "{{pokemonNameWithAffix}} desmaiou!", "statRose": "{{stats}} de {{pokemonNameWithAffix}} aumentou!", "statSharplyRose": "{{stats}} de {{pokemonNameWithAffix}} aumentou bruscamente!", diff --git a/src/locales/zh_CN/battle.ts b/src/locales/zh_CN/battle.ts index 5fab96c422b..3fde016d5cc 100644 --- a/src/locales/zh_CN/battle.ts +++ b/src/locales/zh_CN/battle.ts @@ -59,6 +59,7 @@ export const battle: SimpleTranslationEntries = { "hpIsFull": "{{pokemonName}}的体力已满!", "skipItemQuestion": "你确定要跳过拾取道具吗?", "eggHatching": "咦?", + "stealEatBerry": "{{pokemonName}} stole and ate\n{{targetName}}'s {{berryName}}!", "ivScannerUseQuestion": "对{{pokemonName}}使用个体值扫描仪?", "wildPokemonWithAffix": "野生的{{pokemonName}}", "foePokemonWithAffix": "对手 {{pokemonName}}", diff --git a/src/locales/zh_TW/battle.ts b/src/locales/zh_TW/battle.ts index 553e37dbab6..077933c46d6 100644 --- a/src/locales/zh_TW/battle.ts +++ b/src/locales/zh_TW/battle.ts @@ -51,6 +51,7 @@ export const battle: SimpleTranslationEntries = { "runAwayCannotEscape": "你無法逃脫!", "escapeVerbSwitch": "切換", "escapeVerbFlee": "逃跑", + "stealEatBerry": "{{pokemonName}} stole and ate\n{{targetName}}'s {{berryName}}!", "notDisabled": "{{moveName}} 不再被禁用!", "turnEndHpRestore": "{{pokemonName}}'s HP was restored.", "hpIsFull": "{{pokemonName}}'s\nHP is full!", @@ -128,5 +129,5 @@ export const battle: SimpleTranslationEntries = { "battlerTagsSaltCuredOnAdd": "{{pokemonNameWithAffix}} 陷入了鹽腌狀態!", "battlerTagsSaltCuredLapse": "{{pokemonNameWithAffix}} 受到了{{moveName}}的傷害!", "battlerTagsCursedOnAdd": "{{pokemonNameWithAffix}}削減了自己的體力,並詛咒了{{pokemonName}}!", - "battlerTagsCursedLapse": "{{pokemonNameWithAffix}}正受到詛咒!" + "battlerTagsCursedLapse": "{{pokemonNameWithAffix}}正受到詛咒!", } as const;