aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/hydrorollcore/consts
diff options
context:
space:
mode:
author苏向夜 <fu050409@163.com>2023-12-09 22:34:27 +0800
committer苏向夜 <fu050409@163.com>2023-12-09 22:37:38 +0800
commit974230ca750963bb0346589da98b05f2d47454ed (patch)
treed3d9a481705cd859be4c654c16742ab2b9cde0ab /src/hydrorollcore/consts
parente20c3f29ae8297a8c76587e1e6b732a147798786 (diff)
downloadinfini-974230ca750963bb0346589da98b05f2d47454ed.tar.gz
infini-974230ca750963bb0346589da98b05f2d47454ed.zip
:sparkles: 新增事件及模板
Diffstat (limited to 'src/hydrorollcore/consts')
-rw-r--r--src/hydrorollcore/consts/__init__.py0
-rw-r--r--src/hydrorollcore/consts/templates.py63
2 files changed, 63 insertions, 0 deletions
diff --git a/src/hydrorollcore/consts/__init__.py b/src/hydrorollcore/consts/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/hydrorollcore/consts/__init__.py
diff --git a/src/hydrorollcore/consts/templates.py b/src/hydrorollcore/consts/templates.py
new file mode 100644
index 00000000..4cf72989
--- /dev/null
+++ b/src/hydrorollcore/consts/templates.py
@@ -0,0 +1,63 @@
+RULE = """from HydroRollCore import Rule, Result, Dice
+
+class MyRule(Rule):
+ \"\"\"自设规则包\"\"\"
+
+ name = "MyRule"
+ priority: int = 0
+
+ def __init__(self) -> None:
+ \"\"\"初始化你的规则包\"\"\"
+
+ def check(self, dice: Dice) -> Result:
+ \"\"\"声明规则包检定方式\"\"\"
+ return Result("myevent.event1", True)
+"""
+
+EVENT = """from HydroRollCore import Event
+
+__events__ = ["MyEvent"]
+
+class MyEvent(Event):
+ name = "event1"
+ output = "检定成功!"
+"""
+
+DICE = """from HydroRollCore import Dice
+
+class BaseDice(Dice):
+ \"\"\"多面骰\"\"\"
+
+ def __init__(self, roll_string: str = "") -> None:
+ self.roll_string = roll_string
+ self.parse()
+
+ def parse(self) -> "Dice":
+ self.dices = []
+ split = re.split(r"[dD]", self.roll_string)
+
+ if split[0]:
+ self.a = int(split[0])
+ else:
+ self.a = 1
+
+ if split[1]:
+ self.b = int(split[1])
+ else:
+ self.b = 100
+
+ self.db = f"{self.a}D{self.b}"
+ self.dices += [f"D{self.b}"] * self.a
+ return self
+
+ def roll(self) -> int:
+ self.results = []
+
+ for _ in range(self.a):
+ result = random.randint(1, self.b)
+
+ self.results.append(result)
+
+ self.outcome = sum(self.results)
+ return self.outcome
+"""