70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
// explore.php :: Handles all map exploring, chances to fight, etc.
|
|
|
|
namespace Explore;
|
|
|
|
/**
|
|
* Just spit out a blank exploring page. Exploring without a GET string is normally when they first log in, or when
|
|
* they've just finished fighting.
|
|
*/
|
|
function explore()
|
|
{
|
|
page_title('Exploring');
|
|
return <<<HTML
|
|
<div class="title"><img src="/img/title_exploring.gif" alt="Exploring"></div>
|
|
You are exploring the map, and nothing has happened. Continue exploring using the direction buttons or the Travel To menus.
|
|
HTML;
|
|
}
|
|
|
|
function move() {
|
|
// Early exit if fighting
|
|
if (user()->currentaction == 'Fighting') redirect('/fight');
|
|
|
|
// Validate direction
|
|
$form = validate($_POST, ['direction' => ['in:north,west,east,south']]);
|
|
if (!$form['valid']) return ul_from_validate_errors($form['errors']);
|
|
|
|
// Current game state
|
|
$game_size = env('game_size');
|
|
$latitude = user()->latitude;
|
|
$longitude = user()->longitude;
|
|
$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;
|
|
}
|
|
|
|
// Check for town
|
|
$town = get_town_by_xy($longitude, $latitude);
|
|
if ($town !== false) {
|
|
return \Towns\travelto($town['id'], false);
|
|
}
|
|
|
|
// Determine action (1 in 5 chance of fighting)
|
|
if (rand(1, 5) === 1) {
|
|
user()->currentaction = 'Fighting';
|
|
user()->currentfight = 1;
|
|
} else {
|
|
user()->currentaction = 'Exploring';
|
|
}
|
|
|
|
user()->latitude = $latitude;
|
|
user()->longitude = $longitude;
|
|
user()->save();
|
|
|
|
return index();
|
|
}
|