From 9df8b918a58f567369a5f10f9ed30793911c0352 Mon Sep 17 00:00:00 2001 From: nixy <27468039+overefined@users.noreply.github.com> Date: Sat, 26 Apr 2025 13:56:55 -0600 Subject: [PATCH] update attack class for auto attack lua --- scripts/specs/core/CAttack.lua | 2 +- src/map/attack.cpp | 23 +++---- src/map/attack.h | 109 +++++++++++++++++---------------- src/map/lua/lua_attack.cpp | 7 ++- src/map/lua/lua_attack.h | 2 +- src/map/utils/battleutils.cpp | 4 +- 6 files changed, 73 insertions(+), 74 deletions(-) diff --git a/scripts/specs/core/CAttack.lua b/scripts/specs/core/CAttack.lua index 76ed62d51a9..009a145cd55 100644 --- a/scripts/specs/core/CAttack.lua +++ b/scripts/specs/core/CAttack.lua @@ -6,7 +6,7 @@ local CAttack = {} ---@nodiscard ---@return boolean -function CAttack:getCritical() +function CAttack:isCritical() end ---@param critical boolean diff --git a/src/map/attack.cpp b/src/map/attack.cpp index 299f6ece945..d11cc73ffaa 100644 --- a/src/map/attack.cpp +++ b/src/map/attack.cpp @@ -28,11 +28,6 @@ #include "status_effect_container.h" #include "utils/puppetutils.h" -/************************************************************************ - * * - * Constructor. * - * * - ************************************************************************/ CAttack::CAttack(CBattleEntity* attacker, CBattleEntity* defender, PHYSICAL_ATTACK_TYPE type, PHYSICAL_ATTACK_DIRECTION direction, CAttackRound* attackRound) : m_attacker(attacker) , m_victim(defender) @@ -47,17 +42,17 @@ CAttack::CAttack(CBattleEntity* attacker, CBattleEntity* defender, PHYSICAL_ATTA * Returns the attack direction. * * * ************************************************************************/ -PHYSICAL_ATTACK_DIRECTION CAttack::GetAttackDirection() +PHYSICAL_ATTACK_DIRECTION CAttack::GetAttackDirection() const { return m_attackDirection; } /************************************************************************ * * - * Returns the attack type. * + * Returns the attack type. * * * ************************************************************************/ -PHYSICAL_ATTACK_TYPE CAttack::GetAttackType() +PHYSICAL_ATTACK_TYPE CAttack::GetAttackType() const { return m_attackType; } @@ -74,7 +69,7 @@ void CAttack::SetAttackType(PHYSICAL_ATTACK_TYPE type) /************************************************************************ * * - * Returns the isCritical flag. * + * Returns the isCritical flag. * * * ************************************************************************/ bool CAttack::IsCritical() const @@ -459,12 +454,12 @@ bool CAttack::CheckAnticipated() } } -bool CAttack::CheckHadSneakAttack() const +bool CAttack::IsSneakAttack() const { return m_isSA; } -bool CAttack::CheckHadTrickAttack() const +bool CAttack::IsTrickAttack() const { return m_isTA; } @@ -566,7 +561,7 @@ bool CAttack::CheckCover() /************************************************************************ * * - * Processes the damage for this swing. * + * Processes the damage for this swing. * * * ************************************************************************/ void CAttack::ProcessDamage() @@ -650,13 +645,13 @@ void CAttack::ProcessDamage() attackutils::CheckForDamageMultiplier((CCharEntity*)m_attacker, dynamic_cast(m_attacker->m_Weapons[slot]), m_damage, m_attackType, slot, m_isFirstSwing); // Apply Sneak Attack Augment Mod - if (m_attacker->getMod(Mod::AUGMENTS_SA) > 0 && CheckHadSneakAttack() && m_attacker->StatusEffectContainer->HasStatusEffect(EFFECT_SNEAK_ATTACK)) + if (m_attacker->getMod(Mod::AUGMENTS_SA) > 0 && IsSneakAttack() && m_attacker->StatusEffectContainer->HasStatusEffect(EFFECT_SNEAK_ATTACK)) { m_damage += (int32)(m_damage * ((100 + (m_attacker->getMod(Mod::AUGMENTS_SA))) / 100.0f)); } // Apply Trick Attack Augment Mod - if (m_attacker->getMod(Mod::AUGMENTS_TA) > 0 && CheckHadTrickAttack() && m_attacker->StatusEffectContainer->HasStatusEffect(EFFECT_TRICK_ATTACK)) + if (m_attacker->getMod(Mod::AUGMENTS_TA) > 0 && IsTrickAttack() && m_attacker->StatusEffectContainer->HasStatusEffect(EFFECT_TRICK_ATTACK)) { m_damage += (int32)(m_damage * ((100 + (m_attacker->getMod(Mod::AUGMENTS_TA))) / 100.0f)); } diff --git a/src/map/attack.h b/src/map/attack.h index 26f43661890..fd21111a456 100644 --- a/src/map/attack.h +++ b/src/map/attack.h @@ -68,63 +68,66 @@ class CAttackRound; class CAttack { public: - CAttack(CBattleEntity* attacker, CBattleEntity* defender, PHYSICAL_ATTACK_TYPE type, PHYSICAL_ATTACK_DIRECTION direction, CAttackRound* attackRound); - - uint16 GetAnimationID(); // Returns the animation ID. - PHYSICAL_ATTACK_TYPE GetAttackType(); // Returns the attack type (Double, Triple, Zanshin ect). - PHYSICAL_ATTACK_DIRECTION GetAttackDirection(); // Returns the attack direction. - uint8 GetWeaponSlot(); // Returns the attacking slot. - uint8 GetHitRate(); // Returns the hitrate for this swing. - int32 GetDamage() const; // Returns the damage for this attack. - void SetDamage(int32); // Sets the damage for this attack. - bool IsCritical() const; // Returns the isCritical flag. - void SetCritical(bool); // Sets the isCritical flag; - bool IsFirstSwing() const; // Returns the isFirstSwing flag. - void SetAsFirstSwing(bool isFirst = true); // Sets this attack as the first swing. - float GetDamageRatio() const; // Gets the damage ratio. - void SetGuarded(bool); // Sets the isGuarded flag. - bool IsGuarded(); // Sets the isGuarded flag. Also alters the damage ratio accordingly. - bool IsEvaded() const; // Gets the evaded flag. - void SetEvaded(bool value); // Sets the evaded flag. - bool IsBlocked() const; // Returns the blocked flag. - bool IsParried() const; - bool CheckParried(); - bool IsAnticipated() const; - bool IsDeflected() const; - bool CheckAnticipated(); - bool CheckHadSneakAttack() const; - bool CheckHadTrickAttack() const; - bool IsCountered() const; - bool CheckCounter(); - bool IsCovered() const; // Returns the covered flag. - bool CheckCover(); // Sets the covered flag and returns it. - void ProcessDamage(); // Processes the damage for this swing. - - void SetAttackType(PHYSICAL_ATTACK_TYPE type); // Sets the attack type. + CAttack(CBattleEntity* attacker, + CBattleEntity* defender, + PHYSICAL_ATTACK_TYPE type, + PHYSICAL_ATTACK_DIRECTION direction, + CAttackRound* attackRound); + + auto GetAnimationID() -> uint16; + auto GetAttackType() const -> PHYSICAL_ATTACK_TYPE; + auto SetAttackType(PHYSICAL_ATTACK_TYPE type) -> void; + auto GetAttackDirection() const -> PHYSICAL_ATTACK_DIRECTION; + auto GetWeaponSlot() -> uint8; + auto GetHitRate() -> uint8; + auto GetDamage() const -> int32; + auto SetDamage(int32 damage) -> void; + auto IsCritical() const -> bool; + auto SetCritical(bool crit) -> void; + auto IsFirstSwing() const -> bool; + auto SetAsFirstSwing(bool isFirst = true) -> void; + auto GetDamageRatio() const -> float; + auto SetGuarded(bool g) -> void; + auto IsGuarded() -> bool; + auto IsEvaded() const -> bool; + auto SetEvaded(bool e) -> void; + auto IsBlocked() const -> bool; + auto IsParried() const -> bool; + auto CheckParried() -> bool; + auto IsAnticipated() const -> bool; + auto IsDeflected() const -> bool; + auto CheckAnticipated() -> bool; + auto IsSneakAttack() const -> bool; + auto IsTrickAttack() const -> bool; + auto IsCountered() const -> bool; + auto CheckCounter() -> bool; + auto IsCovered() const -> bool; + auto CheckCover() -> bool; + auto ProcessDamage() -> void; private: - CBattleEntity* m_attacker; // The attacker. - CBattleEntity* m_victim; // The victim. - CAttackRound* m_attackRound; // Reference to the parent attack round. - PHYSICAL_ATTACK_TYPE m_attackType; // The attack type (Double, Triple, Zanshin ect). - PHYSICAL_ATTACK_DIRECTION m_attackDirection; // The attack direction (Left, Right). - uint8 m_hitRate{ 0 }; // This attack's hitrate. - bool m_isCritical{ false }; // Flag: Is this attack a critical attack? - bool m_isGuarded{ false }; // Flag: Is this attack guarded by the victim? - bool m_isParried{ false }; // Flag: Is this attack parried by the victim? - bool m_isBlocked{ false }; // Flag: Is this attack blocked by the victim? - bool m_isEvaded{ false }; // Flag: Is this attack evaded by the victim? + CBattleEntity* m_attacker; + CBattleEntity* m_victim; + CAttackRound* m_attackRound; + PHYSICAL_ATTACK_TYPE m_attackType; + PHYSICAL_ATTACK_DIRECTION m_attackDirection; + uint8 m_hitRate{ 0 }; + bool m_isCritical{ false }; + bool m_isGuarded{ false }; + bool m_isParried{ false }; + bool m_isBlocked{ false }; + bool m_isEvaded{ false }; bool m_isCountered{ false }; - bool m_isCovered{ false }; // Flag: Is someone covering the victim? + bool m_isCovered{ false }; bool m_anticipated{ false }; - bool m_isSA{ false }; // Attack had a valid SA proc - bool m_isTA{ false }; // Attack had a valid TA proc - bool m_isFirstSwing{ false }; // Flag: Is this attack the first swing? - float m_damageRatio{ false }; // The damage ratio. - int32 m_damage{ 0 }; // The damage for this attack. - int32 m_bonusBasePhysicalDamage{ 0 }; // The raw increase of base weapon damage from trick attack/consume mana. - int32 m_naturalH2hDamage{ 0 }; // The damage from natural H2H. - int32 m_baseDamage{ 0 }; // The base damage. + bool m_isSA{ false }; + bool m_isTA{ false }; + bool m_isFirstSwing{ false }; + float m_damageRatio{ 0.0f }; + int32 m_damage{ 0 }; + int32 m_bonusBasePhysicalDamage{ 0 }; + int32 m_naturalH2hDamage{ 0 }; + int32 m_baseDamage{ 0 }; }; #endif diff --git a/src/map/lua/lua_attack.cpp b/src/map/lua/lua_attack.cpp index ab236fa6b67..86eaf064cb0 100644 --- a/src/map/lua/lua_attack.cpp +++ b/src/map/lua/lua_attack.cpp @@ -32,7 +32,7 @@ CLuaAttack::CLuaAttack(CAttack* attack) } } -bool CLuaAttack::getCritical() const +bool CLuaAttack::isCritical() const { return m_PLuaAttack->IsCritical(); } @@ -47,9 +47,10 @@ void CLuaAttack::setCritical(bool critical) void CLuaAttack::Register() { SOL_USERTYPE("CAttack", CLuaAttack); - SOL_REGISTER("getCritical", CLuaAttack::getCritical); + + SOL_REGISTER("isCritical", CLuaAttack::isCritical); SOL_REGISTER("setCritical", CLuaAttack::setCritical); -}; +} std::ostream& operator<<(std::ostream& os, const CLuaAttack& attack) { diff --git a/src/map/lua/lua_attack.h b/src/map/lua/lua_attack.h index e339f782079..5ea3ad45eac 100644 --- a/src/map/lua/lua_attack.h +++ b/src/map/lua/lua_attack.h @@ -38,7 +38,7 @@ class CLuaAttack return m_PLuaAttack; } - bool getCritical() const; + bool isCritical() const; void setCritical(bool critical); friend std::ostream& operator<<(std::ostream& out, const CLuaAttack& action); diff --git a/src/map/utils/battleutils.cpp b/src/map/utils/battleutils.cpp index 4989f85e880..003fe1656d3 100644 --- a/src/map/utils/battleutils.cpp +++ b/src/map/utils/battleutils.cpp @@ -1170,13 +1170,13 @@ namespace battleutils float sneakAttackTrickAttackBonus = 0.f; // BG wiki claims 10x bonus for SA - if (attack.CheckHadSneakAttack()) + if (attack.IsSneakAttack()) { sneakAttackTrickAttackBonus += 10.f; } // BG wiki claims 10x bonus for TA - if (attack.CheckHadTrickAttack()) + if (attack.IsTrickAttack()) { sneakAttackTrickAttackBonus += 10.f; }