-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrashWarner.lua
76 lines (61 loc) · 2.3 KB
/
TrashWarner.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
-- Slightly Improved™ Gameplay
-- The MIT License © 2016 Arthur Corenzan
local TrashWarner = ZO_Object:Subclass()
local AUTO_WARN_WAIT_TIME = 60 * 15
local TRIGGERED_WARN_WAIT_TIME = 60 * 15
local settings = {}
function TrashWarner:New()
local warner = ZO_Object.New(self)
warner:Initialize()
return warner
end
function TrashWarner:Initialize()
self.lastWarning = nil
local function OnInventoryFullUpdate()
if self:ShouldWarn(TRIGGERED_WARN_WAIT_TIME) then
self:Warn()
end
end
EVENT_MANAGER:RegisterForEvent("TrashWarner", EVENT_INVENTORY_FULL_UPDATE, OnInventoryFullUpdate)
local function OnInventorySingleSlotUpdate(eventCode, bagId, slotId)
if (bagId == BAG_BACKPACK) and self:ShouldWarn(TRIGGERED_WARN_WAIT_TIME) then
self:Warn()
end
end
EVENT_MANAGER:RegisterForEvent("TrashWarner", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnInventorySingleSlotUpdate)
local function OnUpdate()
if self:ShouldWarn(AUTO_WARN_WAIT_TIME) then
self:Warn()
end
end
EVENT_MANAGER:RegisterForUpdate("TrashWarner", 60 * 1000, OnUpdate)
end
function TrashWarner:IsEnabled()
return settings.isTrashWarnerEnabled
end
function TrashWarner:ShouldWarn(waitTime)
local shouldWarn = false
for i = 1, GetBagSize(BAG_BACKPACK) do
local itemType = GetItemType(BAG_BACKPACK, i)
if (itemType == ITEMTYPE_NONE) then
break
end
if (itemType == ITEMTYPE_TRASH) or (itemType == ITEMTYPE_TROPHY) then
shouldWarn = true
break
end
end
local notInCombat = not IsUnitInCombat("player")
local waitTimeElapsed = (not self.lastWarning or self.lastWarning + waitTime < GetFrameTimeSeconds())
local notInPvp = not IsPlayerInAvAWorld()
local notInDungeon = (GetMapContentType() ~= MAP_CONTENT_DUNGEON)
return self:IsEnabled() and shouldWarn and notInCombat and waitTimeElapsed and notInPvp and notInDungeon
end
function TrashWarner:Warn(waitTime)
ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.JUSTICE_GOLD_REMOVED, SI_HAS_TRASH_ITEM)
self.lastWarning = GetFrameTimeSeconds()
end
CALLBACK_MANAGER:RegisterCallback("SlightlyImprovedGameplay_OnAddOnLoaded", function(savedVars)
settings = savedVars
TRASH_WARNER = TrashWarner:New()
end)