Extract power-up validation helper
This commit is contained in:
parent
5629f052a4
commit
8d31eeafaf
1 changed files with 23 additions and 26 deletions
|
|
@ -15,6 +15,23 @@ POWER_UP_STAMINA_COST_PER_TICK = 2.0 # stamina cost per tick
|
|||
POWER_DOWN_MIN_PL = 1.0 # minimum PL when powering down
|
||||
|
||||
|
||||
async def _check_can_power_up(player: Player) -> str | None:
|
||||
"""Return error message if player can't power up, else None."""
|
||||
# Check if already powering up
|
||||
if player._power_task is not None and not player._power_task.done():
|
||||
return "You're already powering up!\r\n"
|
||||
|
||||
# Check for combat
|
||||
if get_encounter(player) is not None:
|
||||
return "You can't power up during combat!\r\n"
|
||||
|
||||
# Check stamina
|
||||
if player.stamina <= 0:
|
||||
return "You don't have enough stamina to power up!\r\n"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
async def power_up_loop(player: Player, target_pl: float | None = None) -> None:
|
||||
"""Background task that powers up the player over time.
|
||||
|
||||
|
|
@ -118,19 +135,9 @@ async def cmd_power(player: Player, args: str) -> None:
|
|||
|
||||
# Handle power up
|
||||
if args == "up":
|
||||
# Check if already powering up
|
||||
if player._power_task is not None and not player._power_task.done():
|
||||
await player.send("You're already powering up!\r\n")
|
||||
return
|
||||
|
||||
# Check for combat
|
||||
if get_encounter(player) is not None:
|
||||
await player.send("You can't power up during combat!\r\n")
|
||||
return
|
||||
|
||||
# Check stamina
|
||||
if player.stamina <= 0:
|
||||
await player.send("You don't have enough stamina to power up!\r\n")
|
||||
error = await _check_can_power_up(player)
|
||||
if error:
|
||||
await player.send(error)
|
||||
return
|
||||
|
||||
# Check if already at max
|
||||
|
|
@ -181,19 +188,9 @@ async def cmd_power(player: Player, args: str) -> None:
|
|||
|
||||
# If target is higher, start power-up loop to that target
|
||||
if target > player.pl:
|
||||
# Check if already powering up
|
||||
if player._power_task is not None and not player._power_task.done():
|
||||
await player.send("You're already powering up!\r\n")
|
||||
return
|
||||
|
||||
# Check for combat
|
||||
if get_encounter(player) is not None:
|
||||
await player.send("You can't power up during combat!\r\n")
|
||||
return
|
||||
|
||||
# Check stamina
|
||||
if player.stamina <= 0:
|
||||
await player.send("You don't have enough stamina to power up!\r\n")
|
||||
error = await _check_can_power_up(player)
|
||||
if error:
|
||||
await player.send(error)
|
||||
return
|
||||
|
||||
# Start power-up loop to target
|
||||
|
|
|
|||
Loading…
Reference in a new issue