160 lines
8.4 KiB
Lua
160 lines
8.4 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Extend the original Camelot paper-doll rows and tooltips. Never replace its
|
|
-- formatter, invent replicated stats, or change protected-action policy.
|
|
WoWHybridUI = WoWHybridUI or {};
|
|
local state = WoWHybridUI;
|
|
local info = state.characterStats or {};
|
|
state.characterStats = info;
|
|
|
|
local function PublicNumber(value)
|
|
if issecretvalue and issecretvalue(value) then return false; end
|
|
return type(value) == "number" and value == value and math.abs(value) < math.huge;
|
|
end
|
|
local function Clamp(value, maximum)
|
|
return math.max(0, math.min(maximum or 100, value));
|
|
end
|
|
|
|
-- Tortoise Unit::MeleeMissChanceCalc/GetUnitCriticalChance/
|
|
-- RollMeleeOutcomeAgainst; StatSystem::Update{Dodge,Parry,Block}Percentage.
|
|
-- Replicated avoidance already includes extra defense: subtract only the
|
|
-- enemy-level difference, rather than adding defense a second time.
|
|
function info.DefenseComparison(level, defense, dodge, parry, block, enemyLevel, armor)
|
|
local values = {level, defense, dodge, parry, block, enemyLevel};
|
|
for index = 1, 6 do
|
|
if not PublicNumber(values[index]) then return nil; end
|
|
end
|
|
if level < 1 or level > 60 or enemyLevel < 1 or defense < 0 then return nil; end
|
|
local skillDifference = enemyLevel * 5 - defense;
|
|
local avoidancePenalty = (enemyLevel - level) * 5 * 0.04;
|
|
local crushingDifference = enemyLevel * 5 - math.min(defense, level * 5);
|
|
local result = {
|
|
miss = Clamp(5 - skillDifference * 0.04, 60),
|
|
dodge = Clamp(dodge - avoidancePenalty),
|
|
parry = parry > 0 and Clamp(parry - avoidancePenalty) or 0,
|
|
block = block > 0 and Clamp(block - avoidancePenalty) or 0,
|
|
baseCrit = Clamp(5 + skillDifference * 0.04),
|
|
crushingEntry = crushingDifference >= 15 and Clamp(crushingDifference * 2 - 15) or 0,
|
|
};
|
|
-- WorldObject::CalcArmorReducedDamage, without attacker armor penetration.
|
|
if PublicNumber(armor) and armor >= 0 then
|
|
result.armorReduction = Clamp(100 * armor / (armor + 400 + 85 * enemyLevel), 75);
|
|
end
|
|
return result;
|
|
end
|
|
|
|
local function Mounted(frame)
|
|
if frame.unit ~= "player" then return false; end
|
|
local mounted = IsMounted();
|
|
if issecretvalue and issecretvalue(mounted) then return false; end
|
|
return mounted == true;
|
|
end
|
|
local function MovementUpdated(frame)
|
|
if Mounted(frame) and frame.Label then frame.Label:SetText(string.format(STAT_FORMAT or "%s", "Mounted Speed")); end
|
|
-- The original updater restores STAT_MOVEMENT_SPEED after dismounting.
|
|
end
|
|
local function MovementTooltip(frame)
|
|
if frame.unit ~= "player" or not PublicNumber(frame.runSpeed) or not PublicNumber(frame.speed) then return; end
|
|
if Mounted(frame) and GameTooltipTextLeft1 then
|
|
GameTooltipTextLeft1:SetText(string.format("Mounted Movement Speed: %.0f%%", frame.speed));
|
|
end
|
|
GameTooltip:AddLine(" ");
|
|
GameTooltip:AddDoubleLine("Total ground speed", string.format("%.0f%%", frame.runSpeed));
|
|
GameTooltip:AddDoubleLine("Bonus over normal running", string.format("%+.0f%%", frame.runSpeed - 100));
|
|
GameTooltip:AddLine("100% is normal running speed. A +60% bonus means 160% total.", 1, 1, 1, true);
|
|
GameTooltip:Show();
|
|
end
|
|
local function DefenseUpdated(frame, unit)
|
|
frame.sourceDefenseUnit = unit or "player";
|
|
end
|
|
local weaponTypes = {INVTYPE_WEAPON = true, INVTYPE_WEAPONMAINHAND = true,
|
|
INVTYPE_WEAPONOFFHAND = true, INVTYPE_2HWEAPON = true};
|
|
local function EquippedType(slot)
|
|
if type(GetInventoryItemID) ~= "function" then return nil, false; end
|
|
local id = GetInventoryItemID("player", slot);
|
|
if issecretvalue and issecretvalue(id) then return nil, false; end
|
|
if not id then return nil, true; end
|
|
if not C_Item or type(C_Item.GetItemInfoInstant) ~= "function" then return nil, false; end
|
|
local _, _, _, inventoryType = C_Item.GetItemInfoInstant(id);
|
|
if issecretvalue and issecretvalue(inventoryType) then return nil, false; end
|
|
if type(inventoryType) ~= "string" then return nil, false; end
|
|
if type(GetInventoryItemDurability) ~= "function" then return nil, false; end
|
|
local durability, maximum = GetInventoryItemDurability(slot);
|
|
if issecretvalue and (issecretvalue(durability) or issecretvalue(maximum)) then return nil, false; end
|
|
if PublicNumber(durability) and PublicNumber(maximum) and maximum > 0 and durability == 0 then return nil, true; end
|
|
return inventoryType, true;
|
|
end
|
|
local function HasDefenseEquipment(stat)
|
|
local offType, offKnown = EquippedType(17);
|
|
if stat == "BLOCK" then
|
|
if offKnown then return offType == "INVTYPE_SHIELD"; end
|
|
else
|
|
local mainType, mainKnown = EquippedType(16);
|
|
if weaponTypes[mainType] or weaponTypes[offType] then return true; end
|
|
if mainKnown and offKnown then return false; end
|
|
end
|
|
end
|
|
local function AddComparison(label, values)
|
|
GameTooltip:AddLine(" ");
|
|
GameTooltip:AddLine(label, 1, 0.82, 0);
|
|
for _, row in ipairs({{"Enemy miss", "miss"}, {"Dodge", "dodge"}, {"Parry", "parry"},
|
|
{"Block", "block"}, {"Base incoming melee crit", "baseCrit"}, {"Crushing table entry", "crushingEntry"}}) do
|
|
GameTooltip:AddDoubleLine(row[1], values[row[2]] and string.format("%.2f%%", values[row[2]]) or "Unavailable");
|
|
end
|
|
if values.armorReduction then
|
|
GameTooltip:AddDoubleLine("Physical armor reduction", string.format("%.2f%%", values.armorReduction));
|
|
end
|
|
end
|
|
local function DefenseTooltip(frame)
|
|
if frame.sourceDefenseUnit ~= "player" then return; end
|
|
local level, defense = UnitLevel("player"), frame.effectiveDefenseSkill;
|
|
local dodge, parry, block = GetDodgeChance(), GetParryChance(), GetBlockChance();
|
|
local _, armor = UnitArmor("player");
|
|
if not PublicNumber(level) then return; end
|
|
local same = info.DefenseComparison(level, defense, dodge, parry, block, level, armor);
|
|
local higher = info.DefenseComparison(level, defense, dodge, parry, block, level + 3, armor);
|
|
if not same or not higher then return; end
|
|
for _, stat in ipairs({"block", "parry"}) do
|
|
local usable = HasDefenseEquipment(string.upper(stat));
|
|
if usable == false then same[stat], higher[stat] = 0, 0;
|
|
elseif usable == nil then same[stat], higher[stat] = nil, nil; end
|
|
end
|
|
AddComparison(string.format("Same-level enemy (level %d)", level), same);
|
|
AddComparison(string.format(level == 60 and "Boss baseline (level %d)" or "Higher-level enemy (level %d)", level + 3), higher);
|
|
GameTooltip:AddLine("PvE melee estimates: standing, facing an unmodified single-weapon attacker. Usable weapons/shields are required. Separate hit/crit effects, control states and encounter rules can change these values. Crushing is an attack-table entry before avoidance coverage.", 1, 1, 1, true);
|
|
GameTooltip:Show();
|
|
end
|
|
-- Camelot supplies all five stat formatters. Its default category hides zero
|
|
-- avoidance and omits Block without a shield. Keep the native Armor and Defense
|
|
-- rows (including both tooltips), and show verified equipment-limited chances.
|
|
local function AvoidanceChance(stat)
|
|
local getter = GetParryChance;
|
|
if stat == "BLOCK" then getter = GetBlockChance; end
|
|
if type(getter) ~= "function" then return nil; end
|
|
local chance = getter();
|
|
if not PublicNumber(chance) or chance < 0 then return nil; end
|
|
if chance == 0 then return 0; end
|
|
local usable = HasDefenseEquipment(stat);
|
|
if usable == true then return chance; end
|
|
if usable == false then return 0; end
|
|
end
|
|
-- The independent Octo panel may read these values after native OnShow.
|
|
-- Do not register addon callbacks in PAPERDOLL_STATCATEGORIES.
|
|
info.ReadAvoidanceChance = AvoidanceChance;
|
|
local function Install()
|
|
if info.installed then return true; end
|
|
for _, name in ipairs({"MovementSpeed_OnUpdate", "MovementSpeed_OnEnter", "PaperDollFrame_SetDefense", "CharacterDefenseFrame_OnEnter"}) do
|
|
if type(_G[name]) ~= "function" then return false; end
|
|
end
|
|
hooksecurefunc("MovementSpeed_OnUpdate", MovementUpdated);
|
|
hooksecurefunc("MovementSpeed_OnEnter", MovementTooltip);
|
|
hooksecurefunc("PaperDollFrame_SetDefense", DefenseUpdated);
|
|
hooksecurefunc("CharacterDefenseFrame_OnEnter", DefenseTooltip);
|
|
info.installed = true;
|
|
return true;
|
|
end
|
|
local events = CreateFrame("Frame");
|
|
events:RegisterEvent("ADDON_LOADED");
|
|
events:SetScript("OnEvent", function() if Install() then events:UnregisterEvent("ADDON_LOADED"); end end);
|
|
Install();
|