currentaction == 'Fighting') redirect('/fight'); // Validate direction $form = validate($_POST, ['direction' => ['in:north,west,east,south']]); if (!$form['valid']) display(ul_from_validate_errors($form['errors']), 'Move Error'); // Current game state $game_size = $controlrow['gamesize']; $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) { Towns\travelto($town['id'], false); return; } // Determine action (1 in 5 chance of fighting) $action = (rand(1, 5) === 1) ? "currentaction='Fighting', currentfight='1'," : "currentaction='Exploring',"; // Update user's position db()->query( "UPDATE users SET $action latitude = ?, longitude = ?, dropcode = 0 WHERE id = ?;", [$latitude, $longitude, user()->id] ); redirect('/'); }