-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlor_position.lua
More file actions
120 lines (98 loc) · 4.2 KB
/
Copy pathlor_position.lua
File metadata and controls
120 lines (98 loc) · 4.2 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
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
--[[
Position object
Author: Ragnarok.Lorand
--]]
local lor_position = {}
lor_position._author = 'Ragnarok.Lorand'
lor_position._version = '2018.05.20.0'
require('lor/lor_utils')
_libs.lor.req('ffxi')
_libs.lor.position = lor_position
local quadrants = {NW = {-1, 1}, SW = {1, -1}, NE = {0, -1}, SE = {0, 1} }
local ffxi = _libs.lor.ffxi
function lor_position.new(...)
local self = {pos={}}
local tempPos = {}
local args = {...}
if type(args[1]) == 'table' then
tempPos = args[1]
else
tempPos = args
end
self.pos.x = tempPos.x or tempPos[1] or 0
self.pos.y = tempPos.y or tempPos[2] or 0
self.pos.z = tempPos.z or tempPos[3] or 0
return setmetatable(self, {__index = lor_position, __eq = lor_position.equals, __tostring = lor_position.toString})
end
function lor_position.of(targ)
local mob = ffxi.get_target(targ or 'me')
if (mob ~= nil) then
return lor_position.new(mob.x, mob.y, mob.z)
end
return nil
end
function lor_position.current_position()
local mob = windower.ffxi.get_mob_by_target('me')
if mob ~= nil then
return lor_position.new(mob.x, mob.y, mob.z)
end
return nil
end
function lor_position:x()
return self.pos.x
end
function lor_position:y()
return self.pos.y
end
function lor_position:z()
return self.pos.z
end
function lor_position:equals(other)
if other == nil then return nil end
return (self.pos.x == other:x()) and (self.pos.y == other:y()) and (self.pos.z == other:z())
end
function lor_position:getDistance(other)
if other == nil then return nil end
local dx = self.pos.x - other:x()
local dy = self.pos.y - other:y()
return math.sqrt((dx^2)+(dy^2))
end
local function roundPos(pos)
return math.floor(pos*100)/100
end
function lor_position:toString()
return ('(%s,%s,%s)'):format(roundPos(self.pos.x), roundPos(self.pos.y), roundPos(self.pos.z))
end
--[[
Returns the quandrant in which the given point lies
--]]
local function getQuadrant(x, y)
if (not x) or (not y) then return nil end
local quad = (y > 0 and 'S' or 'N')
quad = quad .. (x > 0 and 'W' or 'E')
return quad
end
--[[
Returns the direction in radians to face position other from this position
--]]
function lor_position:getDirRadian(other)
if not other then return nil end
local dx = self.pos.x - other:x()
local dy = self.pos.y - other:y()
local quad = getQuadrant(dx, dy)
local theta = math.atan(math.abs(dy)/math.abs(dx))
local phi = (math.pi * quadrants[quad][1]) + (theta * quadrants[quad][2])
return phi
end
return lor_position
-----------------------------------------------------------------------------------------------------------
--[[
Copyright © 2018, Ragnarok.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 libs/lor 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.
--]]
-----------------------------------------------------------------------------------------------------------