From 8fd1dfb4f1a865a3f3a5dcd0838ece1488b10d0e Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 22 Mar 2026 18:44:43 -0700 Subject: [PATCH] feat: add UnitArmor and UnitResistance for character sheet addons UnitArmor(unit) returns base, effective, armor, posBuff, negBuff matching WoW's 5-return signature. Uses server-authoritative armor from UNIT_FIELD_RESISTANCES[0]. UnitResistance(unit, school) returns base, effective, posBuff, negBuff for physical (school 0 = armor) and magical resistances (1-6: Holy/Fire/Nature/Frost/Shadow/Arcane). Needed by character sheet addons (PaperDollFrame, DejaCharacterStats) to display armor and resistance values. --- src/addons/lua_engine.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 40f48e37..4700c102 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -4787,6 +4787,32 @@ void LuaEngine::registerCoreAPI() { {"GetMerchantItemLink", lua_GetMerchantItemLink}, {"CanMerchantRepair", lua_CanMerchantRepair}, {"UnitStat", lua_UnitStat}, + {"UnitArmor", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + int32_t armor = gh ? gh->getArmorRating() : 0; + if (armor < 0) armor = 0; + lua_pushnumber(L, armor); // base + lua_pushnumber(L, armor); // effective + lua_pushnumber(L, armor); // armor (again for compat) + lua_pushnumber(L, 0); // posBuff + lua_pushnumber(L, 0); // negBuff + return 5; + }}, + {"UnitResistance", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + int school = static_cast(luaL_optnumber(L, 2, 0)); + int32_t val = 0; + if (gh) { + if (school == 0) val = gh->getArmorRating(); // physical = armor + else if (school >= 1 && school <= 6) val = gh->getResistance(school); + } + if (val < 0) val = 0; + lua_pushnumber(L, val); // base + lua_pushnumber(L, val); // effective + lua_pushnumber(L, 0); // posBuff + lua_pushnumber(L, 0); // negBuff + return 4; + }}, {"GetDodgeChance", lua_GetDodgeChance}, {"GetParryChance", lua_GetParryChance}, {"GetBlockChance", lua_GetBlockChance},