refactor: remove switch weapon action

This commit is contained in:
bridge
2026-01-08 22:19:56 +08:00
parent 9c21259577
commit c6a574a2ac
4 changed files with 5 additions and 105 deletions

View File

@@ -33,7 +33,6 @@ from .devour_mortals import DevourMortals
from .self_heal import SelfHeal
from .catch import Catch
from .nurture_weapon import NurtureWeapon
from .switch_weapon import SwitchWeapon
from .assassinate import Assassinate
from .move_to_direction import MoveToDirection
from .cast import Cast
@@ -69,7 +68,6 @@ 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)
register_action(actual=True)(Assassinate)
register_action(actual=True)(MoveToDirection)
register_action(actual=True)(Cast)
@@ -108,7 +106,6 @@ __all__ = [
"SelfHeal",
"Catch",
"NurtureWeapon",
"SwitchWeapon",
"Assassinate",
"MoveToDirection",
"Cast",

View File

@@ -1,98 +0,0 @@
from __future__ import annotations
from src.classes.action import InstantAction
from src.classes.event import Event
from src.classes.weapon import get_random_weapon_by_realm
from src.classes.weapon_type import WeaponType
from src.classes.cultivation import Realm
from src.classes.normalize import normalize_weapon_type
class SwitchWeapon(InstantAction):
"""
切换兵器:将当前兵器切换为指定类型的练气兵器。
熟练度重置为0。
"""
ACTION_NAME = "切换兵器"
EMOJI = "🔄"
DESC = "切换到指定类型的练气兵器或卸下兵器。当前兵器会丧失熟练度会重置为0。适用于想要更换兵器类型或从头修炼新兵器的情况。"
DOABLES_REQUIREMENTS = "无前置条件"
PARAMS = {"weapon_type_name": "str"}
def _execute(self, weapon_type_name: str) -> None:
# 处理卸下兵器的情况
if weapon_type_name in ["", "None", "none", ""]:
self.avatar.change_weapon(None)
return
# 规范化兵器类型名称
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_random_weapon_by_realm(Realm.Qi_Refinement, 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) -> tuple[bool, str]:
# 处理卸下兵器的情况
if weapon_type_name in ["", "None", "none", ""]:
if self.avatar.weapon is None:
return False, "当前已处于无兵器状态"
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 is not None and \
self.avatar.weapon.weapon_type == target_weapon_type and \
self.avatar.weapon.realm == Realm.Qi_Refinement:
return False, f"已经装备了基础{target_weapon_type.value}"
# 检查练气兵器是否存在
common_weapon = get_random_weapon_by_realm(Realm.Qi_Refinement, 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:
if weapon_type_name in ["", "None", "none", ""]:
return Event(
self.world.month_stamp,
f"{self.avatar.name} 卸下了兵器",
related_avatars=[self.avatar.id]
)
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]
)
async def finish(self, weapon_type_name: str) -> list[Event]:
return []

View File

@@ -31,7 +31,7 @@ class StoreMixin:
def get_store_info(self) -> str:
"""
获取商店信息描述
例如:交易练气剑、练气刀100灵石练气破境丹50灵石
例如:出售练气剑、练气刀100灵石练气破境丹50灵石
"""
# 如果没有初始化或者没有物品
if not hasattr(self, 'store_items') or not self.store_items:
@@ -52,12 +52,12 @@ class StoreMixin:
# 按价格从低到高排序
for price in sorted(items_by_price.keys()):
names = items_by_price[price]
# 去重并保持顺序 (Python 3.7+ dict key insertion order)
# 去重并保持顺序
unique_names = list(dict.fromkeys(names))
names_str = "".join(unique_names)
parts.append(f"{names_str}{price}灵石)")
return "交易" + "".join(parts)
return "出售" + "".join(parts)
def is_selling(self, item_name: str) -> bool:
"""

View File

@@ -60,9 +60,10 @@ class World():
"天地灵机": "世界每隔数年会有一次天象变动(如灵气潮汐),影响角色能力。",
"灵石": "修仙界的通用货币。可用于购买法宝丹药,通过采集、交易或掠夺获取。",
"宗门": "修士的庇护所。加入宗门可习得独门功法、获同门庇护;散修自由但资源匮乏。",
"战斗": "弱肉强食境界压制极大,高境界者对低境界者有绝对优势。若对方死亡,胜者可掠夺败者财物。",
"战斗": "弱肉强食境界压制极大,高境界者对低境界者有绝对优势。若对方死亡,胜者可掠夺败者财物。",
"动作": "你有一系列可以执行的动作。要注意动作的效果、限制条件、区域和时间。",
"装备与丹药": "通过兵器、辅助装备、丹药等装备,可以获得额外的属性加成,获得或小或大的增益。拥有好的装备或者服用好的丹药,能获得很大好处。",
"购物": "在城市区域可以购买练气级别丹药、兵器。购买丹药后会立刻服用强化自身。购买兵器可以帮自己切换兵器类型为顺手的类型。",
}
return desc