ESOUI SVN HyperToxicsHealerHelper

[/] [trunk/] [HyperToxicsHealerHelper.lua] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 HyperToxic-7971
--
2 HyperToxic-7971
htHealerHelper = {}
3 HyperToxic-7971
htHealerHelper.name = "HyperToxicsHealerHelper"
4 HyperToxic-7971
htHealerHelper.version = 0.1
5 HyperToxic-7971
htHealerHelper.unitTags = {}
6 HyperToxic-7971
htHealerHelper.inCombat = false
7 HyperToxic-7971
htHealerHelper.playerName = ""
8 4 HyperToxic-7971
htHealerHelper.LOW_HEALTH = 0.60
9 2 HyperToxic-7971
 
10 HyperToxic-7971
-- Initialize our addon
11 HyperToxic-7971
function htHealerHelper.OnAddOnLoaded(eventCode, addOnName)
12 HyperToxic-7971
        if (addOnName == htHealerHelper.name) then
13 HyperToxic-7971
                htHealerHelper:Initialize()
14 HyperToxic-7971
        end
15 HyperToxic-7971
end
16 HyperToxic-7971
 
17 HyperToxic-7971
 
18 HyperToxic-7971
--integer eventCode, string unitTag, integer powerIndex, integer powerType, integer powerValue, integer powerMax, integer powerEffectiveMax
19 HyperToxic-7971
function htHealerHelper.OnPowerUpdate(eventCode, unitTag, powerIndex, powerType, powerValue, powerMax, powerEffectiveMax)
20 HyperToxic-7971
        htHealerHelper.UpdateVolatileUnitInfo(unitTag)
21 HyperToxic-7971
end
22 HyperToxic-7971
 
23 HyperToxic-7971
 
24 HyperToxic-7971
function htHealerHelper:Initialize()
25 HyperToxic-7971
        self.inCombat = IsUnitInCombat("player")
26 HyperToxic-7971
        self.playerName = GetUnitName("player")
27 HyperToxic-7971
        EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState);
28 HyperToxic-7971
        EVENT_MANAGER:RegisterForEvent(self.name, EVENT_POWER_UPDATE, htHealerHelper.OnPowerUpdate);
29 HyperToxic-7971
 
30 HyperToxic-7971
 
31 HyperToxic-7971
        --self.savedVariables = ZO_SavedVars:New("HyperToxicHealerHelperSavedVariables", 1, nil, {})
32 HyperToxic-7971
        self.savedVariables = ZO_SavedVars:NewAccountWide("HyperToxicHealerHelperSavedVariables", 1, nil, {})
33 HyperToxic-7971
 
34 HyperToxic-7971
        self:RestorePosition()
35 HyperToxic-7971
 
36 HyperToxic-7971
    htHealerHelperIndicatorBG:SetAlpha(0)
37 HyperToxic-7971
 
38 3 HyperToxic-7971
        htHealerHelperIndicator:SetWidth( 600 )
39 2 HyperToxic-7971
        htHealerHelperIndicator:SetHeight( 50 )
40 HyperToxic-7971
 
41 HyperToxic-7971
    htHealerHelperIndicatorT:ClearAnchors();
42 HyperToxic-7971
    htHealerHelperIndicatorT:SetAnchor(CENTER, htHealerHelperIndicator, CENTER, 0, 0)
43 HyperToxic-7971
 
44 3 HyperToxic-7971
    htHealerHelperIndicatorT:SetWidth( 600 )
45 HyperToxic-7971
        htHealerHelperIndicatorT:SetHeight( 50 )
46 2 HyperToxic-7971
        htHealerHelperIndicatorT:SetHorizontalAlignment(1)
47 HyperToxic-7971
 
48 HyperToxic-7971
        EVENT_MANAGER:RegisterForEvent(self.name, EVENT_GAME_CAMERA_UI_MODE_CHANGED, htHealerHelper.UIModeChanged)
49 HyperToxic-7971
 
50 HyperToxic-7971
        EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_ACTIVATED, htHealerHelper.LateInitialize);
51 HyperToxic-7971
        EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_ADD_ON_LOADED);
52 HyperToxic-7971
 
53 HyperToxic-7971
    EVENT_MANAGER:RegisterForEvent(self.name,  EVENT_ACTION_LAYER_POPPED , htHealerHelper.ShowInterface)
54 HyperToxic-7971
    EVENT_MANAGER:RegisterForEvent(self.name,  EVENT_ACTION_LAYER_PUSHED , htHealerHelper.HideInterface)
55 HyperToxic-7971
 
56 HyperToxic-7971
end
57 HyperToxic-7971
 
58 HyperToxic-7971
-- Fancy loaded message
59 HyperToxic-7971
function htHealerHelper.LateInitialize(eventCode, addOnName)
60 HyperToxic-7971
        d("HyperToxic's Healer Helper loaded...")
61 HyperToxic-7971
 
62 HyperToxic-7971
        EVENT_MANAGER:UnregisterForEvent(htHealerHelper.name, EVENT_PLAYER_ACTIVATED);
63 HyperToxic-7971
end
64 HyperToxic-7971
 
