Dragon-Knight/src/fight.php

465 lines
22 KiB
PHP
Raw Normal View History

2024-12-12 18:52:12 -06:00
<?php
2024-12-12 18:52:12 -06:00
// fight.php :: Handles all fighting action.
2024-12-12 18:52:12 -06:00
/**
* 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");
2024-12-12 21:28:19 -06:00
$pagearray = ["magiclist" => "", "yourturn" => "", "monsterturn" => "", "monsterhp" => "", "command" => ""];
$playerisdead = 0;
2024-12-12 21:28:19 -06:00
// Populate magic list
2024-12-12 18:52:12 -06:00
$userspells = explode(",", $userrow["spells"]);
2024-12-12 21:28:19 -06:00
$spellquery = db()->query('SELECT id, name FROM spells ORDER BY id;');
2024-12-12 18:52:12 -06:00
while ($spellrow = $spellquery->fetchArray(SQLITE3_ASSOC)) {
2024-12-12 21:28:19 -06:00
if (in_array($spellrow["id"], $userspells)) {
$pagearray["magiclist"] .= "<option value=\"{$spellrow["id"]}\">{$spellrow["name"]}</option>\n";
}
}
2024-12-12 21:28:19 -06:00
$pagearray["magiclist"] = $pagearray["magiclist"] ?: "<option value=\"0\">None</option>\n";
$magiclist = $pagearray["magiclist"];
2024-12-12 21:28:19 -06:00
// Determine initial combat parameters
$chancetoswingfirst = rand(1, 10) + (int)ceil(sqrt($userrow["dexterity"]));
if ($userrow["currentfight"] == 1) {
2024-12-12 21:28:19 -06:00
$maxlevel = (int)floor(max(abs($userrow["latitude"]) + 5, abs($userrow["longitude"]) + 5) / 5);
$minlevel = max(1, $maxlevel - 2);
2024-12-12 21:28:19 -06:00
$monsterrow = db()->query('SELECT * FROM monsters WHERE level >= ? AND level <= ? ORDER BY RANDOM() LIMIT 1;', [
$minlevel, $maxlevel
])->fetchArray(SQLITE3_ASSOC);
$userrow["currentmonster"] = $monsterrow["id"];
2024-12-12 21:28:19 -06:00
$userrow["currentmonsterhp"] = rand((int)(($monsterrow["maxhp"]/5)*4), $monsterrow["maxhp"]);
$userrow["currentmonstersleep"] = 0;
$userrow["currentmonsterimmune"] = $monsterrow["immune"];
2024-12-12 21:28:19 -06:00
$chancetoswingfirst = ($chancetoswingfirst > (rand(1,7) + (int)ceil(sqrt($monsterrow["maxdam"])))) ? 1 : 0;
}
2024-12-12 21:28:19 -06:00
// Get monster statistics
$monsterrow = get_monster($userrow['currentmonster']);
$pagearray["monstername"] = $monsterrow["name"];
2024-12-12 21:28:19 -06:00
// Run action
if (isset($_POST["run"])) {
2024-12-12 21:28:19 -06:00
$chancetorun = rand(4,10) + (int)ceil(sqrt($userrow["dexterity"]));
if ($chancetorun <= (rand(1,5) + (int)ceil(sqrt($monsterrow["maxdam"])))) {
2024-12-12 11:28:19 -06:00
$pagearray["yourturn"] = "You tried to run away, but were blocked in front!<br><br>";
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
2024-12-12 21:28:19 -06:00
// Monster turn logic (similar to original function)
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
2024-12-12 21:28:19 -06:00
db()->query("UPDATE users SET currentaction='Exploring' WHERE id=?;", [$userrow['id']]);
redirect('index.php');
}
}
// Fight action
if (isset($_POST["fight"])) {
// Player's attack
$min = (int)($userrow["attackpower"] * 0.75);
$max = (int)($userrow["attackpower"] / 3);
$tohit = (int)ceil(mt_rand(min($min, $max), max($min, $max)));
$toexcellent = rand(1,150);
2024-12-12 21:28:19 -06:00
if ($toexcellent <= sqrt($userrow["strength"])) {
$tohit *= 2;
$pagearray["yourturn"] .= "Excellent hit!<br>";
}
$min = (int)($monsterrow["armor"] * 0.75);
$max = (int)$monsterrow["armor"];
$toblock = (int)ceil(rand(min($min, $max), max($min, $max)) / 3);
$tododge = rand(1,200);
2024-12-12 21:28:19 -06:00
$monsterdamage = max(1, $tohit - $toblock);
if ($tododge <= sqrt($monsterrow["armor"])) {
$monsterdamage = 0;
2024-12-12 21:28:19 -06:00
$pagearray["yourturn"] .= "The monster is dodging. No damage has been scored.<br>";
}
2024-12-12 21:28:19 -06:00
if ($userrow["currentuberdamage"] != 0) {
$monsterdamage += (int)ceil($monsterdamage * ($userrow["currentuberdamage"]/100));
}
$userrow["currentmonsterhp"] -= $monsterdamage;
2024-12-12 21:28:19 -06:00
$pagearray["yourturn"] .= "You attack the monster for $monsterdamage damage.<br><br>";
2024-12-12 11:28:19 -06:00
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
2024-12-12 21:28:19 -06:00
// Check for monster defeat
if ($userrow["currentmonsterhp"] <= 0) {
2024-12-12 21:28:19 -06:00
db()->query('UPDATE users SET currentmonsterhp=0 WHERE id=?;', [$userrow['id']]);
2024-12-12 18:52:12 -06:00
redirect('index.php?do=victory');
}
2024-12-12 21:28:19 -06:00
// Monster's turn
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
}
2024-12-12 21:28:19 -06:00
// Spell action
if (isset($_POST["spell"])) {
$pickedspell = $_POST["userspell"];
2024-12-12 21:28:19 -06:00
if ($pickedspell == 0) {
display("You must select a spell first. Please go back and try again.", "Error");
die();
}
2024-12-12 21:28:19 -06:00
$newspellrow = get_spell($pickedspell);
$spell = in_array($pickedspell, $userspells);
if (!$spell) {
display("You have not yet learned this spell. Please go back and try again.", "Error");
die();
}
2024-12-12 21:28:19 -06:00
if ($userrow["currentmp"] < $newspellrow["mp"]) {
display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error");
die();
}
2024-12-12 21:28:19 -06:00
// Spell type handling (similar to original function)
$pagearray["yourturn"] = handleSpellCast($userrow, $newspellrow);
2024-12-12 11:28:19 -06:00
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
2024-12-12 21:28:19 -06:00
// Check for monster defeat
if ($userrow["currentmonsterhp"] <= 0) {
2024-12-12 21:28:19 -06:00
db()->query('UPDATE users SET currentmonsterhp=0, currenthp=?, currentmp=? WHERE id=?;', [
$userrow['currenthp'], $userrow['currentmp'], $userrow['id']
]);
2024-12-12 18:52:12 -06:00
redirect('index.php?do=victory');
}
2024-12-12 21:28:19 -06:00
// Monster's turn
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
}
2024-12-12 21:28:19 -06:00
// Monster's turn if player lost first swing
if (!isset($_POST["run"]) && !isset($_POST["fight"]) && !isset($_POST["spell"]) && $chancetoswingfirst == 0) {
2024-12-12 11:28:19 -06:00
$pagearray["yourturn"] = "The monster attacks before you are ready!<br><br>";
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
2024-12-12 21:28:19 -06:00
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
}
2024-12-12 21:28:19 -06:00
// Prepare command or death message
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=?;", [
$userrow['currenthp'],
$userrow['currentmp'],
$userrow['currentfight'] + 1,
$userrow['currentmonster'],
$userrow['currentmonsterhp'],
$userrow['currentmonstersleep'],
$userrow['currentmonsterimmune'],
$userrow['currentuberdamage'],
$userrow['currentuberdefense'],
$userrow['id']
]);
} else {
2024-12-12 21:28:19 -06:00
$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.";
}
2024-12-12 21:28:19 -06:00
// Finalize page and display it
2024-12-12 18:52:12 -06:00
display(parsetemplate(gettemplate("fight"), $pagearray), "Fighting");
}
2024-12-12 21:28:19 -06:00
function victory()
{
global $userrow;
if ($userrow["currentmonsterhp"] != 0) { header("Location: index.php?do=fight"); die(); }
if ($userrow["currentfight"] == 0) { header("Location: index.php"); die(); }
2024-12-12 21:10:24 -06:00
$monsterrow = get_monster($userrow['currentmonster']);
2024-12-12 21:28:19 -06:00
$min = (int)(($monsterrow["maxexp"] / 6) * 5);
$max = (int)$monsterrow["maxexp"];
$exp = mt_rand(min($min, $max), max($min, $max));
if ($exp < 1) { $exp = 1; }
2024-12-12 21:28:19 -06:00
if ($userrow["expbonus"] != 0) { $exp += ceil(($userrow["expbonus"]/100)*$exp); }
2024-12-12 21:28:19 -06:00
$min = (int)(($monsterrow["maxgold"] / 6) * 5);
$max = (int)$monsterrow["maxgold"];
$gold = mt_rand(min($min, $max), max($min, $max));
if ($gold < 1) { $gold = 1; }
2024-12-12 21:28:19 -06:00
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."; }
2024-12-12 21:10:24 -06:00
$levelrow = db()->query('SELECT * FROM levels WHERE id=? LIMIT 1;', [$userrow['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"];
$newlevel = $levelrow["id"];
if ($levelrow[$userrow["charclass"]."_spells"] != 0) {
$userspells = $userrow["spells"] . ",".$levelrow[$userrow["charclass"]."_spells"];
$newspell = "spells='$userspells',";
2024-12-12 11:28:19 -06:00
$spelltext = "You have learned a new spell.<br>";
} else { $spelltext = ""; $newspell=""; }
2024-12-12 11:28:19 -06:00
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br><b>You have gained a level!</b><br><br>You gain ".$levelrow[$userrow["charclass"]."_hp"]." hit points.<br>You gain ".$levelrow[$userrow["charclass"]."_mp"]." magic points.<br>You gain ".$levelrow[$userrow["charclass"]."_tp"]." travel points.<br>You gain ".$levelrow[$userrow["charclass"]."_strength"]." strength.<br>You gain ".$levelrow[$userrow["charclass"]."_dexterity"]." dexterity.<br>$spelltext<br>You can now continue <a href=\"index.php\">exploring</a>.";
$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 = "";
2024-12-12 11:28:19 -06:00
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br>";
2024-12-12 21:10:24 -06:00
if (rand(1, 30) === 1) {
$droprow = db()->query('SELECT * FROM drops WHERE mlevel <= ? ORDER BY RANDOM() LIMIT 1;', [$monsterrow['level']])->fetchArray(SQLITE3_ASSOC);
$dropcode = "dropcode='".$droprow["id"]."',";
$page .= "This monster has dropped an item. <a href=\"index.php?do=drop\">Click here</a> to reveal and equip the item, or you may also move on and continue <a href=\"index.php\">exploring</a>.";
} else {
$dropcode = "";
$page .= "You can now continue <a href=\"index.php\">exploring</a>.";
}
$title = "Victory!";
}
}
2024-12-12 21:10:24 -06:00
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']
]);
display($page, $title);
}
2024-12-12 21:10:24 -06:00
function drop()
{
global $userrow;
2024-12-12 21:10:24 -06:00
if ($userrow["dropcode"] == 0) redirect('index.php');
2024-12-12 21:10:24 -06:00
$droprow = get_drop($userrow['dropcode']);
if (isset($_POST["submit"])) {
$slot = $_POST["slot"];
if ($slot == 0) { display("Please go back and select an inventory slot to continue.","Error"); }
2024-12-12 21:10:24 -06:00
if ($userrow["slot{$slot}id"] != 0) {
$slotrow = get_drop($userrow["slot{$slot}id"]);
$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]; }
$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]; }
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"]; }
2024-12-12 21:10:24 -06:00
$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']
]);
} 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]; }
2024-12-12 21:10:24 -06:00
$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']
]);
}
2024-12-12 21:10:24 -06:00
display("The item has been equipped. You can now continue <a href=\"index.php\">exploring</a>.", "Item Drop");
}
$attributearray = array("maxhp"=>"Max HP",
"maxmp"=>"Max MP",
"maxtp"=>"Max TP",
"defensepower"=>"Defense Power",
"attackpower"=>"Attack Power",
"strength"=>"Strength",
"dexterity"=>"Dexterity",
"expbonus"=>"Experience Bonus",
"goldbonus"=>"Gold Bonus");
2024-12-12 11:28:19 -06:00
$page = "The monster dropped the following item: <b>".$droprow["name"]."</b><br><br>";
$page .= "This item has the following attribute(s):<br>";
$attribute1 = explode(",",$droprow["attribute1"]);
$page .= $attributearray[$attribute1[0]];
2024-12-12 11:28:19 -06:00
if ($attribute1[1] > 0) { $page .= " +" . $attribute1[1] . "<br>"; } else { $page .= $attribute1[1] . "<br>"; }
if ($droprow["attribute2"] != "X") {
$attribute2 = explode(",",$droprow["attribute2"]);
$page .= $attributearray[$attribute2[0]];
2024-12-12 11:28:19 -06:00
if ($attribute2[1] > 0) { $page .= " +" . $attribute2[1] . "<br>"; } else { $page .= $attribute2[1] . "<br>"; }
}
2024-12-12 11:28:19 -06:00
$page .= "<br>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 .= "<form action=\"index.php?do=drop\" method=\"post\"><select name=\"slot\"><option value=\"0\">Choose One</option><option value=\"1\">Slot 1: ".$userrow["slot1name"]."</option><option value=\"2\">Slot 2: ".$userrow["slot2name"]."</option><option value=\"3\">Slot 3: ".$userrow["slot3name"]."</option></select> <input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";
$page .= "You may also choose to just continue <a href=\"index.php\">exploring</a> and give up this item.";
display($page, "Item Drop");
}
2024-12-12 18:52:12 -06:00
function dead()
{
2024-12-12 21:28:19 -06:00
$page = <<<HTML
2024-12-12 18:52:12 -06:00
<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;
2024-12-12 21:28:19 -06:00
display($page, 'You Died');
}
function handleMonsterTurn(&$userrow, $monsterrow)
{
$pagearray = "";
if ($userrow["currentmonstersleep"] != 0) {
$chancetowake = rand(1,15);
if ($chancetowake > $userrow["currentmonstersleep"]) {
$userrow["currentmonstersleep"] = 0;
$pagearray .= "The monster has woken up.<br>";
} else {
$pagearray .= "The monster is still asleep.<br>";
}
}
if ($userrow["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);
$tododge = rand(1, 150);
if ($tododge <= sqrt($userrow["dexterity"])) {
$tohit = 0;
$pagearray .= "You dodge the monster's attack. No damage has been scored.<br>";
$persondamage = 0;
} else {
$persondamage = max(1, $tohit - $toblock);
if ($userrow["currentuberdefense"] != 0) {
$persondamage -= (int)ceil($persondamage * ($userrow["currentuberdefense"]/100));
}
$persondamage = max(1, $persondamage);
}
$pagearray .= "The monster attacks you for $persondamage damage.<br><br>";
$userrow["currenthp"] -= $persondamage;
if ($userrow["currenthp"] <= 0) {
$newgold = (int)ceil($userrow["gold"]/2);
$newhp = (int)ceil($userrow["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']
]);
dead();
}
}
return $pagearray;
}
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"];
$pagearray = "You have cast the {$newspellrow["name"]} spell, and gained {$newspellrow["attribute"]} Hit Points.<br><br>";
break;
case 2: // Hurt spell
if ($userrow["currentmonsterimmune"] == 0) {
$monsterdamage = mt_rand((int)(($newspellrow["attribute"]/6)*5), $newspellrow["attribute"]);
$userrow["currentmonsterhp"] -= $monsterdamage;
$pagearray = "You have cast the {$newspellrow["name"]} spell for $monsterdamage damage.<br><br>";
} else {
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
}
$userrow["currentmp"] -= $newspellrow["mp"];
break;
case 3: // Sleep spell
if ($userrow["currentmonsterimmune"] != 2) {
$userrow["currentmonstersleep"] = $newspellrow["attribute"];
$pagearray = "You have cast the {$newspellrow["name"]} spell. The monster is asleep.<br><br>";
} else {
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
}
$userrow["currentmp"] -= $newspellrow["mp"];
break;
case 4: // +Damage spell
$userrow["currentuberdamage"] = $newspellrow["attribute"];
$userrow["currentmp"] -= $newspellrow["mp"];
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% damage until the end of this fight.<br><br>";
break;
case 5: // +Defense spell
$userrow["currentuberdefense"] = $newspellrow["attribute"];
$userrow["currentmp"] -= $newspellrow["mp"];
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% defense until the end of this fight.<br><br>";
break;
}
return $pagearray;
}