comparison Main.lua @ 6:e987658a8c7d

Cleanup.
author James D. Callahan III <jcallahan@curse.com>
date Mon, 30 Apr 2012 00:57:32 -0500
parents 59400bdcf95c
children 17900d196389
comparison
equal deleted inserted replaced
5:59400bdcf95c 6:e987658a8c7d
63 63
64 64
65 ----------------------------------------------------------------------- 65 -----------------------------------------------------------------------
66 -- Helper Functions. 66 -- Helper Functions.
67 ----------------------------------------------------------------------- 67 -----------------------------------------------------------------------
68 local function NPCEntry(id_num)
69 if not id_num then
70 return
71 end
72 local npc = db.npcs[id_num]
73
74 if not npc then
75 db.npcs[id_num] = {}
76 npc = db.npcs[id_num]
77 end
78 return npc
79 end
80
81
68 local function CurrentLocationData() 82 local function CurrentLocationData()
69 local map_level = _G.GetCurrentMapDungeonLevel() or 0 83 local map_level = _G.GetCurrentMapDungeonLevel() or 0
70 local x, y = _G.GetPlayerMapPosition("player") 84 local x, y = _G.GetPlayerMapPosition("player")
71 85
72 x = x or 0 86 x = x or 0
187 201
188 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 202 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
189 return 203 return
190 end 204 end
191 local zone_name, x, y, map_level = CurrentLocationData() 205 local zone_name, x, y, map_level = CurrentLocationData()
192 local npc_data = db.npcs[unit_idnum].stats[("level_%d"):format(_G.UnitLevel("target"))] 206 local npc_data = NPCEntry(unit_idnum).stats[("level_%d"):format(_G.UnitLevel("target"))]
193 207 npc_data.locations = npc_data.locations or {}
194 if not npc_data.locations then
195 npc_data.locations = {}
196 end
197 208
198 if not npc_data.locations[zone_name] then 209 if not npc_data.locations[zone_name] then
199 npc_data.locations[zone_name] = {} 210 npc_data.locations[zone_name] = {}
200 end 211 end
201 npc_data.locations[zone_name][("%s:%s:%s"):format(map_level, x, y)] = true 212 npc_data.locations[zone_name][("%s:%s:%s"):format(map_level, x, y)] = true
240 } 251 }
241 252
242 253
243 local LOOT_UPDATE_FUNCS = { 254 local LOOT_UPDATE_FUNCS = {
244 [AF.NPC] = function() 255 [AF.NPC] = function()
245 local npc = db.npcs[action_data.id_num] 256 local npc = NPCEntry(action_data.id_num)
246
247 if not npc then
248 db.npcs[action_data.id_num] = {}
249 npc = db.npcs[action_data.id_num]
250 end
251 npc.drops = npc.drops or {} 257 npc.drops = npc.drops or {}
252 258
253 for index = 1, #action_data.drops do 259 for index = 1, #action_data.drops do
254 table.insert(npc.drops, action_data.drops[index]) 260 table.insert(npc.drops, action_data.drops[index])
255 end 261 end
303 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 309 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
304 310
305 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 311 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
306 return 312 return
307 end 313 end
308 local npc = db.npcs[unit_idnum] 314 local merchant = NPCEntry(unit_idnum)
309 315 merchant.sells = merchant.sells or {}
310 if not npc then
311 db.npcs[unit_idnum] = {}
312 npc = db.npcs[unit_idnum]
313 end
314 npc.sells = npc.sells or {}
315 316
316 for item_index = 1, _G.GetMerchantNumItems() do 317 for item_index = 1, _G.GetMerchantNumItems() do
317 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index) 318 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
318 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index)) 319 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
319 320
369 370
370 for currency_index = 1, #currency_list do 371 for currency_index = 1, #currency_list do
371 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) 372 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
372 end 373 end
373 end 374 end
374 npc.sells[("%s:%s:[%s]"):format(item_id, stack_size, price_string)] = num_available 375 merchant.sells[("%s:%s:[%s]"):format(item_id, stack_size, price_string)] = num_available
375 end 376 end
376 end 377 end
377 end 378 end
378 379
379 380
412 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 413 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
413 414
414 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 415 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
415 return 416 return
416 end 417 end
417 418 local npc = NPCEntry(unit_idnum)
418 local npc = db.npcs[unit_idnum]
419
420 if not npc then
421 db.npcs[unit_idnum] = {}
422 npc = db.npcs[unit_idnum]
423 end
424 local _, class_token = _G.UnitClass("target") 419 local _, class_token = _G.UnitClass("target")
425 npc.class = class_token 420 npc.class = class_token
426 -- TODO: Add faction here 421 -- TODO: Add faction here
427 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED" 422 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"
428 npc.is_pvp = _G.UnitIsPVP("target") and true or nil 423 npc.is_pvp = _G.UnitIsPVP("target") and true or nil