2024-12-12 09:33:17 -06:00
|
|
|
<?php
|
2017-02-05 10:49:37 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
// explore.php :: Handles all map exploring, chances to fight, etc.
|
|
|
|
|
|
|
|
function move()
|
|
|
|
{
|
2017-02-05 10:49:37 -06:00
|
|
|
global $userrow, $controlrow;
|
2024-12-12 09:33:17 -06:00
|
|
|
|
2024-12-13 11:42:22 -06:00
|
|
|
if ($userrow["currentaction"] == "Fighting") { redirect('/fight'); }
|
2024-12-12 09:33:17 -06:00
|
|
|
|
2017-02-05 10:49:37 -06:00
|
|
|
$latitude = $userrow["latitude"];
|
|
|
|
$longitude = $userrow["longitude"];
|
2024-12-13 12:40:13 -06:00
|
|
|
|
|
|
|
$form = validate($_POST, [
|
|
|
|
'direction' => ['in:north,west,east,south']
|
|
|
|
]);
|
|
|
|
if (!$form['valid']) display(ul_from_validate_errors($form['errors']), 'Move Error');
|
|
|
|
$d = $form['data']['direction'];
|
|
|
|
|
|
|
|
if ($d === 'north') { $latitude++; if ($latitude > $controlrow["gamesize"]) { $latitude = $controlrow["gamesize"]; } }
|
|
|
|
if ($d === 'south') { $latitude--; if ($latitude < ($controlrow["gamesize"]*-1)) { $latitude = ($controlrow["gamesize"]*-1); } }
|
|
|
|
if ($d === 'east') { $longitude++; if ($longitude > $controlrow["gamesize"]) { $longitude = $controlrow["gamesize"]; } }
|
|
|
|
if ($d === 'west') { $longitude--; if ($longitude < ($controlrow["gamesize"]*-1)) { $longitude = ($controlrow["gamesize"]*-1); } }
|
2024-12-12 09:33:17 -06:00
|
|
|
|
2024-12-12 10:20:49 -06:00
|
|
|
$town = get_town_by_xy($longitude, $latitude);
|
|
|
|
if ($town !== false) {
|
2024-12-13 15:24:08 -06:00
|
|
|
Towns\travelto($town['id'], false);
|
2024-12-12 10:20:49 -06:00
|
|
|
return;
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$chancetofight = rand(1, 5);
|
|
|
|
$action = $chancetofight === 1 ? "currentaction='Fighting', currentfight='1'," : "currentaction='Exploring',";
|
|
|
|
|
|
|
|
db()->query("UPDATE users SET $action latitude = ?, longitude = ?, dropcode = 0 WHERE id = ?;", [$latitude, $longitude, $userrow['id']]);
|
2024-12-13 11:42:22 -06:00
|
|
|
redirect('/');
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|