35 lines
1.4 KiB
PHP
35 lines
1.4 KiB
PHP
<?php
|
|
|
|
// heal.php :: Handles stuff from the Quick Spells menu. (Healing spells only... other spells are handled in fight.php.)
|
|
|
|
function healspells(int $id): string
|
|
{
|
|
$user_spells = user()->spells();
|
|
$spell = get_spell($id);
|
|
$has_spell = false;
|
|
foreach ($user_spells as $us) if ($us['id'] === $id) $has_spell = true;
|
|
|
|
if ($has_spell !== true) {
|
|
$page = 'You have not yet learned this spell. Please go back and try again.';
|
|
} elseif ($spell['type'] !== 1) {
|
|
$page = 'This is not a healing spell. Please go back and try again.';
|
|
} elseif (user()->currentmp < $spell['mp']) {
|
|
$page = 'You do not have enough Magic Points to cast this spell. Please go back and try again.';
|
|
} elseif (user()->currentaction === 'Fighting') {
|
|
$page = '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.';
|
|
} elseif (user()->currenthp == user()->maxhp) {
|
|
$page = 'Your HP is already full. You don\'t need to use a Healing spell now.';
|
|
} else {
|
|
$restored = user()->restore_hp($spell['attribute']);
|
|
user()->currentmp -= $spell['mp'];
|
|
user()->save();
|
|
|
|
$page = <<<HTML
|
|
You have cast the {$spell['name']} spell, and gained {$restored} HP. You can now continue <a href="/" hx-get="/" hx-target="#middle">exploring</a>.
|
|
HTML;
|
|
}
|
|
|
|
page_title('Casting '.$spell['name']);
|
|
return is_htmx() ? $page : display($page, '');
|
|
}
|