From fae8d2273dfad2dd0cf9709f15e24640e7ebfd8d Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Mon, 15 Jul 2024 18:38:53 +0800 Subject: feat(Improve the underlying business directory): Improve the underlying business directory Add { doc | feat | perf | dev } mods --- .vscode/settings.json | 5 +- docs/_static/.$Structures.svg.dtmp | 4 ++ docs/_static/hrc_code.png | Bin 0 -> 1016554 bytes examples/rules/BRP/__init__.py | 6 -- examples/rules/COC/Character.py | 132 +++++++++++++++++++++++++++++++++++++ examples/rules/COC/Command.py | 1 + examples/rules/COC/Wiki.py | 3 + examples/rules/COC/__init__.py | 62 +++++++++++++++++ examples/rules/COC7/Character.py | 132 ------------------------------------- examples/rules/COC7/Command.py | 1 - examples/rules/COC7/Wiki.py | 3 - examples/rules/COC7/__init__.py | 52 --------------- hrc/rule/__init__.py | 6 ++ src/dev/mod.rs | 0 src/doc/mod.rs | 0 src/feat/mod.rs | 0 src/lib.rs | 13 +++- src/perf/mod.rs | 1 + 18 files changed, 225 insertions(+), 196 deletions(-) create mode 100644 docs/_static/.$Structures.svg.dtmp create mode 100644 docs/_static/hrc_code.png delete mode 100644 examples/rules/BRP/__init__.py create mode 100644 examples/rules/COC/Character.py create mode 100644 examples/rules/COC/Command.py create mode 100644 examples/rules/COC/Wiki.py create mode 100644 examples/rules/COC/__init__.py delete mode 100644 examples/rules/COC7/Character.py delete mode 100644 examples/rules/COC7/Command.py delete mode 100644 examples/rules/COC7/Wiki.py delete mode 100644 examples/rules/COC7/__init__.py create mode 100644 src/dev/mod.rs create mode 100644 src/doc/mod.rs create mode 100644 src/feat/mod.rs create mode 100644 src/perf/mod.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 414a2fa..355946f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,8 @@ { "restructuredtext.preview.name": "sphinx", "iis.configDir": "", - "livePreview.defaultPreviewPath": "/docs/_build/html/index.html" + "livePreview.defaultPreviewPath": "/docs/_build/html/index.html", + "Lua.diagnostics.disable": [ + "doc-field-no-class" + ] } \ No newline at end of file diff --git a/docs/_static/.$Structures.svg.dtmp b/docs/_static/.$Structures.svg.dtmp new file mode 100644 index 0000000..acace65 --- /dev/null +++ b/docs/_static/.$Structures.svg.dtmp @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/docs/_static/hrc_code.png b/docs/_static/hrc_code.png new file mode 100644 index 0000000..50c5139 Binary files /dev/null and b/docs/_static/hrc_code.png differ diff --git a/examples/rules/BRP/__init__.py b/examples/rules/BRP/__init__.py deleted file mode 100644 index 54f2261..0000000 --- a/examples/rules/BRP/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from hrc.rule import Rule - -class BRP(Rule): - async def handle(self) -> None: ... - - async def rule(self) -> bool: return False \ No newline at end of file diff --git a/examples/rules/COC/Character.py b/examples/rules/COC/Character.py new file mode 100644 index 0000000..bb30661 --- /dev/null +++ b/examples/rules/COC/Character.py @@ -0,0 +1,132 @@ +# MyRule +import math + +from typing import Union +from dataclasses import dataclass + +from hrc.rule import Rule +from hrc.rule.BaseRule import CharacterCard + +aliases = Rule.aliases + +@dataclass +class Attributes(CharacterCard.Attribute): + + @aliases(["luck", "运气"], ignore_case=True) + def LUK(self) -> Union[str, int, None]: ... + + @aliases(["伤害加值", "DamageBonus"], ignore_case=True) + def DB(self) -> Union[str, int, None]: + sum = self.STR() + self.SIZ() + return ( + str(math.ceil((sum - 164) / 80)) + "D6" + if sum > 164 + else "1D4" + if sum > 124 + else "0" + if sum > 84 + else "-1" + if sum > 64 + else "-2" + if sum > 0 + else None + ) + + @aliases(["年龄", "age"], ignore_case=True) + def AGE(self) -> Union[str, int, None]: ... + + @aliases(["HitPoints", "生命值", "生命"], ignore_case=True) + def HP(self) -> Union[str, int, None]: + return self.MAX_HP + + @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 + else: + return None + + @aliases(["理智", "Sanity", "SanityPoint", "理智值", "san值"], ignore_case=True) + def SAN(self) -> Union[str, int, None]: + return self.POW() + + @aliases(["最大理智值", "MaximumSanity"], ignore_case=True) + def MAX_SAN(self) -> Union[str, int, None]: + return 99 - self.player_card.CM() + + @aliases(["魔法", "魔法值", "MagicPoints"], ignore_case=True) + def MP(self) -> Union[str, int, None]: + if hasattr(self, "POW"): + return math.floor(self.POW() / 5) + else: + return None + + @aliases(["伤害加值", "DamageBonus"], ignore_case=True) + def DB(self) -> Union[int, str, None]: # noqa: F811 + sum = self.STR() + self.SIZ() + return ( + str(math.ceil((sum - 164) / 80)) + "D6" + if sum > 164 + else "1D4" + if sum > 124 + else "0" + if sum > 84 + else "-1" + if sum > 64 + else "-2" + if sum > 0 + else None + ) + + @aliases(["体格", "build"], ignore_case=True) + def BUILD(self) -> Union[str, int, None]: + sum = self.STR() + self.SIZ() + return ( + math.ceil((sum - 84) / 80) + if sum > 164 + else 1 + if sum > 124 + else 0 + if sum > 84 + else -1 + if sum > 64 + else -2 + if sum > 0 + else None + ) + + @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() + + if age >= 40: + mov -= math.floor(age / 10 - 3) + + if str_val > siz and dex > siz: + mov += 1 + elif siz > str_val and siz > dex: + mov -= 1 + + return mov + + @aliases(["兴趣技能点", "PersonalInterests"], ignore_case=True) + def PI(self) -> Union[str, int, None]: + return self.player_card.INT() * 2 + + @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 + + @aliases(["锁匠", "开锁", "撬锁", "Locksmith"], ignore_case=True) + def LOCKSMITH(self) -> Union[str, int, None]: + return 1 + + @aliases(["动物驯养", "驯兽", "AnimalHandling"], ignore_case=True) + def ANIMAL_HANDLING(self) -> Union[str, int, None]: + return 1 diff --git a/examples/rules/COC/Command.py b/examples/rules/COC/Command.py new file mode 100644 index 0000000..9819841 --- /dev/null +++ b/examples/rules/COC/Command.py @@ -0,0 +1 @@ +class Command: ... \ No newline at end of file diff --git a/examples/rules/COC/Wiki.py b/examples/rules/COC/Wiki.py new file mode 100644 index 0000000..b97f717 --- /dev/null +++ b/examples/rules/COC/Wiki.py @@ -0,0 +1,3 @@ +# MyRule + +class Wiki(): ... \ No newline at end of file diff --git a/examples/rules/COC/__init__.py b/examples/rules/COC/__init__.py new file mode 100644 index 0000000..260bfb5 --- /dev/null +++ b/examples/rules/COC/__init__.py @@ -0,0 +1,62 @@ +import math + +from hrc.core import Core +from hrc.rule import Rule, BaseRule # noqa: F401 +from hrc.dependencies import Depends + +from .Character import Attributes +from .Wiki import Wiki +from .Command import Command + +core = Core() + + +class COC7(Rule): + + # 规则、指令、词条,必须至少实现任意一个 + attr: Attributes = Depends() # CharacterCard.Attribute + wiki: Wiki = Depends() # Wiki + cmd: Command = Depends() # Command # noqa: F821 + + async def handle(self): ... + + async def rule(self): ... + + @core.event_postprocessor_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", "?")) + ) + + +class COC6(Rule): + async def handle(self): ... + + async def rule(self): ... diff --git a/examples/rules/COC7/Character.py b/examples/rules/COC7/Character.py deleted file mode 100644 index bb30661..0000000 --- a/examples/rules/COC7/Character.py +++ /dev/null @@ -1,132 +0,0 @@ -# MyRule -import math - -from typing import Union -from dataclasses import dataclass - -from hrc.rule import Rule -from hrc.rule.BaseRule import CharacterCard - -aliases = Rule.aliases - -@dataclass -class Attributes(CharacterCard.Attribute): - - @aliases(["luck", "运气"], ignore_case=True) - def LUK(self) -> Union[str, int, None]: ... - - @aliases(["伤害加值", "DamageBonus"], ignore_case=True) - def DB(self) -> Union[str, int, None]: - sum = self.STR() + self.SIZ() - return ( - str(math.ceil((sum - 164) / 80)) + "D6" - if sum > 164 - else "1D4" - if sum > 124 - else "0" - if sum > 84 - else "-1" - if sum > 64 - else "-2" - if sum > 0 - else None - ) - - @aliases(["年龄", "age"], ignore_case=True) - def AGE(self) -> Union[str, int, None]: ... - - @aliases(["HitPoints", "生命值", "生命"], ignore_case=True) - def HP(self) -> Union[str, int, None]: - return self.MAX_HP - - @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 - else: - return None - - @aliases(["理智", "Sanity", "SanityPoint", "理智值", "san值"], ignore_case=True) - def SAN(self) -> Union[str, int, None]: - return self.POW() - - @aliases(["最大理智值", "MaximumSanity"], ignore_case=True) - def MAX_SAN(self) -> Union[str, int, None]: - return 99 - self.player_card.CM() - - @aliases(["魔法", "魔法值", "MagicPoints"], ignore_case=True) - def MP(self) -> Union[str, int, None]: - if hasattr(self, "POW"): - return math.floor(self.POW() / 5) - else: - return None - - @aliases(["伤害加值", "DamageBonus"], ignore_case=True) - def DB(self) -> Union[int, str, None]: # noqa: F811 - sum = self.STR() + self.SIZ() - return ( - str(math.ceil((sum - 164) / 80)) + "D6" - if sum > 164 - else "1D4" - if sum > 124 - else "0" - if sum > 84 - else "-1" - if sum > 64 - else "-2" - if sum > 0 - else None - ) - - @aliases(["体格", "build"], ignore_case=True) - def BUILD(self) -> Union[str, int, None]: - sum = self.STR() + self.SIZ() - return ( - math.ceil((sum - 84) / 80) - if sum > 164 - else 1 - if sum > 124 - else 0 - if sum > 84 - else -1 - if sum > 64 - else -2 - if sum > 0 - else None - ) - - @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() - - if age >= 40: - mov -= math.floor(age / 10 - 3) - - if str_val > siz and dex > siz: - mov += 1 - elif siz > str_val and siz > dex: - mov -= 1 - - return mov - - @aliases(["兴趣技能点", "PersonalInterests"], ignore_case=True) - def PI(self) -> Union[str, int, None]: - return self.player_card.INT() * 2 - - @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 - - @aliases(["锁匠", "开锁", "撬锁", "Locksmith"], ignore_case=True) - def LOCKSMITH(self) -> Union[str, int, None]: - return 1 - - @aliases(["动物驯养", "驯兽", "AnimalHandling"], ignore_case=True) - def ANIMAL_HANDLING(self) -> Union[str, int, None]: - return 1 diff --git a/examples/rules/COC7/Command.py b/examples/rules/COC7/Command.py deleted file mode 100644 index 9819841..0000000 --- a/examples/rules/COC7/Command.py +++ /dev/null @@ -1 +0,0 @@ -class Command: ... \ No newline at end of file diff --git a/examples/rules/COC7/Wiki.py b/examples/rules/COC7/Wiki.py deleted file mode 100644 index b97f717..0000000 --- a/examples/rules/COC7/Wiki.py +++ /dev/null @@ -1,3 +0,0 @@ -# MyRule - -class Wiki(): ... \ No newline at end of file diff --git a/examples/rules/COC7/__init__.py b/examples/rules/COC7/__init__.py deleted file mode 100644 index 65f40ab..0000000 --- a/examples/rules/COC7/__init__.py +++ /dev/null @@ -1,52 +0,0 @@ -import math - -from hrc.core import Core -from hrc.rule import Rule, BaseRule # noqa: F401 -from hrc.dependencies import Depends - -from .Character import Attributes -from .Wiki import Wiki -from .Command import Command - -core = Core() - - -class COC7(Rule): - - # 规则、指令、词条,必须至少实现任意一个 - attr: Attributes = Depends() # CharacterCard.Attribute - wiki: Wiki = Depends() # Wiki - cmd: Command = Depends() # Command # noqa: F821 - - @core.event_postprocessor_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", "?")) - ) diff --git a/hrc/rule/__init__.py b/hrc/rule/__init__.py index ecced24..4b3d259 100644 --- a/hrc/rule/__init__.py +++ b/hrc/rule/__init__.py @@ -154,6 +154,12 @@ class Rule(ABC, Generic[EventT, StateT, ConfigT]): It is not recommended to implement event processing directly in this method. Please leave the specific processing of events to the ``handle()`` method. """ raise NotImplementedError + + @staticmethod + async def enable(): ... + + @staticmethod + async def disable(): ... @staticmethod def aliases(names, ignore_case=False): diff --git a/src/dev/mod.rs b/src/dev/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/doc/mod.rs b/src/doc/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/feat/mod.rs b/src/feat/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/lib.rs b/src/lib.rs index 1c11a3d..5337470 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,16 @@ use pyo3::prelude::*; use pyo3::wrap_pyfunction; +use dev::*; +use doc::*; +use feat::*; +use perf::*; + +pub mod dev; +pub mod doc; +pub mod feat; +pub mod perf; + #[pyfunction] fn process_rule_pack(rule_pack: &str) -> PyResult { // 处理规则包的逻辑 @@ -12,5 +22,6 @@ fn process_rule_pack(rule_pack: &str) -> PyResult { #[pyo3(name = "LibCore")] fn libcore(_py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(process_rule_pack, m)?)?; + perf::Asparagus; Ok(()) -} \ No newline at end of file +} diff --git a/src/perf/mod.rs b/src/perf/mod.rs new file mode 100644 index 0000000..0444a3a --- /dev/null +++ b/src/perf/mod.rs @@ -0,0 +1 @@ +pub struct Asparagus {} \ No newline at end of file -- cgit v1.2.3-70-g09d2