-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackHealthstonesCreated.lua
75 lines (60 loc) · 2.73 KB
/
TrackHealthstonesCreated.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local HST, C, L = unpack(select(2, ...))
local MODULE_NAME = "TrackHealthstonesCreated"
---------------------------------------------
-- CONSTANTS
---------------------------------------------
local CREATE_HEALTHSTONE_SPELLIDS = { 5699, 6201, 6202, 11729, 11730 }
local PLAYER_NAME = UnitName("player")
---------------------------------------------
-- VARIABLES
---------------------------------------------
local createHealthstoneSpellsByName = {}
local healthstonesByItemId = {}
---------------------------------------------
-- TRACK HEALTHSTONE CREATED
---------------------------------------------
local function trackHealthstoneCreated(...)
local timestamp, event, hideCaster, srcGuid, srcName, srcFlags, srcRaidFlags, dstGuid, dstName, dstFlags, dstRaidFlags = ...
local isPlayer = bit.band(srcFlags, COMBATLOG_OBJECT_TYPE_PLAYER) > 0
if ( event == "SPELL_CAST_SUCCESS" and isPlayer ) then
local spellName = select(13, ...)
local isFriendly = bit.band(srcFlags, COMBATLOG_OBJECT_REACTION_FRIENDLY ) > 0
HST:trace(MODULE_NAME, "trackHealthstoneCreated", srcName, spellName, createHealthstoneSpellsByName[spellName], isFriendly)
if ( spellName and createHealthstoneSpellsByName[spellName] and isFriendly ) then
HST:debug(srcName, "successfully casted", spellName)
HST:SetPlayerHealthstone(timestamp, srcName, true)
end
end
end
local function checkPlayerInventoryForHealthstone(...)
for bagId = 0,4 do
for slotId = 1,GetContainerNumSlots(bagId) do
local itemId = GetContainerItemID(bagId, slotId)
if ( itemId and healthstonesByItemId[itemId] ) then
HST:SetPlayerHealthstone(nil, PLAYER_NAME, true)
return
end
end
end
HST:SetPlayerHealthstone(nil, PLAYER_NAME, false)
end
---------------------------------------------
-- INITIALIZE
---------------------------------------------
HST.RegisterCallback(MODULE_NAME, "initialize", function()
-- Watch combat log for healthstone created
HST.RegisterEvent(MODULE_NAME, "COMBAT_LOG_EVENT_UNFILTERED", function(event)
trackHealthstoneCreated(CombatLogGetCurrentEventInfo())
end)
-- Convert list of create healthstone spellIDs to spellNames
for _,spellId in ipairs(CREATE_HEALTHSTONE_SPELLIDS) do
local spellName = GetSpellInfo(spellId)
createHealthstoneSpellsByName[spellName] = true
end
-- Check player bags for healstone upon zoning in
HST.RegisterEvent(MODULE_NAME, "PLAYER_ENTERING_WORLD", checkPlayerInventoryForHealthstone)
-- Convert list of create healthstone itemIds to a map
for _,itemId in ipairs(HST.HEALTHSTONES_BY_ITEMID) do
healthstonesByItemId[itemId] = true
end
end)