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.
|
|
|
|
|
2024-12-17 22:10:49 -06:00
|
|
|
function move() {
|
|
|
|
global $controlrow;
|
|
|
|
|
|
|
|
// Early exit if fighting
|
|
|
|
if (user()->currentaction == 'Fighting') redirect('/fight');
|
|
|
|
|
|
|
|
// Validate direction
|
|
|
|
$form = validate($_POST, ['direction' => ['in:north,west,east,south']]);
|
2024-12-18 17:00:23 -06:00
|
|
|
if (!$form['valid']) return display(ul_from_validate_errors($form['errors']), 'Move Error');
|
2024-12-17 22:10:49 -06:00
|
|
|
|
|
|
|
// Current game state
|
|
|
|
$game_size = $controlrow['gamesize'];
|
2024-12-18 17:00:23 -06:00
|
|
|
$latitude = user()->latitude;
|
|
|
|
$longitude = user()->longitude;
|
2024-12-17 22:10:49 -06:00
|
|
|
$direction = $form['data']['direction'];
|
|
|
|
|
|
|
|
// Calculate new coordinates with boundary checks
|
|
|
|
switch ($direction) {
|
|
|
|
case 'north':
|
|
|
|
$latitude = min($latitude + 1, $game_size);
|
|
|
|
break;
|
|
|
|
case 'south':
|
|
|
|
$latitude = max($latitude - 1, -$game_size);
|
|
|
|
break;
|
|
|
|
case 'east':
|
|
|
|
$longitude = min($longitude + 1, $game_size);
|
|
|
|
break;
|
|
|
|
case 'west':
|
|
|
|
$longitude = max($longitude - 1, -$game_size);
|
|
|
|
break;
|
|
|
|
}
|
2024-12-12 09:33:17 -06:00
|
|
|
|
2024-12-17 22:10:49 -06:00
|
|
|
// Check for town
|
|
|
|
$town = get_town_by_xy($longitude, $latitude);
|
2024-12-12 10:20:49 -06:00
|
|
|
if ($town !== false) {
|
2024-12-18 17:00:23 -06:00
|
|
|
return Towns\travelto($town['id'], false);
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
|
|
|
|
2024-12-17 22:10:49 -06:00
|
|
|
// Determine action (1 in 5 chance of fighting)
|
2024-12-18 17:00:23 -06:00
|
|
|
if (rand(1, 5) === 1) {
|
|
|
|
user()->currentaction = 'Fighting';
|
|
|
|
user()->currentfight = 1;
|
|
|
|
} else {
|
|
|
|
user()->currentaction = 'Exploring';
|
|
|
|
}
|
|
|
|
|
|
|
|
user()->latitude = $latitude;
|
|
|
|
user()->longitude = $longitude;
|
|
|
|
user()->save();
|
2024-12-12 09:33:17 -06:00
|
|
|
|
2024-12-13 11:42:22 -06:00
|
|
|
redirect('/');
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|