From e099fcc09a8b37605b22f5aea90129494d7bb661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 2 Jan 2022 15:04:01 +0100 Subject: [PATCH] Fix swapping arrows while targeting Fixes #184. Note that MM3D does not let you switch from one magic arrow type to another; that is not a Project Restoration bug and we currently make no attempt to fix that. --- source/rst/link.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/source/rst/link.cpp b/source/rst/link.cpp index a47c5ed..b32ef52 100644 --- a/source/rst/link.cpp +++ b/source/rst/link.cpp @@ -136,6 +136,8 @@ bool ShouldEndGoronRoll(game::act::Player* player) { struct FastArrowState { std::optional override_action; + /// The item button slot that was used with the override_action. + std::optional item_btn_slot; int magic_cost_update_timer = -1; }; @@ -194,14 +196,22 @@ void HandleFastArrowSwitch(game::act::Player* player) { // Reset the override action if the player is not using a bow. constexpr u8 first = u8(game::Action::Arrow); constexpr u8 last = u8(game::Action::LightArrow); - const bool is_using = player->action_type == game::act::Player::ActionType::Type3 || - player->projectile_actor || - player->flags1.IsSet(game::act::Player::Flag1::ZTargeting); + const bool is_using = + player->action_type == game::act::Player::ActionType::Type3 || player->projectile_actor; if (first > u8(player->current_action) || u8(player->current_action) > last || !is_using) { s_fast_arrow_state = {}; return; } + if (s_fast_arrow_state.item_btn_slot != player->item_btn_slot) { + // The player switched to a different item button slot. + // Reset the action override and any other internal state. + util::Print("%s: detected item button slot change, resetting", __func__); + s_fast_arrow_state = {}; + } + + s_fast_arrow_state.item_btn_slot = player->item_btn_slot; + if (s_fast_arrow_state.magic_cost_update_timer > 0) --s_fast_arrow_state.magic_cost_update_timer;