diff --git a/src/fight.php b/src/fight.php
index b2a4ad2..d8a47aa 100644
--- a/src/fight.php
+++ b/src/fight.php
@@ -1,26 +1,27 @@
- Get a life, loser.", "Error"); }
+/**
+ * One big long function that determines the outcome of the fight.
+ */
+function fight()
+{
+ global $userrow;
+ if ($userrow["currentaction"] != "Fighting") display("Cheat attempt detected.
Get a life, loser.", "Error");
$pagearray = array();
$playerisdead = 0;
$pagearray["magiclist"] = "";
- $userspells = explode(",",$userrow["spells"]);
- $spellquery = doquery("SELECT id,name FROM {{table}}", "spells");
- while ($spellrow = mysql_fetch_array($spellquery)) {
+ $userspells = explode(",", $userrow["spells"]);
+ $spellquery = db()->query('SELECT id, name FROM spells ORDER BY id;');
+ while ($spellrow = $spellquery->fetchArray(SQLITE3_ASSOC)) {
$spell = false;
- foreach ($userspells as $a => $b) {
- if ($b == $spellrow["id"]) { $spell = true; }
- }
- if ($spell == true) {
- $pagearray["magiclist"] .= "\n";
- }
+ foreach ($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
+ if ($spell == true) $pagearray["magiclist"] .= "\n";
unset($spell);
}
- if ($pagearray["magiclist"] == "") { $pagearray["magiclist"] = "\n"; }
+ if ($pagearray["magiclist"] == "") $pagearray["magiclist"] = "\n";
$magiclist = $pagearray["magiclist"];
$chancetoswingfirst = 1;
@@ -37,8 +38,9 @@ function fight() { // One big long function that determines the outcome of the f
// Pick a monster.
- $monsterquery = doquery("SELECT * FROM {{table}} WHERE level>='$minlevel' AND level<='$maxlevel' ORDER BY RAND() LIMIT 1", "monsters");
- $monsterrow = mysql_fetch_array($monsterquery);
+ $monsterrow = 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((($monsterrow["maxhp"]/5)*4),$monsterrow["maxhp"]);
$userrow["currentmonstersleep"] = 0;
@@ -49,12 +51,10 @@ function fight() { // One big long function that determines the outcome of the f
unset($monsterquery);
unset($monsterrow);
-
}
// Next, get the monster statistics.
- $monsterquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["currentmonster"]."' LIMIT 1", "monsters");
- $monsterrow = mysql_fetch_array($monsterquery);
+ $monsterrow = get_monster($userrow['currentmonster']);
$pagearray["monstername"] = $monsterrow["name"];
// Do run stuff.
@@ -96,15 +96,16 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
- $updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
+ 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']
+ ]);
$playerisdead = 1;
}
}
}
- $updatequery = doquery("UPDATE {{table}} SET currentaction='Exploring' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
- header("Location: index.php");
- die();
+ db()->query("UPDATE users SET currentaction='Exploring' WHERE id=?;", [$userrow['id']]);
+ redirect('index.php');
// Do fight stuff.
} elseif (isset($_POST["fight"])) {
@@ -130,9 +131,8 @@ function fight() { // One big long function that determines the outcome of the f
$userrow["currentmonsterhp"] -= $monsterdamage;
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "
";
if ($userrow["currentmonsterhp"] <= 0) {
- $updatequery = doquery("UPDATE {{table}} SET currentmonsterhp='0' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
- header("Location: index.php?do=victory");
- die();
+ db()->query('UPDATE users SET currentmonsterhp=0 WHERE id=?;', [$userrow['id']]);
+ redirect('index.php?do=victory');
}
// Monster's turn.
@@ -166,8 +166,10 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
- $updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
- $playerisdead = 1;
+ 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']
+ ]);
+ $playerisdead = 1;
}
}
@@ -178,8 +180,7 @@ function fight() { // One big long function that determines the outcome of the f
$pickedspell = $_POST["userspell"];
if ($pickedspell == 0) { display("You must select a spell first. Please go back and try again.", "Error"); die(); }
- $newspellquery = doquery("SELECT * FROM {{table}} WHERE id='$pickedspell' LIMIT 1", "spells");
- $newspellrow = mysql_fetch_array($newspellquery);
+ $newspellrow = get_spell($pickedspell);
$spell = false;
foreach($userspells as $a => $b) {
if ($b == $pickedspell) { $spell = true; }
@@ -222,9 +223,10 @@ function fight() { // One big long function that determines the outcome of the f
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "
";
if ($userrow["currentmonsterhp"] <= 0) {
- $updatequery = doquery("UPDATE {{table}} SET currentmonsterhp='0',currenthp='".$userrow["currenthp"]."',currentmp='".$userrow["currentmp"]."' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
- header("Location: index.php?do=victory");
- die();
+ db()->query('UPDATE users SET currentmonsterhp=0, currenthp=?, currentmp=? WHERE id=?;', [
+ $userrow['currenthp'], $userrow['currentmp'], $userrow['id']
+ ]);
+ redirect('index.php?do=victory');
}
// Monster's turn.
@@ -258,8 +260,10 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
- $updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
- $playerisdead = 1;
+ 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']
+ ]);
+ $playerisdead = 1;
}
}
@@ -297,8 +301,10 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4);
- $updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
- $playerisdead = 1;
+ 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']
+ ]);
+ $playerisdead = 1;
}
}
@@ -319,26 +325,25 @@ function fight() { // One big long function that determines the outcome of the f
$newhp = $userrow["currenthp"];
$newmp = $userrow["currentmp"];
-if ($playerisdead != 1) {
-$pagearray["command"] = <<
-
-END;
- $updatequery = doquery("UPDATE {{table}} SET currentaction='Fighting',currenthp='$newhp',currentmp='$newmp',currentfight='$newfight',currentmonster='$newmonster',currentmonsterhp='$newmonsterhp',currentmonstersleep='$newmonstersleep',currentmonsterimmune='$newmonsterimmune',currentuberdamage='$newuberdamage',currentuberdefense='$newuberdefense' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
-} 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.";
-}
+ if ($playerisdead != 1) {
+ $pagearray["command"] = <<
+
+ HTML;
+
+ db()->query("UPDATE users SET currentaction='Fighting', currenthp=?, currentmp=?, currentfight=?, currentmonster=?, currentmonsterhp=?, currentmonstersleep=?, currentmonsterimmune=?, currentuberdamage=?, currentuberdefense=? WHERE id=?;", [
+ $newhp, $newmp, $newfight, $newmonster, $newmonsterhp, $newmonstersleep, $newmonsterimmune, $newuberdamage, $newuberdefense, $userrow['id']
+ ]);
+ } 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.";
+ }
// Finalize page and display it.
- $template = gettemplate("fight");
- $page = parsetemplate($template,$pagearray);
-
- display($page, "Fighting");
-
+ display(parsetemplate(gettemplate("fight"), $pagearray), "Fighting");
}
function victory() {
@@ -515,12 +520,12 @@ function drop() {
}
-function dead() {
-
- $page = "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.";
-
+function dead()
+{
+ return <<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.
+ HTML;
}
-
-
-
-?>