comparison Main.lua @ 331:998f3264b482 WoD

Cleanups, and eradicate usage of select() where it isn't a one-time thing (such as in the main chunk).
author James D. Callahan III <jcallahan@curse.com>
date Tue, 26 Aug 2014 10:41:52 -0500
parents 84817627cb22
children 5ef583564381
comparison
equal deleted inserted replaced
329:84817627cb22 331:998f3264b482
378 __index = npc_prototype 378 __index = npc_prototype
379 } 379 }
380 380
381 function NPCEntry(identifier) 381 function NPCEntry(identifier)
382 local npc = DBEntry("npcs", identifier) 382 local npc = DBEntry("npcs", identifier)
383 383 return npc and _G.setmetatable(npc, npc_meta) or nil
384 if not npc then
385 return
386 end
387 return _G.setmetatable(npc, npc_meta)
388 end 384 end
389 385
390 function npc_prototype:EncounterData(difficulty_token) 386 function npc_prototype:EncounterData(difficulty_token)
391 self.encounter_data = self.encounter_data or {} 387 self.encounter_data = self.encounter_data or {}
392 self.encounter_data[difficulty_token] = self.encounter_data[difficulty_token] or {} 388 self.encounter_data[difficulty_token] = self.encounter_data[difficulty_token] or {}
682 678
683 if current_loot.target_type == AF.ITEM then 679 if current_loot.target_type == AF.ITEM then
684 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc) 680 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc)
685 source_id = current_loot.identifier 681 source_id = current_loot.identifier
686 else 682 else
687 local unit_ID = select(2, ParseGUID(source_guid)) 683 local _, unit_ID = ParseGUID(source_guid)
688 if unit_ID then 684 if unit_ID then
689 if current_loot.target_type == AF.OBJECT then 685 if current_loot.target_type == AF.OBJECT then
690 source_id = ("%s:%s"):format(current_loot.spell_label, unit_ID) 686 source_id = ("%s:%s"):format(current_loot.spell_label, unit_ID)
691 else 687 else
692 source_id = unit_ID 688 source_id = unit_ID
813 809
814 if not map_visible then 810 if not map_visible then
815 _G.SetCVar("Sound_EnableSFX", 0) 811 _G.SetCVar("Sound_EnableSFX", 0)
816 world_map:Show() 812 world_map:Show()
817 end 813 end
818 local micro_dungeon_id = MICRO_DUNGEON_IDS[select(5, _G.GetMapInfo())] 814 local _, _, _, _, micro_dungeon_map_name = _G.GetMapInfo()
815 local micro_dungeon_id = MICRO_DUNGEON_IDS[micro_dungeon_map_name]
819 816
820 _G.SetMapToCurrentZone() 817 _G.SetMapToCurrentZone()
821 818
822 if micro_dungeon_id then 819 if micro_dungeon_id then
823 current_area_id = micro_dungeon_id 820 current_area_id = micro_dungeon_id
980 977
981 -- do-block 978 -- do-block
982 979
983 980
984 local function RecordItemData(item_id, item_link, durability) 981 local function RecordItemData(item_id, item_link, durability)
985 local item_string = select(3, item_link:find("^|%x+|H(.+)|h%[.+%]")) 982 local _, _, item_string = item_link:find("^|%x+|H(.+)|h%[.+%]")
986 local item 983 local item
987 984
988 if item_string then 985 if item_string then
989 local _, _, _, _, _, _, _, suffix_id, unique_id, _, upgrade_id, instance_difficulty_id, num_bonus_ids = (":"):split(item_string) 986 local _, _, _, _, _, _, _, suffix_id, unique_id, _, upgrade_id, instance_difficulty_id, num_bonus_ids = (":"):split(item_string)
990 local bonus_ids = {select(14, (":"):split(item_string))} 987 local _, _, _, _, _, _, _, _, _, _, _, _, _, bonus_ids = (":"):split(item_string)
988
991 upgrade_id = tonumber(upgrade_id) 989 upgrade_id = tonumber(upgrade_id)
992 instance_difficulty_id = tonumber(instance_difficulty_id) 990 instance_difficulty_id = tonumber(instance_difficulty_id)
993 num_bonus_ids = tonumber(num_bonus_ids) 991 num_bonus_ids = tonumber(num_bonus_ids)
994 if (not num_bonus_ids) or (num_bonus_ids == 0) then 992
993 if not num_bonus_ids or num_bonus_ids == 0 then
995 if (suffix_id and suffix_id ~= 0) or (instance_difficulty_id and instance_difficulty_id ~= 0) then 994 if (suffix_id and suffix_id ~= 0) or (instance_difficulty_id and instance_difficulty_id ~= 0) then
996 item = DBEntry("items", item_id) 995 item = DBEntry("items", item_id)
997 item.unique_id = bit.band(unique_id, 0xFFFF) 996 item.unique_id = bit.band(unique_id, 0xFFFF)
998 if (suffix_id and suffix_id ~= 0) then 997
998 if suffix_id and suffix_id ~= 0 then
999 item.suffix_id = suffix_id 999 item.suffix_id = suffix_id
1000 end 1000 end
1001 if (instance_difficulty_id and instance_difficulty_id ~= 0) then 1001
1002 if instance_difficulty_id and instance_difficulty_id ~= 0 then
1002 item.instance_difficulty_id = instance_difficulty_id 1003 item.instance_difficulty_id = instance_difficulty_id
1003 end 1004 end
1004 end 1005 end
1005 elseif num_bonus_ids > 0 then 1006 elseif num_bonus_ids > 0 then
1006 item = DBEntry("items", item_id) 1007 item = DBEntry("items", item_id)
1007 1008
1008 item.unique_id = bit.band(unique_id, 0xFFFF) 1009 item.unique_id = bit.band(unique_id, 0xFFFF)
1009 item.instance_difficulty_id = instance_difficulty_id 1010 item.instance_difficulty_id = instance_difficulty_id
1010 1011
1011 if not item.bonus_ids then 1012 if not item.bonus_ids then
1012 item.bonus_ids = {} 1013 item.bonus_ids = {}
1013 end 1014 end
1014 1015
1015 for bonus_index = 1, num_bonus_ids do 1016 for bonus_index = 1, num_bonus_ids do
1016 item.bonus_ids[bonus_ids[bonus_index]] = true 1017 item.bonus_ids[bonus_ids[bonus_index]] = true
1017 end 1018 end
1018 else 1019 else
1019 Debug("RecordItemData: Item_system is supposed to be 0 or positive, instead it was %s.", item_system) 1020 Debug("RecordItemData: Item_system is supposed to be 0 or positive, instead it was %s.", item_system)
1465 end 1466 end
1466 end 1467 end
1467 end 1468 end
1468 1469
1469 1470
1470 do -- do-block 1471 do
1471 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC) 1472 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
1472 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC) 1473 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
1473 1474
1474 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) 1475 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
1475 if not spell_id or spell_id == SPELL_ID_CHI_WAVE or spell_id == SPELL_ID_DISGUISE then 1476 if not spell_id or spell_id == SPELL_ID_CHI_WAVE or spell_id == SPELL_ID_DISGUISE then
1753 local difficulty_token = InstanceDifficultyToken() 1754 local difficulty_token = InstanceDifficultyToken()
1754 local loot_label = current_loot.label 1755 local loot_label = current_loot.label
1755 local source_list = {} 1756 local source_list = {}
1756 1757
1757 for source_guid, loot_data in pairs(current_loot.sources) do 1758 for source_guid, loot_data in pairs(current_loot.sources) do
1758 local source_id = select(2, ParseGUID(source_guid)) 1759 local _, source_id = ParseGUID(source_guid)
1759 local npc = NPCEntry(source_id) 1760 local npc = NPCEntry(source_id)
1760 1761
1761 if npc then 1762 if npc then
1762 local encounter_data = npc:EncounterData(difficulty_token) 1763 local encounter_data = npc:EncounterData(difficulty_token)
1763 encounter_data[loot_label] = encounter_data[loot_label] or {} 1764 encounter_data[loot_label] = encounter_data[loot_label] or {}
1889 elseif UnitTypeIsNPC(unit_type) then 1890 elseif UnitTypeIsNPC(unit_type) then
1890 current_action.loot_label = loot_label 1891 current_action.loot_label = loot_label
1891 current_action.target_type = AF.NPC 1892 current_action.target_type = AF.NPC
1892 current_action.identifier = unit_idnum 1893 current_action.identifier = unit_idnum
1893 num_npcs = num_npcs + 1 1894 num_npcs = num_npcs + 1
1894 -- Item container GUIDs are currently of the 'PLAYER' type; this may be unintended and could change in the future.
1895 elseif unit_type == private.UNIT_TYPES.PLAYER then 1895 elseif unit_type == private.UNIT_TYPES.PLAYER then
1896 -- Item container GUIDs are currently of the 'PLAYER' type; this may be unintended and could change in the future.
1896 current_action.loot_label = loot_label 1897 current_action.loot_label = loot_label
1897 current_action.target_type = AF.ITEM 1898 current_action.target_type = AF.ITEM
1898 -- current_action.identifier assigned during loot verification. 1899 -- current_action.identifier assigned during loot verification.
1899 num_itemcontainers = num_itemcontainers + 1 1900 num_itemcontainers = num_itemcontainers + 1
1900 end 1901 end
2064 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc")) 2065 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
2065 2066
2066 if not unit_idnum or not UnitTypeIsNPC(unit_type) then 2067 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
2067 return 2068 return
2068 end 2069 end
2069 merchant_standing = select(2, UnitFactionStanding("npc")) 2070 local _, faction_standing = UnitFactionStanding("npc")
2071 merchant_standing = faction_standing
2070 current_merchant = NPCEntry(unit_idnum) 2072 current_merchant = NPCEntry(unit_idnum)
2071 current_merchant.sells = current_merchant.sells or {} 2073 current_merchant.sells = current_merchant.sells or {}
2072 end 2074 end
2073 local current_filters = _G.GetMerchantFilter() 2075 local current_filters = _G.GetMerchantFilter()
2074 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL) 2076 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL)
2387 local trainer = NPCEntry(unit_idnum) 2389 local trainer = NPCEntry(unit_idnum)
2388 2390
2389 if not trainer then 2391 if not trainer then
2390 return 2392 return
2391 end 2393 end
2392 local trainer_standing = select(2, UnitFactionStanding("npc")) 2394 local _, trainer_standing = UnitFactionStanding("npc")
2393 trainer.teaches = trainer.teaches or {} 2395 trainer.teaches = trainer.teaches or {}
2394 2396
2395 private.trainer_shown = true 2397 private.trainer_shown = true
2396 2398
2397 -- Get the initial trainer filters 2399 -- Get the initial trainer filters
2487 current_action.target_type = AF.ITEM 2489 current_action.target_type = AF.ITEM
2488 2490
2489 if item_name and item_name == target_name then 2491 if item_name and item_name == target_name then
2490 current_action.identifier = ItemLinkToID(item_link) 2492 current_action.identifier = ItemLinkToID(item_link)
2491 elseif target_name and target_name ~= "" then 2493 elseif target_name and target_name ~= "" then
2492 current_action.identifier = ItemLinkToID(select(2, _G.GetItemInfo(target_name))) 2494 local _, item_link = _G.GetItemInfo(target_name)
2495 current_action.identifier = ItemLinkToID(item_link)
2493 end 2496 end
2494 elseif not item_name and not unit_name then 2497 elseif not item_name and not unit_name then
2495 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then 2498 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
2496 if target_name == "" then 2499 if target_name == "" then
2497 return 2500 return