";
+ $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!
";
// 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"] . "
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.
";
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.
";
- 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:
";
- 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 = '