From 8fe0b7bfe85b5cf30392068664d096442de6cc5a Mon Sep 17 00:00:00 2001 From: Duke Date: Fri, 20 Dec 2024 05:16:22 -0600 Subject: [PATCH] refactor attackround logic to remove redundant dynamic cast --- src/map/attackround.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/map/attackround.cpp b/src/map/attackround.cpp index f4d7d2aa789..19ec34ac5c7 100644 --- a/src/map/attackround.cpp +++ b/src/map/attackround.cpp @@ -51,19 +51,25 @@ CAttackRound::CAttackRound(CBattleEntity* attacker, CBattleEntity* defender) m_coverAbilityUserEntity = nullptr; } - if (IsH2H()) // Build H2H attacks. - { - CreateAttacks(dynamic_cast(attacker->m_Weapons[SLOT_MAIN]), LEFTATTACK); - CreateAttacks(dynamic_cast(attacker->m_Weapons[SLOT_MAIN]), LEFTATTACK); - } - else // Build main weapon attacks. + auto* PMain = dynamic_cast(attacker->m_Weapons[SLOT_MAIN]); + auto* PSub = dynamic_cast(attacker->m_Weapons[SLOT_SUB]); + + if (PMain) { - CreateAttacks(dynamic_cast(attacker->m_Weapons[SLOT_MAIN]), RIGHTATTACK); + if (IsH2H()) // Build H2H attacks. + { + CreateAttacks(PMain, LEFTATTACK); + CreateAttacks(PMain, LEFTATTACK); + } + else // Build main weapon attacks. + { + CreateAttacks(PMain, RIGHTATTACK); + } } - if (attacker->m_dualWield) + if (PSub && attacker->m_dualWield) { - CreateAttacks(dynamic_cast(attacker->m_Weapons[SLOT_SUB]), LEFTATTACK); + CreateAttacks(PSub, LEFTATTACK); } // Build kick attacks.