forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcs.cs
More file actions
83 lines (67 loc) · 2.46 KB
/
Copy pathCalcs.cs
File metadata and controls
83 lines (67 loc) · 2.46 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
using System;
using L2dotNET.Models;
namespace L2dotNET.Tools
{
class Calcs
{
public static bool CheckIfInRange(int range, L2Object obj1, int x, int y, int z, bool includeZAxis)
{
if (obj1 == null)
return false;
if (range == -1)
return true; // not limited
double rad = obj1.Radius;
double dx = obj1.X - x;
double dy = obj1.Y - y;
if (includeZAxis)
{
double dz = obj1.Z - z;
double d = (dx * dx) + (dy * dy) + (dz * dz);
return d <= ((range * range) + (2 * range * rad) + (rad * rad));
}
else
{
double d = (dx * dx) + (dy * dy);
return d <= ((range * range) + (2 * range * rad) + (rad * rad));
}
}
public static bool CheckIfInRange(int range, L2Object obj1, L2Object obj2, bool includeZAxis)
{
if ((obj1 == null) || (obj2 == null))
return false;
if (range == -1)
return true; // not limited
double rad = obj1.Radius + obj2.Radius;
double dx = obj1.X - obj2.X;
double dy = obj1.Y - obj2.Y;
if (includeZAxis)
{
double dz = obj1.Z - obj2.Z;
double d = (dx * dx) + (dy * dy) + (dz * dz);
return d <= ((range * range) + (2 * range * rad) + (rad * rad));
}
else
{
double d = (dx * dx) + (dy * dy);
return d <= ((range * range) + (2 * range * rad) + (rad * rad));
}
}
public static double CalculateDistance(int x1, int y1, int z1, int x2, int y2)
{
return CalculateDistance(x1, y1, 0, x2, y2, 0, false);
}
public static double CalculateDistance(int x1, int y1, int z1, int x2, int y2, int z2, bool includeZAxis)
{
double dx = (double)x1 - x2;
double dy = (double)y1 - y2;
if (!includeZAxis)
return Math.Sqrt((dx * dx) + (dy * dy));
double dz = z1 - z2;
return Math.Sqrt((dx * dx) + (dy * dy) + (dz * dz));
}
public static double CalculateDistance(L2Object obj1, L2Object obj2, bool includeZAxis)
{
return CalculateDistance(obj1.X, obj1.Y, obj1.Z, obj2.X, obj2.Y, obj2.Z, includeZAxis);
}
}
}