Dragon-Knight/src/actions/heal.php

35 lines
1.4 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(int $id): string
2024-12-12 10:20:49 -06:00
{
$user_spells = user()->spells();
$spell = get_spell($id);
$has_spell = false;
foreach ($user_spells as $us) if ($us['id'] === $id) $has_spell = true;
2024-12-12 10:20:49 -06:00
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();
2024-12-12 10:20:49 -06:00
$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;
}
2024-12-12 10:20:49 -06:00
page_title('Casting '.$spell['name']);
return is_htmx() ? $page : display($page, '');
}