-
Notifications
You must be signed in to change notification settings - Fork 2
/
ffxikeys.lua
103 lines (90 loc) · 3.32 KB
/
ffxikeys.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
_addon.name = 'FFXIKeys'
_addon.author = 'Areint/Alzade'
_addon.version = '2.3.6'
_addon.commands = {'keys'}
--------------------------------------------------------------------------------
require('logger')
packets = require('util/packets')
settings = require('util/settings')
local CommandFactory = require('command/factory')
local Aliases = require('util/aliases')
local FileLogger = require('util/logger')
local NilCommand = require('command/nil')
--------------------------------------------------------------------------------
local state = {}
state.command = NilCommand:NilCommand()
--------------------------------------------------------------------------------
local function Restart()
state.command(state)
end
--------------------------------------------------------------------------------
local function OnReward(reward)
if reward then
if settings.config.printlinks then
log('https://www.ffxiah.com/item/' .. reward .. '/')
end
if settings.config.openlinks then
windower.open_url('https://www.ffxiah.com/item/' .. reward .. '/')
end
if settings.config.logitems then
FileLogger.AddItem(reward)
end
return true
end
return false
end
--------------------------------------------------------------------------------
local function OnCommandSuccess(reward)
if OnReward(reward) and settings.config.loop
and state.command:IsRepeatable() then
state.command:Reset()
coroutine.schedule(Restart, settings.config.delay)
else
state.command = NilCommand:NilCommand()
FileLogger.Flush()
end
end
--------------------------------------------------------------------------------
local function OnCommandFailure(reward)
OnReward(reward)
state.command = NilCommand:NilCommand()
FileLogger.Flush()
end
--------------------------------------------------------------------------------
local function OnLoad()
settings.load()
Aliases.Update()
end
--------------------------------------------------------------------------------
local function OnIncomingData(id, _, pkt, b, i)
if not packets.is_duplicate(id, pkt) then
return state.command:OnIncomingData(id, pkt)
else
return false
end
end
--------------------------------------------------------------------------------
local function OnOutgoingData(id, _, pkt, b, i)
return state.command:OnOutgoingData(id, pkt)
end
--------------------------------------------------------------------------------
local function OnCommand(cmd, name)
local new_command = CommandFactory.CreateCommand(cmd, name)
if new_command:IsSimple() then
new_command(state)
elseif state.command:IsSimple() then
state.command = new_command
state.command:SetSuccessCallback(OnCommandSuccess)
state.command:SetFailureCallback(OnCommandFailure)
state.command(state)
else
log('Already running a complex command')
end
end
--------------------------------------------------------------------------------
windower.register_event('login', OnLoad)
windower.register_event('load', OnLoad)
windower.register_event('zone change', OnLoad)
windower.register_event('addon command', OnCommand)
windower.register_event('incoming chunk', OnIncomingData)
windower.register_event('outgoing chunk', OnOutgoingData)