mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-03 12:10:01 +00:00
libhealth: add option to enable health estimation
This commit is contained in:
@@ -50,6 +50,7 @@ function pfUI:LoadConfig()
|
||||
pfUI:UpdateConfig("global", nil, "servertime", "0")
|
||||
pfUI:UpdateConfig("global", nil, "autosell", "0")
|
||||
pfUI:UpdateConfig("global", nil, "autorepair", "0")
|
||||
pfUI:UpdateConfig("global", nil, "libhealth", "0")
|
||||
|
||||
pfUI:UpdateConfig("gui", nil, "reloadmarker", "0")
|
||||
pfUI:UpdateConfig("gui", nil, "showdisabled", "0")
|
||||
|
||||
+17
-3
@@ -1,8 +1,9 @@
|
||||
-- load pfUI environment
|
||||
setfenv(1, pfUI:GetEnvironment())
|
||||
|
||||
local mobdb
|
||||
local mobdb, enabled = {}, true
|
||||
local target, dmg, perc, diff = nil, 0, 0, 0, 0
|
||||
local UnitHealth, UnitHealthMax
|
||||
local libhealth = CreateFrame("Frame")
|
||||
libhealth:RegisterEvent("UNIT_HEALTH")
|
||||
libhealth:RegisterEvent("UNIT_COMBAT")
|
||||
@@ -10,9 +11,21 @@ libhealth:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||
libhealth:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
libhealth:SetScript("OnEvent", function()
|
||||
if event == "PLAYER_ENTERING_WORLD" then
|
||||
-- create initial health cache tables
|
||||
pfUI_cache["libhealth"] = pfUI_cache["libhealth"] or {}
|
||||
mobdb = pfUI_cache["libhealth"]
|
||||
elseif event == "PLAYER_TARGET_CHANGED" then
|
||||
|
||||
-- load enable state and set functions
|
||||
enabled = pfUI_config["global"]["libhealth"] == "1" and true or nil
|
||||
pfUI.api.UnitHealth = enabled and UnitHealth or nil
|
||||
pfUI.api.UnitHealthMax = enabled and UnitHealthMax or nil
|
||||
end
|
||||
|
||||
-- return as we're not supposed to be here
|
||||
if not enabled then this:UnregisterAllEvents() return end
|
||||
|
||||
-- try to estimate mob health based on combat and health events
|
||||
if event == "PLAYER_TARGET_CHANGED" then
|
||||
dmg, perc = 0, _G.UnitHealth("target")
|
||||
if UnitName("target") and UnitLevel("target") and _G.UnitHealthMax("target") == 100 then
|
||||
target = string.format("%s:%d",UnitName("target"), UnitLevel("target"))
|
||||
@@ -28,12 +41,12 @@ libhealth:SetScript("OnEvent", function()
|
||||
if not mobdb[target][2] or diff > mobdb[target][2] then
|
||||
mobdb[target][1] = ceil(dmg / diff * 100)
|
||||
mobdb[target][2] = diff
|
||||
-- print(string.format("New Health of %s is %s", target, mobdb[target][1]))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- core function to query the generated database
|
||||
local unit, level, cur, max, dbstring
|
||||
local function GetHealthPairs(unitstr)
|
||||
unit = UnitName(unitstr)
|
||||
@@ -51,6 +64,7 @@ local function GetHealthPairs(unitstr)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- functions to overwrite the default health api with estimated values
|
||||
pfUI.api.UnitHealth = function(unitstr)
|
||||
cur, max = GetHealthPairs(unitstr)
|
||||
return cur or _G.UnitHealth(unitstr)
|
||||
|
||||
@@ -1415,6 +1415,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
|
||||
CreateConfig(nil, T["Disable All UIErrors"], C.global, "errors_hide", "checkbox")
|
||||
CreateConfig(nil, T["Highlight Settings That Require Reload"], C.gui, "reloadmarker", "checkbox")
|
||||
CreateConfig(nil, T["Show Incompatible Config Entries"], C.gui, "showdisabled", "checkbox")
|
||||
CreateConfig(nil, T["Estimate Enemy Health Points"], C.global, "libhealth", "checkbox")
|
||||
|
||||
-- Delete / Reset
|
||||
CreateConfig(nil, T["Delete / Reset"], nil, nil, "header")
|
||||
|
||||
Reference in New Issue
Block a user