comparison Main.lua @ 248:4cb26edfd905

Cleanup for npc_prototype:EncounterData()
author James D. Callahan III <jcallahan@curse.com>
date Tue, 12 Mar 2013 08:44:32 -0500
parents f506c09d75a9
children 3fe3e55c327e
comparison
equal deleted inserted replaced
247:9fb6530325e0 248:4cb26edfd905
314 return 314 return
315 end 315 end
316 return _G.setmetatable(npc, npc_meta) 316 return _G.setmetatable(npc, npc_meta)
317 end 317 end
318 318
319 function npc_prototype:EncounterData() 319 function npc_prototype:EncounterData(difficulty_token)
320 local instance_token = InstanceDifficultyToken()
321 self.encounter_data = self.encounter_data or {} 320 self.encounter_data = self.encounter_data or {}
322 self.encounter_data[instance_token] = self.encounter_data[instance_token] or {} 321 self.encounter_data[difficulty_token] = self.encounter_data[difficulty_token] or {}
323 self.encounter_data[instance_token].stats = self.encounter_data[instance_token].stats or {} 322 self.encounter_data[difficulty_token].stats = self.encounter_data[difficulty_token].stats or {}
324 323
325 return self.encounter_data 324 return self.encounter_data[difficulty_token]
326 end 325 end
327 end 326 end
328 327
329 328
330 local function CurrentLocationData() 329 local function CurrentLocationData()
929 npc.genders = npc.genders or {} 928 npc.genders = npc.genders or {}
930 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true 929 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
931 npc.is_pvp = _G.UnitIsPVP("target") and true or nil 930 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
932 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")]) 931 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
933 932
934 local encounter_data = npc:EncounterData()[InstanceDifficultyToken()].stats 933 local encounter_data = npc:EncounterData(InstanceDifficultyToken()).stats
935 local npc_level = ("level_%d"):format(_G.UnitLevel("target")) 934 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
936 935
937 if not encounter_data[npc_level] then 936 if not encounter_data[npc_level] then
938 encounter_data[npc_level] = { 937 encounter_data[npc_level] = {
939 max_health = _G.UnitHealthMax("target"), 938 max_health = _G.UnitHealthMax("target"),
969 968
970 if not npc then 969 if not npc then
971 return 970 return
972 end 971 end
973 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData() 972 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
974 local npc_data = npc:EncounterData()[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))] 973 local npc_data = npc:EncounterData(difficulty_token).stats[("level_%d"):format(_G.UnitLevel("target"))]
975 local zone_token = ("%s:%d"):format(zone_name, area_id) 974 local zone_token = ("%s:%d"):format(zone_name, area_id)
976 npc_data.locations = npc_data.locations or {} -- TODO: Fix this. It is broken. Possibly something to do with the timed updates. 975 npc_data.locations = npc_data.locations or {} -- TODO: Fix this. It is broken. Possibly something to do with the timed updates.
977 976
978 local zone_data = npc_data.locations[zone_token] 977 local zone_data = npc_data.locations[zone_token]
979 978
1062 if not item_id then 1061 if not item_id then
1063 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) 1062 Debug("%s: ItemID is nil, from item link %s", event_name, item_link)
1064 return 1063 return
1065 end 1064 end
1066 local loot_type = "drops" 1065 local loot_type = "drops"
1067 local encounter_data = npc:EncounterData()[InstanceDifficultyToken()] 1066 local encounter_data = npc:EncounterData(InstanceDifficultyToken())
1068 encounter_data[loot_type] = encounter_data[loot_type] or {} 1067 encounter_data[loot_type] = encounter_data[loot_type] or {}
1069 encounter_data.loot_counts = encounter_data.loot_counts or {} 1068 encounter_data.loot_counts = encounter_data.loot_counts or {}
1070 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 1069 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
1071 1070
1072 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity)) 1071 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity))
1222 if not source_id or not UnitTypeIsNPC(source_type) then 1221 if not source_id or not UnitTypeIsNPC(source_type) then
1223 return 1222 return
1224 end 1223 end
1225 1224
1226 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then 1225 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
1227 local encounter_data = NPCEntry(source_id):EncounterData()[InstanceDifficultyToken()] 1226 local encounter_data = NPCEntry(source_id):EncounterData(InstanceDifficultyToken())
1228 encounter_data.spells = encounter_data.spells or {} 1227 encounter_data.spells = encounter_data.spells or {}
1229 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1 1228 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
1230 end 1229 end
1231 end 1230 end
1232 1231
1527 for source_guid, loot_data in pairs(current_loot.sources) do 1526 for source_guid, loot_data in pairs(current_loot.sources) do
1528 local source_id = select(2, ParseGUID(source_guid)) 1527 local source_id = select(2, ParseGUID(source_guid))
1529 local npc = NPCEntry(source_id) 1528 local npc = NPCEntry(source_id)
1530 1529
1531 if npc then 1530 if npc then
1532 local encounter_data = npc:EncounterData()[difficulty_token] 1531 local encounter_data = npc:EncounterData(difficulty_token)
1533 encounter_data[loot_type] = encounter_data[loot_type] or {} 1532 encounter_data[loot_type] = encounter_data[loot_type] or {}
1534 1533
1535 if not source_list[source_guid] then 1534 if not source_list[source_guid] then
1536 encounter_data.loot_counts = encounter_data.loot_counts or {} 1535 encounter_data.loot_counts = encounter_data.loot_counts or {}
1537 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 1536 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
1551 local npc = NPCEntry(current_loot.identifier) 1550 local npc = NPCEntry(current_loot.identifier)
1552 1551
1553 if not npc then 1552 if not npc then
1554 return 1553 return
1555 end 1554 end
1556 local encounter_data = npc:EncounterData()[difficulty_token] 1555 local encounter_data = npc:EncounterData(difficulty_token)
1557 encounter_data[loot_type] = encounter_data[loot_type] or {} 1556 encounter_data[loot_type] = encounter_data[loot_type] or {}
1558 1557
1559 if not source_list[current_loot.identifier] then 1558 if not source_list[current_loot.identifier] then
1560 encounter_data.loot_counts = encounter_data.loot_counts or {} 1559 encounter_data.loot_counts = encounter_data.loot_counts or {}
1561 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 1560 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1