From 5fa648ab7b1a010a1020c583a1a7e4671431ba85 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Wed, 18 Dec 2024 17:00:23 -0600 Subject: [PATCH] Continue updating rendering and user access --- public/css/help.css | 2 +- public/index.php | 3 +- src/actions/explore.php | 26 +- src/actions/fight.php | 354 +++++++++++------------- src/actions/forum.php | 12 +- src/actions/heal.php | 12 +- src/actions/help.php | 12 +- src/actions/towns.php | 71 +++-- src/actions/users.php | 22 +- src/bootstrap.php | 2 +- src/lib.php | 38 +-- src/render.php | 9 + templates/layouts/primary.php | 2 +- templates/{leftnav.php => left_nav.php} | 31 ++- templates/right_nav.php | 6 +- templates/towns.php | 4 +- 16 files changed, 286 insertions(+), 320 deletions(-) rename templates/{leftnav.php => left_nav.php} (60%) diff --git a/public/css/help.css b/public/css/help.css index ea0a07e..f5331aa 100644 --- a/public/css/help.css +++ b/public/css/help.css @@ -8,7 +8,7 @@ html { } body { - background-image: url('/img/backgrounds/background.jpg'); + background-image: url('/img/backgrounds/classic.jpg'); padding: 2rem; } table { diff --git a/public/index.php b/public/index.php index 8ac8a0c..e4b3e56 100644 --- a/public/index.php +++ b/public/index.php @@ -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 .= ''.page_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; diff --git a/src/actions/explore.php b/src/actions/explore.php index 37251c5..bf7efa8 100644 --- a/src/actions/explore.php +++ b/src/actions/explore.php @@ -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('/'); } diff --git a/src/actions/fight.php b/src/actions/fight.php index 4097603..21be638 100644 --- a/src/actions/fight.php +++ b/src/actions/fight.php @@ -20,56 +20,55 @@ function register_routes(Router $r): Router */ function fight() { - global $userrow; - if ($userrow["currentaction"] != "Fighting") display("Cheat attempt detected.

Get a life, loser.", "Error"); + if (user()->currentaction !== 'Fighting') exit('Cheat attempt detected.

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"] .= "\n"; - } - } - $pagearray["magiclist"] = $pagearray["magiclist"] ?: "\n"; - $magiclist = $pagearray["magiclist"]; + // Generate spell list + $user_spells = user()->spells(); + if (!empty($user_spells)) { + $page['magiclist'] = '

'; + } // 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!

"; - $pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "

"; + $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!

"; + $page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "

"; // 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!
"; + $page["yourturn"] .= "Excellent hit!
"; } - $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.
"; + $page["yourturn"] .= "The monster is dodging. No damage has been scored.
"; } - 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.

"; - $pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "

"; + user()->currentmonsterhp -= $monsterdamage; + $page["yourturn"] .= "You attack the monster for $monsterdamage damage.

"; + $page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "

"; // 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"] . "

"; + $page["yourturn"] = handleSpellCast($userrow, $newspellrow); + $page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "

"; // 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!

"; - $pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "

"; - $pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow); + $page["yourturn"] = "The monster attacks before you are ready!

"; + $page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "

"; + $page["monsterturn"] = handleMonsterTurn($userrow, $monster); } // Prepare command or death message if ($playerisdead != 1) { - $pagearray["command"] = <<
-

-

-

+

+ {$page['magiclist']} +

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"] = "You have died.

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.

You may now continue back to town, 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.
"; } else { $spelltext = ""; $newspell=""; } - $page = "Congratulations. You have defeated the ".$monsterrow["name"].".
You gain $exp experience. $warnexp
You gain $gold gold. $warngold

You have gained a level!

You gain ".$levelrow[$userrow["charclass"]."_hp"]." hit points.
You gain ".$levelrow[$userrow["charclass"]."_mp"]." magic points.
You gain ".$levelrow[$userrow["charclass"]."_tp"]." travel points.
You gain ".$levelrow[$userrow["charclass"]."_strength"]." strength.
You gain ".$levelrow[$userrow["charclass"]."_dexterity"]." dexterity.
$spelltext
You can now continue exploring."; + $page = "Congratulations. You have defeated the ".$monsterrow["name"].".
You gain $exp experience. $warnexp
You gain $gold gold. $warngold

You have gained a level!

You gain ".$levelrow[user()->charclass."_hp"]." hit points.
You gain ".$levelrow[user()->charclass."_mp"]." magic points.
You gain ".$levelrow[user()->charclass."_tp"]." travel points.
You gain ".$levelrow[user()->charclass."_strength"]." strength.
You gain ".$levelrow[user()->charclass."_dexterity"]." dexterity.
$spelltext
You can now continue exploring."; $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"].".
You gain $exp experience. $warnexp
You gain $gold gold. $warngold

"; 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 exploring.", "Item Drop"); + user()->save(); + return display("The item has been equipped. You can now continue exploring.", "Item Drop"); } $attributearray = array("maxhp"=>"Max HP", @@ -370,10 +346,10 @@ function drop() } $page .= "
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 .= "
"; + $page .= "
"; $page .= "You may also choose to just continue exploring and give up this item."; - display($page, "Item Drop"); + return display($page, "Item Drop"); } @@ -385,45 +361,45 @@ function dead() to continue your journey.

You may now continue back to town, 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.
"; } else { $pagearray .= "The monster is still asleep.
"; } } - 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.
"; $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.

"; - $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.

"; 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.

"; } else { $pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.

"; } - $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.

"; } else { $pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.

"; } - $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.

"; 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.

"; break; } diff --git a/src/actions/forum.php b/src/actions/forum.php index c95b3fd..a587229 100644 --- a/src/actions/forum.php +++ b/src/actions/forum.php @@ -34,7 +34,7 @@ function donothing($start = 0) $page .= ""; - display($page, "Forum"); + return display($page, "Forum"); } function showthread($id, $start) @@ -49,7 +49,7 @@ function showthread($id, $start) $page .= "
"; $page .= "
Reply To This Thread:

"; - 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 = "
Make A New Post:

Title:


Message:


"; - display($page, "Forum"); + return display($page, "Forum"); } diff --git a/src/actions/heal.php b/src/actions/heal.php index dca06da..acb8bd1 100644 --- a/src/actions/heal.php +++ b/src/actions/heal.php @@ -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 exploring.", "Healing Spell"); + return display("You have cast the ".$spellrow["name"]." spell, and gained ".$spellrow["attribute"]." Hit Points. You can now continue exploring.", "Healing Spell"); } diff --git a/src/actions/help.php b/src/actions/help.php index c3246ac..31d4cda 100644 --- a/src/actions/help.php +++ b/src/actions/help.php @@ -246,7 +246,7 @@ function main() [ Top ] HTML; - display_help(parse($page, $controlrow)); + return display_help(parse($page, $controlrow)); } function items() @@ -313,7 +313,7 @@ function items() } $page .= ''; - display_help($page); + return display_help($page); } @@ -349,7 +349,7 @@ function spells() HTML; - display_help($page); + return display_help($page); } function monsters() @@ -368,7 +368,7 @@ function monsters() $page .= "".$m["name"]."".$m["maxhp"]."".$m["maxdam"]."".$m["armor"]."".$m["level"]."".$m["maxexp"]."".$m["maxgold"]."$immune\n"; } - display_help($page.''); + return display_help($page.''); } 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, diff --git a/src/actions/towns.php b/src/actions/towns.php index 4b1f6b8..26a461b 100644 --- a/src/actions/towns.php +++ b/src/actions/towns.php @@ -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"] = '
Latest News
'; - $townrow["news"] .= "[".pretty_date($newsrow["postdate"])."]
".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'] = <<Latest News + $news_date
+ $news_content + HTML; } // Who's Online. Currently just members. Guests maybe later. - if ($controlrow["showonline"] == 1) { + if ($controlrow['showonline'] === 1) { $onlinequery = db()->query(<<= 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[] = "".$onlinerow["username"].""; } - $townrow["whosonline"] = '
Who\'s Online
'; - $townrow["whosonline"] .= "There are $online_count user(s) online within the last 10 minutes: "; - $townrow["whosonline"] .= rtrim(implode(', ', $online_rows), ', '); - } - - if ($controlrow["showbabble"] == 1) { - $townrow["babblebox"] = <<Babble Box - + $online_rows = implode(', ', $online_rows); + $page['whos_online'] = <<Who's Online + There are $online_count 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.

