Dragon-Knight/src/heal.php

29 lines
1.7 KiB
PHP
Raw Normal View History

2024-12-12 10:20:49 -06:00
<?php
2024-12-12 10:20:49 -06:00
// heal.php :: Handles stuff from the Quick Spells menu. (Healing spells only... other spells are handled in fight.php.)
function healspells($id)
{
global $userrow;
2024-12-12 10:20:49 -06:00
$userspells = explode(",", $userrow["spells"]);
$spellrow = get_spell($id);
// All the various ways to error out.
$spell = false;
2024-12-12 10:20:49 -06:00
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"];
2024-12-12 10:20:49 -06:00
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 <a href=\"/\">exploring</a>.", "Healing Spell");
}