65 HyperToxic-7971
 
66 HyperToxic-7971
function htHealerHelper.OnPlayerCombatState(event, inCombat)
67 HyperToxic-7971
        -- The ~= operator is "not equal to" in Lua.
68 HyperToxic-7971
        if inCombat ~= htHealerHelper.inCombat then
69 HyperToxic-7971
                -- The player's state has changed. Update the stored state...
70 HyperToxic-7971
                htHealerHelper.inCombat = inCombat
71 HyperToxic-7971
                if inCombat then
72 HyperToxic-7971
                        -- entering combat - clear unitTags
73 HyperToxic-7971
                        htHealerHelper.unitTags = {}
74 HyperToxic-7971
                else
75 HyperToxic-7971
                        -- exiting combat - clear indicator
76 3 HyperToxic-7971
                        htHealerHelperIndicatorT:SetColor(255, 255, 255, 255)
77 2 HyperToxic-7971
                        htHealerHelperIndicatorT:SetText("")
78 HyperToxic-7971
                end
79 HyperToxic-7971
        end
80 HyperToxic-7971
end
81 HyperToxic-7971
 
82 HyperToxic-7971
function htHealerHelper.UpdateIndicator()
83 HyperToxic-7971
 
84 HyperToxic-7971
        --unit.Name = GetUnitName(unitTag)
85 HyperToxic-7971
        --unit.Dead = IsUnitDead(unitTag)
86 HyperToxic-7971
        --unit.Online = IsUnitOnline(unitTag)
87 HyperToxic-7971
        --unit.HealthPercent = currentHp / maxHp
88 4 HyperToxic-7971
        --unit.LowHealth = unit.HealthPercent <= htHealerHelper.LOW_HEALTH
89 2 HyperToxic-7971
        --unit.InSupportRange = IsUnitInGroupSupportRange(unitTag)
90 HyperToxic-7971
        --unit.UnitTag = unitTag
91 HyperToxic-7971
 
92 HyperToxic-7971
        local priorityUnit = nil;
93 HyperToxic-7971
 
94 HyperToxic-7971
 
95 HyperToxic-7971
 
96 HyperToxic-7971
 
97 HyperToxic-7971
        if htHealerHelper.inCombat then
98 HyperToxic-7971
 
99 HyperToxic-7971
                --do we have a low health ally nearby
100 HyperToxic-7971
                for i, unit in pairs(htHealerHelper.unitTags) do
101 HyperToxic-7971
                        if unit.Online and (not unit.Dead) and unit.InSupportRange and unit.LowHealth then
102 HyperToxic-7971
                                if not priorityUnit then
103 HyperToxic-7971
                                        priorityUnit = unit
104 HyperToxic-7971
                                else
105 HyperToxic-7971
                                        if unit.HealthPercent < priorityUnit.HealthPercent then
106 HyperToxic-7971
                                                priorityUnit = unit
107 HyperToxic-7971
                                        end
108 HyperToxic-7971
                                end
109 HyperToxic-7971
                        end
110 HyperToxic-7971
                end
111 HyperToxic-7971
                --if we dont have a low health ally nearby select a low health out of range ally.
112 HyperToxic-7971
                if not priorityUnit then
113 HyperToxic-7971
                        for i, unit in pairs(htHealerHelper.unitTags) do
114 HyperToxic-7971
                                if unit.Online and (not unit.Dead) and (not unit.InSupportRange) and unit.LowHealth then
115 HyperToxic-7971
                                        if not priorityUnit then
116 HyperToxic-7971
                                                priorityUnit = unit
117 HyperToxic-7971
                                        else
118 HyperToxic-7971
                                                if unit.HealthPercent < priorityUnit.HealthPercent then
119 HyperToxic-7971
                                                        priorityUnit = unit
120 HyperToxic-7971
                                                end
121 HyperToxic-7971
                                        end
122 HyperToxic-7971
                                end
123 HyperToxic-7971
                        end
124 HyperToxic-7971
                end
125 HyperToxic-7971
 
126 HyperToxic-7971
                if priorityUnit then
127 HyperToxic-7971
                        if priorityUnit.InSupportRange then
128 3 HyperToxic-7971
                                htHealerHelperIndicatorT:SetColor(255, 0, 0, 255)
129 2 HyperToxic-7971
                                if htHealerHelper.playerName == priorityUnit.Name then
130 HyperToxic-7971
                                        htHealerHelperIndicatorT:SetText("Heal yourself!")
131 HyperToxic-7971
                                else
132 HyperToxic-7971
                                        htHealerHelperIndicatorT:SetText("Heal " .. priorityUnit.Name .. ".")
133 HyperToxic-7971
                                end
134 HyperToxic-7971
                        else
135 3 HyperToxic-7971
                                htHealerHelperIndicatorT:SetColor(255, 255, 0, 255)
136 2 HyperToxic-7971
                                htHealerHelperIndicatorT:SetText(priorityUnit.Name .. " is out of range.")
137 HyperToxic-7971
                        end
138 HyperToxic-7971
                else
139 HyperToxic-7971
                        htHealerHelperIndicatorT:SetText("")
140 HyperToxic-7971
                end
