From cfe29a77c2620698c6dd083e1b56d840ca3973d0 Mon Sep 17 00:00:00 2001 From: Umeboshi Date: Sun, 19 Apr 2026 07:55:30 -0700 Subject: [PATCH] [lua] Have core use lua functions for fSTR --- scripts/globals/combat/physical_utilities.lua | 2 +- src/map/utils/battleutils.cpp | 97 ++----------------- src/map/utils/battleutils.h | 2 +- 3 files changed, 10 insertions(+), 91 deletions(-) diff --git a/scripts/globals/combat/physical_utilities.lua b/scripts/globals/combat/physical_utilities.lua index e8c821a1a7b..e9ee229f9ca 100644 --- a/scripts/globals/combat/physical_utilities.lua +++ b/scripts/globals/combat/physical_utilities.lua @@ -323,7 +323,7 @@ xi.combat.physical.calculateRangedStatFactor = function(actor, target) end -- Players and Trusts - local weaponRank = actor:getWeaponDmgRank() + local weaponRank = actor:getRangedDmgRank() local statLowerCap = (7 + weaponRank * 2) * -2 local statUpperCap = (14 + weaponRank * 2) * 2 diff --git a/src/map/utils/battleutils.cpp b/src/map/utils/battleutils.cpp index a9e003e98a1..f9c021f6ffa 100644 --- a/src/map/utils/battleutils.cpp +++ b/src/map/utils/battleutils.cpp @@ -2777,105 +2777,24 @@ float GetDamageRatio(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool is * * ************************************************************************/ -int32 GetFSTR(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 SlotID) +auto GetFSTR(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 SlotID) -> int32 { - int32 rank = 0; - int32 fstr = 0; - float dif = (float)(PAttacker->STR() - PDefender->VIT()); + int32 fSTR = 0; - // does mob FSTR2 for ranged attack apply here? - if (PAttacker->objtype == TYPE_MOB || PAttacker->objtype == TYPE_PET) - { - fstr = (PAttacker->STR() - PDefender->VIT() + 4) / 4; - - // Level -1 mobs are coded as level 1, but they have an fSTR of 1 always - if (PAttacker->objtype == TYPE_MOB && PAttacker->GetMLevel() == 1) - { - return 1; - } - - return std::clamp(fstr, -20, 24); - } - - if (dif >= 12) - { - fstr = static_cast((dif + 4) / 2); - } - else if (dif >= 6) - { - fstr = static_cast((dif + 6) / 2); - } - else if (dif >= 1) - { - fstr = static_cast((dif + 7) / 2); - } - else if (dif >= -2) - { - fstr = static_cast((dif + 8) / 2); - } - else if (dif >= -7) - { - fstr = static_cast((dif + 9) / 2); - } - else if (dif >= -15) + if (SlotID == SLOT_RANGED || SlotID == SLOT_AMMO) { - fstr = static_cast((dif + 10) / 2); + fSTR = luautils::callGlobal("xi.combat.physical.calculateRangedStatFactor", PAttacker, PDefender); } - else if (dif >= -21) + else if (SlotID == SLOT_MAIN || SlotID == SLOT_SUB) { - fstr = static_cast((dif + 12) / 2); + fSTR = luautils::callGlobal("xi.combat.physical.calculateMeleeStatFactor", PAttacker, PDefender); } else { - fstr = static_cast((dif + 13) / 2); - } - - if (SlotID == SLOT_RANGED || SlotID == SLOT_AMMO) - { - rank = PAttacker->GetRangedWeaponRank(); - // Different caps than melee weapons - if (fstr <= (-rank * 2)) - { - return (-rank * 2); - } - - if ((fstr > (-rank * 2)) && (fstr <= (2 * (rank + 8)))) - { - return fstr; - } - else - { - return 2 * (rank + 8); - } + ShowError("battleutils::GetFSTR() failed to run lua calls"); } - else - { - fstr /= 2; - if (SlotID == SLOT_MAIN) - { - rank = PAttacker->GetMainWeaponRank(); - } - else if (SlotID == SLOT_SUB) - { - rank = PAttacker->GetSubWeaponRank(); - } - - // Everything else - if (fstr <= (-rank)) - { - return (-rank); - } - - if ((fstr > (-rank)) && (fstr <= rank + 8)) - { - return fstr; - } - else - { - return rank + 8; - } - } + return fSTR; } /************************************************************************ diff --git a/src/map/utils/battleutils.h b/src/map/utils/battleutils.h index 09b11b98e81..52d456d077c 100644 --- a/src/map/utils/battleutils.h +++ b/src/map/utils/battleutils.h @@ -144,7 +144,7 @@ bool IsParalyzed(CBattleEntity* PAttacker); bool IsAbsorbByShadow(CBattleEntity* PDefender, CBattleEntity* PAttacker); bool IsIntimidated(CBattleEntity* PAttacker, CBattleEntity* PDefender); -int32 GetFSTR(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 SlotID); +auto GetFSTR(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 SlotID) -> int32; uint8 GetHitRateEx(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 attackNumber, int16 offsetAccuracy); uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender); uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 attackNumber);