This repository was archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgetAdjacentTargets.lua
More file actions
52 lines (47 loc) · 1.42 KB
/
Copy pathgetAdjacentTargets.lua
File metadata and controls
52 lines (47 loc) · 1.42 KB
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
--[[
For complete API reference see
https://github.com/VladimirMakeev/D2ModdingToolset/blob/master/luaApi.md
If the script is used as SEL_SCRIPT, no unit is selected yet (selected.position == -1).
Unit positions on a battlefield are mirrored.
Frontline positions are even, backline - odd.
1 0 0 1
3 2 vs 2 3
5 4 4 5
--]]
function getTargets(attacker, selected, allies, targets, targetsAreAllies)
-- If targets are enemies and the attacker stands on the backline (position % 2 ~= 0)
if not targetsAreAllies and attacker.backline then
for i = 1, #allies do
-- If any ally stands on the frontline (position % 2 == 0)
if allies[i].frontline then
-- Ally prevents us to reach adjacent targets
return {}
end
end
end
-- Determine closest distance to adjacent target (excluding self)
local closestDistance = 99
for i = 1, #targets do
local target = targets[i]
if target ~= attacker then
local distance = target:distance(attacker)
if closestDistance > distance then
closestDistance = distance
end
end
end
-- Allow closest targets only (including self)
local result = {}
for i = 1, #targets do
local target = targets[i]
if target == attacker or target:distance(attacker) == closestDistance then
if target == selected then
-- Ensure first target in case of custom damage ratio
table.insert(result, 1, target)
else
table.insert(result, target)
end
end
end
return result
end