-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwow_alpha_proximity.php
executable file
·193 lines (153 loc) · 4.97 KB
/
wow_alpha_proximity.php
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
<?php
/*
Author: X'Genesis Qhulut <XGenesis-Qhulut@protonmail.com>
Date: August 2022
See LICENSE for license details.
*/
// PROXIMITY
function showProximityDetails ($info)
{
global $creatures;
$prox_location = $info ['prox_location'];
$prox_distance = $info ['prox_distance'];
$ok = preg_match ('`^\s*' .
'(?P<x>[+\-]?(\d*\.)?\d+)\s+' .
'(?P<y>[+\-]?(\d*\.)?\d+)\s+' .
'(?P<z>[+\-]?(\d*\.)?\d+)\s+' .
'(?P<map>\d+)\s*$`', $prox_location, $matches);
if (!$ok)
{
boxTitle ("Invalid location. Must be in form 'x y z map' (all numbers)");
return;
}
if (!preg_match ('/^\d+$/', $prox_distance))
{
boxTitle ("Invalid distance. Must be a number.");
return;
}
// extract fields from supplied string
$x = $matches ['x'];
$y = $matches ['y'];
$z = $matches ['z'];
$map = $matches ['map'];
$results = dbQueryParam ("SELECT *,
SQRT(POWER(? - position_x, 2) + POWER(? - position_y, 2) + POWER(? - position_z, 2))
AS distance
FROM ".SPAWNS_CREATURES." LEFT JOIN ".CREATURE_TEMPLATE." ON (spawn_entry1 = entry)
WHERE map = ? AND ignored = 0
HAVING distance <= ?
ORDER BY distance
LIMIT " . QUERY_LIMIT * 2, // more generous query limit for this
array ('dddii', &$x, &$y, &$z, &$map, &$prox_distance));
$count = count ($results);
if ($count >= QUERY_LIMIT * 2)
$notice = ' (Query limited to ' . QUERY_LIMIT * 2 . ' results)';
else
$notice = '';
if ($count > 0)
boxTitle ("NPCs within $prox_distance yards ($count)$notice");
else
{
boxTitle ("No NPCs within $prox_distance yards");
return;
}
echo "
<table class='table-rows'>
<thead>
<tr>
<th>Entry</th>
<th>Name</th>
<th>Distance (yards)</th>
<th>Flags</th>
</tr>
</thead>
<tbody>
";
foreach ($results as $row)
{
$distance = $row ['distance'] ;
for ($i = 1; $i <= 4; $i++)
if ($row ["spawn_entry$i"])
{
echo "<tr>\n";
$id = $row ["spawn_entry$i"];
tdh ("<a href='?action=show_creature&id=$id'>$id</a>");
tdh ("<a href='?action=show_creature&id=$id'>" . fixHTML ($creatures [$id]) . "</a>");
td (round ($distance, 0));
if ($row ['npc_flags'])
td (expandShiftedMask (NPC_FLAG, $row ['npc_flags'], false));
else
td ('');
echo "</tr>\n";
}
} // end of foreach result
echo "</tbody>
</table>";
// if (count ($results) >= QUERY_LIMIT * 2)
// echo "<p>Query limited to " . (QUERY_LIMIT * 2) . " matches. There may be more.";
} // end of showProximityDetails
define ('PROX_LOCATION_SIZE', 50);
define ('PROX_DISTANCE_SIZE', 50);
define ('PROX_DEFAULT_DISTANCE', 100);
function showProximity ()
{
$prox_location = getP ('prox_location', PROX_LOCATION_SIZE);
$prox_distance = getP ('prox_distance', PROX_DISTANCE_SIZE);
// default to 100 yards
if (!$prox_distance)
$prox_distance = PROX_DEFAULT_DISTANCE;
$PHP_SELF = $_SERVER['PHP_SELF'];
setTitle ("Proximity search");
searchContainerStart ('', 'Proximity search');
echo "
<form method='post' action='$PHP_SELF'>
<input Type=hidden Name=action Value=proximity>
<div class='search-bar'>
<div class='search-bar__main'>
<input
class='custom-input'
id='proximity-coord'
type='text'
size='" . PROX_LOCATION_SIZE . "'
value='" . fixHTML ($prox_location) . "'
placeholder='x y z map'
autofocus='autofocus'
title='Enter a number, text, or a regular expression.\nRegexp help at: regex101.com'
name='prox_location'
/>
</div>
<div class='search-bar__filters'>
<label for='proximity-distance'>Within distance (yards)</label>
<input
class='custom-input'
id='proximity-distance'
type='text'
name='prox_distance'
size='" . PROX_DISTANCE_SIZE. "'
value='" . fixHTML ($prox_distance) . "'
placeholder='" . PROX_DEFAULT_DISTANCE . "'
/>
</div>
</div>
<button class='search-button' type='submit' name='SubmitFilter' title='Click to search'>
<i class='fas fa-search'></i>
</button>
</form>
";
searchContainerEnd ();
$info = array ('prox_location' => $prox_location, 'prox_distance' => $prox_distance);
echo "
<!-- PAGE CONTENT -->
<div class='creature-details page-content'>
<!-- TABLE CONTAINER -->
<div class='table-container table-container--full'>
";
if ($prox_location && $prox_distance)
{
showProximityDetails ($info);
}
endDiv ('table-container table-container--full');
endDiv ('creature-details page-content');
echo "</section>\n";
} // end of showProximity
?>