aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/hydrorollcore/rule.py
blob: 7dd24836167669d276581fb8bfea5e0182190e8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from abc import ABCMeta, abstractmethod
from enum import Enum

__all__ = ["RuleLoadType", "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


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()

    @abstractmethod
    def parse(self) -> "Dice":
        raise NotImplementedError

    @abstractmethod
    def roll(self) -> int:
        raise NotImplementedError


class Rule(metaclass=ABCMeta):
    """规则基类"""

    name: str
    priority: int = 0

    @abstractmethod
    def __init__(self) -> None:
        raise NotImplementedError

    @abstractmethod
    def check(self) -> Result:
        raise NotImplementedError