Mercurial > wow > wowdb-profiler
comparison Main.lua @ 31:728f1e5dcdc8
Revamp coordinate storage, and check for coordinates which are very close to one another to avoid semi-redundant storage.
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Wed, 30 May 2012 14:22:57 -0500 |
parents | bdb3d8a2c3a7 |
children | 81d7d84df629 |
comparison
equal
deleted
inserted
replaced
30:bdb3d8a2c3a7 | 31:728f1e5dcdc8 |
---|---|
135 end | 135 end |
136 | 136 |
137 if _G.DungeonUsesTerrainMap() then | 137 if _G.DungeonUsesTerrainMap() then |
138 map_level = map_level - 1 | 138 map_level = map_level - 1 |
139 end | 139 end |
140 local x_floor = floor(x * 1000) | 140 local x = _G.floor(x * 1000) |
141 local y_floor = floor(y * 1000) | 141 local y = _G.floor(y * 1000) |
142 | 142 |
143 if x_floor % 2 ~= 0 then | 143 if x % 2 ~= 0 then |
144 x_floor = x_floor + 1 | 144 x = x + 1 |
145 end | 145 end |
146 | 146 |
147 if y_floor % 2 ~= 0 then | 147 if y % 2 ~= 0 then |
148 y_floor = y_floor + 1 | 148 y = y + 1 |
149 end | 149 end |
150 -- print(("x: %d - y: %d"):format(x_floor, y_floor)) | 150 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), x, y, map_level, InstanceDifficultyToken() |
151 | |
152 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level, InstanceDifficultyToken() | |
153 end | 151 end |
154 | 152 |
155 | 153 |
156 local function ItemLinkToID(item_link) | 154 local function ItemLinkToID(item_link) |
157 if not item_link then | 155 if not item_link then |
182 | 180 |
183 local function UpdateObjectLocation(identifier) | 181 local function UpdateObjectLocation(identifier) |
184 if not identifier then | 182 if not identifier then |
185 return | 183 return |
186 end | 184 end |
187 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() | 185 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData() |
188 local object = DBEntry("objects", identifier) | 186 local object = DBEntry("objects", identifier) |
189 object[instance_token] = object[instance_token] or {} | 187 object[difficulty_token] = object[difficulty_token] or {} |
190 object[instance_token].locations = object[instance_token].locations or {} | 188 object[difficulty_token].locations = object[difficulty_token].locations or {} |
191 | 189 |
192 local location_token = ("%s:%d"):format(zone_name, area_id) | 190 local zone_token = ("%s:%d"):format(zone_name, area_id) |
193 | 191 local zone_data = object[difficulty_token].locations[zone_token] |
194 if not object[instance_token].locations[location_token] then | 192 |
195 object[instance_token].locations[location_token] = {} | 193 if not zone_data then |
196 end | 194 zone_data = {} |
197 object[instance_token].locations[location_token][("%s:%s:%s"):format(map_level, x, y)] = true | 195 object[difficulty_token].locations[zone_token] = zone_data |
196 end | |
197 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true | |
198 end | 198 end |
199 | 199 |
200 | 200 |
201 local function HandleItemUse(item_link, bag_index, slot_index) | 201 local function HandleItemUse(item_link, bag_index, slot_index) |
202 if not item_link then | 202 if not item_link then |
282 function WDP:OnEnable() | 282 function WDP:OnEnable() |
283 for event_name, mapping in pairs(EVENT_MAPPING) do | 283 for event_name, mapping in pairs(EVENT_MAPPING) do |
284 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil) | 284 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil) |
285 end | 285 end |
286 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30) | 286 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30) |
287 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.2) | 287 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5) |
288 | 288 |
289 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit) | 289 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit) |
290 if target_unit then | 290 if target_unit then |
291 return | 291 return |
292 end | 292 end |
336 end | 336 end |
337 end | 337 end |
338 end | 338 end |
339 | 339 |
340 | 340 |
341 local COORD_MAX = 5 | |
342 | |
341 function WDP:UpdateTargetLocation() | 343 function WDP:UpdateTargetLocation() |
342 local is_dead = _G.UnitIsDead("target") | 344 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then |
343 | |
344 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not is_dead) then | |
345 return | 345 return |
346 end | 346 end |
347 | 347 |
348 for index = 1, 4 do | 348 for index = 1, 4 do |
349 if not _G.CheckInteractDistance("target", index) then | 349 if not _G.CheckInteractDistance("target", index) then |
354 local unit_type, unit_idnum = self:ParseGUID(target_guid) | 354 local unit_type, unit_idnum = self:ParseGUID(target_guid) |
355 | 355 |
356 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then | 356 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then |
357 return | 357 return |
358 end | 358 end |
359 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() | 359 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData() |
360 local npc_data = NPCEntry(unit_idnum).encounter_data[instance_token].stats[("level_%d"):format(_G.UnitLevel("target"))] | 360 local npc_data = NPCEntry(unit_idnum).encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))] |
361 local location_token = ("%s:%d"):format(zone_name, area_id) | 361 local zone_token = ("%s:%d"):format(zone_name, area_id) |
362 npc_data.locations = npc_data.locations or {} | 362 npc_data.locations = npc_data.locations or {} |
363 npc_data.locations[location_token] = npc_data.locations[location_token] or {} | 363 |
364 | 364 local zone_data = npc_data.locations[zone_token] |
365 -- Only record corpse location if there is no entry for this GUID. | 365 |
366 if is_dead and npc_data.locations[location_token][target_guid] then | 366 if not zone_data then |
367 return | 367 zone_data = {} |
368 end | 368 npc_data.locations[zone_token] = zone_data |
369 npc_data.locations[location_token][target_guid] = ("%s:%s:%s"):format(map_level, x, y) | 369 end |
370 | |
371 for location_token in pairs(zone_data) do | |
372 local loc_level, loc_x, loc_y = (":"):split(location_token) | |
373 loc_level = tonumber(loc_level) | |
374 | |
375 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then | |
376 return | |
377 end | |
378 end | |
379 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true | |
370 end | 380 end |
371 | 381 |
372 | 382 |
373 ----------------------------------------------------------------------- | 383 ----------------------------------------------------------------------- |
374 -- Event handlers. | 384 -- Event handlers. |
495 local loot_data | 505 local loot_data |
496 | 506 |
497 if top_field then | 507 if top_field then |
498 entry[top_field] = entry[top_field] or {} | 508 entry[top_field] = entry[top_field] or {} |
499 entry[top_field][loot_type] = entry[top_field][loot_type] or {} | 509 entry[top_field][loot_type] = entry[top_field][loot_type] or {} |
500 | |
501 loot_data = entry[top_field][loot_type] | 510 loot_data = entry[top_field][loot_type] |
502 else | 511 else |
503 entry[loot_type] = entry[loot_type] or {} | 512 entry[loot_type] = entry[loot_type] or {} |
504 | |
505 loot_data = entry[loot_type] | 513 loot_data = entry[loot_type] |
506 end | 514 end |
507 | 515 |
508 for index = 1, #action_data.loot_list do | 516 for index = 1, #action_data.loot_list do |
509 table.insert(loot_data, action_data.loot_list[index]) | 517 table.insert(loot_data, action_data.loot_list[index]) |
795 end | 803 end |
796 table.wipe(action_data) | 804 table.wipe(action_data) |
797 action_data.type = AF.NPC | 805 action_data.type = AF.NPC |
798 action_data.identifier = unit_idnum | 806 action_data.identifier = unit_idnum |
799 action_data.npc_level = npc_level | 807 action_data.npc_level = npc_level |
808 | |
809 self:UpdateTargetLocation() | |
800 end | 810 end |
801 end -- do-block | 811 end -- do-block |
802 | 812 |
803 do | 813 do |
804 local function UpdateQuestJuncture(point) | 814 local function UpdateQuestJuncture(point) |