Dragon-Knight/src/explore.php

32 lines
1.5 KiB
PHP
Raw Normal View History

<?php
// explore.php :: Handles all map exploring, chances to fight, etc.
function move()
{
global $userrow, $controlrow;
if ($userrow["currentaction"] == "Fighting") { header("Location: index.php?do=fight"); die(); }
$latitude = $userrow["latitude"];
$longitude = $userrow["longitude"];
if (isset($_POST["north"])) { $latitude++; if ($latitude > $controlrow["gamesize"]) { $latitude = $controlrow["gamesize"]; } }
if (isset($_POST["south"])) { $latitude--; if ($latitude < ($controlrow["gamesize"]*-1)) { $latitude = ($controlrow["gamesize"]*-1); } }
if (isset($_POST["east"])) { $longitude++; if ($longitude > $controlrow["gamesize"]) { $longitude = $controlrow["gamesize"]; } }
if (isset($_POST["west"])) { $longitude--; if ($longitude < ($controlrow["gamesize"]*-1)) { $longitude = ($controlrow["gamesize"]*-1); } }
$townquery = db()->query('SELECT id FROM towns WHERE latitude = ? AND longitude = ? LIMIT 1;', [$latitude, $longitude]);
if ($townquery !== false) {
$townrow = $townquery->fetchArray(SQLITE3_ASSOC);
require_once __DIR__ . '/towns.php';
travelto($townrow["id"], false);
exit;
}
$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']]);
header("Location: index.php");
}