This commit is contained in:
bridge
2025-11-13 18:57:16 +08:00
parent 62fa84a809
commit 3a8032124f
5 changed files with 122 additions and 11 deletions

View File

@@ -33,6 +33,7 @@ from .devour_mortals import DevourMortals
from .self_heal import SelfHeal
from .catch import Catch
from .nurture_weapon import NurtureWeapon
from .switch_weapon import SwitchWeapon
# 注册到 ActionRegistry标注是否为实际可执行动作
register_action(actual=False)(Action)
@@ -62,6 +63,7 @@ register_action(actual=True)(DevourMortals)
register_action(actual=True)(SelfHeal)
register_action(actual=True)(Catch)
register_action(actual=True)(NurtureWeapon)
register_action(actual=True)(SwitchWeapon)
# Talk 已移动到 mutual_action 模块,在那里注册
__all__ = [
@@ -93,6 +95,8 @@ __all__ = [
"DevourMortals",
"SelfHeal",
"Catch",
"NurtureWeapon",
"SwitchWeapon",
# Talk 已移动到 mutual_action 模块
]

View File

@@ -0,0 +1,80 @@
from __future__ import annotations
from src.classes.action import InstantAction
from src.classes.event import Event
from src.classes.weapon import get_common_weapon
from src.classes.weapon_type import WeaponType
from src.classes.normalize import normalize_weapon_type
class SwitchWeapon(InstantAction):
"""
切换兵器:将当前兵器切换为指定类型的凡品兵器。
熟练度重置为0。
"""
COMMENT = "切换到指定类型的凡品兵器。当前兵器会丧失熟练度会重置为0。适用于想要更换兵器类型或从头修炼新兵器的情况。"
DOABLES_REQUIREMENTS = "无前置条件"
PARAMS = {"weapon_type_name": "str"}
def _execute(self, weapon_type_name: str) -> None:
# 规范化兵器类型名称
normalized_type = normalize_weapon_type(weapon_type_name)
# 匹配 WeaponType 枚举
target_weapon_type = None
for wt in WeaponType:
if wt.value == normalized_type:
target_weapon_type = wt
break
if target_weapon_type is None:
return
# 获取凡品兵器
common_weapon = get_common_weapon(target_weapon_type)
if common_weapon is None:
return
# 切换兵器(使用 Avatar 的 change_weapon 方法)
self.avatar.change_weapon(common_weapon)
def can_start(self, weapon_type_name: str | None = None) -> tuple[bool, str]:
if weapon_type_name is None:
# AI调用总是可以切换兵器
return True, ""
# 规范化并验证兵器类型
normalized_type = normalize_weapon_type(weapon_type_name)
target_weapon_type = None
for wt in WeaponType:
if wt.value == normalized_type:
target_weapon_type = wt
break
if target_weapon_type is None:
return False, f"未知兵器类型: {weapon_type_name}(支持的类型:剑/刀/枪/棍/扇/鞭/琴/笛/暗器)"
# 检查是否已经是该类型的凡品兵器
if self.avatar.weapon.weapon_type == target_weapon_type and \
self.avatar.weapon.name == f"凡品{target_weapon_type.value}":
return False, f"已经装备了凡品{target_weapon_type.value}"
# 检查凡品兵器是否存在
common_weapon = get_common_weapon(target_weapon_type)
if common_weapon is None:
return False, f"系统中不存在凡品{target_weapon_type.value}"
return True, ""
def start(self, weapon_type_name: str) -> Event:
normalized_type = normalize_weapon_type(weapon_type_name)
return Event(
self.world.month_stamp,
f"{self.avatar.name} 切换兵器为凡品{normalized_type}",
related_avatars=[self.avatar.id]
)
def finish(self, weapon_type_name: str) -> list[Event]:
return []