comparison Main.lua @ 133:a6e36b3f51d6 1.0.11

Ensure that the NPC data we're looking at when visiting a merchant remains unchanged until MERCHANT_CLOSE fires. Bumped DB version to 8.
author James D. Callahan III <jcallahan@curse.com>
date Mon, 24 Sep 2012 11:59:30 -0500
parents 05b77c08b211
children 3b9d44976319
comparison
equal deleted inserted replaced
132:05b77c08b211 133:a6e36b3f51d6
29 29
30 30
31 ----------------------------------------------------------------------- 31 -----------------------------------------------------------------------
32 -- Local constants. 32 -- Local constants.
33 ----------------------------------------------------------------------- 33 -----------------------------------------------------------------------
34 local DB_VERSION = 7 34 local DB_VERSION = 8
35 35
36 36
37 local DATABASE_DEFAULTS = { 37 local DATABASE_DEFAULTS = {
38 char = {}, 38 char = {},
39 global = { 39 global = {
63 GUILDBANKFRAME_OPENED = true, 63 GUILDBANKFRAME_OPENED = true,
64 ITEM_TEXT_BEGIN = true, 64 ITEM_TEXT_BEGIN = true,
65 LOOT_CLOSED = true, 65 LOOT_CLOSED = true,
66 LOOT_OPENED = true, 66 LOOT_OPENED = true,
67 MAIL_SHOW = true, 67 MAIL_SHOW = true,
68 MERCHANT_CLOSED = true,
68 MERCHANT_SHOW = "UpdateMerchantItems", 69 MERCHANT_SHOW = "UpdateMerchantItems",
69 MERCHANT_UPDATE = "UpdateMerchantItems", 70 MERCHANT_UPDATE = "UpdateMerchantItems",
70 PET_BAR_UPDATE = true, 71 PET_BAR_UPDATE = true,
71 PET_JOURNAL_LIST_UPDATE = true, 72 PET_JOURNAL_LIST_UPDATE = true,
72 PLAYER_TARGET_CHANGED = true, 73 PLAYER_TARGET_CHANGED = true,
1230 1231
1231 if not loot_guid_registry[source_guid] then 1232 if not loot_guid_registry[source_guid] then
1232 local loot_quantity = loot_info[loot_index + 1] 1233 local loot_quantity = loot_info[loot_index + 1]
1233 local source_type, source_id = ParseGUID(source_guid) 1234 local source_type, source_id = ParseGUID(source_guid)
1234 -- TODO: Remove debugging 1235 -- TODO: Remove debugging
1235 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) 1236 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
1236 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity)) 1237 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity))
1237 1238
1238 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 1239 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
1239 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} 1240 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
1240 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity 1241 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity
1241 guids_used[source_guid] = true 1242 guids_used[source_guid] = true
1277 1278
1278 local ITEM_REQ_REPUTATION_MATCH = "Requires (.-) %- (.*)" 1279 local ITEM_REQ_REPUTATION_MATCH = "Requires (.-) %- (.*)"
1279 local ITEM_REQ_QUEST_MATCH1 = "Requires: .*" 1280 local ITEM_REQ_QUEST_MATCH1 = "Requires: .*"
1280 local ITEM_REQ_QUEST_MATCH2 = "Must have completed: .*" 1281 local ITEM_REQ_QUEST_MATCH2 = "Must have completed: .*"
1281 1282
1283 local current_merchant
1284 local merchant_standing
1285
1286 function WDP:MERCHANT_CLOSED(event_name)
1287 current_merchant = nil
1288 merchant_standing = nil
1289 end
1290
1291
1282 function WDP:UpdateMerchantItems(event_name) 1292 function WDP:UpdateMerchantItems(event_name)
1283 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) 1293 if not current_merchant then
1284 1294 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
1285 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then 1295
1286 return 1296 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
1287 end 1297 return
1298 end
1299 merchant_standing = select(2, UnitFactionStanding("target"))
1300 current_merchant = NPCEntry(unit_idnum)
1301 current_merchant.sells = current_merchant.sells or {}
1302 end
1303 local num_items = _G.GetMerchantNumItems()
1288 local current_filters = _G.GetMerchantFilter() 1304 local current_filters = _G.GetMerchantFilter()
1289 local _, merchant_standing = UnitFactionStanding("target")
1290 local merchant = NPCEntry(unit_idnum)
1291 merchant.sells = merchant.sells or {}
1292
1293 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL) 1305 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL)
1294 _G.MerchantFrame_Update() 1306 _G.MerchantFrame_Update()
1295
1296 local num_items = _G.GetMerchantNumItems()
1297 1307
1298 for item_index = 1, num_items do 1308 for item_index = 1, num_items do
1299 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index) 1309 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
1300 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index)) 1310 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
1301 1311
1381 1391
1382 for currency_index = 1, #currency_list do 1392 for currency_index = 1, #currency_list do
1383 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) 1393 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
1384 end 1394 end
1385 end 1395 end
1386 merchant.sells[item_id] = ("%s:%s:[%s]"):format(num_available, stack_size, price_string) 1396 current_merchant.sells[item_id] = ("%s:%s:[%s]"):format(num_available, stack_size, price_string)
1387 end 1397 end
1388 end 1398 end
1389 1399
1390 if _G.CanMerchantRepair() then 1400 if _G.CanMerchantRepair() then
1391 merchant.can_repair = true 1401 current_merchant.can_repair = true
1392 end 1402 end
1393 _G.SetMerchantFilter(current_filters) 1403 _G.SetMerchantFilter(current_filters)
1394 _G.MerchantFrame_Update() 1404 _G.MerchantFrame_Update()
1395 end 1405 end
1396 end -- do-block 1406 end -- do-block