-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFenceWarner.lua
64 lines (51 loc) · 2.02 KB
/
FenceWarner.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
-- Slightly Improved™ Gameplay
-- The MIT License © 2016 Arthur Corenzan
local FenceWarner = ZO_Object:Subclass()
local AUTO_WARN_WAIT_TIME = 60 * 15
local TRIGGERED_WARN_WAIT_TIME = 60 * 15
local settings = {}
function FenceWarner:New()
local warner = ZO_Object.New(self)
warner:Initialize()
return warner
end
function FenceWarner:Initialize()
self.lastWarning = nil
local function OnInventoryFullUpdate()
if self:ShouldWarn(TRIGGERED_WARN_WAIT_TIME) then
self:Warn()
end
end
EVENT_MANAGER:RegisterForEvent("FenceWarner", 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("FenceWarner", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnInventorySingleSlotUpdate)
local function OnUpdate()
if self:ShouldWarn(AUTO_WARN_WAIT_TIME) then
self:Warn()
end
end
EVENT_MANAGER:RegisterForUpdate("FenceWarner", 60 * 1000, OnUpdate)
end
function FenceWarner:IsEnabled()
return settings.isFenceWarnerEnabled
end
function FenceWarner:ShouldWarn(waitTime)
local shouldWarn = AreAnyItemsStolen(BAG_BACKPACK)
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 FenceWarner:Warn(waitTime)
ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.FENCE_ITEM_LAUNDERED, SI_HAS_STOLEN_ITEM)
self.lastWarning = GetFrameTimeSeconds()
end
CALLBACK_MANAGER:RegisterCallback("SlightlyImprovedGameplay_OnAddOnLoaded", function(savedVars)
settings = savedVars
FENCE_WARNER = FenceWarner:New()
end)