1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00
royalnet/rpgpack/commands/dnddamage.py

35 lines
1,001 B
Python
Raw Normal View History

2020-03-04 18:29:33 +00:00
from typing import *
import royalnet
import royalnet.commands as rc
import royalnet.utils as ru
from ..tables import DndBattleUnit
from ..utils import find_unit_in_current_battle
class DnddamageCommand(rc.Command):
name: str = "dnddamage"
description: str = "Damage a unit in the currently active battle."
syntax: str = "[name] {damage}"
aliases = ["dmg", "ddmg", "dnddmg", "damage", "ddamage"]
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
if len(args) > 1:
name = args[0]
damage = int(args[1])
else:
name = None
damage = int(args[0])
unit = await find_unit_in_current_battle(data, name)
if unit is None:
raise rc.InvalidInputError("No such unit is fighting in the currently active battle.")
health = unit.health
health.change(-damage)
unit.health = health
await data.session_commit()
await data.reply(f"{unit}")