comparison Main.lua @ 30:bdb3d8a2c3a7

Slight re-structuring for proper serialization in the web service.
author James D. Callahan III <jcallahan@curse.com>
date Tue, 22 May 2012 14:49:39 -0500
parents 5802628b2bf0
children 728f1e5dcdc8
comparison
equal deleted inserted replaced
29:5802628b2bf0 30:bdb3d8a2c3a7
107 return 107 return
108 end 108 end
109 local instance_token = InstanceDifficultyToken() 109 local instance_token = InstanceDifficultyToken()
110 npc.encounter_data = npc.encounter_data or {} 110 npc.encounter_data = npc.encounter_data or {}
111 npc.encounter_data[instance_token] = npc.encounter_data[instance_token] or {} 111 npc.encounter_data[instance_token] = npc.encounter_data[instance_token] or {}
112 npc.encounter_data[instance_token].stats = npc.encounter_data[instance_token].stats or {}
112 return npc 113 return npc
113 end 114 end
114 115
115 116
116 local function CurrentLocationData() 117 local function CurrentLocationData()
354 355
355 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
356 return 357 return
357 end 358 end
358 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData() 359 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
359 local npc_data = NPCEntry(unit_idnum).encounter_data[instance_token][("level_%d"):format(_G.UnitLevel("target"))] 360 local npc_data = NPCEntry(unit_idnum).encounter_data[instance_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
360 local location_token = ("%s:%d"):format(zone_name, area_id) 361 local location_token = ("%s:%d"):format(zone_name, area_id)
361 npc_data.locations = npc_data.locations or {} 362 npc_data.locations = npc_data.locations or {}
362 npc_data.locations[location_token] = npc_data.locations[location_token] or {} 363 npc_data.locations[location_token] = npc_data.locations[location_token] or {}
363 364
364 -- Only record corpse location if there is no entry for this GUID. 365 -- Only record corpse location if there is no entry for this GUID.
421 local npc = NPCEntry(action_data.identifier) 422 local npc = NPCEntry(action_data.identifier)
422 423
423 if not npc then 424 if not npc then
424 return 425 return
425 end 426 end
426 local encounter_data = npc.encounter_data[InstanceDifficultyToken()] 427 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats
427 encounter_data[action_data.npc_level].reputations = encounter_data[action_data.npc_level].reputations or {} 428 encounter_data[action_data.npc_level].reputations = encounter_data[action_data.npc_level].reputations or {}
428 encounter_data[action_data.npc_level].reputations[faction_name] = amount 429 encounter_data[action_data.npc_level].reputations[faction_name] = amount
429 end 430 end
430 431
431 432
775 npc.genders = npc.genders or {} 776 npc.genders = npc.genders or {}
776 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true 777 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
777 npc.is_pvp = _G.UnitIsPVP("target") and true or nil 778 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
778 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")]) 779 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
779 780
780 local encounter_data = npc.encounter_data[InstanceDifficultyToken()] 781 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats
781 local npc_level = ("level_%d"):format(_G.UnitLevel("target")) 782 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
782 783
783 if not encounter_data[npc_level] then 784 if not encounter_data[npc_level] then
784 encounter_data[npc_level] = { 785 encounter_data[npc_level] = {
785 max_health = _G.UnitHealthMax("target"), 786 max_health = _G.UnitHealthMax("target"),