forked from beerman212/BuffTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelperFunctions.lua
261 lines (205 loc) · 9.01 KB
/
HelperFunctions.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
equip_slots = {'main','sub','range','ammo','head','neck','left_ear','right_ear','body','hands','left_ring','right_ring','back','waist','legs','feet'}
function calculate_enhancing_duration(player, spell, target, equipment, buffs)
--local spell_info, equipment, player, buffs = get_basic_info(spell, equipment)
if not (player or spell or target or equipment or buffs) then return end
local composure_modifier = get_base_enhancing_composure_modifier(player, spell, target, buffs)
local composure_count = 0
local base_duration = spell.duration or 0
local duration_modifier = 1
local duration_bonus = get_enhancing_duration_bonus(spell, player, buffs)
local augment_duration_modifier = 1
local perpetuance_modifier = buffs.Perpetuance and 2 or 1
local embolden_modifier = buffs.Embolden and (target.id == player.id and -0.5) or 1
for _, slot in ipairs(equip_slots) do
local item = windower.ffxi.get_items(equipment[slot .. '_bag'], equipment[slot])
local modifiers = enhancing_modifiers[item.id]
if modifiers then
for index, value in pairs(modifiers) do
if index == 1 then
duration_modifier = duration_modifier + value
elseif index == 'augment' then
augment_duration_modifier = augment_duration_modifier + value
elseif index == 'perpetuance' and buffs.Perpetuance then
perpetuance_modifier = perpetuance_modifier + value
elseif index == 'embolden' and buffs.Embolden then
embolden_modifier = embolden_modifier + value
elseif spell.english:startswith(index) then
duration_bonus = duration_bonus + value
end
end
end
if enhancing_relic_bonus[item.id] then
duration_bonus = duration_bonus + (player.merits.enhancing_magic_duration and (player.merits.enhancing_magic_duration * 3) or 0)
end
if composure_gear[item.id] then
composure_count = composure_count + 1
end
end
if buffs.Composure and target.id ~= player.id then
composure_modifier = composure_modifier + composure_modifiers[composure_count] or 0
end
local enhancing_duration = base_duration + duration_bonus
for _, modifier in ipairs({duration_modifier, augment_duration_modifier, composure_modifier, perpetuance_modifier, embolden_modifier}) do
enhancing_duration = enhancing_duration * modifier
end
if (not (spell.english:startswith("Protect") or spell.english:startswith("Shell") or spell.english == "Aquaveil")) and enhancing_duration > 60 * 30 then
enhancing_duration = 60 * 30
end
local modifiers = {
["Flat Bonus"] = duration_bonus,
["Duration"] = duration_modifier,
["Augment"] = augment_duration_modifier,
["Composure"] = composure_modifier,
["Perpetuance"] = perpetuance_modifier,
["Embolden"] = embolden_modifier
}
return enhancing_duration, modifiers
end
function calculate_enfeebling_duration(player, spell, target, equipment, buffs)
if not (player or spell or target or equipment or buffs) then return end
local current_time = os.time()
local composure_modifier = 1
local composure_count = 0
local saboteur_modifier = get_base_saboteur_modifier(spell, target, buffs, mob_data.NMs or L{})
local duration_modifier = 1
local augment_duration_modifier = 1
local base_duration = (spell.duration or 0)
local duration_bonus = (player.main_job == "RDM" and player.merits.enfeebling_magic_duration and (player.merits.enfeebling_magic_duration * 6) or 0)
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].enfeebling_magic_duration or 0)
if buffs.Stymie then
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].stymie_effect or 0)
end
for _, slot in ipairs(equip_slots) do
local item = windower.ffxi.get_items(equipment[slot .. '_bag'], equipment[slot])
local modifiers = enfeebling_modifiers[item.id]
if modifiers then
for index, value in pairs(modifiers) do
if index == 1 then
duration_modifier = duration_modifier + value
elseif index == 'augment' then
augment_duration_modifier = augment_duration_modifier + value
elseif index == 'saboteur' and buffs.saboteur then
saboteur_modifier = saboteur_modifier + value
end
end
end
if enfeebling_relic_bonus[item.id] then
duration_bonus = duration_bonus + (player.merits.enfeebling_magic_duration and (player.merits.enfeebling_magic_duration * 6) or 0)
end
if composure_gear:contains(item.id) then
composure_count = composure_count + 1
end
end
composure_modifier = composure_modifier + (composure_modifiers[composure_count] or 0)
local duration = (base_duration * saboteur_modifier) + duration_bonus
for _, modifier in ipairs({duration_modifier, augment_duration_modifier, composure_modifier}) do
duration = duration * modifier
end
duration = math.floor(duration)
local duration_map = table.map(enfeebling_resist_states,
function(resist_multiplier)
return math.floor(duration * resist_multiplier)
end
)
local modifiers = {
["Saboteur"] = saboteur_modifier,
["Flat Bonus"] = duration_bonus,
["Duration"] = duration_modifier,
["Augment"] = augment_duration_modifier,
["Composure"] = composure_modifier
}
return duration_map, modifiers
end
function get_basic_info(spell, equipment)
local spell_info = windower.res.spells[spell.recast_id]
local equipment = equipment or windower.ffxi.get_items('equipment')
local player = windower.ffxi.get_player()
local buffs = get_player_buffs(player)
return spell_info, equipment, player, buffs
end
function get_base_saboteur_modifier(spell, target, buffs, nm_table)
local saboteur_modifier = 1
if buffs.Saboteur then
if nm_table:contains(target:get_name()) then
saboteur_modifier = 1.25
else
saboteur_modifier = 2
end
end
return saboteur_modifier
end
function get_base_enhancing_composure_modifier(player, spell, target, buffs)
local composure_modifier = 1
if buffs.Composure and target.id == player.id and not (spell.english:startswith("Protect") or spell.english:startswith("Shell") or spell.english == "Aquaveil") then
composure_modifier = 3
end
return composure_modifier
end
function get_enhancing_duration_bonus(spell, player, buffs)
local duration_bonus = 0
if player.main_job == "RDM" then
if player.merits.enhancing_magic_duration then
duration_bonus = duration_bonus + (player.merits.enhancing_magic_duration * 6)
end
duration_bonus = duration_bonus + (player.job_points[player.main_job:lower()].enhancing_magic_duration or 0)
elseif player.main_job == "SCH" then
if spell.english:startswith("Regen") and (buffs["Light Arts"] or buffs["Addendum: White"]) then
local regen_bonus = math.floor((player.main_job_level - 1) / 4) * 2
if buffs["Tabula Rasa"] then
regen_bonus = regen_bonus * 2
end
duration_bonus = duration_bonus + regen_bonus
if player.job_points[player.main_job].light_arts_effect then
duration_bonus = duration_bonus + (player.job_points[player.main_job].light_arts_effect * 3)
end
end
else
end
return duration_bonus
end
function update_gear_map()
-- TODO: Look at inventory and update augmented gear maps
end
function get_player_buffs(player)
player = player or windower.ffxi.get_player()
if not player or not player.buffs then return {} end
local buffs = T{}
for _, buff_id in pairs(player.buffs) do
buffs[buff_id] = (buffs[buff_id] or 0) + 1
local buff_info = res.buffs[buff_id]
if buff_info then
local name = buff_info.english:lower()
buffs[name] = (buffs[name] or 0) + 1
end
end
setmetatable(buffs, {
__index = function(t, key)
if key and type(key) == 'string' then
key = key:lower()
end
return rawget(t, key)
end
})
return buffs
end
function convert_seconds_to_timer(duration)
local hours, minutes, seconds
hours = math.floor(duration / 3600)
minutes = math.floor(duration % 3600 / 60)
seconds = math.floor(duration % 60)
return string.format("%02d:%02d:%02d", hours, minutes, seconds)
end
function get_time_utc(time)
if not time then
return os.date("'!%Y-%m-%dT%H:%M:%SZ'")
else
return os.date("'!%Y-%m-%dT%H:%M:%SZ'", time)
end
end
function get_time_stamp(time)
if not time then
return os.date("%X")
else
return os.date("%X", time)
end
end