-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.lua
219 lines (176 loc) · 6.73 KB
/
run.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
--------------------------------------------------------------------------------
-- Setup functions for this job. Generally should not be modified.
--------------------------------------------------------------------------------
-- Initialization function for this job file.
function get_sets()
mote_include_version = 2
-- Load and initialize the include file.
include('Mote-Include.lua')
end
-- Setup vars that are user-independent.
function job_setup()
-- Table of entries
rune_timers = T{}
-- entry = rune, index, expires
if player.main_job_level >= 65 then
max_runes = 3
elseif player.main_job_level >= 35 then
max_runes = 2
elseif player.main_job_level >= 5 then
max_runes = 1
else
max_runes = 0
end
end
------------------------------------------------------------------
-- Action events
------------------------------------------------------------------
-- Run after the default midcast() is done.
-- eventArgs is the same one used in job_midcast, in case information needs to be persisted.
function job_post_midcast(spell, action, spellMap, eventArgs)
if spell.english == 'Lunge' or spell.english == 'Swipe' then
local obi = get_obi(get_rune_obi_element())
if obi then
equip({waist=obi})
end
end
end
function job_aftercast(spell)
if not spell.interrupted then
if spell.type == 'Rune' then
update_timers(spell)
elseif spell.name == "Lunge" or spell.name == "Gambit" or spell.name == 'Rayke' then
reset_timers()
elseif spell.name == "Swipe" then
send_command(trim(1))
end
end
end
-------------------------------------------------------------------------------------------------------------------
-- Customization hooks for idle and melee sets, after they've been automatically constructed.
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
-- General hooks for other events.
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
-- User code that supplements self-commands.
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
-- Utility functions specific to this job.
-------------------------------------------------------------------------------------------------------------------
function get_rune_obi_element()
weather_rune = buffactive[elements.rune_of[world.weather_element] or '']
day_rune = buffactive[elements.rune_of[world.day_element] or '']
local found_rune_element
if weather_rune and day_rune then
if weather_rune > day_rune then
found_rune_element = world.weather_element
else
found_rune_element = world.day_element
end
elseif weather_rune then
found_rune_element = world.weather_element
elseif day_rune then
found_rune_element = world.day_element
end
return found_rune_element
end
function get_obi(element)
if element and elements.obi_of[element] then
return (player.inventory[elements.obi_of[element]] or player.wardrobe[elements.obi_of[element]]) and elements.obi_of[element]
end
end
------------------------------------------------------------------
-- Timer manipulation
------------------------------------------------------------------
-- Add a new run to the custom timers, and update index values for existing timers.
function update_timers(spell)
local expires_time = os.time() + 300
local entry_index = rune_count(spell.name) + 1
local entry = {rune=spell.name, index=entry_index, expires=expires_time}
rune_timers:append(entry)
local cmd_queue = create_timer(entry).. ';wait 0.05;'
cmd_queue = cmd_queue .. trim()
-- Pretty sure this is a debugging line.
--add_to_chat(123,'cmd_queue='..cmd_queue)
send_command(cmd_queue)
end
-- Get the command string to create a custom timer for the provided entry.
function create_timer(entry)
local timer_name = '"Rune: ' .. entry.rune .. '-' .. tostring(entry.index) .. '"'
local duration = entry.expires - os.time()
return 'timers c ' .. timer_name .. ' ' .. tostring(duration) .. ' down'
end
-- Get the command string to delete a custom timer for the provided entry.
function delete_timer(entry)
local timer_name = '"Rune: ' .. entry.rune .. '-' .. tostring(entry.index) .. '"'
return 'timers d ' .. timer_name .. ''
end
-- Reset all timers
function reset_timers()
local cmd_queue = ''
for index,entry in pairs(rune_timers) do
cmd_queue = cmd_queue .. delete_timer(entry) .. ';wait 0.05;'
end
rune_timers:clear()
send_command(cmd_queue)
end
-- Get a count of the number of runes of a given type
function rune_count(rune)
local count = 0
local current_time = os.time()
for _,entry in pairs(rune_timers) do
if entry.rune == rune and entry.expires > current_time then
count = count + 1
end
end
return count
end
-- Remove the oldest rune(s) from the table, until we're below the max_runes limit.
-- If given a value n, remove n runes from the table.
function trim(n)
local cmd_queue = ''
local to_remove = n or (rune_timers:length() - max_runes)
while to_remove > 0 and rune_timers:length() > 0 do
local oldest
for index,entry in pairs(rune_timers) do
if oldest == nil or entry.expires < rune_timers[oldest].expires then
oldest = index
end
end
cmd_queue = cmd_queue .. prune(rune_timers[oldest].rune)
to_remove = to_remove - 1
end
return cmd_queue
end
-- Drop the index of all runes of a given type.
-- If the index drops to 0, it is removed from the table.
function prune(rune)
local cmd_queue = ''
for index,entry in pairs(rune_timers) do
if entry.rune == rune then
cmd_queue = cmd_queue .. delete_timer(entry) .. ';wait 0.05;'
entry.index = entry.index - 1
end
end
for index,entry in pairs(rune_timers) do
if entry.rune == rune then
if entry.index == 0 then
rune_timers[index] = nil
else
cmd_queue = cmd_queue .. create_timer(entry) .. ';wait 0.05;'
end
end
end
return cmd_queue
end
------------------------------------------------------------------
-- Reset events
------------------------------------------------------------------
windower.raw_register_event('zone change',reset_timers)
windower.raw_register_event('logout',reset_timers)
windower.raw_register_event('status change',function(new, old)
if gearswap.res.statuses[new].english == 'Dead' then
reset_timers()
end
end)