Continue updating rendering and user access
This commit is contained in:
parent
58012f5808
commit
5fa648ab7b
|
@ -8,7 +8,7 @@ html {
|
|||
}
|
||||
|
||||
body {
|
||||
background-image: url('/img/backgrounds/background.jpg');
|
||||
background-image: url('/img/backgrounds/classic.jpg');
|
||||
padding: 2rem;
|
||||
}
|
||||
table {
|
||||
|
|
|
@ -50,13 +50,14 @@ $l = $r->lookup($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
|||
|
||||
if (is_int($l)) exit("Error: $l");
|
||||
$content = $l['handler'](...$l['params'] ?? []);
|
||||
if (is_htmx()) {
|
||||
if (is_htmx() && $uri[0] !== 'babblebox') {
|
||||
$content .= '<title>'.page_title().'</title>';
|
||||
$content .= Render\debug_db_info();
|
||||
if (env('debug', false)) $content .= Render\debug_query_log();
|
||||
|
||||
if ($GLOBALS['state']['user-state-changed'] ?? false) {
|
||||
$content .= Render\right_nav();
|
||||
$content .= Render\left_nav();
|
||||
}
|
||||
}
|
||||
echo $content;
|
||||
|
|
|
@ -10,12 +10,12 @@ function move() {
|
|||
|
||||
// Validate direction
|
||||
$form = validate($_POST, ['direction' => ['in:north,west,east,south']]);
|
||||
if (!$form['valid']) display(ul_from_validate_errors($form['errors']), 'Move Error');
|
||||
if (!$form['valid']) return display(ul_from_validate_errors($form['errors']), 'Move Error');
|
||||
|
||||
// Current game state
|
||||
$game_size = $controlrow['gamesize'];
|
||||
$latitude = user('latitude');
|
||||
$longitude = user('longitude');
|
||||
$latitude = user()->latitude;
|
||||
$longitude = user()->longitude;
|
||||
$direction = $form['data']['direction'];
|
||||
|
||||
// Calculate new coordinates with boundary checks
|
||||
|
@ -37,20 +37,20 @@ function move() {
|
|||
// Check for town
|
||||
$town = get_town_by_xy($longitude, $latitude);
|
||||
if ($town !== false) {
|
||||
Towns\travelto($town['id'], false);
|
||||
return;
|
||||
return Towns\travelto($town['id'], false);
|
||||
}
|
||||
|
||||
// Determine action (1 in 5 chance of fighting)
|
||||
$action = (rand(1, 5) === 1)
|
||||
? "currentaction='Fighting', currentfight='1',"
|
||||
: "currentaction='Exploring',";
|
||||
if (rand(1, 5) === 1) {
|
||||
user()->currentaction = 'Fighting';
|
||||
user()->currentfight = 1;
|
||||
} else {
|
||||
user()->currentaction = 'Exploring';
|
||||
}
|
||||
|
||||
// Update user's position
|
||||
db()->query(
|
||||
"UPDATE users SET $action latitude = ?, longitude = ?, dropcode = 0 WHERE id = ?;",
|
||||
[$latitude, $longitude, user()->id]
|
||||
);
|
||||
user()->latitude = $latitude;
|
||||
user()->longitude = $longitude;
|
||||
user()->save();
|
||||
|
||||
redirect('/');
|
||||
}
|
||||
|
|
|
@ -20,56 +20,55 @@ function register_routes(Router $r): Router
|
|||
*/
|
||||
function fight()
|
||||
{
|
||||
global $userrow;
|
||||
if ($userrow["currentaction"] != "Fighting") display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
|
||||
if (user()->currentaction !== 'Fighting') exit('Cheat attempt detected.<br><br>Get a life, loser.');
|
||||
|
||||
$pagearray = ["magiclist" => "", "yourturn" => "", "monsterturn" => "", "monsterhp" => "", "command" => ""];
|
||||
$page = ["magiclist" => "", "yourturn" => "", "monsterturn" => "", "monsterhp" => "", "command" => ""];
|
||||
$playerisdead = 0;
|
||||
|
||||
// Populate magic list
|
||||
$userspells = explode(",", $userrow["spells"]);
|
||||
$spellquery = db()->query('SELECT id, name FROM spells ORDER BY id;');
|
||||
while ($spellrow = $spellquery->fetchArray(SQLITE3_ASSOC)) {
|
||||
if (in_array($spellrow["id"], $userspells)) {
|
||||
$pagearray["magiclist"] .= "<option value=\"{$spellrow["id"]}\">{$spellrow["name"]}</option>\n";
|
||||
}
|
||||
}
|
||||
$pagearray["magiclist"] = $pagearray["magiclist"] ?: "<option value=\"0\">None</option>\n";
|
||||
$magiclist = $pagearray["magiclist"];
|
||||
// Generate spell list
|
||||
$user_spells = user()->spells();
|
||||
if (!empty($user_spells)) {
|
||||
$page['magiclist'] = '<select name="userspell">';
|
||||
foreach ($user_spells as $spell) {
|
||||
$page['magiclist'] .= "<option value=\"{$spell['id']}\">{$spell['name']}</option>\n";
|
||||
}
|
||||
$page['magiclist'] .= '</select> <input type="submit" name="spell" value="Spell"><br><br>';
|
||||
}
|
||||
|
||||
// Determine initial combat parameters
|
||||
$chancetoswingfirst = rand(1, 10) + (int)ceil(sqrt($userrow["dexterity"]));
|
||||
if ($userrow["currentfight"] == 1) {
|
||||
$maxlevel = (int)floor(max(abs($userrow["latitude"]) + 5, abs($userrow["longitude"]) + 5) / 5);
|
||||
$chancetoswingfirst = rand(1, 10) + (int)ceil(sqrt(user()->dexterity));
|
||||
if (user()->currentfight === 1) {
|
||||
$maxlevel = (int)floor(max(abs(user()->latitude) + 5, abs(user()->longitude) + 5) / 5);
|
||||
$minlevel = max(1, $maxlevel - 2);
|
||||
|
||||
$monsterrow = db()->query('SELECT * FROM monsters WHERE level >= ? AND level <= ? ORDER BY RANDOM() LIMIT 1;', [
|
||||
$monster = db()->query('SELECT * FROM monsters WHERE level >= ? AND level <= ? ORDER BY RANDOM() LIMIT 1;', [
|
||||
$minlevel, $maxlevel
|
||||
])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$userrow["currentmonster"] = $monsterrow["id"];
|
||||
$userrow["currentmonsterhp"] = rand((int)(($monsterrow["maxhp"]/5)*4), $monsterrow["maxhp"]);
|
||||
$userrow["currentmonstersleep"] = 0;
|
||||
$userrow["currentmonsterimmune"] = $monsterrow["immune"];
|
||||
user()->currentmonster = $monster["id"];
|
||||
user()->currentmonsterhp = rand((int)(($monster["maxhp"]/5)*4), $monster["maxhp"]);
|
||||
user()->currentmonstersleep = 0;
|
||||
user()->currentmonsterimmune = $monster["immune"];
|
||||
|
||||
$chancetoswingfirst = ($chancetoswingfirst > (rand(1,7) + (int)ceil(sqrt($monsterrow["maxdam"])))) ? 1 : 0;
|
||||
$chancetoswingfirst = ($chancetoswingfirst > (rand(1,7) + (int)ceil(sqrt($monster["maxdam"])))) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Get monster statistics
|
||||
$monsterrow = get_monster($userrow['currentmonster']);
|
||||
$pagearray["monstername"] = $monsterrow["name"];
|
||||
$monster = get_monster(user()->currentmonster);
|
||||
$page['monstername'] = $monster['name'];
|
||||
|
||||
// Run action
|
||||
if (isset($_POST["run"])) {
|
||||
$chancetorun = rand(4,10) + (int)ceil(sqrt($userrow["dexterity"]));
|
||||
if ($chancetorun <= (rand(1,5) + (int)ceil(sqrt($monsterrow["maxdam"])))) {
|
||||
$pagearray["yourturn"] = "You tried to run away, but were blocked in front!<br><br>";
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
$chancetorun = rand(4,10) + (int)ceil(sqrt(user()->dexterity));
|
||||
if ($chancetorun <= (rand(1,5) + (int)ceil(sqrt($monster["maxdam"])))) {
|
||||
$page["yourturn"] = "You tried to run away, but were blocked in front!<br><br>";
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
|
||||
// Monster turn logic (similar to original function)
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
|
||||
db()->query("UPDATE users SET currentaction='Exploring' WHERE id=?;", [$userrow['id']]);
|
||||
user()->currentaction = 'Exploring';
|
||||
user()->save();
|
||||
redirect('/');
|
||||
}
|
||||
}
|
||||
|
@ -77,147 +76,125 @@ function fight()
|
|||
// Fight action
|
||||
if (isset($_POST["fight"])) {
|
||||
// Player's attack
|
||||
$min = (int)($userrow["attackpower"] * 0.75);
|
||||
$max = (int)($userrow["attackpower"] / 3);
|
||||
$min = (int)(user()->attackpower * 0.75);
|
||||
$max = (int)(user()->attackpower / 3);
|
||||
$tohit = (int)ceil(mt_rand(min($min, $max), max($min, $max)));
|
||||
|
||||
$toexcellent = rand(1,150);
|
||||
if ($toexcellent <= sqrt($userrow["strength"])) {
|
||||
if ($toexcellent <= sqrt(user()->strength)) {
|
||||
$tohit *= 2;
|
||||
$pagearray["yourturn"] .= "Excellent hit!<br>";
|
||||
$page["yourturn"] .= "Excellent hit!<br>";
|
||||
}
|
||||
|
||||
$min = (int)($monsterrow["armor"] * 0.75);
|
||||
$max = (int)$monsterrow["armor"];
|
||||
$min = (int)($monster["armor"] * 0.75);
|
||||
$max = (int)$monster["armor"];
|
||||
$toblock = (int)ceil(rand(min($min, $max), max($min, $max)) / 3);
|
||||
|
||||
$tododge = rand(1,200);
|
||||
$tododge = rand(1, 100);
|
||||
|
||||
$monsterdamage = max(1, $tohit - $toblock);
|
||||
if ($tododge <= sqrt($monsterrow["armor"])) {
|
||||
if ($tododge <= sqrt($monster["armor"])) {
|
||||
$monsterdamage = 0;
|
||||
$pagearray["yourturn"] .= "The monster is dodging. No damage has been scored.<br>";
|
||||
$page["yourturn"] .= "The monster is dodging. No damage has been scored.<br>";
|
||||
}
|
||||
|
||||
if ($userrow["currentuberdamage"] != 0) {
|
||||
$monsterdamage += (int)ceil($monsterdamage * ($userrow["currentuberdamage"]/100));
|
||||
if (user()->currentuberdamage != 0) {
|
||||
$monsterdamage += (int)ceil($monsterdamage * (user()->currentuberdamage / 100));
|
||||
}
|
||||
|
||||
$userrow["currentmonsterhp"] -= $monsterdamage;
|
||||
$pagearray["yourturn"] .= "You attack the monster for $monsterdamage damage.<br><br>";
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
user()->currentmonsterhp -= $monsterdamage;
|
||||
$page["yourturn"] .= "You attack the monster for $monsterdamage damage.<br><br>";
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
|
||||
// Check for monster defeat
|
||||
if ($userrow["currentmonsterhp"] <= 0) {
|
||||
db()->query('UPDATE users SET currentmonsterhp=0 WHERE id=?;', [$userrow['id']]);
|
||||
if (user()->currentmonsterhp <= 0) {
|
||||
user()->currentmonsterhp = 0;
|
||||
user()->save();
|
||||
redirect('/victory');
|
||||
}
|
||||
|
||||
// Monster's turn
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
}
|
||||
|
||||
// Spell action
|
||||
if (isset($_POST["spell"])) {
|
||||
$pickedspell = $_POST["userspell"];
|
||||
if ($pickedspell == 0) {
|
||||
display("You must select a spell first. Please go back and try again.", "Error");
|
||||
return display("You must select a spell first. Please go back and try again.", "Error");
|
||||
die();
|
||||
}
|
||||
|
||||
$newspellrow = get_spell($pickedspell);
|
||||
$spell = in_array($pickedspell, $userspells);
|
||||
$spell = in_array($pickedspell, explode(',', user()->spells));
|
||||
|
||||
if (!$spell) {
|
||||
display("You have not yet learned this spell. Please go back and try again.", "Error");
|
||||
return display("You have not yet learned this spell. Please go back and try again.", "Error");
|
||||
die();
|
||||
}
|
||||
|
||||
if ($userrow["currentmp"] < $newspellrow["mp"]) {
|
||||
display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error");
|
||||
if (user()->currentmp < $newspellrow["mp"]) {
|
||||
return display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error");
|
||||
die();
|
||||
}
|
||||
|
||||
// Spell type handling (similar to original function)
|
||||
$pagearray["yourturn"] = handleSpellCast($userrow, $newspellrow);
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
$page["yourturn"] = handleSpellCast($userrow, $newspellrow);
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
|
||||
// Check for monster defeat
|
||||
if ($userrow["currentmonsterhp"] <= 0) {
|
||||
db()->query('UPDATE users SET currentmonsterhp=0, currenthp=?, currentmp=? WHERE id=?;', [
|
||||
$userrow['currenthp'], $userrow['currentmp'], $userrow['id']
|
||||
]);
|
||||
if (user()->currentmonsterhp <= 0) {
|
||||
user()->currentmonsterhp = 0;
|
||||
user()->save();
|
||||
redirect('/victory');
|
||||
}
|
||||
|
||||
// Monster's turn
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
}
|
||||
|
||||
// Monster's turn if player lost first swing
|
||||
if (!isset($_POST["run"]) && !isset($_POST["fight"]) && !isset($_POST["spell"]) && $chancetoswingfirst == 0) {
|
||||
$pagearray["yourturn"] = "The monster attacks before you are ready!<br><br>";
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
$page["yourturn"] = "The monster attacks before you are ready!<br><br>";
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
}
|
||||
|
||||
// Prepare command or death message
|
||||
if ($playerisdead != 1) {
|
||||
$pagearray["command"] = <<<HTML
|
||||
$page["command"] = <<<HTML
|
||||
Command?<br><br>
|
||||
<form action="/fight" method="post">
|
||||
<input type="submit" name="fight" value="Fight" /><br><br>
|
||||
<select name="userspell"><option value="0">Choose One</option>$magiclist</select> <input type="submit" name="spell" value="Spell" /><br><br>
|
||||
<input type="submit" name="run" value="Run" /><br><br>
|
||||
<input type="submit" name="fight" value="Fight"><br><br>
|
||||
{$page['magiclist']}
|
||||
<input type="submit" name="run" value="Run"><br><br>
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
db()->query("UPDATE users SET
|
||||
currentaction='Fighting',
|
||||
currenthp=?,
|
||||
currentmp=?,
|
||||
currentfight=?,
|
||||
currentmonster=?,
|
||||
currentmonsterhp=?,
|
||||
currentmonstersleep=?,
|
||||
currentmonsterimmune=?,
|
||||
currentuberdamage=?,
|
||||
currentuberdefense=?
|
||||
WHERE id=?;", [
|
||||
$userrow['currenthp'],
|
||||
$userrow['currentmp'],
|
||||
$userrow['currentfight'] + 1,
|
||||
$userrow['currentmonster'],
|
||||
$userrow['currentmonsterhp'],
|
||||
$userrow['currentmonstersleep'],
|
||||
$userrow['currentmonsterimmune'],
|
||||
$userrow['currentuberdamage'],
|
||||
$userrow['currentuberdefense'],
|
||||
$userrow['id']
|
||||
]);
|
||||
user()->currentfight += 1;
|
||||
} else {
|
||||
$pagearray["command"] = "<b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href=\"/\">town</a>, and we hope you fair better next time.";
|
||||
}
|
||||
|
||||
user()->save();
|
||||
|
||||
// Finalize page and display it
|
||||
display(render('fight', ['page' => $pagearray]), "Fighting");
|
||||
return display(render('fight', ['page' => $page]), "Fighting");
|
||||
}
|
||||
|
||||
function victory()
|
||||
{
|
||||
global $userrow;
|
||||
if (user()->currentmonsterhp != 0) redirect('/fight');
|
||||
if (user()->currentfight == 0) redirect('/');
|
||||
|
||||
if ($userrow["currentmonsterhp"] != 0) redirect('/fight');
|
||||
if ($userrow["currentfight"] == 0) redirect('/');
|
||||
|
||||
$monsterrow = get_monster($userrow['currentmonster']);
|
||||
$monsterrow = get_monster(user()->currentmonster);
|
||||
|
||||
$min = (int)(($monsterrow["maxexp"] / 6) * 5);
|
||||
$max = (int)$monsterrow["maxexp"];
|
||||
$exp = mt_rand(min($min, $max), max($min, $max));
|
||||
if ($exp < 1) { $exp = 1; }
|
||||
|
||||
if ($userrow["expbonus"] != 0) { $exp += ceil(($userrow["expbonus"]/100)*$exp); }
|
||||
if (user()->expbonus != 0) { $exp += ceil((user()->expbonus/100)*$exp); }
|
||||
|
||||
$min = (int)(($monsterrow["maxgold"] / 6) * 5);
|
||||
$max = (int)$monsterrow["maxgold"];
|
||||
|
@ -225,42 +202,33 @@ function victory()
|
|||
$gold = mt_rand(min($min, $max), max($min, $max));
|
||||
if ($gold < 1) { $gold = 1; }
|
||||
|
||||
if ($userrow["goldbonus"] != 0) { $gold += ceil(($userrow["goldbonus"]/100)*$exp); }
|
||||
if ($userrow["experience"] + $exp < 16777215) { $newexp = $userrow["experience"] + $exp; $warnexp = ""; } else { $newexp = $userrow["experience"]; $exp = 0; $warnexp = "You have maxed out your experience points."; }
|
||||
if ($userrow["gold"] + $gold < 16777215) { $newgold = $userrow["gold"] + $gold; $warngold = ""; } else { $newgold = $userrow["gold"]; $gold = 0; $warngold = "You have maxed out your experience points."; }
|
||||
if (user()->goldbonus != 0) { $gold += ceil((user()->goldbonus/100)*$exp); }
|
||||
if (user()->experience + $exp < 16777215) { $newexp = user()->experience += $exp; $warnexp = ""; } else { $newexp = user()->experience; $exp = 0; $warnexp = "You have maxed out your experience points."; }
|
||||
if (user()->gold + $gold < 16777215) { $newgold = user()->gold += $gold; $warngold = ""; } else { $newgold = user()->gold; $gold = 0; $warngold = "You have maxed out your gold."; }
|
||||
|
||||
$levelrow = db()->query('SELECT * FROM levels WHERE id=? LIMIT 1;', [$userrow['level'] + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
$levelrow = db()->query('SELECT * FROM levels WHERE id=? LIMIT 1;', [user()->level + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($userrow["level"] < 100) {
|
||||
if ($newexp >= $levelrow[$userrow["charclass"]."_exp"]) {
|
||||
$newhp = $userrow["maxhp"] + $levelrow[$userrow["charclass"]."_hp"];
|
||||
$newmp = $userrow["maxmp"] + $levelrow[$userrow["charclass"]."_mp"];
|
||||
$newtp = $userrow["maxtp"] + $levelrow[$userrow["charclass"]."_tp"];
|
||||
$newstrength = $userrow["strength"] + $levelrow[$userrow["charclass"]."_strength"];
|
||||
$newdexterity = $userrow["dexterity"] + $levelrow[$userrow["charclass"]."_dexterity"];
|
||||
$newattack = $userrow["attackpower"] + $levelrow[$userrow["charclass"]."_strength"];
|
||||
$newdefense = $userrow["defensepower"] + $levelrow[$userrow["charclass"]."_dexterity"];
|
||||
if (user()->level < 100) {
|
||||
if ($newexp >= $levelrow[user()->charclass."_exp"]) {
|
||||
user()->maxhp += $levelrow[user()->charclass."_hp"];
|
||||
user()->maxmp += $levelrow[user()->charclass."_mp"];
|
||||
user()->maxtp += $levelrow[user()->charclass."_tp"];
|
||||
user()->strength += $levelrow[user()->charclass."_strength"];
|
||||
user()->dexterity += $levelrow[user()->charclass."_dexterity"];
|
||||
user()->attackpower += $levelrow[user()->charclass."_strength"];
|
||||
user()->defensepower += $levelrow[user()->charclass."_dexterity"];
|
||||
user()->level += 1;
|
||||
$newlevel = $levelrow["id"];
|
||||
|
||||
if ($levelrow[$userrow["charclass"]."_spells"] != 0) {
|
||||
$userspells = $userrow["spells"] . ",".$levelrow[$userrow["charclass"]."_spells"];
|
||||
$newspell = "spells='$userspells',";
|
||||
if ($levelrow[user()->charclass."_spells"] != 0) {
|
||||
user()->spells .= ",".$levelrow[user()->charclass."_spells"];
|
||||
$spelltext = "You have learned a new spell.<br>";
|
||||
} else { $spelltext = ""; $newspell=""; }
|
||||
|
||||
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br><b>You have gained a level!</b><br><br>You gain ".$levelrow[$userrow["charclass"]."_hp"]." hit points.<br>You gain ".$levelrow[$userrow["charclass"]."_mp"]." magic points.<br>You gain ".$levelrow[$userrow["charclass"]."_tp"]." travel points.<br>You gain ".$levelrow[$userrow["charclass"]."_strength"]." strength.<br>You gain ".$levelrow[$userrow["charclass"]."_dexterity"]." dexterity.<br>$spelltext<br>You can now continue <a href=\"/\">exploring</a>.";
|
||||
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br><b>You have gained a level!</b><br><br>You gain ".$levelrow[user()->charclass."_hp"]." hit points.<br>You gain ".$levelrow[user()->charclass."_mp"]." magic points.<br>You gain ".$levelrow[user()->charclass."_tp"]." travel points.<br>You gain ".$levelrow[user()->charclass."_strength"]." strength.<br>You gain ".$levelrow[user()->charclass."_dexterity"]." dexterity.<br>$spelltext<br>You can now continue <a href=\"/\">exploring</a>.";
|
||||
$title = "Courage and Wit have served thee well!";
|
||||
$dropcode = "";
|
||||
} else {
|
||||
$newhp = $userrow["maxhp"];
|
||||
$newmp = $userrow["maxmp"];
|
||||
$newtp = $userrow["maxtp"];
|
||||
$newstrength = $userrow["strength"];
|
||||
$newdexterity = $userrow["dexterity"];
|
||||
$newattack = $userrow["attackpower"];
|
||||
$newdefense = $userrow["defensepower"];
|
||||
$newlevel = $userrow["level"];
|
||||
$newspell = "";
|
||||
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br>";
|
||||
|
||||
if (rand(1, 30) === 1) {
|
||||
|
@ -276,74 +244,82 @@ function victory()
|
|||
}
|
||||
}
|
||||
|
||||
db()->query("UPDATE users SET currentaction='Exploring', level=?, maxhp=?, maxmp=?, maxtp=?, strength=?, dexterity=?, attackpower=?, defensepower=?, $newspell currentfight=0, currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentuberdamage=0, currentuberdefense=0,$dropcode experience=?, gold=? WHERE id=?;", [
|
||||
$newlevel, $newhp, $newmp, $newtp, $newstrength, $newdexterity, $newattack, $newdefense, $newexp, $newgold, $userrow['id']
|
||||
]);
|
||||
user()->currentaction = 'Exploring';
|
||||
user()->currentfight = 0;
|
||||
user()->currentuberdamage = 0;
|
||||
user()->currentuberdefense = 0;
|
||||
user()->currentmonstersleep = 0;
|
||||
user()->currentmonsterimmune = 0;
|
||||
user()->save();
|
||||
|
||||
display($page, $title);
|
||||
return display($page, $title);
|
||||
}
|
||||
|
||||
function drop()
|
||||
{
|
||||
global $userrow;
|
||||
if (user()->dropcode == 0) redirect('/');
|
||||
|
||||
if ($userrow["dropcode"] == 0) redirect('/');
|
||||
|
||||
$droprow = get_drop($userrow['dropcode']);
|
||||
$droprow = get_drop(user()->dropcode);
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$slot = $_POST["slot"];
|
||||
|
||||
if ($slot == 0) { display("Please go back and select an inventory slot to continue.","Error"); }
|
||||
if ($slot == 0) { return display("Please go back and select an inventory slot to continue.","Error"); }
|
||||
|
||||
if ($userrow["slot{$slot}id"] != 0) {
|
||||
$slotrow = get_drop($userrow["slot{$slot}id"]);
|
||||
$slotstr = 'slot'.$slot.'id';
|
||||
if (user()->$slotstr != 0) {
|
||||
$slotrow = get_drop(user()->$slotstr);
|
||||
|
||||
$old1 = explode(",",$slotrow["attribute1"]);
|
||||
if ($slotrow["attribute2"] != "X") { $old2 = explode(",",$slotrow["attribute2"]); } else { $old2 = array(0=>"maxhp",1=>0); }
|
||||
$new1 = explode(",",$droprow["attribute1"]);
|
||||
if ($droprow["attribute2"] != "X") { $new2 = explode(",",$droprow["attribute2"]); } else { $new2 = array(0=>"maxhp",1=>0); }
|
||||
|
||||
$userrow[$old1[0]] -= $old1[1];
|
||||
$userrow[$old2[0]] -= $old2[1];
|
||||
if ($old1[0] == "strength") { $userrow["attackpower"] -= $old1[1]; }
|
||||
if ($old1[0] == "dexterity") { $userrow["defensepower"] -= $old1[1]; }
|
||||
if ($old2[0] == "strength") { $userrow["attackpower"] -= $old2[1]; }
|
||||
if ($old2[0] == "dexterity") { $userrow["defensepower"] -= $old2[1]; }
|
||||
user()->$old1[0] -= $old1[1];
|
||||
user()->$old2[0] -= $old2[1];
|
||||
if ($old1[0] == "strength") { user()->attackpower -= $old1[1]; }
|
||||
if ($old1[0] == "dexterity") { user()->defensepower -= $old1[1]; }
|
||||
if ($old2[0] == "strength") { user()->attackpower -= $old2[1]; }
|
||||
if ($old2[0] == "dexterity") { user()->defensepower -= $old2[1]; }
|
||||
|
||||
$userrow[$new1[0]] += $new1[1];
|
||||
$userrow[$new2[0]] += $new2[1];
|
||||
if ($new1[0] == "strength") { $userrow["attackpower"] += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { $userrow["defensepower"] += $new1[1]; }
|
||||
if ($new2[0] == "strength") { $userrow["attackpower"] += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { $userrow["defensepower"] += $new2[1]; }
|
||||
user()->$new1[0] += $new1[1];
|
||||
user()->$new2[0] += $new2[1];
|
||||
if ($new1[0] == "strength") { user()->attackpower += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { user()->defensepower += $new1[1]; }
|
||||
if ($new2[0] == "strength") { user()->attackpower += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { user()->defensepower += $new2[1]; }
|
||||
|
||||
if ($userrow["currenthp"] > $userrow["maxhp"]) { $userrow["currenthp"] = $userrow["maxhp"]; }
|
||||
if ($userrow["currentmp"] > $userrow["maxmp"]) { $userrow["currentmp"] = $userrow["maxmp"]; }
|
||||
if ($userrow["currenttp"] > $userrow["maxtp"]) { $userrow["currenttp"] = $userrow["maxtp"]; }
|
||||
if (user()->currenthp > user()->maxhp) { user()->currenthp = user()->maxhp; }
|
||||
if (user()->currentmp > user()->maxmp) { user()->currentmp = user()->maxmp; }
|
||||
if (user()->currenttp > user()->maxtp) { user()->currenttp = user()->maxtp; }
|
||||
|
||||
$slot_s = 'slot'.$_POST["slot"];
|
||||
db()->query("UPDATE users SET {$slot_s}name=?, {$slot_s}id=?, {$old1[0]}=?, {$old2[0]}=?, {$new1[0]}=?, {$new2[0]}=?, attackpower=?, defensepower=?, currenthp=?, currentmp=?, currenttp=?, dropcode=0 WHERE id=?;", [
|
||||
$droprow["name"], $droprow["id"], $userrow[$old1[0]], $userrow[$old2[0]], $userrow[$new1[0]], $userrow[$new2[0]], $userrow["attackpower"], $userrow["defensepower"], $userrow["currenthp"], $userrow["currentmp"], $userrow["currenttp"], $userrow['id']
|
||||
]);
|
||||
$slot_name = "{$slot_s}name";
|
||||
$slot_id = "{$slot_s}id";
|
||||
|
||||
user()->$slot_name = $droprow['name'];
|
||||
user()->$slot_id = $droprow['id'];
|
||||
} else {
|
||||
$new1 = explode(",",$droprow["attribute1"]);
|
||||
if ($droprow["attribute2"] != "X") { $new2 = explode(",",$droprow["attribute2"]); } else { $new2 = array(0=>"maxhp",1=>0); }
|
||||
|
||||
$userrow[$new1[0]] += $new1[1];
|
||||
$userrow[$new2[0]] += $new2[1];
|
||||
if ($new1[0] == "strength") { $userrow["attackpower"] += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { $userrow["defensepower"] += $new1[1]; }
|
||||
if ($new2[0] == "strength") { $userrow["attackpower"] += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { $userrow["defensepower"] += $new2[1]; }
|
||||
user()->$new1[0] += $new1[1];
|
||||
user()->$new2[0] += $new2[1];
|
||||
if ($new1[0] == "strength") { user()->attackpower += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { user()->defensepower += $new1[1]; }
|
||||
if ($new2[0] == "strength") { user()->attackpower += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { user()->defensepower += $new2[1]; }
|
||||
|
||||
$slot_s = 'slot'.$_POST["slot"];
|
||||
db()->query("UPDATE users SET {$slot_s}name=?, {$slot_s}id=?, {$new1[0]}=?, {$new2[0]}=?, attackpower=?, defensepower=?, currenthp=?, currentmp=?, currenttp=?, dropcode=0 WHERE id=?;", [
|
||||
$droprow["name"], $droprow["id"], $userrow[$new1[0]], $userrow[$new2[0]], $userrow["attackpower"], $userrow["defensepower"], $userrow["currenthp"], $userrow["currentmp"], $userrow["currenttp"], $userrow['id']
|
||||
]);
|
||||
$slot_name = "{$slot_s}name";
|
||||
$slot_id = "{$slot_s}id";
|
||||
|
||||
user()->$slot_name = $droprow['name'];
|
||||
user()->$slot_id = $droprow['id'];
|
||||
}
|
||||
|
||||
display("The item has been equipped. You can now continue <a href=\"/\">exploring</a>.", "Item Drop");
|
||||
user()->save();
|
||||
return display("The item has been equipped. You can now continue <a href=\"/\">exploring</a>.", "Item Drop");
|
||||
}
|
||||
|
||||
$attributearray = array("maxhp"=>"Max HP",
|
||||
|
@ -370,10 +346,10 @@ function drop()
|
|||
}
|
||||
|
||||
$page .= "<br>Select an inventory slot from the list below to equip this item. If the inventory slot is already full, the old item will be discarded.";
|
||||
$page .= "<form action=\"/drop\" method=\"post\"><select name=\"slot\"><option value=\"0\">Choose One</option><option value=\"1\">Slot 1: ".$userrow["slot1name"]."</option><option value=\"2\">Slot 2: ".$userrow["slot2name"]."</option><option value=\"3\">Slot 3: ".$userrow["slot3name"]."</option></select> <input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";
|
||||
$page .= "<form action=\"/drop\" method=\"post\"><select name=\"slot\"><option value=\"0\">Choose One</option><option value=\"1\">Slot 1: ".user()->slot1name."</option><option value=\"2\">Slot 2: ".user()->slot2name."</option><option value=\"3\">Slot 3: ".user()->slot3name."</option></select> <input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";
|
||||
$page .= "You may also choose to just continue <a href=\"/\">exploring</a> and give up this item.";
|
||||
|
||||
display($page, "Item Drop");
|
||||
return display($page, "Item Drop");
|
||||
}
|
||||
|
||||
|
||||
|
@ -385,45 +361,45 @@ function dead()
|
|||
to continue your journey.<br><br>
|
||||
You may now continue back to <a href="/">town</a>, and we hope you fair better next time.
|
||||
HTML;
|
||||
display($page, 'You Died');
|
||||
return display($page, 'You Died');
|
||||
}
|
||||
|
||||
function handleMonsterTurn(&$userrow, $monsterrow)
|
||||
{
|
||||
$pagearray = "";
|
||||
if ($userrow["currentmonstersleep"] != 0) {
|
||||
if (user()->currentmonstersleep != 0) {
|
||||
$chancetowake = rand(1,15);
|
||||
if ($chancetowake > $userrow["currentmonstersleep"]) {
|
||||
$userrow["currentmonstersleep"] = 0;
|
||||
if ($chancetowake > user()->currentmonstersleep) {
|
||||
user()->currentmonstersleep = 0;
|
||||
$pagearray .= "The monster has woken up.<br>";
|
||||
} else {
|
||||
$pagearray .= "The monster is still asleep.<br>";
|
||||
}
|
||||
}
|
||||
|
||||
if ($userrow["currentmonstersleep"] == 0) {
|
||||
if (user()->currentmonstersleep == 0) {
|
||||
$tohit = (int)ceil(mt_rand((int)($monsterrow["maxdam"] * 0.5), (int)$monsterrow["maxdam"]));
|
||||
$toblock = (int)ceil(mt_rand((int)($userrow["defensepower"] * 0.75), (int)$userrow["defensepower"]) / 4);
|
||||
$toblock = (int)ceil(mt_rand((int)(user()->defensepower * 0.75), (int)user()->defensepower) / 4);
|
||||
$tododge = rand(1, 150);
|
||||
|
||||
if ($tododge <= sqrt($userrow["dexterity"])) {
|
||||
if ($tododge <= sqrt(user()->dexterity)) {
|
||||
$tohit = 0;
|
||||
$pagearray .= "You dodge the monster's attack. No damage has been scored.<br>";
|
||||
$persondamage = 0;
|
||||
} else {
|
||||
$persondamage = max(1, $tohit - $toblock);
|
||||
if ($userrow["currentuberdefense"] != 0) {
|
||||
$persondamage -= (int)ceil($persondamage * ($userrow["currentuberdefense"]/100));
|
||||
if (user()->currentuberdefense != 0) {
|
||||
$persondamage -= (int)ceil($persondamage * (user()->currentuberdefense/100));
|
||||
}
|
||||
$persondamage = max(1, $persondamage);
|
||||
}
|
||||
|
||||
$pagearray .= "The monster attacks you for $persondamage damage.<br><br>";
|
||||
$userrow["currenthp"] -= $persondamage;
|
||||
user()->currenthp -= $persondamage;
|
||||
|
||||
if ($userrow["currenthp"] <= 0) {
|
||||
$newgold = (int)ceil($userrow["gold"]/2);
|
||||
$newhp = (int)ceil($userrow["maxhp"]/4);
|
||||
if (user()->currenthp <= 0) {
|
||||
$newgold = (int)ceil(user()->gold/2);
|
||||
$newhp = (int)ceil(user()->maxhp/4);
|
||||
db()->query("UPDATE users SET currenthp=?, currentaction='In Town', currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentfight=0, latitude=0, longitude=0, gold=? WHERE id=?;", [
|
||||
$newhp, $newgold, $userrow['id']
|
||||
]);
|
||||
|
@ -438,38 +414,38 @@ function handleSpellCast(&$userrow, $newspellrow)
|
|||
$pagearray = "";
|
||||
switch ($newspellrow["type"]) {
|
||||
case 1: // Heal spell
|
||||
$newhp = min($userrow["currenthp"] + $newspellrow["attribute"], $userrow["maxhp"]);
|
||||
$userrow["currenthp"] = $newhp;
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
$newhp = min(user()->currenthp + $newspellrow["attribute"], user()->maxhp);
|
||||
user()->currenthp = $newhp;
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and gained {$newspellrow["attribute"]} Hit Points.<br><br>";
|
||||
break;
|
||||
case 2: // Hurt spell
|
||||
if ($userrow["currentmonsterimmune"] == 0) {
|
||||
if (user()->currentmonsterimmune == 0) {
|
||||
$monsterdamage = mt_rand((int)(($newspellrow["attribute"]/6)*5), $newspellrow["attribute"]);
|
||||
$userrow["currentmonsterhp"] -= $monsterdamage;
|
||||
user()->currentmonsterhp -= $monsterdamage;
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell for $monsterdamage damage.<br><br>";
|
||||
} else {
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
|
||||
}
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
break;
|
||||
case 3: // Sleep spell
|
||||
if ($userrow["currentmonsterimmune"] != 2) {
|
||||
$userrow["currentmonstersleep"] = $newspellrow["attribute"];
|
||||
if (user()->currentmonsterimmune != 2) {
|
||||
user()->currentmonstersleep = $newspellrow["attribute"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell. The monster is asleep.<br><br>";
|
||||
} else {
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
|
||||
}
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
break;
|
||||
case 4: // +Damage spell
|
||||
$userrow["currentuberdamage"] = $newspellrow["attribute"];
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
user()->currentuberdamage = $newspellrow["attribute"];
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% damage until the end of this fight.<br><br>";
|
||||
break;
|
||||
case 5: // +Defense spell
|
||||
$userrow["currentuberdefense"] = $newspellrow["attribute"];
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
user()->currentuberdefense = $newspellrow["attribute"];
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% defense until the end of this fight.<br><br>";
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ function donothing($start = 0)
|
|||
|
||||
$page .= "</table></td></tr></table>";
|
||||
|
||||
display($page, "Forum");
|
||||
return display($page, "Forum");
|
||||
}
|
||||
|
||||
function showthread($id, $start)
|
||||
|
@ -49,7 +49,7 @@ function showthread($id, $start)
|
|||
$page .= "</table></td></tr></table><br>";
|
||||
$page .= "<table width=\"100%\"><tr><td><b>Reply To This Thread:</b><br><form action=\"/forum/reply\" method=\"post\"><input type=\"hidden\" name=\"parent\" value=\"$id\" /><input type=\"hidden\" name=\"title\" value=\"Re: ".$title["title"]."\" /><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
||||
|
||||
display($page, "Forum");
|
||||
return display($page, "Forum");
|
||||
}
|
||||
|
||||
function reply()
|
||||
|
@ -68,7 +68,7 @@ function reply()
|
|||
$form = $form['data'];
|
||||
|
||||
db()->query('INSERT INTO forum (author, title, content, parent) VALUES (?, ?, ?, ?);', [
|
||||
$userrow['username'], $form['title'], $form['content'], $form['parent']
|
||||
user()->username, $form['title'], $form['content'], $form['parent']
|
||||
]);
|
||||
db()->query('UPDATE forum SET newpostdate=CURRENT_TIMESTAMP, replies=replies + 1 WHERE id=?;', [$form['parent']]);
|
||||
redirect("/forum/thread/{$form['parent']}/0");
|
||||
|
@ -76,8 +76,6 @@ function reply()
|
|||
|
||||
function newthread()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$form = validate($_POST, [
|
||||
'title' => ['length:2-30'],
|
||||
|
@ -90,11 +88,11 @@ function newthread()
|
|||
|
||||
$form = $form['data'];
|
||||
db()->query('INSERT INTO forum (author, title, content) VALUES (?, ?, ?);', [
|
||||
$userrow['username'], $form['title'], $form['content']
|
||||
user()->username, $form['title'], $form['content']
|
||||
]);
|
||||
redirect('/forum');
|
||||
}
|
||||
|
||||
$page = "<table width=\"100%\"><tr><td><b>Make A New Post:</b><br><br/ ><form action=\"/forum/new\" method=\"post\">Title:<br><input type=\"text\" name=\"title\" size=\"50\" maxlength=\"50\" /><br><br>Message:<br><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
||||
display($page, "Forum");
|
||||
return display($page, "Forum");
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ function healspells($id)
|
|||
// All the various ways to error out.
|
||||
$spell = false;
|
||||
foreach ($userspells as $b) if ($b == $id) $spell = true;
|
||||
if ($spell !== true) display("You have not yet learned this spell. Please go back and try again.", "Error");
|
||||
if ($spellrow["type"] != 1) display("This is not a healing spell. Please go back and try again.", "Error");
|
||||
if ($userrow["currentmp"] < $spellrow["mp"]) display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error");
|
||||
if ($userrow["currentaction"] == "Fighting") display("You cannot use the Quick Spells list during a fight. Please go back and select the Healing Spell you wish to use from the Spells box on the main fighting screen to continue.", "Error");
|
||||
if ($userrow["currenthp"] == $userrow["maxhp"]) display("Your Hit Points are already full. You don't need to use a Healing spell now.", "Error");
|
||||
if ($spell !== true) return display("You have not yet learned this spell. Please go back and try again.", "Error");
|
||||
if ($spellrow["type"] != 1) return display("This is not a healing spell. Please go back and try again.", "Error");
|
||||
if ($userrow["currentmp"] < $spellrow["mp"]) return display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error");
|
||||
if ($userrow["currentaction"] == "Fighting") return display("You cannot use the Quick Spells list during a fight. Please go back and select the Healing Spell you wish to use from the Spells box on the main fighting screen to continue.", "Error");
|
||||
if ($userrow["currenthp"] == $userrow["maxhp"]) return display("Your Hit Points are already full. You don't need to use a Healing spell now.", "Error");
|
||||
|
||||
$newhp = $userrow["currenthp"] + $spellrow["attribute"];
|
||||
if ($userrow["maxhp"] < $newhp) { $spellrow["attribute"] = $userrow["maxhp"] - $userrow["currenthp"]; $newhp = $userrow["currenthp"] + $spellrow["attribute"]; }
|
||||
|
@ -24,5 +24,5 @@ function healspells($id)
|
|||
|
||||
db()->query('UPDATE users SET currenthp=?, currentmp=? WHERE id=?;', [$newhp, $newmp, $userrow['id']]);
|
||||
|
||||
display("You have cast the ".$spellrow["name"]." spell, and gained ".$spellrow["attribute"]." Hit Points. You can now continue <a href=\"/\">exploring</a>.", "Healing Spell");
|
||||
return display("You have cast the ".$spellrow["name"]." spell, and gained ".$spellrow["attribute"]." Hit Points. You can now continue <a href=\"/\">exploring</a>.", "Healing Spell");
|
||||
}
|
||||
|
|
|
@ -246,7 +246,7 @@ function main()
|
|||
[ <a href="#top">Top</a> ]
|
||||
HTML;
|
||||
|
||||
display_help(parse($page, $controlrow));
|
||||
return display_help(parse($page, $controlrow));
|
||||
}
|
||||
|
||||
function items()
|
||||
|
@ -313,7 +313,7 @@ function items()
|
|||
}
|
||||
$page .= '</table>';
|
||||
|
||||
display_help($page);
|
||||
return display_help($page);
|
||||
}
|
||||
|
||||
|
||||
|
@ -349,7 +349,7 @@ function spells()
|
|||
</ul>
|
||||
HTML;
|
||||
|
||||
display_help($page);
|
||||
return display_help($page);
|
||||
}
|
||||
|
||||
function monsters()
|
||||
|
@ -368,7 +368,7 @@ function monsters()
|
|||
$page .= "<tr><td width=\"30%\">".$m["name"]."</td><td width=\"10%\">".$m["maxhp"]."</td><td width=\"10%\">".$m["maxdam"]."</td><td width=\"10%\">".$m["armor"]."</td><td width=\"10%\">".$m["level"]."</td><td width=\"10%\">".$m["maxexp"]."</td><td width=\"10%\">".$m["maxgold"]."</td><td width=\"20%\">$immune</td></tr>\n";
|
||||
}
|
||||
|
||||
display_help($page.'</table>');
|
||||
return display_help($page.'</table>');
|
||||
}
|
||||
|
||||
function levels()
|
||||
|
@ -489,13 +489,13 @@ function levels()
|
|||
Experience points listed are total values up until that point. All other values are just the new amount that you gain for each level.
|
||||
HTML;
|
||||
|
||||
display_help(parse($page, $controlrow));
|
||||
return display_help(parse($page, $controlrow));
|
||||
}
|
||||
|
||||
function display_help(string $content)
|
||||
{
|
||||
global $controlrow;
|
||||
echo render('layouts/help', [
|
||||
return render('layouts/help', [
|
||||
'control' => $controlrow,
|
||||
'content' => $content,
|
||||
'version' => VERSION,
|
||||
|
|
|
@ -27,28 +27,31 @@ function town()
|
|||
{
|
||||
global $controlrow;
|
||||
|
||||
$townrow = get_town_by_xy(user()->longitude, user()->latitude);
|
||||
if ($townrow === false) display("There is an error with your user account, or with the town data. Please try again.","Error");
|
||||
$town = get_town_by_xy(user()->longitude, user()->latitude);
|
||||
if ($town === false) exit('There is an error with your user account, or with the town data. Please try again.');
|
||||
|
||||
$townrow["news"] = "";
|
||||
$townrow["whosonline"] = "";
|
||||
$townrow["babblebox"] = "";
|
||||
$page = ['news' => '', 'whos_online' => ''];
|
||||
|
||||
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
|
||||
if ($controlrow["shownews"] == 1) {
|
||||
$newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
|
||||
$townrow["news"] = '<div class="title">Latest News</div>';
|
||||
$townrow["news"] .= "<span class=\"light\">[".pretty_date($newsrow["postdate"])."]</span><br>".nl2br($newsrow["content"]);
|
||||
if ($controlrow['shownews'] === 1) {
|
||||
$news = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
|
||||
$news_date = pretty_date($news["postdate"]);
|
||||
$news_content = nl2br($news["content"]);
|
||||
$page['news'] = <<<HTML
|
||||
<div class="title">Latest News</div>
|
||||
<span class="light">$news_date</span><br>
|
||||
$news_content
|
||||
HTML;
|
||||
}
|
||||
|
||||
// Who's Online. Currently just members. Guests maybe later.
|
||||
if ($controlrow["showonline"] == 1) {
|
||||
if ($controlrow['showonline'] === 1) {
|
||||
$onlinequery = db()->query(<<<SQL
|
||||
SELECT id, username
|
||||
FROM users
|
||||
WHERE onlinetime >= datetime('now', '-600 seconds')
|
||||
ORDER BY username;
|
||||
SQL);
|
||||
SELECT id, username
|
||||
FROM users
|
||||
WHERE onlinetime >= datetime('now', '-600 seconds')
|
||||
ORDER BY username;
|
||||
SQL);
|
||||
|
||||
$online_count = 0;
|
||||
$online_rows = [];
|
||||
|
@ -58,23 +61,15 @@ function town()
|
|||
$online_rows[] = "<a href=\"javascript:opencharpopup({$onlinerow['id']})\">".$onlinerow["username"]."</a>";
|
||||
}
|
||||
|
||||
$townrow["whosonline"] = '<div class="title">Who\'s Online</div>';
|
||||
$townrow["whosonline"] .= "There are <b>$online_count</b> user(s) online within the last 10 minutes: ";
|
||||
$townrow["whosonline"] .= rtrim(implode(', ', $online_rows), ', ');
|
||||
}
|
||||
|
||||
if ($controlrow["showbabble"] == 1) {
|
||||
$townrow["babblebox"] = <<<HTML
|
||||
<div class="title">Babble Box</div>
|
||||
<iframe src="/babblebox" name="sbox" width="100%" height="250" frameborder="0" id="bbox">
|
||||
Your browser does not support inline frames! The Babble Box will not be available until you upgrade to
|
||||
a newer <a href="http://www.mozilla.org" target="_new">browser</a>.
|
||||
</iframe>
|
||||
$online_rows = implode(', ', $online_rows);
|
||||
$page['whos_online'] = <<<HTML
|
||||
<div class="title">Who's Online</div>
|
||||
There are <b>$online_count</b> user(s) online within the last 10 minutes: $online_rows
|
||||
HTML;
|
||||
}
|
||||
|
||||
page_title($townrow['name']);
|
||||
return render('towns', ['town' => $townrow]);
|
||||
page_title($town['name']);
|
||||
return render('towns', ['town' => $town, 'news' => $page['news'], 'whos_online' => $page['whos_online']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -383,21 +378,20 @@ function travelto($id, bool $usepoints = true)
|
|||
|
||||
if ($usepoints) {
|
||||
if (user()->currenttp < $townrow["travelpoints"]) {
|
||||
display("You do not have enough TP to travel here. Please go back and try again when you get more TP.", "Travel To");
|
||||
return display("You do not have enough TP to travel here. Please go back and try again when you get more TP.", "Travel To");
|
||||
}
|
||||
$mapped = explode(",",user()->towns);
|
||||
if (!in_array($id, $mapped)) { display("Cheat attempt detected.<br><br>Get a life, loser.", "Error"); }
|
||||
}
|
||||
|
||||
if ((user()->latitude == $townrow["latitude"]) && (user()->longitude == $townrow["longitude"])) {
|
||||
display("You are already in this town. <a href=\"/\">Click here</a> to return to the main town screen.", "Travel To");
|
||||
return display("You are already in this town. <a href=\"/\">Click here</a> to return to the main town screen.", "Travel To");
|
||||
}
|
||||
|
||||
$newtp = ($usepoints) ? user()->currenttp - $townrow["travelpoints"] : user()->currenttp;
|
||||
|
||||
$newlat = $townrow["latitude"];
|
||||
$newlon = $townrow["longitude"];
|
||||
$newid = user()->id;
|
||||
|
||||
// If they got here by exploring, add this town to their map.
|
||||
$mapped = explode(",",user()->towns);
|
||||
|
@ -406,12 +400,13 @@ function travelto($id, bool $usepoints = true)
|
|||
$mapped = implode(",", $mapped);
|
||||
if ($town == false) $mapped .= ",$id";
|
||||
|
||||
$mapped = "towns='".$mapped."',";
|
||||
|
||||
db()->query("UPDATE users SET currentaction='In Town',$mapped currenttp=?, latitude=?, longitude=? WHERE id=?;", [
|
||||
$newtp, $newlat, $newlon, $newid
|
||||
]);
|
||||
user()->currentaction = 'In Town';
|
||||
user()->towns = $mapped;
|
||||
user()->currenttp = $newtp;
|
||||
user()->longitude = $newlon;
|
||||
user()->latitude = $newlat;
|
||||
user()->save();
|
||||
|
||||
$page = "You have travelled to ".$townrow["name"].". You may now <a href=\"/\">enter this town</a>.";
|
||||
display($page, "Travel To");
|
||||
return display($page, "Travel To");
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ function login()
|
|||
redirect('/');
|
||||
}
|
||||
|
||||
display(render('login'), 'Log In', true, false, false);
|
||||
return display(render('login'), 'Log In', true, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +109,7 @@ function register()
|
|||
$page = render('register', ['controlrow' => $controlrow]);
|
||||
}
|
||||
|
||||
display($page, 'Register', true, false, false);
|
||||
return display($page, 'Register', true, false, false);
|
||||
}
|
||||
|
||||
function verify()
|
||||
|
@ -124,10 +124,10 @@ function verify()
|
|||
|
||||
db()->query("UPDATE users SET verify='g2g' WHERE username=?;", [$u]);
|
||||
|
||||
display("Your account was verified successfully.<br><br>You may now continue to the <a href=\"/login\">Login Page</a> and start playing the game.<br><br>Thanks for playing!","Verify Email",false,false,false);
|
||||
return display("Your account was verified successfully.<br><br>You may now continue to the <a href=\"/login\">Login Page</a> and start playing the game.<br><br>Thanks for playing!","Verify Email",false,false,false);
|
||||
}
|
||||
|
||||
display(render('verify'), "Verify Email", true, false, false);
|
||||
return display(render('verify'), "Verify Email", true, false, false);
|
||||
}
|
||||
|
||||
function lostpassword()
|
||||
|
@ -143,13 +143,13 @@ function lostpassword()
|
|||
db()->query('UPDATE users SET password=? WHERE email=?;', [$hashed, $e]);
|
||||
|
||||
if (sendpassemail($e, $newpass)) {
|
||||
display("Your new password was emailed to the address you provided.<br><br>Once you receive it, you may <a href=\"/login\">Log In</a> and continue playing.<br><br>Thank you.","Lost Password",false,false,false);
|
||||
return display("Your new password was emailed to the address you provided.<br><br>Once you receive it, you may <a href=\"/login\">Log In</a> and continue playing.<br><br>Thank you.","Lost Password",false,false,false);
|
||||
} else {
|
||||
display("There was an error sending your new password.<br><br>Please check with the game administrator for more information.<br><br>We apologize for the inconvience.","Lost Password",false,false,false);
|
||||
return display("There was an error sending your new password.<br><br>Please check with the game administrator for more information.<br><br>We apologize for the inconvience.","Lost Password",false,false,false);
|
||||
}
|
||||
}
|
||||
|
||||
display(render('lostpassword'), "Lost Password", true, false, false);
|
||||
return display(render('lostpassword'), "Lost Password", true, false, false);
|
||||
}
|
||||
|
||||
function changepassword()
|
||||
|
@ -179,10 +179,10 @@ function changepassword()
|
|||
|
||||
set_cookie('dkgame', '', -3600);
|
||||
|
||||
display("Your password was changed successfully.<br><br>You have been logged out of the game to avoid errors.<br><br>Please <a href=\"/login\">log back in</a> to continue playing.","Change Password",false,false,false);
|
||||
return display("Your password was changed successfully.<br><br>You have been logged out of the game to avoid errors.<br><br>Please <a href=\"/login\">log back in</a> to continue playing.","Change Password",false,false,false);
|
||||
}
|
||||
|
||||
display(render('changepassword'), "Change Password", true, false, false);
|
||||
return display(render('changepassword'), "Change Password", true, false, false);
|
||||
}
|
||||
|
||||
function settings()
|
||||
|
@ -198,10 +198,10 @@ function settings()
|
|||
user()->save();
|
||||
|
||||
$alert = '<div class="alert">Settings updated</div>';
|
||||
display($alert . render('settings'), "Account Settings");
|
||||
return display($alert . render('settings'), "Account Settings");
|
||||
}
|
||||
|
||||
display(render('settings'), "Account Settings");
|
||||
return display(render('settings'), "Account Settings");
|
||||
}
|
||||
|
||||
function sendpassemail($emailaddress, $password)
|
||||
|
|
|
@ -27,7 +27,7 @@ if (!file_exists('../.installed') && $uri[0] !== 'install') {
|
|||
redirect('/install');
|
||||
} elseif (file_exists(('../.installed')) && $uri[0] === 'install') {
|
||||
redirect('/');
|
||||
} else {
|
||||
} elseif (file_exists(('../.installed')) && $uri[0] !== 'install') {
|
||||
$controlrow = get_control_row();
|
||||
|
||||
if (!$controlrow["gameopen"]) {
|
||||
|
|
38
src/lib.php
38
src/lib.php
|
@ -107,45 +107,13 @@ function display($content, $title, bool $topnav = true, bool $leftnav = true, bo
|
|||
{
|
||||
global $controlrow;
|
||||
|
||||
$game_skin = 0;
|
||||
|
||||
$topnav = $topnav ? Render\header_links() : '';
|
||||
|
||||
if (user() !== false) {
|
||||
$game_skin = user()->game_skin;
|
||||
|
||||
if (user()->currentaction == 'In Town') {
|
||||
$town = get_town_by_xy(user()->latitude, user()->longitude);
|
||||
$current_town = "Welcome to <b>{$town['name']}</b>.<br><br>";
|
||||
} else {
|
||||
$current_town = '';
|
||||
}
|
||||
|
||||
// Format various userrow stuffs...
|
||||
if (user()->latitude < 0) { user()->latitude = user()->latitude * -1 . "S"; } else { user()->latitude .= "N"; }
|
||||
if (user()->longitude < 0) { user()->longitude = user()->longitude * -1 . "W"; } else { user()->longitude .= "E"; }
|
||||
|
||||
// Travel To list.
|
||||
$townslist = explode(",",user()->towns);
|
||||
$townquery2 = db()->query('SELECT * FROM towns ORDER BY id;');
|
||||
$town_list_html = '';
|
||||
while ($townrow2 = $townquery2->fetchArray(SQLITE3_ASSOC)) {
|
||||
$town = false;
|
||||
foreach($townslist as $id) {
|
||||
if ($id == $townrow2["id"]) { $town = true; }
|
||||
}
|
||||
if ($town == true) {
|
||||
$town_list_html .= "<a href=\"/gotown/{$townrow2["id"]}\">".$townrow2["name"]."</a><br>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$game_skin = user() !== false ? user()->game_skin : 0;
|
||||
|
||||
return render('layouts/primary', [
|
||||
"dkgamename" => $controlrow["gamename"],
|
||||
"content" => $content,
|
||||
"game_skin" => $game_skin,
|
||||
"leftnav" => $leftnav ? render('leftnav', ['town_list' => $town_list_html, 'current_town' => $current_town]) : '',
|
||||
"topnav" => $topnav,
|
||||
"topnav" => $topnav ? Render\header_links() : ''
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -555,6 +523,8 @@ function get_spells_from_list(array|string $spell_ids): array|false
|
|||
function generate_stat_bar(int $current, int $max): string
|
||||
{
|
||||
$percent = $max > 0 ? round(max(0, $current) / $max * 100, 4) : 0;
|
||||
if ($percent < 0) $percent = 0;
|
||||
if ($percent > 100) $percent = 100;
|
||||
$color = $percent >= 66 ? 'green' : ($percent >= 33 ? 'yellow' : 'red');
|
||||
|
||||
return <<<HTML
|
||||
|
|
|
@ -39,6 +39,15 @@ function right_nav(): string
|
|||
return $template;
|
||||
}
|
||||
|
||||
function left_nav(): string
|
||||
{
|
||||
if (user() === false) return '';
|
||||
|
||||
$template = render('left_nav');
|
||||
if (is_htmx()) $template = '<section id="left" hx-swap-oob="true">'.$template."</section>";
|
||||
return $template;
|
||||
}
|
||||
|
||||
function babblebox(): string
|
||||
{
|
||||
return render('babblebox', ['messages' => babblebox_messages()]);
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
</header>
|
||||
|
||||
<main>
|
||||
<section id="left"><?= $leftnav ?></section>
|
||||
<section id="left"><?= Render\left_nav() ?></section>
|
||||
<section id="middle"><?= $content ?></section>
|
||||
<section id="right"><?= Render\right_nav() ?></section>
|
||||
</main>
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
<section>
|
||||
<div class="title"><img src="/img/button_location.gif" alt="Location" title="Location"></div>
|
||||
Currently: <?= user()->currentaction ?><br>
|
||||
Latitude: <?= user()->latitude ?><br>
|
||||
Longitude: <?= user()->longitude ?><br>
|
||||
<?php
|
||||
$lat = user()->latitude;
|
||||
$lon = user()->longitude;
|
||||
if ($lat < 0) { $lat = ($lat * -1) . "S"; } else { $lat .= "N"; }
|
||||
if ($lon < 0) { $lon = ($lon * -1) . "W"; } else { $lon .= "E"; }
|
||||
?>
|
||||
Latitude: <?= $lat ?><br>
|
||||
Longitude: <?= $lon ?><br>
|
||||
<a href="javascript:openmappopup()">View Map</a><br>
|
||||
<form action="/move" method="post" class="move-compass">
|
||||
<button type="submit" name="direction" value="north" class="north">North</button>
|
||||
|
@ -17,13 +23,24 @@
|
|||
<section>
|
||||
<div class="title"><img src="/img/button_towns.gif" alt="Towns" title="Towns"></div>
|
||||
<?php
|
||||
if (user()->currentaction == 'In Town') {
|
||||
$town = get_town_by_xy((int) user()->latitude, (int) user()->longitude);
|
||||
echo "Welcome to <b>{$town['name']}</b>.<br><br>";
|
||||
}
|
||||
if (user()->currentaction == 'In Town') {
|
||||
$town = get_town_by_xy((int) user()->latitude, (int) user()->longitude);
|
||||
echo "Welcome to <b>{$town['name']}</b>.<br><br>";
|
||||
}
|
||||
?>
|
||||
Travel To:<br>
|
||||
<?= $town_list ?>
|
||||
<?php
|
||||
$town_list = explode(",", user()->towns);
|
||||
$towns = db()->query('SELECT * FROM towns ORDER BY id;');
|
||||
$mapped = false;
|
||||
while ($row = $towns->fetchArray(SQLITE3_ASSOC)) {
|
||||
$mapped = true;
|
||||
if (in_array($row['id'], $town_list)) {
|
||||
echo "<a href=\"/gotown/{$row["id"]}\">".$row["name"]."</a><br>";
|
||||
}
|
||||
}
|
||||
if (!$mapped) echo 'You have no towns mapped.';
|
||||
?>
|
||||
</section>
|
||||
|
||||
<section>
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
<section>
|
||||
<div class="title"><img src="/img/button_inventory.gif" alt="Inventory" title="Inventory"></div>
|
||||
<img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon"> Weapon: <?= user()->weaponname ?><br>
|
||||
<img src="/img/icon_armor.gif" alt="Armor" title="Armor"> Armor: <?= user()->armorname ?><br>
|
||||
<img src="/img/icon_shield.gif" alt="Shield" title="Shield"> Shield: <?= user()->shieldname ?><br>
|
||||
<img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon"> <?= user()->weaponname ?><br>
|
||||
<img src="/img/icon_armor.gif" alt="Armor" title="Armor"> <?= user()->armorname ?><br>
|
||||
<img src="/img/icon_shield.gif" alt="Shield" title="Shield"> <?= user()->shieldname ?><br>
|
||||
Slot 1: <?= user()->slot1name ?><br>
|
||||
Slot 2: <?= user()->slot2name ?><br>
|
||||
Slot 3: <?= user()->slot3name ?>
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
</div>
|
||||
|
||||
<div class="news">
|
||||
<?= $town['news'] ?>
|
||||
<?= $news ?>
|
||||
</div>
|
||||
|
||||
<div class="whos-online">
|
||||
<?= $town['whosonline'] ?>
|
||||
<?= $whos_online ?>
|
||||
</div>
|
||||
|
||||
<div class="babblebox">
|
||||
|
|
Loading…
Reference in New Issue
Block a user