141 HyperToxic-7971
 
142 HyperToxic-7971
        end
143 HyperToxic-7971
end
144 HyperToxic-7971
 
145 HyperToxic-7971
function htHealerHelper.UpdateVolatileUnitInfo(unitTag)
146 HyperToxic-7971
 
147 HyperToxic-7971
        if not unitTag then
148 HyperToxic-7971
                return
149 HyperToxic-7971
        end
150 HyperToxic-7971
 
151 HyperToxic-7971
        local currentHp, maxHp, effectiveMaxHp
152 HyperToxic-7971
        local unit = {}
153 HyperToxic-7971
 
154 HyperToxic-7971
 
155 HyperToxic-7971
 
156 HyperToxic-7971
        if htHealerHelper.inCombat and (string.sub(unitTag,1,string.len("group"))=="group" or string.sub(unitTag,1,string.len("player"))=="player") then
157 HyperToxic-7971
 
158 HyperToxic-7971
                currentHp, maxHp, effectiveMaxHp = GetUnitPower(unitTag, POWERTYPE_HEALTH)
159 HyperToxic-7971
 
160 HyperToxic-7971
                unit.Name = GetUnitName(unitTag)
161 HyperToxic-7971
                unit.Dead = IsUnitDead(unitTag)
162 HyperToxic-7971
                unit.Online = IsUnitOnline(unitTag)
163 HyperToxic-7971
                unit.HealthPercent = currentHp / maxHp
164 4 HyperToxic-7971
                unit.LowHealth = unit.HealthPercent <= htHealerHelper.LOW_HEALTH
165 2 HyperToxic-7971
                unit.InSupportRange = IsUnitInGroupSupportRange(unitTag)
166 HyperToxic-7971
                unit.UnitTag = unitTag
167 HyperToxic-7971
 
168 HyperToxic-7971
                htHealerHelper.unitTags[unitTag] = unit
169 HyperToxic-7971
 
170 HyperToxic-7971
                htHealerHelper.UpdateIndicator()
171 HyperToxic-7971
        end
172 HyperToxic-7971
 
173 HyperToxic-7971
 
174 HyperToxic-7971
end
175 HyperToxic-7971
 
176 HyperToxic-7971
 
177 HyperToxic-7971
function htHealerHelper.OnIndicatorMoveStop()
178 HyperToxic-7971
        htHealerHelper.savedVariables.left = htHealerHelperIndicator:GetLeft()
179 HyperToxic-7971
        htHealerHelper.savedVariables.top = htHealerHelperIndicator:GetTop()
180 HyperToxic-7971
end
181 HyperToxic-7971
 
182 HyperToxic-7971
function htHealerHelper:RestorePosition()
183 HyperToxic-7971
        local left = self.savedVariables.left
184 HyperToxic-7971
        local top = self.savedVariables.top
185 HyperToxic-7971
 
186 HyperToxic-7971
        htHealerHelperIndicator:ClearAnchors()
187 HyperToxic-7971
        htHealerHelperIndicator:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
188 HyperToxic-7971
end
189 HyperToxic-7971
 
190 HyperToxic-7971
function htHealerHelper.UIModeChanged()
191 HyperToxic-7971
 
192 HyperToxic-7971
        -- zo_callLater(function () d(IsMenuVisisble()) end, 1000)
193 HyperToxic-7971
 
194 HyperToxic-7971
        if (IsReticleHidden()) then
195 HyperToxic-7971
                htHealerHelperIndicatorBG:SetAlpha(100)
196 HyperToxic-7971
                htHealerHelperIndicatorT:SetText("Healer Helper")
197 HyperToxic-7971
        else
198 HyperToxic-7971
                htHealerHelperIndicatorBG:SetAlpha(0)
199 HyperToxic-7971
                htHealerHelperIndicatorT:SetText("")
200 HyperToxic-7971
        end
201 HyperToxic-7971
end
202 HyperToxic-7971
 
203 HyperToxic-7971
-- Hide or show the add-on when other panels are open, like inventory.
204 HyperToxic-7971
-- There's probably a better way to hook this into the scene manager.
205 HyperToxic-7971
function htHealerHelper.HideInterface(eventCode,layerIndex,activeLayerIndex)
206 HyperToxic-7971
    --d(layerIndex .. ":" .. activeLayerIndex)
207 HyperToxic-7971
    -- We don't want to hide the interface if this is the user pressing the "." key, only if there's an interface displayed
208 HyperToxic-7971
    if (activeLayerIndex == 3) then
209 HyperToxic-7971
        htHealerHelperIndicator:SetHidden(true)
210 HyperToxic-7971
    end
211 HyperToxic-7971
end
212 HyperToxic-7971
 
213 HyperToxic-7971
function htHealerHelper.ShowInterface(...)
214 HyperToxic-7971
    htHealerHelperIndicator:SetHidden(false)
215 HyperToxic-7971
end
216 HyperToxic-7971
 
217 HyperToxic-7971
EVENT_MANAGER:RegisterForEvent(htHealerHelper.name, EVENT_ADD_ON_LOADED, htHealerHelper.OnAddOnLoaded);