comparison Main.lua @ 10:94bc939c2ca6

Minor refactoring. Added recording of quest-givers.
author James D. Callahan III <jcallahan@curse.com>
date Mon, 30 Apr 2012 17:14:23 -0500
parents 796bf179557a
children 0ec5c8f4b72b
comparison
equal deleted inserted replaced
9:796bf179557a 10:94bc939c2ca6
67 67
68 68
69 ----------------------------------------------------------------------- 69 -----------------------------------------------------------------------
70 -- Helper Functions. 70 -- Helper Functions.
71 ----------------------------------------------------------------------- 71 -----------------------------------------------------------------------
72 local function NPCEntry(id_num) 72 local function UnitEntry(unit_type, unit_id)
73 if not id_num then 73 if not unit_type or not unit_id then
74 return 74 return
75 end 75 end
76 local npc = db.npcs[id_num] 76 local unit = db[unit_type][unit_id]
77 77
78 if not npc then 78 if not unit then
79 db.npcs[id_num] = {} 79 db[unit_type][unit_id] = {}
80 npc = db.npcs[id_num] 80 unit = db[unit_type][unit_id]
81 end 81 end
82 return npc 82 return unit
83 end 83 end
84 84
85 85
86 local function CurrentLocationData() 86 local function CurrentLocationData()
87 local map_level = _G.GetCurrentMapDungeonLevel() or 0 87 local map_level = _G.GetCurrentMapDungeonLevel() or 0
127 return 127 return
128 end 128 end
129 local types = private.UNIT_TYPES 129 local types = private.UNIT_TYPES
130 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK) 130 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
131 131
132 if unit_type ~= types.PLAYER or unit_type ~= types.OBJECT or unit_type ~= types.PET then 132 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
133 return unit_type, tonumber(guid:sub(-12, -9), 16) 133 return unit_type, tonumber(guid:sub(-12, -9), 16)
134 end 134 end
135 135
136 return unit_type 136 return unit_type
137 end 137 end
138 end -- do-block 138 end -- do-block
139
140
141 local function UpdateObjectLocation(identifier)
142 if not identifier then
143 return
144 end
145 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
146 local object = UnitEntry("objects", identifier)
147
148 if not object[zone_name] then
149 object[zone_name] = {}
150 end
151 object[zone_name][("%s:%s:%s:%s"):format(instance_type, map_level, x, y)] = true
152 end
139 153
140 154
141 ----------------------------------------------------------------------- 155 -----------------------------------------------------------------------
142 -- Methods. 156 -- Methods.
143 ----------------------------------------------------------------------- 157 -----------------------------------------------------------------------
205 219
206 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 220 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
207 return 221 return
208 end 222 end
209 local zone_name, x, y, map_level, instance_type = CurrentLocationData() 223 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
210 local npc_data = NPCEntry(unit_idnum).stats[("level_%d"):format(_G.UnitLevel("target"))] 224 local npc_data = UnitEntry("npcs", unit_idnum).stats[("level_%d"):format(_G.UnitLevel("target"))]
211 npc_data.locations = npc_data.locations or {} 225 npc_data.locations = npc_data.locations or {}
212 226
213 if not npc_data.locations[zone_name] then 227 if not npc_data.locations[zone_name] then
214 npc_data.locations[zone_name] = {} 228 npc_data.locations[zone_name] = {}
215 end 229 end
255 } 269 }
256 270
257 271
258 local LOOT_UPDATE_FUNCS = { 272 local LOOT_UPDATE_FUNCS = {
259 [AF.NPC] = function() 273 [AF.NPC] = function()
260 local npc = NPCEntry(action_data.id_num) 274 local npc = UnitEntry("npcs", action_data.id_num)
261 npc.drops = npc.drops or {} 275 npc.drops = npc.drops or {}
262 276
263 for index = 1, #action_data.drops do 277 for index = 1, #action_data.drops do
264 table.insert(npc.drops, action_data.drops[index]) 278 table.insert(npc.drops, action_data.drops[index])
265 end 279 end
314 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 328 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
315 329
316 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 330 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
317 return 331 return
318 end 332 end
319 local merchant = NPCEntry(unit_idnum) 333 local merchant = UnitEntry("npcs", unit_idnum)
320 merchant.sells = merchant.sells or {} 334 merchant.sells = merchant.sells or {}
321 335
322 for item_index = 1, _G.GetMerchantNumItems() do 336 for item_index = 1, _G.GetMerchantNumItems() do
323 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index) 337 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
324 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index)) 338 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
418 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target")) 432 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
419 433
420 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 434 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
421 return 435 return
422 end 436 end
423 local npc = NPCEntry(unit_idnum) 437 local npc = UnitEntry("npcs", unit_idnum)
424 local _, class_token = _G.UnitClass("target") 438 local _, class_token = _G.UnitClass("target")
425 npc.class = class_token 439 npc.class = class_token
426 -- TODO: Add faction here 440 -- TODO: Add faction here
427 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED" 441 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"
428 npc.is_pvp = _G.UnitIsPVP("target") and true or nil 442 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
449 function WDP:QUEST_COMPLETE() 463 function WDP:QUEST_COMPLETE()
450 end 464 end
451 465
452 466
453 function WDP:QUEST_DETAIL() 467 function WDP:QUEST_DETAIL()
468 local unit_name = _G.UnitName("questnpc")
469
470 if not unit_name then
471 return
472 end
473 local unit_type, unit_id = self:ParseGUID(_G.UnitGUID("questnpc"))
474
475 if unit_type == private.UNIT_TYPES.OBJECT then
476 UpdateObjectLocation(unit_id)
477 end
478 local quest = UnitEntry("quests", _G.GetQuestID())
479 quest.begin = quest.begin or {}
480 quest.begin[("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
454 end 481 end
455 482
456 483
457 function WDP:QUEST_LOG_UPDATE() 484 function WDP:QUEST_LOG_UPDATE()
458 self:UnregisterEvent("QUEST_LOG_UPDATE") 485 self:UnregisterEvent("QUEST_LOG_UPDATE")