Repair most of fight
This commit is contained in:
parent
9348c17179
commit
98204ee9f1
131
src/fight.php
131
src/fight.php
|
@ -1,26 +1,27 @@
|
|||
<?php // fight.php :: Handles all fighting action.
|
||||
<?php
|
||||
|
||||
function fight() { // One big long function that determines the outcome of the fight.
|
||||
// fight.php :: Handles all fighting action.
|
||||
|
||||
global $userrow, $controlrow;
|
||||
if ($userrow["currentaction"] != "Fighting") { display("Cheat attempt detected.<br><br>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.<br><br>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"] .= "<option value=\"".$spellrow["id"]."\">".$spellrow["name"]."</option>\n";
|
||||
}
|
||||
foreach ($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
|
||||
if ($spell == true) $pagearray["magiclist"] .= "<option value=\"".$spellrow["id"]."\">".$spellrow["name"]."</option>\n";
|
||||
unset($spell);
|
||||
}
|
||||
if ($pagearray["magiclist"] == "") { $pagearray["magiclist"] = "<option value=\"0\">None</option>\n"; }
|
||||
if ($pagearray["magiclist"] == "") $pagearray["magiclist"] = "<option value=\"0\">None</option>\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"] . "<br><br>";
|
||||
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"] . "<br><br>";
|
||||
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
|
||||
Command?<br><br>
|
||||
<form action="index.php?do=fight" method="post">
|
||||
<input type="submit" name="fight" value="Fight" /><br><br>
|
||||
<select name="userspell"><option value="0">Choose One</option>$magiclist</select> <input type="submit" name="spell" value="Spell" /><br><br>
|
||||
<input type="submit" name="run" value="Run" /><br><br>
|
||||
</form>
|
||||
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"] = "<b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time.";
|
||||
}
|
||||
if ($playerisdead != 1) {
|
||||
$pagearray["command"] = <<<HTML
|
||||
Command?<br><br>
|
||||
<form action="index.php?do=fight" method="post">
|
||||
<input type="submit" name="fight" value="Fight" /><br><br>
|
||||
<select name="userspell"><option value="0">Choose One</option>$magiclist</select> <input type="submit" name="spell" value="Spell" /><br><br>
|
||||
<input type="submit" name="run" value="Run" /><br><br>
|
||||
</form>
|
||||
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"] = "<b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href=\"index.php\">town</a>, 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 = "<b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time.";
|
||||
|
||||
function dead()
|
||||
{
|
||||
return <<<HTML
|
||||
<b>You have died.</b><br><br>
|
||||
As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points
|
||||
to continue your journey.<br><br>
|
||||
You may now continue back to <a href="index.php">town</a>, and we hope you fair better next time.
|
||||
HTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue
Block a user