Advertisement
Guest User

Untitled

a guest
Aug 12th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.72 KB | None | 0 0
  1. local LastSearchTimeStamp = nil
  2. local IsStoreUIOpen = false
  3. local MinSearchDelay = 5000
  4. local SearchAdditionalDelay = 1000
  5.  
  6. local function UpdateScanButtonStatus()
  7. if (IsStoreUIOpen) then
  8. KEYBIND_STRIP:UpdateKeybindButton(TamrielTradeCentre.Buttons.StartScanButton)
  9. else
  10. KEYBIND_STRIP:RemoveKeybindButton(TamrielTradeCentre.Buttons.StartScanButton)
  11. end
  12. end
  13.  
  14. local ScanStatus = {}
  15. ScanStatus.SessionID = 0
  16. function ScanStatus:Reset()
  17. self.IsScanning = false
  18. self.IsPaused = false
  19. self.GuildName = nil
  20. self.CurrentPage = -1
  21. self.IsFinishPending = false
  22. UpdateScanButtonStatus()
  23. end
  24.  
  25. function ScanStatus:Start()
  26. self:Reset()
  27. self.SessionID = self.SessionID + 1
  28.  
  29. local _, guildName = GetCurrentTradingHouseGuildDetails()
  30. if (guildName == nil or guildName == "") then
  31. return
  32. end
  33.  
  34. self.IsScanning = true
  35. self.IsPaused = false
  36. self.GuildName = guildName
  37. self.CurrentPage = -1
  38. self.IsFinishPending = false
  39. UpdateScanButtonStatus()
  40. end
  41.  
  42. function ScanStatus:Pause()
  43. self.IsScanning = false
  44. self.IsPaused = true
  45. end
  46.  
  47. function ScanStatus:Resume()
  48. local _, guildName = GetCurrentTradingHouseGuildDetails()
  49. if (guildName == nil or guildName == "") then
  50. return
  51. end
  52.  
  53. self.SessionID = self.SessionID + 1
  54. self.IsScanning = true
  55. self.IsPaused = false
  56. end
  57.  
  58.  
  59.  
  60. local function CloseMsgBox()
  61. ZO_Dialogs_ReleaseDialog("TamrielTradeCentreDialog", false)
  62. end
  63.  
  64. local function ShowMsgBox(title, msg, btnText, callback)
  65. local confirmDialog =
  66. {
  67. title = { text = title },
  68. mainText = { text = msg },
  69. buttons =
  70. {
  71. {
  72. text = btnText,
  73. callback = callback
  74. }
  75. }
  76. }
  77.  
  78. ZO_Dialogs_RegisterCustomDialog("TamrielTradeCentreDialog", confirmDialog)
  79. CloseMsgBox()
  80. ZO_Dialogs_ShowDialog("TamrielTradeCentreDialog")
  81. end
  82.  
  83.  
  84.  
  85. local function OnTradingHouseClosed()
  86. IsStoreUIOpen = false
  87. if (ScanStatus.IsScanning) then
  88. ScanStatus:Pause()
  89. end
  90.  
  91. UpdateScanButtonStatus()
  92. end
  93.  
  94. local function GetScanDelay()
  95. return math.max(GetTradingHouseCooldownRemaining() + SearchAdditionalDelay, MinSearchDelay)
  96. end
  97.  
  98. local function GuildListingScanLoop(sessionID)
  99. if (not ScanStatus.IsScanning or ScanStatus.SessionID ~= sessionID or ScanStatus.IsPaused) then
  100. TamrielTradeCentre:DebugWriteLine("Scan loop session = " .. sessionID .. " ended" )
  101. return
  102. end
  103.  
  104. TamrielTradeCentre:DebugWriteLine("Scanning page " .. ScanStatus.CurrentPage + 1 .. " SessionID = " .. sessionID)
  105. d("Scanning page " .. ScanStatus.CurrentPage + 1) --TODO: remove once ZOS fix store UI bug
  106. ExecuteTradingHouseSearch(ScanStatus.CurrentPage + 1)
  107.  
  108. local delay = GetScanDelay()
  109. zo_callLater(function()
  110. GuildListingScanLoop(sessionID)
  111. end, delay)
  112. end
  113.  
  114. local function StartGuildListingScanLoop()
  115. if (not ScanStatus.IsScanning) then
  116. return
  117. end
  118.  
  119. if (not TamrielTradeCentre.Settings.EnableAutoRecordStoreEntries) then
  120. ShowMsgBox(GetString(TTC_ERROR), GetString(TTC_ERROR_AUTORECORDSEARCHRESULTNOTENABLED), SI_DIALOG_CONFIRM)
  121. ScanStatus:Reset()
  122. return
  123. end
  124.  
  125. if (TamrielTradeCentre:GetCurrentKioskID() == nil) then
  126. ShowMsgBox(GetString(TTC_ERROR), GetString(TTC_ERROR_GUILDDOESNOTOWNKIOSK), SI_DIALOG_CONFIRM)
  127. ScanStatus:Reset()
  128. return
  129. end
  130.  
  131. TRADING_HOUSE_SEARCH:ResetAllSearchData()
  132.  
  133. ShowMsgBox(GetString(TTC_MSG_SCANINPROGRESS),
  134. GetString(TTC_MSG_SCANNINGALLLISTINGSINSTORE) .. "\n\nP.S. StoreUI won't update while scanning due to ZOS bug (please check chat box for progress)", --TODO: remove once ZOS fix store UI bug
  135. SI_DIALOG_BUTTON_TEXT_QUIT_FORCE,
  136. function()
  137. ShowMsgBox(GetString(TTC_MSG_SCANCANCELED), GetString(TTC_MSG_OPERATIONCANCELEDBYUSER), SI_DIALOG_CONFIRM)
  138. ScanStatus:Reset()
  139. end)
  140.  
  141. TamrielTradeCentre:DebugWriteLine("Starting GuildListingScanLoop with SessionID = " .. ScanStatus.SessionID)
  142. GuildListingScanLoop(ScanStatus.SessionID)
  143. end
  144.  
  145. function TamrielTradeCentre:StartNewGuildListingScan()
  146. if (ScanStatus.IsScanning or not IsStoreUIOpen) then --Bail if another scan is in progress
  147. return
  148. end
  149.  
  150. ScanStatus:Start()
  151. StartGuildListingScanLoop()
  152. end
  153.  
  154. local function UpdateGuildList()
  155. --Get a list of current guilds
  156. for i = 1, GetNumGuilds() do
  157. local guildId = GetGuildId(i)
  158. local guildName = GetGuildName(guildId)
  159. if (guildName ~= "") then
  160. if (TamrielTradeCentre.Guilds[guildName] == nil) then
  161. TamrielTradeCentre.Guilds[guildName] = {}
  162. TamrielTradeCentre.Guilds[guildName].ID = guildId
  163. TamrielTradeCentre.Guilds[guildName].LastScannedHistoryIndex = 0
  164. TamrielTradeCentre.Guilds[guildName].HasRequestedOldHistory = false
  165. end
  166.  
  167. local savedVarGuildInfo = TamrielTradeCentre.Data.Guilds[guildName]
  168. if (savedVarGuildInfo ~= nil) then
  169. savedVarGuildInfo.KioskLocationID = TamrielTradeCentre:NPCNameToKioskID(GetGuildOwnedKioskInfo(guildId))
  170. end
  171. end
  172. end
  173.  
  174. --Remove guilds from SavedVariable if the player is not in it anymore
  175. for key, value in pairs(TamrielTradeCentre.Data.Guilds) do
  176. if (TamrielTradeCentre.Guilds[key] == nil) then
  177. TamrielTradeCentre.Data.Guilds[key] = nil
  178. end
  179. end
  180. end
  181.  
  182. local function OnTradingHouseOpened()
  183. IsStoreUIOpen = true
  184. if (not KEYBIND_STRIP:HasKeybindButton(TamrielTradeCentre.Buttons.StartScanButton)) then
  185. KEYBIND_STRIP:AddKeybindButton(TamrielTradeCentre.Buttons.StartScanButton)
  186. end
  187.  
  188. TamrielTradeCentre:DebugWriteLine(TamrielTradeCentre:GetCurrentKioskID())
  189.  
  190. if (ScanStatus.IsPaused) then
  191. local _, guildName = GetCurrentTradingHouseGuildDetails()
  192. if (guildName ~= "" and guildName ~= nil and guildName == ScanStatus.GuildName) then
  193. ScanStatus:Resume()
  194. StartGuildListingScanLoop()
  195. return
  196. end
  197. end
  198.  
  199. UpdateGuildList()
  200. end
  201.  
  202. --Full update on guild listing for current selected guild inside guild store interface
  203. local function UpdateGuildListingData()
  204. local guildID, _, _ = GetCurrentTradingHouseGuildDetails()
  205. local guildName = GetGuildName(guildID)
  206. if (currentGuildID == 0 or guildName == "") then
  207. return
  208. end
  209.  
  210. local numListing = GetNumTradingHouseListings()
  211. local newGuildData = {}
  212. newGuildData.KioskLocationID = TamrielTradeCentre:GetCurrentKioskID()
  213. newGuildData.Entries = {}
  214. for i = 1, numListing do
  215. local itemLink = GetTradingHouseListingItemLink(i)
  216. local _, _, _, stackCount, _, _, price, _, uid = GetTradingHouseListingItemInfo(i)
  217. if (itemLink == nil or stackCount == 0) then
  218. break
  219. end
  220.  
  221. local listEntry = TamrielTradeCentre_ItemInfo:New(itemLink)
  222. listEntry.Amount = stackCount
  223. listEntry.TotalPrice = price
  224. listEntry.ItemLink = itemLink
  225. listEntry.UID = Id64ToString(uid)
  226.  
  227. newGuildData.Entries[i - 1] = listEntry
  228. end
  229.  
  230. newGuildData.LastUpdate = GetTimeStamp()
  231. newGuildData.LastFullScan = GetTimeStamp()
  232.  
  233. TamrielTradeCentre.Data.Guilds[guildName] = newGuildData
  234. end
  235.  
  236. local function RemoveAllSimilarRecordedEntries(guildName, sellerName, uid)
  237. local uidString = Id64ToString(uid)
  238.  
  239. local autoRecordEntries = TamrielTradeCentre.Data.AutoRecordEntries
  240. local recordedGuildData = autoRecordEntries.Guilds[guildName]
  241.  
  242. if (recordedGuildData == nil) then
  243. TamrielTradeCentre:DebugWriteLine("Recorded guild data nil")
  244. return
  245. end
  246.  
  247. local playerListings = recordedGuildData.PlayerListings[sellerName]
  248. if (playerListings == nil) then
  249. TamrielTradeCentre:DebugWriteLine("PlayerListings nil")
  250. return
  251. end
  252.  
  253. local indexesToRemove = {}
  254. for index, listEntry in pairs(playerListings) do
  255. if (listEntry.UID == uidString) then
  256. table.insert(indexesToRemove, index)
  257. end
  258. end
  259.  
  260. for _, index in pairs(indexesToRemove) do
  261. playerListings[index] = nil
  262. autoRecordEntries.Count = autoRecordEntries.Count - 1
  263. end
  264. end
  265.  
  266. local function ProcessTradingHouseSearchResults()
  267. local autoRecordEntries = TamrielTradeCentre.Data.AutoRecordEntries
  268. local numItemsOnPage, currentPage, _ = GetTradingHouseSearchResultsInfo()
  269. TamrielTradeCentre:DebugWriteLine("numItemsOnPage = " .. numItemsOnPage)
  270. TamrielTradeCentre:DebugWriteLine("currentPage = " .. currentPage)
  271.  
  272. if (numItemsOnPage == 0) then
  273. if (ScanStatus.IsScanning and currentPage == ScanStatus.CurrentPage + 1) then
  274. if (ScanStatus.IsFinishPending) then
  275. ShowMsgBox(GetString(TTC_MSG_TASKENDED), GetString(TTC_MSG_FULLGUILDLISTINGSSCANFINISHED), SI_DIALOG_CONFIRM)
  276. ScanStatus:Reset()
  277. else
  278. TamrielTradeCentre:DebugWriteLine("Setting IsFinishPending to true")
  279. ScanStatus.IsFinishPending = true
  280. end
  281. end
  282.  
  283. return
  284. end
  285.  
  286. if (ScanStatus.IsScanning and currentPage == ScanStatus.CurrentPage + 1) then
  287. ScanStatus.CurrentPage = currentPage
  288. ScanStatus.IsFinishPending = false
  289. end
  290.  
  291. if (not TamrielTradeCentre.Settings.EnableAutoRecordStoreEntries) then
  292. return
  293. end
  294.  
  295. if (autoRecordEntries.Count > TamrielTradeCentre.Settings.MaxAutoRecordStoreEntryCount) then
  296. d(GetString(TTC_MSG_MAXRECORDCOUNTREACHED))
  297. d(GetString(TTC_MSG_CLEARRECORDEDENTRIESINSTRUCTION))
  298.  
  299. if (ScanStatus.IsScanning) then
  300. ScanStatus:Reset()
  301. ShowMsgBox(GetString(TTC_MSG_TASKENDED), GetString(TTC_ERROR_SCANENDEDDUETORECORDLIMITREACHED), SI_DIALOG_CONFIRM)
  302. end
  303.  
  304. return
  305. end
  306.  
  307. LastSearchTimeStamp = GetTimeStamp()
  308. local _, guildName = GetCurrentTradingHouseGuildDetails()
  309.  
  310. local recordedGuildData = autoRecordEntries.Guilds[guildName]
  311. if (recordedGuildData == nil) then
  312. recordedGuildData = {}
  313. recordedGuildData.PlayerListings = {}
  314. autoRecordEntries.Guilds[guildName] = recordedGuildData
  315. end
  316.  
  317. recordedGuildData.KioskLocationID = TamrielTradeCentre:GetCurrentKioskID()
  318. if (recordedGuildData.KioskLocationID == nil) then
  319. return
  320. end
  321.  
  322. for i = 1, numItemsOnPage do
  323. local link = GetTradingHouseSearchResultItemLink(i)
  324. if (link == nil or link == "") then
  325. break
  326. end
  327.  
  328. local _, _, _, stackCount, sellerName, timeRemaining, totalPrice, _, uid = GetTradingHouseSearchResultItemInfo(i)
  329. local newEntry = TamrielTradeCentre_AutoRecordEntry:New(link, stackCount, totalPrice, LastSearchTimeStamp + timeRemaining, uid)
  330.  
  331. sellerName = sellerName:gsub("|c.*|r", "")
  332.  
  333. local playerListings = recordedGuildData.PlayerListings[sellerName]
  334. if (playerListings == nil) then
  335. playerListings = {}
  336. recordedGuildData.PlayerListings[sellerName] = playerListings
  337. end
  338.  
  339. RemoveAllSimilarRecordedEntries(guildName, sellerName, uid)
  340.  
  341. table.insert(playerListings, newEntry)
  342. autoRecordEntries.Count = autoRecordEntries.Count + 1
  343. end
  344. end
  345.  
  346.  
  347. local function OnTradingHouseResponseReceived(eventCode, responseType, result)
  348. TamrielTradeCentre:DebugWriteLine("Trading house response type " .. responseType)
  349. if (responseType == TRADING_HOUSE_RESULT_LISTINGS_PENDING or responseType == TRADING_HOUSE_RESULT_CANCEL_SALE_PENDING or responseType == TRADING_HOUSE_RESULT_POST_PENDING) then
  350. UpdateGuildListingData()
  351. elseif (responseType == TRADING_HOUSE_RESULT_SEARCH_PENDING) then
  352. ProcessTradingHouseSearchResults()
  353. end
  354. end
  355.  
  356. --[[
  357. Updates based on guild history
  358. --]]
  359.  
  360. local function RequestAllGuildStoreNewHistory()
  361. for i = 1, GetNumGuilds() do
  362. local guildId = GetGuildId(i)
  363. if (guildId ~= 0) then
  364. zo_callLater(function() RequestGuildHistoryCategoryNewest(guildId, GUILD_HISTORY_STORE) end, i * 2000)
  365. end
  366. end
  367.  
  368. zo_callLater(RequestAllGuildStoreNewHistory, 10 * 60 * 1000)
  369. end
  370.  
  371. local function ScanStoreHistory(eventCode, guildId, category)
  372. if (category ~= GUILD_HISTORY_STORE) then
  373. return
  374. end
  375.  
  376. local guildName = GetGuildName(guildId)
  377. local tempGuildInfo = TamrielTradeCentre.Guilds[guildName]
  378. local savedVarGuildInfo = TamrielTradeCentre.Data.Guilds[guildName]
  379. local numGuildEvents = GetNumGuildEvents(guildId, GUILD_HISTORY_STORE)
  380. if (savedVarGuildInfo == nil or savedVarGuildInfo.LastUpdate == nil) then
  381. TamrielTradeCentre:DebugWriteLine(string.format("Guild %s is not yet on saved variable record, skipping", guildName))
  382. return
  383. end
  384.  
  385. for i = tempGuildInfo.LastScannedHistoryIndex + 1, numGuildEvents do
  386. local eventType, secSinceEvent, seller, _, amount, itemLink, price = GetGuildEventInfo(guildId, GUILD_HISTORY_STORE, i)
  387. if (eventType == GUILD_EVENT_ITEM_SOLD and seller == TamrielTradeCentre.PlayerID) then
  388. if (GetTimeStamp() - secSinceEvent - 1 > savedVarGuildInfo.LastUpdate) then
  389. --unrecorded sold, update list
  390. if (TamrielTradeCentre.Settings.EnableItemSoldNotification) then
  391. d(TamrielTradeCentre:StringFormatPOSIX(GetString(TTC_MSG_ITEMSOLDDETECTED), amount, itemLink, guildName))
  392. end
  393.  
  394. for key, value in pairs(savedVarGuildInfo.Entries) do
  395. if (value.ItemLink == itemLink and value.Amount == amount and value.TotalPrice == price) then
  396. TamrielTradeCentre:DebugWriteLine("Matching record found, removing from trade list")
  397. savedVarGuildInfo.Entries[key] = nil
  398. break
  399. end
  400. end
  401.  
  402. end
  403. end
  404. end
  405.  
  406. tempGuildInfo.LastScannedHistoryIndex = numGuildEvents
  407. savedVarGuildInfo.LastUpdate = GetTimeStamp()
  408. TamrielTradeCentre:DebugWriteLine(string.format("Scanning guild %s store history completed", guildName))
  409. end
  410.  
  411. local function OnOldStoreHistoryRequested(eventCode, guildId, category)
  412. if (category ~= GUILD_HISTORY_STORE) then
  413. return
  414. end
  415.  
  416. local guildName = GetGuildName(guildId)
  417. local lastEventIndex = GetNumGuildEvents(guildId, GUILD_HISTORY_STORE)
  418. local _, secSinceLastEvent = GetGuildEventInfo(guildId, GUILD_HISTORY_STORE, lastEventIndex)
  419. local savedVarGuildInfo = TamrielTradeCentre.Data.Guilds[guildName]
  420.  
  421. --No need to request for old history if there is no data for that guild yet
  422. if (savedVarGuildInfo ~= nil and savedVarGuildInfo.LastUpdate ~= nil) then
  423. TamrielTradeCentre:DebugWriteLine(string.format("Guild - %s: %d sec since event requested, goal is %d", guildName, secSinceLastEvent, GetTimeStamp() - savedVarGuildInfo.LastUpdate - 1))
  424. if (GetTimeStamp() - secSinceLastEvent - 1 > savedVarGuildInfo.LastUpdate) then
  425. if (DoesGuildHistoryCategoryHaveMoreEvents(guildId, GUILD_HISTORY_STORE)) then
  426. return
  427. end
  428. end
  429. end
  430.  
  431. --If we get here then it means we have finished requesting old histories
  432. TamrielTradeCentre:DebugWriteLine(string.format("Request history for %s completed", guildName))
  433. TamrielTradeCentre.Guilds[guildName].HasRequestedOldHistory = true
  434. end
  435.  
  436. local function RequestAllOldStoreHistory()
  437. for i = 1, GetNumGuilds() do
  438. local guildId = GetGuildId(i)
  439. if (guildId ~= 0) then
  440. local guildName = GetGuildName(guildId)
  441.  
  442. local guildRecord = TamrielTradeCentre.Guilds[guildName]
  443. if (guildRecord ~= nil and not guildRecord.HasRequestedOldHistory) then
  444. if (RequestMoreGuildHistoryCategoryEvents(guildId, GUILD_HISTORY_STORE)) then
  445. TamrielTradeCentre:DebugWriteLine("History requested on guild " .. guildName)
  446. zo_callLater(RequestAllOldStoreHistory, 5 * SearchAdditionalDelay)
  447. return
  448. else
  449. guildRecord.HasRequestedOldHistory = true
  450. TamrielTradeCentre:DebugWriteLine("History requested to end on guild " .. guildName)
  451. end
  452. end
  453. end
  454. end
  455.  
  456. --All old histories had been requested, register event handler for new requests
  457. TamrielTradeCentre:DebugWriteLine("Performing full event scan")
  458. for i = 1, GetNumGuilds() do
  459. local guildId = GetGuildId(i)
  460. if (guildId ~= 0) then
  461. ScanStoreHistory(nil, guildId, GUILD_HISTORY_STORE)
  462. end
  463. end
  464.  
  465. EVENT_MANAGER:UnregisterForEvent(TamrielTradeCentre.AddonName, EVENT_GUILD_HISTORY_RESPONSE_RECEIVED)
  466. EVENT_MANAGER:RegisterForEvent(TamrielTradeCentre.AddonName, EVENT_GUILD_HISTORY_CATEGORY_UPDATED, ScanStoreHistory)
  467. zo_callLater(RequestAllGuildStoreNewHistory, 10 * 60 * 1000)
  468. end
  469.  
  470. function OnTradingHouseConfirmItemPurchase(eventCode, pendingPurchaseIndex) --fires before the confirm prompt shows up
  471. if (LastSearchTimeStamp == nil or pendingPurchaseIndex == nil) then
  472. return
  473. end
  474.  
  475. local _, guildName = GetCurrentTradingHouseGuildDetails()
  476.  
  477. local _, _, _, _, sellerName, _, _, _, uid = GetTradingHouseSearchResultItemInfo(pendingPurchaseIndex)
  478. sellerName = sellerName:gsub("|c.*|r", "")
  479.  
  480. if (uid == nil or uid == "") then
  481. TamrielTradeCentre:DebugWriteLine("OnTradingHouseConfirmItemPurchase: UID is null")
  482. return
  483. end
  484.  
  485. RemoveAllSimilarRecordedEntries(guildName, sellerName, uid)
  486. end
  487.  
  488. function TamrielTradeCentre:CleanUpAutoRecordEntries()
  489. local now = GetTimeStamp()
  490.  
  491. local autoRecordEntries = self.Data.AutoRecordEntries
  492.  
  493. --Resets count just in case we had some sync problem
  494. autoRecordEntries.Count = 0
  495. for guildName, guildData in pairs(autoRecordEntries.Guilds) do
  496. local hasGuildData = false
  497. for playerID, listEntries in pairs(guildData.PlayerListings) do
  498. local hasPlayerData = false
  499. for id, listEntry in pairs(listEntries) do
  500. if (now - listEntry.DiscoverTime > 3600 * 6) then
  501. listEntries[id] = nil
  502. else
  503. autoRecordEntries.Count = autoRecordEntries.Count + 1
  504. hasGuildData = true
  505. hasPlayerData = true
  506. end
  507. end
  508.  
  509. if (not hasPlayerData) then
  510. guildData.PlayerListings[playerID] = nil
  511. end
  512. end
  513.  
  514. if (not hasGuildData) then
  515. autoRecordEntries.Guilds[guildName] = nil
  516. end
  517. end
  518. end
  519.  
  520. function TamrielTradeCentre:GenerateDefaultSavedVar()
  521. local default = {}
  522. local naData = {}
  523. local euData = {}
  524.  
  525. naData["Guilds"] = {}
  526. naData["AutoRecordEntries"] = {}
  527. naData["AutoRecordEntries"].Count = 0
  528. naData["AutoRecordEntries"].Guilds = {}
  529. naData["IsFirstExecute"] = true
  530. default["NAData"] = naData
  531.  
  532. euData["Guilds"] = {}
  533. euData["AutoRecordEntries"] = {}
  534. euData["AutoRecordEntries"].Count = 0
  535. euData["AutoRecordEntries"].Guilds = {}
  536. euData["IsFirstExecute"] = true
  537. default["EUData"] = euData
  538.  
  539. default["ActualVersion"] = 10
  540. default["Settings"] = {}
  541. default["Settings"].EnableItemSoldNotification = true
  542. default["Settings"].EnableItemToolTipPricing = true
  543. default["Settings"].EnableItemPriceToChatBtn = true
  544. default["Settings"].EnableAutoRecordStoreEntries = true
  545. default["Settings"].EnableSelfEntriesUpload = true
  546.  
  547. default["Settings"].EnablePriceToChatSuggested = true
  548. default["Settings"].EnablePriceToChatAggregate = false
  549. default["Settings"].EnablePriceToChatStat = true
  550. default["Settings"].EnablePriceToChatLastUpdate = false
  551.  
  552. default["Settings"].EnableToolTipSuggested = true
  553. default["Settings"].EnableToolTipAggregate = true
  554. default["Settings"].EnableToolTipStat = true
  555. default["Settings"].EnableToolTipLastUpdate = true
  556.  
  557. default["Settings"].MaxAutoRecordStoreEntryCount = 20000
  558.  
  559. default["Settings"].AdditionalPriceToChatLang = {}
  560.  
  561. return default
  562. end
  563.  
  564. function TamrielTradeCentre:GetCurrentServerRegion()
  565. local serverRegion = nil
  566. local lastPlatform = GetCVar("LastPlatform")
  567. local lastRealm = GetCVar("LastRealm")
  568. if (lastPlatform == "Live") then
  569. serverRegion = "NA"
  570. elseif (lastPlatform == "Live-EU") then
  571. serverRegion = "EU"
  572. elseif (lastRealm:find("^NA") ~= nil) then
  573. serverRegion = "NA"
  574. elseif (lastRealm:find("^EU") ~= nil) then
  575. serverRegion = "EU"
  576. end
  577.  
  578. return serverRegion
  579. end
  580.  
  581. function TamrielTradeCentre:Init()
  582. self:DebugWriteLine("TTC Init")
  583.  
  584. local clientCulture = string.lower(GetCVar("language.2"))
  585. if (clientCulture~= "en" and clientCulture ~= "de" and clientCulture ~= "fr" and clientCulture ~= "zh" and clientCulture ~= "ru") then
  586. ShowMsgBox("Error", "Tamriel Trade Centre only supports English client at this time. We are planning on adding support for other languages soon", SI_DIALOG_ACCEPT)
  587. return
  588. end
  589.  
  590. if (self.LoadItemLookUpTable == nil) then
  591. ShowMsgBox(GetString(TTC_ERROR), GetString(TTC_ERROR_ItemLookUpTableMissing), SI_DIALOG_CONFIRM)
  592. return
  593. end
  594.  
  595. self:LoadItemLookUpTable()
  596.  
  597. local default = self:GenerateDefaultSavedVar()
  598. local savedVars = ZO_SavedVars:NewAccountWide("TamrielTradeCentreVars", 3, nil, default)
  599. savedVars.ClientCulture = clientCulture
  600.  
  601. self:UpgradeSavedVar(savedVars)
  602.  
  603. local serverRegion = self:GetCurrentServerRegion()
  604. if (serverRegion == nil) then
  605. ShowMsgBox(GetString(TTC_ERROR), GetString(TTC_ERROR_UNABLETODETECTSERVERREGION), SI_DIALOG_CONFIRM)
  606. return
  607. elseif (serverRegion == "NA") then
  608. self.Data = savedVars.NAData
  609. else
  610. self.Data = savedVars.EUData
  611. end
  612. self.Settings = savedVars.Settings
  613.  
  614. self.PlayerID = GetUnitDisplayName('player')
  615. self.Guilds = {}
  616.  
  617. local FlagIsFirstExecute = function()
  618. self.Data.IsFirstExecute = false
  619. end
  620.  
  621. if (self.Data.IsFirstExecute == nil or self.Data.IsFirstExecute) then
  622. ShowMsgBox(GetString(TTC_MSG_THANKSFORUSINGTTC),
  623. GetString(TTC_MSG_FIRSTLOADINFO),
  624. SI_DIALOG_ACCEPT,
  625. FlagIsFirstExecute)
  626. end
  627.  
  628. self:CleanUpAutoRecordEntries()
  629. UpdateGuildList()
  630. self:InitSettingMenu()
  631.  
  632. ZO_CreateStringId("SI_BINDING_NAME_TTC_SCAN_START", GetString(TTC_SCANALLLISTINGS))
  633.  
  634. self.Buttons = {}
  635. self.Buttons.StartScanButton = {
  636. name = GetString(TTC_SCANALLLISTINGS),
  637. keybind = "TTC_SCAN_START",
  638. callback = function()
  639. TamrielTradeCentre:StartNewGuildListingScan()
  640. end,
  641. enabled = function()
  642. return not ScanStatus.IsScanning
  643. end,
  644. alignment = KEYBIND_STRIP_ALIGN_LEFT,
  645. }
  646.  
  647. EVENT_MANAGER:RegisterForEvent(self.AddonName, EVENT_CLOSE_TRADING_HOUSE, OnTradingHouseClosed)
  648. EVENT_MANAGER:RegisterForEvent(self.AddonName, EVENT_TRADING_HOUSE_RESPONSE_RECEIVED, OnTradingHouseResponseReceived)
  649. EVENT_MANAGER:RegisterForEvent(self.AddonName, EVENT_OPEN_TRADING_HOUSE, OnTradingHouseOpened)
  650. EVENT_MANAGER:RegisterForEvent(self.AddonName, EVENT_GUILD_HISTORY_RESPONSE_RECEIVED, OnOldStoreHistoryRequested)
  651. EVENT_MANAGER:RegisterForEvent(self.AddonName, EVENT_TRADING_HOUSE_CONFIRM_ITEM_PURCHASE, OnTradingHouseConfirmItemPurchase)
  652.  
  653. RequestAllOldStoreHistory()
  654.  
  655. TamrielTradeCentrePrice:Init()
  656. end
  657.  
  658. local function OnAddOnLoaded(eventCode, addOnName)
  659. if(addOnName ~= TamrielTradeCentre.AddonName) then
  660. return
  661. end
  662.  
  663. EVENT_MANAGER:UnregisterForEvent(TamrielTradeCentre.AddonName, EVENT_ADD_ON_LOADED)
  664.  
  665. TamrielTradeCentre:Init()
  666. end
  667.  
  668. EVENT_MANAGER:RegisterForEvent(TamrielTradeCentre.AddonName, EVENT_ADD_ON_LOADED, OnAddOnLoaded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement