From 9df90861e2d5b246547641b26a955510b4db5bc9 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Thu, 12 Dec 2024 10:20:49 -0600 Subject: [PATCH] Fix explore, refactor heal --- public/admin.php | 4 ++-- src/explore.php | 9 ++++----- src/heal.php | 45 ++++++++++++++++++++------------------------- src/lib.php | 10 ++++++++++ 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/public/admin.php b/public/admin.php index 806fbc7..3f25424 100644 --- a/public/admin.php +++ b/public/admin.php @@ -772,7 +772,7 @@ END; $class2name = $controlrow["class2name"]; $class3name = $controlrow["class3name"]; -$page = <<Edit Users

@@ -846,7 +846,7 @@ $page = << -END; +HTML; if ($row["authlevel"] == 0) { $row["auth0select"] = "selected=\"selected\" "; } else { $row["auth0select"] = ""; } if ($row["authlevel"] == 1) { $row["auth1select"] = "selected=\"selected\" "; } else { $row["auth1select"] = ""; } diff --git a/src/explore.php b/src/explore.php index ebc7b5e..87a8eba 100644 --- a/src/explore.php +++ b/src/explore.php @@ -15,12 +15,11 @@ function move() if (isset($_POST["east"])) { $longitude++; if ($longitude > $controlrow["gamesize"]) { $longitude = $controlrow["gamesize"]; } } if (isset($_POST["west"])) { $longitude--; if ($longitude < ($controlrow["gamesize"]*-1)) { $longitude = ($controlrow["gamesize"]*-1); } } - $townquery = db()->query('SELECT id FROM towns WHERE latitude = ? AND longitude = ? LIMIT 1;', [$latitude, $longitude]); - if ($townquery !== false) { - $townrow = $townquery->fetchArray(SQLITE3_ASSOC); + $town = get_town_by_xy($longitude, $latitude); + if ($town !== false) { require_once __DIR__ . '/towns.php'; - travelto($townrow["id"], false); - exit; + travelto($town['id'], false); + return; } $chancetofight = rand(1, 5); diff --git a/src/heal.php b/src/heal.php index 24ae715..9d03323 100644 --- a/src/heal.php +++ b/src/heal.php @@ -1,33 +1,28 @@ - $b) { - if ($b == $id) { $spell = true; } - } - if ($spell != true) { display("You have not yet learned this spell. Please go back and try again.", "Error"); die(); } - if ($spellrow["type"] != 1) { display("This is not a healing spell. Please go back and try again.", "Error"); die(); } - if ($userrow["currentmp"] < $spellrow["mp"]) { display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error"); die(); } - 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"); die(); } - if ($userrow["currenthp"] == $userrow["maxhp"]) { display("Your Hit Points are already full. You don't need to use a Healing spell now.", "Error"); die(); } - + 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"); + $newhp = $userrow["currenthp"] + $spellrow["attribute"]; if ($userrow["maxhp"] < $newhp) { $spellrow["attribute"] = $userrow["maxhp"] - $userrow["currenthp"]; $newhp = $userrow["currenthp"] + $spellrow["attribute"]; } $newmp = $userrow["currentmp"] - $spellrow["mp"]; - - $updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp', currentmp='$newmp' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); - - display("You have cast the ".$spellrow["name"]." spell, and gained ".$spellrow["attribute"]." Hit Points. You can now continue exploring.", "Healing Spell"); - die(); - -} -?> \ No newline at end of file + 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"); +} diff --git a/src/lib.php b/src/lib.php index 3fbc3b2..4e13a93 100644 --- a/src/lib.php +++ b/src/lib.php @@ -293,3 +293,13 @@ function get_item(int $id): array|false if ($query === false) return false; return $query->fetchArray(SQLITE3_ASSOC); } + +/** + * Get a spell by it's ID. + */ +function get_spell(int $id): array|false +{ + $query = db()->query('SELECT * FROM spells WHERE id=? LIMIT 1;', [$id]); + if ($query === false) return false; + return $query->fetchArray(SQLITE3_ASSOC); +}