Get a life, loser.", "Error"); } } if ((user()->latitude == $townrow["latitude"]) && (user()->longitude == $townrow["longitude"])) { - display("You are already in this town. Click here to return to the main town screen.", "Travel To"); + return display("You are already in this town. Click here 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 enter this town."; - display($page, "Travel To"); + return display($page, "Travel To"); } diff --git a/src/actions/users.php b/src/actions/users.php index c26c2bb..b629765 100644 --- a/src/actions/users.php +++ b/src/actions/users.php @@ -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.

You may now continue to the Login Page and start playing the game.

Thanks for playing!","Verify Email",false,false,false); + return display("Your account was verified successfully.

You may now continue to the Login Page and start playing the game.

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.

Once you receive it, you may Log In and continue playing.

Thank you.","Lost Password",false,false,false); + return display("Your new password was emailed to the address you provided.

Once you receive it, you may Log In and continue playing.

Thank you.","Lost Password",false,false,false); } else { - display("There was an error sending your new password.

Please check with the game administrator for more information.

We apologize for the inconvience.","Lost Password",false,false,false); + return display("There was an error sending your new password.

Please check with the game administrator for more information.

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.

You have been logged out of the game to avoid errors.

Please log back in to continue playing.","Change Password",false,false,false); + return display("Your password was changed successfully.

You have been logged out of the game to avoid errors.

Please log back in 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 = '
Settings updated
'; - 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) diff --git a/src/bootstrap.php b/src/bootstrap.php index 0c52d5a..88ac6bb 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -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"]) { diff --git a/src/lib.php b/src/lib.php index 19031b3..7b0edf1 100644 --- a/src/lib.php +++ b/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 {$town['name']}.

"; - } 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 .= "".$townrow2["name"]."
\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 <<"; + return $template; +} + function babblebox(): string { return render('babblebox', ['messages' => babblebox_messages()]); diff --git a/templates/layouts/primary.php b/templates/layouts/primary.php index cfe7be5..adf990a 100644 --- a/templates/layouts/primary.php +++ b/templates/layouts/primary.php @@ -28,7 +28,7 @@
-
+
diff --git a/templates/leftnav.php b/templates/left_nav.php similarity index 60% rename from templates/leftnav.php rename to templates/left_nav.php index f405321..bc9ee57 100644 --- a/templates/leftnav.php +++ b/templates/left_nav.php @@ -1,8 +1,14 @@
Location
Currently: currentaction ?>
- Latitude: latitude ?>
- Longitude: longitude ?>
+ 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:
+ Longitude:
View Map
@@ -17,13 +23,24 @@
Towns
currentaction == 'In Town') { - $town = get_town_by_xy((int) user()->latitude, (int) user()->longitude); - echo "Welcome to {$town['name']}.

"; - } + if (user()->currentaction == 'In Town') { + $town = get_town_by_xy((int) user()->latitude, (int) user()->longitude); + echo "Welcome to {$town['name']}.

"; + } ?> Travel To:
- + 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 "".$row["name"]."
"; + } + } + if (!$mapped) echo 'You have no towns mapped.'; + ?>
diff --git a/templates/right_nav.php b/templates/right_nav.php index 0e83c33..05e54a0 100644 --- a/templates/right_nav.php +++ b/templates/right_nav.php @@ -13,9 +13,9 @@
Inventory
- Weapon Weapon: weaponname ?>
- Armor Armor: armorname ?>
- Shield Shield: shieldname ?>
+ Weapon weaponname ?>
+ Armor armorname ?>
+ Shield shieldname ?>
Slot 1: slot1name ?>
Slot 2: slot2name ?>
Slot 3: slot3name ?> diff --git a/templates/towns.php b/templates/towns.php index 4ec1e01..693d906 100644 --- a/templates/towns.php +++ b/templates/towns.php @@ -10,11 +10,11 @@
- +
- +