diff options
| author | 2023-12-15 09:11:47 +0800 | |
|---|---|---|
| committer | 2023-12-15 09:11:47 +0800 | |
| commit | be8de118db913711eb72ae5187d26e54a0055727 (patch) | |
| tree | 96cd6c012dafa3f4015e54edef90df5eaaab0ddb /src/hydrorollcore/rule.py | |
| parent | 9b2d27ba1d91a0d5531bc9c0d52c3887a2dfb2aa (diff) | |
| download | infini-be8de118db913711eb72ae5187d26e54a0055727.tar.gz infini-be8de118db913711eb72ae5187d26e54a0055727.zip | |
refactor(docs): optmst `docs` dir & `deps`
Diffstat (limited to 'src/hydrorollcore/rule.py')
| -rw-r--r-- | src/hydrorollcore/rule.py | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/src/hydrorollcore/rule.py b/src/hydrorollcore/rule.py deleted file mode 100644 index a1f04151..00000000 --- a/src/hydrorollcore/rule.py +++ /dev/null @@ -1,75 +0,0 @@ -from abc import ABCMeta, abstractmethod -from enum import Enum -from .exceptions import HydroError -from .typing import Dict - -__all__ = ["RuleLoadType", "Result", "Dice", "Rule"] - - -class RuleLoadType(Enum): - """The Type Of Rules To Be Loaded""" - - DIR = "dir" - NAME = "name" - FILE = "file" - CLASS = "class" - - -class Result(metaclass=ABCMeta): - """规则检定结果基类""" - - event: str - status: bool - exception: HydroError | None = None - - def __init__(self, event: str, status: bool, exception: HydroError | None) -> None: - self.event = event - self.status = status - self.exception = exception - - def ok(self): - """规则执行期间是否产生异常""" - return isinstance(self.exception, HydroError) - - -class Dice(metaclass=ABCMeta): - """掷骰基类""" - - roll_string: str - db: str - outcome: int - - def __repr__(self) -> str: - return f'<HydroDice "{self.db.upper()}">' - - def __str__(self) -> str: - return self.db.upper() - - def __int__(self) -> int: - return self.outcome - - @abstractmethod - def parse(self) -> "Dice": - """解析传入的掷骰字符串`roll_string`,返回一个`Dice`对象""" - raise NotImplementedError - - @abstractmethod - def roll(self) -> int: - """掷骰方法,返回掷骰结果""" - raise NotImplementedError - - -class Rule(metaclass=ABCMeta): - """规则基类""" - - name: str - dices: Dict[str, str] = {} - priority: int = 0 - - @abstractmethod - def __init__(self) -> None: - raise NotImplementedError - - @abstractmethod - def check(self, dice: Dice) -> Result: - raise NotImplementedError |
