forked from PeachBlossomWine/HealBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealBot_queues.lua
227 lines (195 loc) · 9 KB
/
HealBot_queues.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
--==============================================================================
--[[
Author: Ragnarok.Lorand
HealBot action queue building & handling functions
--]]
--==============================================================================
local compFunc = {}
ActionQueue = {}
function ActionQueue.new()
local self = {queue=Q({})}
return setmetatable(self, {__index = ActionQueue})
end
function ActionQueue:getQueue()
return self.queue
end
function ActionQueue:enqueue(actionType, action, name, secondary, msg)
--atcf('ActionQueue:enqueue(%s, %s, %s, %s, %s)', tostring(actionType), tostring(action), tostring(name), tostring(secondary), tostring(msg))
local is_cure = actionType:startswith('cur')
local secLabel = is_cure and 'hpp' or actionType
local pprio = getPlayerPriority[name]
if is_cure and actionType == 'curaga' then
pprio = pprio + 2
end
local qable = {['type']=actionType,['action']=action,['name']=name,[secLabel]=secondary,['msg']=msg,['prio']=pprio}
if self.queue:empty() then
self.queue:insert(1,qable)
else
local highestAbove = 999
for index = 1, self.queue:length() do
local qi = self.queue[index]
local qprio = getPlayerPriority[qi.name]
local higher = compFunc[actionType](-1, pprio, secondary, index, qprio, qi[secLabel])
if (higher == -1) and (index < highestAbove) then
highestAbove = index
end
end
if (highestAbove ~= 999) then
self.queue:insert(highestAbove,qable)
else
local last = self.queue:length()+1
self.queue:insert(last,qable)
end
end
end
function compFunc.default(index1, pa1, pb1, index2, pa2, pb2)
--local function _default(index1, pa1, pb1, index2, pa2, pb2)
--atcf('compFunc.default(%s, %s, %s, %s, %s, %s)', tostring(index1), tostring(pa1), tostring(pb1), tostring(index2), tostring(pa2), tostring(pb2))
if (pa1 < pa2) then --p1 is higher priority
if (pb2 < pb1) then --action 2 is higher priority
return index2
else --action 2 is same or lower priority
return index1
end
elseif (pa1 > pa2) then --p2 is higher priority
if (pb1 < pb2) then --action 1 is higher priority
return index1
else --action 1 is same or lower priority
return index2
end
else --same priority
if (pb2 < pb1) then --action 2 is higher priority
return index2
else --action 2 is same or lower priority
return index1
end
end
end
--compFunc.default = traceable(_default)
function compFunc.spells(index1, prio1, buff1, index2, prio2, buff2)
--atcf('compFunc.buff(%s, %s, %s, %s, %s, %s)', tostring(index1), tostring(prio1), tostring(buff1), tostring(index2), tostring(prio2), tostring(buff2))
local bp1 = getDispelPriority(buff1)
local bp2 = getDispelPriority(buff2)
return compFunc.default(index1, prio1, bp1, index2, prio2, bp2)
end
function compFunc.buff(index1, prio1, buff1, index2, prio2, buff2)
--atcf('compFunc.buff(%s, %s, %s, %s, %s, %s)', tostring(index1), tostring(prio1), tostring(buff1), tostring(index2), tostring(prio2), tostring(buff2))
local bp1 = getBuffPriority(buff1)
local bp2 = getBuffPriority(buff2)
return compFunc.default(index1, prio1, bp1, index2, prio2, bp2)
end
function compFunc.debuff(index1, prio1, debuff1, index2, prio2, debuff2)
--atcf('compFunc.debuff(%s, %s, %s, %s, %s, %s)', tostring(index1), tostring(prio1), tostring(debuff1), tostring(index2), tostring(prio2), tostring(debuff2))
local rp1 = getRemovalPriority(debuff1)
local rp2 = getRemovalPriority(debuff2)
return compFunc.default(index1, prio1, rp1, index2, prio2, rp2)
end
function compFunc.debuff_mob(index1, prio1, debuff1, index2, prio2, debuff2)
--atcf('compFunc.debuff_mob(%s, %s, %s, %s, %s, %s)', tostring(index1), tostring(prio1), tostring(debuff1), tostring(index2), tostring(prio2), tostring(debuff2))
local dbp1 = getDebuffPriority(debuff1)
local dbp2 = getDebuffPriority(debuff2)
return compFunc.default(index1, prio1, dbp1, index2, prio2, dbp2)
end
function compFunc.cure(index1, prio1, hpp1, index2, prio2, hpp2)
local d1 = CureUtils.getDangerLevel(hpp1)
local d2 = CureUtils.getDangerLevel(hpp2)
if (prio1 < prio2) then --p1 is higher priority
if (d2 > d1) then --p2 is in more danger
return index2
else --p2 is in same or less danger
return index1
end
elseif (prio1 > prio2) then --p2 is higher priority
if (d1 > d2) then --p1 is in more danger
return index1
else --p1 is in same or less danger
return index2
end
else --same priority
if (d2 > d1) then --p2 is in more danger
return index2
elseif (d1 > d2) then --p1 is in more danger
return index1
else --same danger
if (hpp1 < hpp2) then
return index1
else
return index2
end
end
end
end
local function _getPlayerPriority(tname)
if (tname == healer.name) then
return 1
end
local prios = hb.config.priorities
local player_mob = windower.ffxi.get_mob_by_name(tname)
if player_mob == nil then
return prios.default
end
if player_mob.spawn_type == 14 then --Trust
return prios.default + 1
end
local pmInfo
for k, v in pairs(windower.ffxi.get_party()) do
if type(v) == 'table' and v.mob ~= nil and v.name:lower() == tname:lower() then
pmInfo = get_registry(v.mob.id):lower()
end
end
local jobprio = prios.default
if pmInfo ~= nil then
jobprio = prios.jobs[pmInfo] or prios.jobs[pmInfo:lower()] or jobprio
end
local playerprio = prios.players[tname] or prios.players[tname:lower()] or prios.default
return math.min(jobprio, playerprio)
end
getPlayerPriority = _libs.lor.advutils.scached(_getPlayerPriority)
function getBuffPriority(buff)
--local function _getBuffPriority(buff)
--atcf('getBuffPriority(%s)', tostring(buff))
local nbuff = buffs.buff_for_action(buff)
local prios = hb.config.priorities
if nbuff == nil then
atcfs('Was unable to retrieve buff for action for %s', buff)
return prios.default
end
return prios.buffs[nbuff.en] or prios.buffs[nbuff.enn] or prios.default
end
--getBuffPriority = traceable(_getBuffPriority)
function getRemovalPriority(ailment)
local debuff = utils.normalize_action(ailment, 'buffs')
local prios = hb.config.priorities
return prios.status_removal_id[debuff.id] or prios.status_removal[debuff.en] or prios.status_removal[debuff.enn] or prios.default
end
function getDebuffPriority(debuff)
local ndebuff = utils.normalize_action(debuff, 'buffs')
local prios = hb.config.priorities
return prios.debuffs[ndebuff.en] or prios.debuffs[ndebuff.enn] or prios.default
end
function getDispelPriority(spells)
local ndebuff = utils.normalize_action(spells, 'spells')
local prios = hb.config.priorities
return prios.debuffs[ndebuff.en] or prios.debuffs[ndebuff.enn] or prios.default
end
--======================================================================================================================
--[[
Copyright © 2016, Lorand
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of ffxiHealer nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Lorand BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--]]
--======================================================================================================================