From 9e1d7cc8273775698fe4bc294308a95615e8b59c Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 2 Dec 2020 23:09:35 -0300 Subject: [PATCH] Implemented Ball Fetch --- data/battle_scripts_1.s | 5 +++++ include/battle.h | 2 ++ include/battle_scripts.h | 1 + include/constants/battle_string_ids.h | 3 ++- src/battle_main.c | 5 +++++ src/battle_message.c | 2 ++ src/battle_script_commands.c | 5 +++++ src/battle_util.c | 14 ++++++++++++++ 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 769ef1daae..8c7f31f1eb 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -6165,6 +6165,11 @@ BattleScript_AttackerFormChangeEnd3:: call BattleScript_AttackerFormChange end3 +BattleScript_BallFetch:: + printstring STRINGID_FETCHEDPOKEBALL + waitmessage 0x40 + end3 + BattleScript_TargetFormChange:: pause 0x5 copybyte gBattlerAbility, gBattlerTarget diff --git a/include/battle.h b/include/battle.h index a6e201a239..5783f50938 100644 --- a/include/battle.h +++ b/include/battle.h @@ -827,5 +827,7 @@ extern u8 gHealthboxSpriteIds[MAX_BATTLERS_COUNT]; extern u8 gMultiUsePlayerCursor; extern u8 gNumberOfMovesToChoose; extern u8 gUnknown_03005D7C[MAX_BATTLERS_COUNT]; +extern bool8 gHasFetchedBall; +extern u8 gLastUsedBall; #endif // GUARD_BATTLE_H diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 62c5ce2e0e..9fa4256b47 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -352,5 +352,6 @@ extern const u8 BattleScript_CheekPouchActivates[]; extern const u8 BattleScript_AnnounceAirLockCloudNine[]; extern const u8 BattleScript_TargetAbilityStatRaiseOnSwitchin[]; extern const u8 BattleScript_CottonDownActivates[]; +extern const u8 BattleScript_BallFetch[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/include/constants/battle_string_ids.h b/include/constants/battle_string_ids.h index 9348d67d5d..4d3ba62a82 100644 --- a/include/constants/battle_string_ids.h +++ b/include/constants/battle_string_ids.h @@ -558,8 +558,9 @@ #define STRINGID_AURABREAKENTERS 554 #define STRINGID_COMATOSEENTERS 555 #define STRINGID_SCREENCLEANERENTERS 556 +#define STRINGID_FETCHEDPOKEBALL 557 -#define BATTLESTRINGS_COUNT 557 +#define BATTLESTRINGS_COUNT 558 //// multichoice message IDs // switch in ability message diff --git a/src/battle_main.c b/src/battle_main.c index 48129c5230..e2c23bd2a3 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -228,6 +228,8 @@ EWRAM_DATA u32 gFieldStatuses = 0; EWRAM_DATA struct FieldTimer gFieldTimers = {0}; EWRAM_DATA u8 gBattlerAbility = 0; EWRAM_DATA u16 gPartnerSpriteId = 0; +EWRAM_DATA bool8 gHasFetchedBall = FALSE; +EWRAM_DATA bool8 gLastUsedBall = 0; // IWRAM common vars void (*gPreBattleCallback1)(void); @@ -2886,6 +2888,9 @@ static void BattleStartClearSetData(void) gLastUsedMove = 0; gFieldStatuses = 0; + gHasFetchedBall = FALSE; + gLastUsedBall = 0; + gBattlerAttacker = 0; gBattlerTarget = 0; gBattleWeather = 0; diff --git a/src/battle_message.c b/src/battle_message.c index 22561dd07c..c62674d536 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -685,9 +685,11 @@ static const u8 sText_FairyAuraActivates[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} static const u8 sText_AuraBreakActivates[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} reversed all\nother POKéMON's auras!"); static const u8 sText_ComatoseActivates[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} is drowsing!"); static const u8 sText_ScreenCleanerActivates[] = _("All screens on the field were\ncleansed!"); +static const u8 sText_FetchedPokeBall[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} has fetched\nyour {B_LAST_ITEM}!"); const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = { + [STRINGID_FETCHEDPOKEBALL - 12] = sText_FetchedPokeBall, [STRINGID_STATWASNOTLOWERED - 12] = sText_StatWasNotLowered, [STRINGID_CLOAKEDINAFREEZINGLIGHT - 12] = sText_CloakedInAFreezingLight, [STRINGID_DESTINYKNOTACTIVATES - 12] = sText_DestinyKnotActivates, diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 45761ce0f7..13a919a534 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -11990,6 +11990,11 @@ static void Cmd_handleballthrow(void) } else // not caught { + if (!gHasFetchedBall) + { + gLastUsedBall = gLastUsedItem; + gBattleResults.catchAttempts[gLastUsedBall]++; + } if (IsCriticalCapture()) gBattleCommunication[MULTISTRING_CHOOSER] = shakes + 3; else diff --git a/src/battle_util.c b/src/battle_util.c index 9372fe6942..cb22de62e1 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4126,6 +4126,20 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move effect++; } break; + case ABILITY_BALL_FETCH: + if (gBattleMons[battler].item == ITEM_NONE + && gBattleResults.catchAttempts[gLastUsedBall] >= 1 + && !gHasFetchedBall) + { + gBattleScripting.battler = battler; + BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gLastUsedBall); + MarkBattlerForControllerExec(battler); + gHasFetchedBall = TRUE; + gLastUsedItem = gLastUsedBall; + BattleScriptPushCursorAndCallback(BattleScript_BallFetch); + effect++; + } + break; } } break;