aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/COC7/Character.py40
-rw-r--r--examples/COC7/__init__.py79
2 files changed, 58 insertions, 61 deletions
diff --git a/examples/COC7/Character.py b/examples/COC7/Character.py
index 70b934b..37e2a4e 100644
--- a/examples/COC7/Character.py
+++ b/examples/COC7/Character.py
@@ -10,14 +10,13 @@ from hrc.rule.BaseRule import CharacterCard
@dataclass
class Attributes(CharacterCard.Attribute):
- @property
+
@aliases(["luck", "运气"], ignore_case=True)
def LUK(self) -> Union[str, int, None]: ...
- @property
@aliases(["伤害加值", "DamageBonus"], ignore_case=True)
def DB(self) -> Union[str, int, None]:
- sum = self.STR + self.SIZ
+ sum = self.STR() + self.SIZ()
return (
str(math.ceil((sum - 164) / 80)) + "D6"
if sum > 164
@@ -32,45 +31,38 @@ class Attributes(CharacterCard.Attribute):
else None
)
- @property
@aliases(["年龄", "age"], ignore_case=True)
def AGE(self) -> Union[str, int, None]: ...
- @property
@aliases(["HitPoints", "生命值", "生命"], ignore_case=True)
def HP(self) -> Union[str, int, None]:
return self.MAX_HP
- @property
@aliases(["最大生命值", "HitPointTotal", "总生命值"], ignore_case=True)
def MAX_HP(self) -> Union[str, int, None]:
if hasattr(self, "CON") and hasattr(self, "SIZ"):
- return (self.CON + self.SIZ) // 10
+ return (self.CON() + self.SIZ()) // 10
else:
return None
- @property
@aliases(["理智", "Sanity", "SanityPoint", "理智值", "san值"], ignore_case=True)
def SAN(self) -> Union[str, int, None]:
- return self.POW
+ return self.POW()
- @property
@aliases(["最大理智值", "MaximumSanity"], ignore_case=True)
def MAX_SAN(self) -> Union[str, int, None]:
- return 99 - self.player_card.CM
+ return 99 - self.player_card.CM()
- @property
@aliases(["魔法", "魔法值", "MagicPoints"], ignore_case=True)
def MP(self) -> Union[str, int, None]:
if hasattr(self, "POW"):
- return math.floor(self.POW / 5)
+ return math.floor(self.POW() / 5)
else:
return None
- @property
@aliases(["伤害加值", "DamageBonus"], ignore_case=True)
def DB(self) -> Union[int, str, None]: # noqa: F811
- sum = self.STR + self.SIZ
+ sum = self.STR() + self.SIZ()
return (
str(math.ceil((sum - 164) / 80)) + "D6"
if sum > 164
@@ -85,10 +77,9 @@ class Attributes(CharacterCard.Attribute):
else None
)
- @property
@aliases(["体格", "build"], ignore_case=True)
def BUILD(self) -> Union[str, int, None]:
- sum = self.STR + self.SIZ
+ sum = self.STR() + self.SIZ()
return (
math.ceil((sum - 84) / 80)
if sum > 164
@@ -103,14 +94,13 @@ class Attributes(CharacterCard.Attribute):
else None
)
- @property
@aliases(["移动速度"], ignore_case=True)
def MOV(self) -> Union[str, int, None]:
mov = 8
- siz = self.player_card.SIZ
- str_val = self.player_card.STR
- dex = self.player_card.DEX
- age = self.AGE
+ siz = self.player_card.SIZ()
+ str_val = self.player_card.STR()
+ dex = self.player_card.DEX()
+ age = self.AGE()
if age >= 40:
mov -= math.floor(age / 10 - 3)
@@ -122,24 +112,20 @@ class Attributes(CharacterCard.Attribute):
return mov
- @property
@aliases(["兴趣技能点", "PersonalInterests"], ignore_case=True)
def PI(self) -> Union[str, int, None]:
- return self.player_card.INT * 2
+ return self.player_card.INT() * 2
- @property
@aliases(["闪避", "Dodge"], ignore_case=True)
def DODGE(self) -> Union[str, int, None]:
if hasattr(self.player_card, "DEX"):
return math.floor(self.player_card.DEX / 2)
return None
- @property
@aliases(["锁匠", "开锁", "撬锁", "Locksmith"], ignore_case=True)
def LOCKSMITH(self) -> Union[str, int, None]:
return 1
- @property
@aliases(["动物驯养", "驯兽", "AnimalHandling"], ignore_case=True)
def ANIMAL_HANDLING(self) -> Union[str, int, None]:
return 1
diff --git a/examples/COC7/__init__.py b/examples/COC7/__init__.py
index 01efe57..50db8f4 100644
--- a/examples/COC7/__init__.py
+++ b/examples/COC7/__init__.py
@@ -1,41 +1,52 @@
import math
from hrc import Core, player_card
+from hrc.rule import Rule, BaseRule
+from hrc.dependencies import Depends
+
+from .Character import Attributes
+from .Wiki import Wiki
core = Core()
-@core.event_post_processor_hook
-async def auto_card(_event="T_Event"):
- g = core.session
- pc = player_card
- if g and core.session.gid and g.ac:
- if hasattr(pc.trans, "生命") or hasattr(pc.trans, "理智"):
- core.session.call(
- "set_group_card", pc.gid, f"card#{pc.uid}", await overview_card(pc.char)
- )
-
-
-async def overview_card(pc: player_card):
- max_hp = math.floor((pc.get("CON", 0) + pc.get("SIZ", 0) / 10))
- max_san = math.floor(99 - pc.get("CM", 0))
- mp = pc.get("MP", 0)
- mp_show = (
- " mp" + str(mp) + "/" + str(math.floor(pc.get("POW", 0) / 5))
- if mp and mp != math.floor(pc.get("POW", 0) / 5)
- else ""
- )
- return (
- pc.get("__Name", "")
- + " hp"
- + str(pc.get("HP", max_hp))
- + "/"
- + str(max_hp)
- + " san"
- + str(pc.get("SAN", "?"))
- + "/"
- + str(max_san)
- + mp_show
- + " DEX"
- + str(pc.get("DEX", "?"))
- )
+class COC7(Rule):
+
+ attr: Attributes = Depends() # 必须实现一个继承自 Character.Attribute 的类
+ wiki: Wiki = Depends() # 可选实现一个 Wiki
+
+ @core.event_post_processor_hook
+ async def auto_card(self):
+ if self.session and self.session.gid and self.ac:
+ if hasattr(self.pc.trans, "生命") or hasattr(self.pc.trans, "理智"):
+ self.event.call_back(
+ "set_group_card", self.pc.gid, f"card#{self.pc.uid}", await self.overview_card()
+ )
+
+ async def overview_card(self):
+ max_hp = math.floor((self.pc.get("CON", 0) + self.pc.get("SIZ", 0) / 10))
+ max_san = math.floor(99 - self.pc.get("CM", 0))
+ mp = self.pc.get("MP", 0)
+ mp_show = (
+ " mp" + str(mp) + "/" + str(math.floor(self.pc.get("POW", 0) / 5))
+ if mp and mp != math.floor(self.pc.get("POW", 0) / 5)
+ else ""
+ )
+ return (
+ self.pc.get("__Name", "")
+ + " hp"
+ + str(self.pc.get("HP", max_hp))
+ + "/"
+ + str(max_hp)
+ + " san"
+ + str(self.pc.get("SAN", "?"))
+ + "/"
+ + str(max_san)
+ + mp_show
+ + " DEX"
+ + str(self.pc.get("DEX", "?"))
+ )
+
+
+print(COC7)
+print(COC7.attr) \ No newline at end of file