-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelvarSaver.lua
432 lines (358 loc) · 16.1 KB
/
TelvarSaver.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
TVS = {}
TVS.name = "Telvar Saver"
TVS.version = "1.4.8"
TVS.author = "Ehansonn"
TVS.SavedVariablesName = "TVSVars"
TVS.SVVersion = "1.4.8"
TVS.CAMPAIGNIDS = {
["Ravenwatch"] = 103,
["Greyhost"] = 102,
["Blackreach"] = 101,
["NOCP"] = 96,
["CP"] = 95,
["Legion Zero"] = 116, -- nocp ic
["Dragonfire"] = 119, -- cp ic
["Quagmire"] = 111,
["Fields of regret"] = 112,
["Ashpit"] = 106,
["Evergloam"] = 105,
["Last visited"] = 95,
}
TVS.defaults = {
CloseLootWindow = true,
AutoKickOffline = true,
midyear = false,
LastICCamp = 95,
AutoAcceptQueue = false,
SkipBankDialog = false,
BackupCamp = "Ravenwatch",
UseBackup = false,
AutoLootGold = false,
AutoLootTelvar = false,
AutoLootKeyFrags = true,
notifications = true,
dragable = true,
locationx = 275,
locationy = 150,
BankScene = true,
AutoDepoTelvar = false,
AutoWithdrawTelvar = false,
DesiredTelvarAmount = 0,
ICCamp = "CP",
CyroCamp = "Ravenwatch",
AutoQueueOut = true,
TelvarCap = 50000,
GroupQueue = false,
DisableKeybindInPVE = true,
}
-- Telvar Icon
TVS.TELVAR_CHAT_ICON = (zo_iconTextFormat("EsoUI/Art/currency/currency_telvar_32.dds",18,18))
TVS.SV = {}
function TVS.onLoad(eventCode, addonName)
EVENT_MANAGER:UnregisterForEvent(TVS.name, EVENT_ADD_ON_LOADED)
TVS.SV = ZO_SavedVars:NewAccountWide(TVS.SavedVariablesName, TVS.SVVersion, nil, TVS.defaults)
-- Check if a SV migration is needed
TVS.HandleMigration()
-- Creating LAM2 Settings
TVS.CreateSettingsMenu()
-- Creating auto queue listener
EVENT_MANAGER:RegisterForEvent(TVS.name,EVENT_CURRENCY_UPDATE, TVS.AutoQueue)
-- Bank Scene
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_OPEN_BANK,TVS.DepositTelvar)
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_CLOSE_BANK,TVS.HideUi)
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_BANKED_CURRENCY_UPDATE,TVS.UpdateText)
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_TELVAR_STONE_UPDATE,TVS.UpdateText)
-- Creating keybinds
ZO_CreateStringId("SI_BINDING_NAME_QUEUETVSCAMP", "Queue into your selected campaign")
SLASH_COMMANDS["/tvs"] = TVS.queueCamp
SLASH_COMMANDS["/tvsdb"] = TVS.DebugStuff
-- Update Bank Scene UI
TVS.UpdateAnchors()
TVS.UpdateText()
-- Auto loot imperial fragments
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_LOOT_UPDATED,TVS.OnLootUpdated)
-- Bank chatter dialog skip
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_CHATTER_BEGIN,TVS.SkipBank)
TVS.UpdateLastLocation()
--Setting the last IC camp the player visited
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_PLAYER_ACTIVATED,TVS.UpdateLastLocation)
end
-- -------------------------------------------------------------------------------
-- Dialog skipper stuff
-- -------------------------------------------------------------------------------
-- Used from lazy writ crafter
function TVS.SkipBank()
if (IsInImperialCity() == false) or (TVS.SV.SkipBankDialog == false) then return end
if GetInteractionType()~=INTERACTION_BANK and GetInteractionType() == INTERACTION_CONVERSATION then
for i= 1, GetChatterOptionCount() do
local _, optiontype = GetChatterOption(i)
if optiontype == CHATTER_START_BANK then
SelectChatterOption(i)
end
end
end
end
-- -------------------------------------------------------------------------------
-- Autoloot stuff
-- -------------------------------------------------------------------------------
-- Checking if we looted a imperial fragments. Thanks smarter auto loot
function TVS.OnLootUpdated()
local name, interactType, actionName, owned = GetLootTargetInfo()
if (IsInImperialCity() == false) then return end
if (TVS.SV.AutoLootGold == true) then LootMoney() end
if (TVS.SV.AutoLootTelvar == true) then
if (name == "Chest") then LootCurrency(CURT_TELVAR_STONES) end
if (name == "Medium Tel Var Sack") or (name == "Hefty Tel Var Crate") or (name == "Light Tel Var Satchel") then
LootCurrency(CURT_TELVAR_STONES)
zo_callLater(function()
if (GetNumLootItems() ~= 0) then return end
local currentScene = SCENE_MANAGER:GetCurrentScene().name
SCENE_MANAGER:Toggle(currentScene)
if (tostring(currentScene) == "inventory") then
SCENE_MANAGER:Show("inventory")
end
end,100)
end
end
-- Looting Imperial Fragments
if (TVS.SV.AutoLootKeyFrags == true) then
LootCurrency(CURT_IMPERIAL_FRAGMENTS)
end
-- Legacy code for key frags
-- if (TVS.SV.AutoLootKeyFrags == true) then
-- local num = GetNumLootItems()
-- for i = 1, num, 1 do
-- local lootId, name, icon, quantity, quality, value, isQuest, isStolen, lootType = GetLootItemInfo(i)
-- local link = GetLootItemLink(lootId)
-- -- Keyfrag id 64487
-- if (GetItemLinkItemId(link) == 64487) then
-- TVS.LootItem(link,lootId,quantity)
-- end
-- end
-- end
end
-- -- Looting the key frag
-- function TVS.LootItem(link, lootId, quantity)
-- LootItemById(lootId)
-- end
-- -------------------------------------------------------------------------------
-- Bank stuff
-- -------------------------------------------------------------------------------
-- Bank scene to help you manage your telvar. opens menu and auto depos or withdraws if enabled
function TVS.DepositTelvar()
if (IsInImperialCity() == false) then TVS.HideUi() return end
if (TVS.SV.BankScene == true) then TVS.ShowUi() end
local currentTelvarOnChar = GetCarriedCurrencyAmount(CURT_TELVAR_STONES)
local currentTelvarStonesInBank = GetBankedCurrencyAmount(CURT_TELVAR_STONES)
if (currentTelvarOnChar > TVS.SV.DesiredTelvarAmount) and (TVS.SV.AutoDepoTelvar == true)then
local amount = currentTelvarOnChar - TVS.SV.DesiredTelvarAmount
DepositCurrencyIntoBank(CURT_TELVAR_STONES, amount)
TVS.dtvs("auto deposited " .. "|c8080ff" .. tostring(amount).. "|r " .. TVS.TELVAR_CHAT_ICON)
return
end
if (currentTelvarOnChar < TVS.SV.DesiredTelvarAmount) and (TVS.SV.AutoWithdrawTelvar == true) then
local amount = TVS.SV.DesiredTelvarAmount - currentTelvarOnChar
if (currentTelvarStonesInBank < amount) then TVS.dtvs("Auto withdraw failed") return end
WithdrawCurrencyFromBank(CURT_TELVAR_STONES, amount )
TVS.dtvs("auto withdrew " .. "|c8080ff" .. tostring(amount).. "|r " .. TVS.TELVAR_CHAT_ICON)
return
end
end
-- Buttons in bank scene, withdraws or depos when clicked
function TVS.TelvarButton(value)
local currentTelvarOnChar = GetCarriedCurrencyAmount(CURT_TELVAR_STONES)
local currentTelvarStonesInBank = GetBankedCurrencyAmount(CURT_TELVAR_STONES)
if (currentTelvarOnChar > value) then
local amount = currentTelvarOnChar - value
DepositCurrencyIntoBank(CURT_TELVAR_STONES, amount)
TVS.dtvs("deposited " .. "|c8080ff" .. tostring(amount).. "|r " .. TVS.TELVAR_CHAT_ICON)
return
end
if (currentTelvarOnChar < value) then
local amount = value - currentTelvarOnChar
if (currentTelvarStonesInBank < amount) then TVS.dtvs("Not enough telvar to withdraw") return end
WithdrawCurrencyFromBank(CURT_TELVAR_STONES, amount)
TVS.UpdateText()
TVS.dtvs("withdrew " .. "|c8080ff" .. tostring(amount).. "|r " .. TVS.TELVAR_CHAT_ICON )
return
end
end
-- -------------------------------------------------------------------------------
-- Queue stuff
-- -------------------------------------------------------------------------------
-- For when you gain telvar and exceed your cap
function TVS.AutoQueue(eventCode, currencyType, currencyLocation, newAmount, oldAmount, reason, reasonSupplementaryInfo)
if (TVS.SV.AutoQueueOut == false) then return end
if not IsInImperialCity() then return end
if not IsInAvAZone() then return end
if currencyType ~= CURT_TELVAR_STONES then return end
if currencyLocation ~= CURRENCY_LOCATION_CHARACTER then return end
if reason ~= CURRENCY_CHANGE_REASON_PVP_KILL_TRANSFER and reason ~= CURRENCY_CHANGE_REASON_LOOT then return end
local currentTelvarOnChar = GetCarriedCurrencyAmount(CURT_TELVAR_STONES)
if (currentTelvarOnChar >= TVS.SV.TelvarCap) then
if (TVS.InSafeZone() == true) then return end
local queueCyro = TVS.CAMPAIGNIDS[TVS.SV.CyroCamp]
if (GetCampaignQueueState(queueCyro) ~= 3) then return else
TVS.dtvs("MAX TELVAR REACHED, queued for campaign [" .. TVS.SV.CyroCamp .. "]")
TVS.UpdateLastLocation()
local groupQueue = TVS.GetGroupQueue()
if (groupQueue) then if (TVS.AutoKickOfflinePlayers(queueCyro) ~= 0) then return end end
QueueForCampaign(queueCyro,groupQueue)
if (TVS.SV.UseBackup == true) then TVS.QueueControl() end
TVS.AutoQueueControl()
end
end
end
-- For the keybind button press
function TVS.queueCamp()
local queueIC = TVS.CAMPAIGNIDS[TVS.SV.ICCamp]
local queueCyro = TVS.CAMPAIGNIDS[TVS.SV.CyroCamp]
if (TVS.SV.ICCamp == "Last visited") then queueIC = TVS.SV.LastICCamp end
local groupQueue = TVS.GetGroupQueue()
if not IsInAvAZone() then
if TVS.SV.DisableKeybindInPVE == true then return end
end
if (IsInImperialCity() == true) then
if (GetCampaignQueueState(queueCyro) ~= 3) then return else
if (groupQueue) then if (TVS.AutoKickOfflinePlayers(queueCyro) ~= 0) then return end end
TVS.dtvs("Queued for cyro campaign [" .. TVS.SV.CyroCamp .. "]")
TVS.UpdateLastLocation()
QueueForCampaign(queueCyro,groupQueue)
if (TVS.SV.UseBackup == true) then TVS.QueueControl() end
TVS.AutoQueueControl()
end
elseif (IsInCyrodiil() == true) or (IsInAvAZone() == false) then
if (GetCampaignQueueState(queueIC) ~= 3) then return else
if (groupQueue) then if (TVS.AutoKickOfflinePlayers(queueIC) ~= 0) then return end end
TVS.dtvs("Queued for IC campaign [" .. TVS.SV.ICCamp .. "]")
QueueForCampaign(queueIC,groupQueue)
TVS.AutoQueueControl()
end
end
end
-- Checking to see if the preferred camp has a queue
function TVS.QueueControl()
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_POSITION_CHANGED,TVS.CheckQueue)
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_LEFT,TVS.QueueExit)
end
-- We left the queue
function TVS.QueueExit()
EVENT_MANAGER:UnregisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_POSITION_CHANGED)
EVENT_MANAGER:UnregisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_LEFT)
end
-- Queueing for backup incase of queue
function TVS.CheckQueue()
local queueCyro = TVS.CAMPAIGNIDS[TVS.SV.CyroCamp]
if (GetCampaignQueuePosition(queueCyro) > 0) then
local newqueueCyro = TVS.CAMPAIGNIDS[TVS.SV.BackupCamp]
if (newqueueCyro ~= queueCyro) then
local groupQueue = TVS.GetGroupQueue()
LeaveCampaignQueue(queueCyro)
QueueForCampaign(newqueueCyro,groupQueue)
TVS.dtvs("Preferred campaign has a queue, queued for backup [" .. TVS.SV.BackupCamp .. "]")
end
-- We dont care about these any more
EVENT_MANAGER:UnregisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_POSITION_CHANGED)
EVENT_MANAGER:UnregisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_LEFT)
end
end
-- Auto queue stuff
function TVS.AutoQueueControl()
if (TVS.SV.AutoAcceptQueue == false) then
EVENT_MANAGER:UnregisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_STATE_CHANGED)
return
end
EVENT_MANAGER:RegisterForEvent(TVS.name, EVENT_CAMPAIGN_QUEUE_STATE_CHANGED,TVS.AutoAccept)
end
function TVS.AutoAccept(eventCode, id, isGroup, state)
local groupQueue = TVS.GetGroupQueue()
if (state == CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING) then
TVS.dtvs("Entering campaign")
ConfirmCampaignEntry(id, groupQueue, true)
end
end
-- a bunch of squares that accurately contains the IC safe zones
-- x increases to the right on the map
-- y increases going down on the map
TVS.SafeZones = {
[1] = {lowx = 263010, lowy=177811, highx=277158, highy=183151}, --right side of AD base
[2] = {lowx = 259061, lowy=173749, highx=263010, highy=183151}, -- left side of AD base
[3] = {lowx = 162000, lowy=17400, highx=181900, highy=25000}, -- top of EP
[4] = {lowx = 179500 , lowy=25000, highx=181900, highy= 29500}, -- bottom of EP
[5] = {lowx = 1400 , lowy=155800, highx=5420, highy= 171000}, -- middle of DC
[6] = {lowx = 1400 , lowy=168700, highx=11000, highy=172000 }, -- bottom of DC
[7] = {lowx = 1400 , lowy=153580, highx=6700, highy=159320 }, -- top of DC
}
-- Checking if the player is currently within any of the safe zones since midyear boxes give the CURRENCY_CHANGE_REASON_LOOT code
function TVS.InSafeZone()
local zoneId, px, pz, py = GetUnitRawWorldPosition("player")
if (zoneId ~= 643) then return false end
for i,zone in ipairs(TVS.SafeZones) do
if (px >= zone.lowx) and (py >= zone.lowy) and (px <= zone.highx) and (py <= zone.highy) then return true end
end
return false
end
-- Checking if we should group queue or not
function TVS.GetGroupQueue()
local groupQueue = false
if (IsUnitGrouped('player') == true) and (IsUnitGroupLeader("player") == true) then groupQueue = TVS.SV.GroupQueue end
return groupQueue
end
-- If the player is in a group, is group leader, and has an offline member in the group,
-- Kick them and then queue again after x ms
function TVS.AutoKickOfflinePlayers(campaignID)
if (TVS.SV.AutoKickOffline == false) or (TVS.GetGroupQueue() == false) then return 0 end
local size = GetGroupSize()
local count = 0
if size < 1 then return count end
for player = 1, size do
if not (IsUnitOnline(GetGroupUnitTagByIndex(player))) then
GroupKick(GetGroupUnitTagByIndex(player))
count = count + 1
TVS.dtvs("Kicking " .. GetUnitName(GetGroupUnitTagByIndex(player)))
end
end
if (count > 0) then
zo_callLater(function()
local newGroupQueue = TVS.GetGroupQueue()
QueueForCampaign(campaignID,newGroupQueue)
if (TVS.SV.UseBackup == true) then TVS.QueueControl() end
TVS.AutoQueueControl()
TVS.dtvs("Removed offline players and queued for campaign")
end,200)
end
return count
end
-- -------------------------------------------------------------------------------
-- misc stuff
-- -------------------------------------------------------------------------------
function TVS.UpdateLastLocation()
if (IsInImperialCity() == false) then return end
TVS.SV.LastICCamp = GetCurrentCampaignId()
end
function TVS.HandleMigration()
local SVVersion = TVS.SV.version
if (SVVersion == TVS.version) then return end
if (SVVersion == "1.4.7") then
-- TODO here for 1.4.8
end
-- Prior to 1.4.7
if (SVVersion == "1.0" or SVVersion == "1.3" or SVVersion == "1.4.5" or SVVersion == "1.4.6") then
-- Fix for 'Ravenswatch' typo
if (TVS.SV.CyroCamp == "Ravenswatch") then
TVS.SV.CyroCamp = TVS.defaults.CyroCamp
end
end
end
function TVS.dtvs(value)
if (TVS.SV.notifications == false) then return end
if (value == nil) then return end
d("|c8080ffTel Var Saver:|r " .. value)
end
function TVS.DebugStuff()
d("cyrocamp: ".. TVS.SV.CyroCamp)
local currentScene = SCENE_MANAGER:GetCurrentScene().name
SCENE_MANAGER:Toggle(currentScene)
end
-- Entry Point
EVENT_MANAGER:RegisterForEvent(TVS.name,EVENT_ADD_ON_LOADED,TVS.onLoad)