comparison Main.lua @ 0:2e4d83460542

Initial commit, with support for recording durability of items in equipment and inventory.
author James D. Callahan III <jcallahan@curse.com>
date Thu, 26 Apr 2012 13:03:54 -0500
parents
children d9375a473042
comparison
equal deleted inserted replaced
-1:000000000000 0:2e4d83460542
1 -----------------------------------------------------------------------
2 -- Upvalued Lua API.
3 -----------------------------------------------------------------------
4 local _G = getfenv(0)
5
6 local pairs = _G.pairs
7
8 -----------------------------------------------------------------------
9 -- AddOn namespace.
10 -----------------------------------------------------------------------
11 local ADDON_NAME, private = ...
12
13 local LibStub = _G.LibStub
14 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0")
15
16 -----------------------------------------------------------------------
17 -- Function declarations.
18 -----------------------------------------------------------------------
19 local HandleSpellFailure
20 local HandleZoneChange
21
22 -----------------------------------------------------------------------
23 -- Local constants.
24 -----------------------------------------------------------------------
25 local DATABASE_DEFAULTS = {
26 global = {
27 items = {},
28 npcs = {},
29 objects = {},
30 quests = {},
31 }
32 }
33
34
35 local EVENT_MAPPING = {-- ARTIFACT_COMPLETE = true,
36 -- ARTIFACT_HISTORY_READY = true,
37 -- AUCTION_HOUSE_SHOW = true,
38 -- BANKFRAME_OPENED = true,
39 -- BATTLEFIELDS_SHOW = true,
40 -- CHAT_MSG_ADDON = true,
41 -- CHAT_MSG_MONSTER_EMOTE = true,
42 -- CHAT_MSG_MONSTER_SAY = true,
43 -- CHAT_MSG_MONSTER_WHISPER = true,
44 -- CHAT_MSG_MONSTER_YELL = true,
45 -- CHAT_MSG_SYSTEM = true,
46 -- COMBAT_LOG_EVENT_UNFILTERED = true,
47 -- COMBAT_TEXT_UPDATE = true,
48 -- CONFIRM_BINDER = true,
49 -- CONFIRM_PET_UNLEARN = true,
50 -- CONFIRM_TALENT_WIPE = true,
51 -- CURRENCY_DISPLAY_UPDATE = true,
52 -- GOSSIP_ENTER_CODE = true,
53 -- GOSSIP_SHOW = true,
54 -- ITEM_TEXT_BEGIN = true,
55 -- LOCALPLAYER_PET_RENAMED = true,
56 -- LOOT_CLOSED = true,
57 -- LOOT_OPENED = true,
58 -- MAIL_SHOW = true,
59 -- MERCHANT_SHOW = true,
60 -- MERCHANT_UPDATE = true,
61 -- OPEN_TABARD_FRAME = true,
62 -- PET_BAR_UPDATE = true,
63 -- PET_STABLE_SHOW = true,
64 -- PLAYER_ALIVE = true,
65 -- PLAYER_ENTERING_WORLD = HandleZoneChange,
66 -- PLAYER_LOGIN = true,
67 -- PLAYER_LOGOUT = true,
68 -- PLAYER_TARGET_CHANGED = true,
69 -- QUEST_COMPLETE = true,
70 -- QUEST_DETAIL = true,
71 -- QUEST_LOG_UPDATE = true,
72 -- QUEST_PROGRESS = true,
73 -- TAXIMAP_OPENED = true,
74 -- TRADE_SKILL_SHOW = true,
75 -- TRADE_SKILL_UPDATE = true,
76 -- TRAINER_SHOW = true,
77 -- UNIT_QUEST_LOG_CHANGED = true,
78 -- UNIT_SPELLCAST_FAILED = HandleSpellFailure,
79 -- UNIT_SPELLCAST_FAILED_QUIET = HandleSpellFailure,
80 -- UNIT_SPELLCAST_INTERRUPTED = HandleSpellFailure,
81 -- UNIT_SPELLCAST_SENT = true,
82 -- UNIT_SPELLCAST_SUCCEEDED = true,
83 -- ZONE_CHANGED = HandleZoneChange,
84 -- ZONE_CHANGED_NEW_AREA = HandleZoneChange,
85 }
86
87
88 -----------------------------------------------------------------------
89 -- Local variables.
90 -----------------------------------------------------------------------
91 local db
92 local durability_timer_handle
93
94
95 -----------------------------------------------------------------------
96 -- Methods.
97 -----------------------------------------------------------------------
98 function WDP:OnInitialize()
99 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
100 end
101
102
103 function WDP:OnEnable()
104 for event_name, mapping in pairs(EVENT_MAPPING) do
105 self:RegisterEvent(event_name, (type(mapping) ~= "boolean") and mapping or nil)
106 end
107 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
108 end
109
110
111 local function RecordDurability(item_id, durability)
112 if not durability or durability <= 0 then
113 return
114 end
115
116 if not db.items[item_id] then
117 db.items[item_id] = {}
118 end
119 db.items[item_id].durability = durability
120 end
121
122
123 function WDP:ProcessDurability()
124 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
125 local item_id = _G.GetInventoryItemID("player", slot_index);
126
127 if item_id and item_id > 0 then
128 local _, max_durability = _G.GetInventoryItemDurability(slot_index);
129 RecordDurability(item_id, max_durability)
130 end
131 end
132
133 for bag_index = 0, _G.NUM_BAG_SLOTS do
134 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
135 local item_id = _G.GetContainerItemID(bag_index, slot_index);
136
137 if item_id and item_id > 0 then
138 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index);
139 RecordDurability(item_id, max_durability)
140 end
141 end
142 end
143 end
144
145
146 -----------------------------------------------------------------------
147 -- Event handlers.
148 -----------------------------------------------------------------------
149 function WDP:AUCTION_HOUSE_SHOW()
150 end
151
152
153 function WDP:CHAT_MSG_MONSTER_EMOTE()
154 end
155
156
157 function WDP:CHAT_MSG_MONSTER_SAY()
158 end
159
160
161 function WDP:CHAT_MSG_MONSTER_WHISPER()
162 end
163
164
165 function WDP:CHAT_MSG_MONSTER_YELL()
166 end
167
168
169 function WDP:CHAT_MSG_SYSTEM(event, message, sender_name, language)
170 end
171
172
173 function WDP:GOSSIP_SHOW()
174 end
175
176
177 function WDP:ADDON_ALIVE()
178 end
179
180
181 function WDP:PLAYER_LOGIN()
182 end
183
184
185 function WDP:PLAYER_LOGOUT()
186 end
187
188
189 function WDP:PLAYER_TARGET_CHANGED()
190 end
191
192
193 function WDP:QUEST_LOG_UPDATE()
194 end
195
196
197 function WDP:TRADE_SKILL_UPDATE()
198 end