fix bugs
This commit is contained in:
@@ -24,11 +24,6 @@ class DevourMortals(TimedAction):
|
||||
tr.devoured_souls = min(10000, int(tr.devoured_souls) + gain)
|
||||
|
||||
def can_start(self) -> bool:
|
||||
region = self.avatar.tile.region
|
||||
# 需持有万魂幡且行为被允许
|
||||
tr = getattr(self.avatar, "treasure", None)
|
||||
if tr is None or tr.name != "万魂幡":
|
||||
return False
|
||||
legal = self.avatar.effects.get("legal_actions", [])
|
||||
return "DevourMortals" in legal
|
||||
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import ast
|
||||
from typing import Any, Callable, Optional
|
||||
|
||||
|
||||
def load_effect_from_str(value: object) -> dict[str, Any]:
|
||||
"""
|
||||
解析 effects 字符串为 dict:
|
||||
- 支持裸键值对格式(如 'k': ['v'])
|
||||
- 支持 JSON 格式(双引号)
|
||||
- 支持 Python 字面量(单引号)
|
||||
将 effects 字段解析为 dict(仅支持标准 JSON 字符串)。
|
||||
- value 为 None/空字符串/'nan' 时返回 {}
|
||||
- 解析非 dict 则返回 {}
|
||||
- 解析失败或结果非 dict 返回 {}
|
||||
"""
|
||||
if value is None:
|
||||
return {}
|
||||
@@ -21,26 +17,11 @@ def load_effect_from_str(value: object) -> dict[str, Any]:
|
||||
s = str(value).strip()
|
||||
if not s or s == "nan":
|
||||
return {}
|
||||
# 使用全局配置中的分隔符将占位分隔符替换回逗号,便于解析
|
||||
try:
|
||||
from src.utils.config import CONFIG
|
||||
sep = str(getattr(getattr(CONFIG, "df", {}), "ids_separator", ","))
|
||||
if sep and sep != ",":
|
||||
s = s.replace(sep, ",")
|
||||
except Exception:
|
||||
pass
|
||||
# 如果不是以 { 开头,则添加花括号包裹
|
||||
if not s.startswith("{"):
|
||||
s = "{" + s + "}"
|
||||
try:
|
||||
obj = json.loads(s)
|
||||
return obj if isinstance(obj, dict) else {}
|
||||
except Exception:
|
||||
try:
|
||||
obj = ast.literal_eval(s)
|
||||
return obj if isinstance(obj, dict) else {}
|
||||
except Exception:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
|
||||
def _merge_effects(base: dict[str, object], addition: dict[str, object]) -> dict[str, object]:
|
||||
|
||||
@@ -53,7 +53,8 @@ def _load_treasures() -> tuple[Dict[int, Treasure], Dict[str, Treasure], Dict[in
|
||||
if raw_sect is not None and str(raw_sect).strip() and str(raw_sect).strip() != "nan":
|
||||
sect_id = int(float(raw_sect))
|
||||
|
||||
effects = load_effect_from_str(row.get("effects", ""))
|
||||
raw_effects_val = row.get("effects", "")
|
||||
effects = load_effect_from_str(raw_effects_val)
|
||||
|
||||
sect_obj: Optional[Sect] = sects_by_id.get(int(sect_id)) if sect_id is not None else None
|
||||
|
||||
@@ -66,6 +67,8 @@ def _load_treasures() -> tuple[Dict[int, Treasure], Dict[str, Treasure], Dict[in
|
||||
sect=sect_obj,
|
||||
)
|
||||
|
||||
# no-op
|
||||
|
||||
treasures_by_id[t.id] = t
|
||||
treasures_by_name[t.name] = t
|
||||
if t.sect_id is not None and t.sect_id not in treasures_by_sect_id:
|
||||
|
||||
Reference in New Issue
Block a user