feat(misfortune): enhance misfortune themes and localization support

- Refactored misfortune theme identifiers for clarity and consistency.
- Introduced a new function `_get_misfortune_theme` to handle theme translations.
- Updated `_pick_misfortune_theme` to utilize theme IDs and improved localization for misfortune results.
- Added new entries in localization files for English and Chinese, covering various misfortune themes and result messages.
- Improved user experience by ensuring all misfortune-related texts are properly translated and formatted.
This commit is contained in:
bridge
2026-02-02 21:47:03 +08:00
parent 4f377551e8
commit ade1379448
8 changed files with 234 additions and 29 deletions

View File

@@ -16,29 +16,29 @@ class MisfortuneKind(Enum):
CULTIVATION_BACKLASH = "backlash" # 修为倒退
MF_LOSS_SPIRIT_STONE_THEMES: list[str] = [
"遭遇扒手",
"误买假货",
"遭人勒索",
"洞府失窃",
"赌石惨败",
"投资失败",
MF_LOSS_SPIRIT_STONE_THEME_IDS: list[str] = [
"misfortune_theme_pickpocket",
"misfortune_theme_fake_goods",
"misfortune_theme_blackmail",
"misfortune_theme_theft",
"misfortune_theme_gambling_loss",
"misfortune_theme_bad_investment",
]
MF_INJURY_THEMES: list[str] = [
"修炼岔气",
"出门摔伤",
"妖兽偷袭",
"仇家闷棍",
"误触机关",
"天降横祸",
MF_INJURY_THEME_IDS: list[str] = [
"misfortune_theme_cultivation_accident",
"misfortune_theme_trip_fall",
"misfortune_theme_beast_ambush",
"misfortune_theme_enemy_attack",
"misfortune_theme_trap",
"misfortune_theme_disaster",
]
MF_BACKLASH_THEMES: list[str] = [
"心魔滋生",
"灵气逆行",
"感悟错乱",
"急火攻心",
MF_BACKLASH_THEME_IDS: list[str] = [
"misfortune_theme_heart_demon",
"misfortune_theme_qi_deviation",
"misfortune_theme_confusion",
"misfortune_theme_anxiety",
]
@@ -63,14 +63,22 @@ def _choose_misfortune_kind(avatar: Avatar) -> Optional[MisfortuneKind]:
return random.choice(candidates)
def _get_misfortune_theme(theme_id: str) -> str:
"""获取翻译后的霉运主题文本"""
from src.i18n import t
return t(theme_id)
def _pick_misfortune_theme(kind: MisfortuneKind) -> str:
theme_id = ""
if kind == MisfortuneKind.LOSS_SPIRIT_STONE:
return random.choice(MF_LOSS_SPIRIT_STONE_THEMES)
theme_id = random.choice(MF_LOSS_SPIRIT_STONE_THEME_IDS)
elif kind == MisfortuneKind.INJURY:
return random.choice(MF_INJURY_THEMES)
theme_id = random.choice(MF_INJURY_THEME_IDS)
elif kind == MisfortuneKind.CULTIVATION_BACKLASH:
return random.choice(MF_BACKLASH_THEMES)
return ""
theme_id = random.choice(MF_BACKLASH_THEME_IDS)
return _get_misfortune_theme(theme_id) if theme_id else ""
async def try_trigger_misfortune(avatar: Avatar) -> list[Event]:
@@ -103,6 +111,8 @@ async def try_trigger_misfortune(avatar: Avatar) -> list[Event]:
theme = _pick_misfortune_theme(kind)
res_text: str = ""
from src.i18n import t
if kind == MisfortuneKind.LOSS_SPIRIT_STONE:
# 破财:随机数,不超过总量
max_loss = avatar.magic_stone.value
@@ -111,7 +121,7 @@ async def try_trigger_misfortune(avatar: Avatar) -> list[Event]:
loss = random.randint(50, 300)
loss = min(loss, max_loss)
avatar.magic_stone.value -= loss
res_text = f"{avatar.name} 损失灵石 {loss}"
res_text = t("misfortune_result_loss_spirit_stone", name=avatar.name, amount=loss)
elif kind == MisfortuneKind.INJURY:
# 受伤扣减HP
@@ -122,7 +132,7 @@ async def try_trigger_misfortune(avatar: Avatar) -> list[Event]:
avatar.hp.cur -= damage
# 注意这里可能扣成负数simulator 会在 _phase_resolve_death 中处理
res_text = f"{avatar.name} 受到伤害 {damage}剩余HP {avatar.hp.cur}/{max_hp}"
res_text = t("misfortune_result_injury", name=avatar.name, damage=damage, current=avatar.hp.cur, max=max_hp)
elif kind == MisfortuneKind.CULTIVATION_BACKLASH:
# 修为倒退
@@ -135,11 +145,11 @@ async def try_trigger_misfortune(avatar: Avatar) -> list[Event]:
actual_loss = min(current_exp, loss)
avatar.cultivation_progress.exp -= actual_loss
res_text = f"{avatar.name} 修为倒退 {actual_loss}"
res_text = t("misfortune_result_backlash", name=avatar.name, amount=actual_loss)
# 生成故事
event_text = f"遭遇霉运({theme}{res_text}"
story_prompt = "请据此写100~300字小故事。只描述倒霉事件本身不要描述角色的心理活动或者愈挫愈勇不要有数值。"
event_text = t("misfortune_event_format", theme=theme, result=res_text)
story_prompt = t("misfortune_story_prompt")
month_at_finish = avatar.world.month_stamp
base_event = Event(month_at_finish, event_text, related_avatars=[avatar.id], is_major=True)

View File

@@ -3426,3 +3426,68 @@ msgstr "found a treasure"
msgid "perished"
msgstr "perished"
# Misfortune System
msgid "misfortune_event_format"
msgstr "Encountered misfortune ({theme}), {result}"
msgid "misfortune_story_prompt"
msgstr "Please write a short story (100-300 words) about this unfortunate event. Focus on the incident itself, do not mention stats."
msgid "misfortune_result_loss_spirit_stone"
msgstr "{name} lost {amount} spirit stones"
msgid "misfortune_result_injury"
msgstr "{name} took {damage} damage, HP remaining {current}/{max}"
msgid "misfortune_result_backlash"
msgstr "{name} cultivation regressed by {amount} points"
msgid "misfortune_theme_pickpocket"
msgstr "Encountered a pickpocket"
msgid "misfortune_theme_fake_goods"
msgstr "Bought fake goods"
msgid "misfortune_theme_blackmail"
msgstr "Blackmailed"
msgid "misfortune_theme_theft"
msgstr "Cave dwelling theft"
msgid "misfortune_theme_gambling_loss"
msgstr "Gambling loss"
msgid "misfortune_theme_bad_investment"
msgstr "Investment failure"
msgid "misfortune_theme_cultivation_accident"
msgstr "Cultivation accident"
msgid "misfortune_theme_trip_fall"
msgstr "Tripped and fell"
msgid "misfortune_theme_beast_ambush"
msgstr "Ambushed by beast"
msgid "misfortune_theme_enemy_attack"
msgstr "Attacked by enemy"
msgid "misfortune_theme_trap"
msgstr "Triggered trap"
msgid "misfortune_theme_disaster"
msgstr "Sudden disaster"
msgid "misfortune_theme_heart_demon"
msgstr "Heart demon emerged"
msgid "misfortune_theme_qi_deviation"
msgstr "Qi deviation"
msgid "misfortune_theme_confusion"
msgstr "Cultivation confusion"
msgid "misfortune_theme_anxiety"
msgstr "Anxiety attack"

View File

@@ -2271,3 +2271,68 @@ msgstr "觅得宝物"
msgid "perished"
msgstr "葬身于"
# Misfortune System
msgid "misfortune_event_format"
msgstr "遭遇霉运({theme}{result}"
msgid "misfortune_story_prompt"
msgstr "请据此写100~300字小故事。只描述倒霉事件本身不要描述角色的心理活动或者愈挫愈勇不要有数值。"
msgid "misfortune_result_loss_spirit_stone"
msgstr "{name} 损失灵石 {amount} 枚"
msgid "misfortune_result_injury"
msgstr "{name} 受到伤害 {damage} 点剩余HP {current}/{max}"
msgid "misfortune_result_backlash"
msgstr "{name} 修为倒退 {amount} 点"
msgid "misfortune_theme_pickpocket"
msgstr "遭遇扒手"
msgid "misfortune_theme_fake_goods"
msgstr "误买假货"
msgid "misfortune_theme_blackmail"
msgstr "遭人勒索"
msgid "misfortune_theme_theft"
msgstr "洞府失窃"
msgid "misfortune_theme_gambling_loss"
msgstr "赌石惨败"
msgid "misfortune_theme_bad_investment"
msgstr "投资失败"
msgid "misfortune_theme_cultivation_accident"
msgstr "修炼岔气"
msgid "misfortune_theme_trip_fall"
msgstr "出门摔伤"
msgid "misfortune_theme_beast_ambush"
msgstr "妖兽偷袭"
msgid "misfortune_theme_enemy_attack"
msgstr "仇家闷棍"
msgid "misfortune_theme_trap"
msgstr "误触机关"
msgid "misfortune_theme_disaster"
msgstr "天降横祸"
msgid "misfortune_theme_heart_demon"
msgstr "心魔滋生"
msgid "misfortune_theme_qi_deviation"
msgstr "灵气逆行"
msgid "misfortune_theme_confusion"
msgstr "感悟错乱"
msgid "misfortune_theme_anxiety"
msgstr "急火攻心"

View File

@@ -2289,3 +2289,68 @@ msgstr "九天虛空殿"
msgid "HIDDEN_DOMAIN_HIDDEN_DOMAIN_PALACE_DESC"
msgstr "漂浮於九天罡風層之上的宏偉宮殿群,非有大毅力者不可通過外圍撕裂肉身的空間裂縫。殿內佈滿上古禁制與層疊幻陣,一步踏錯便是形神俱滅,永墜虛空。雖藏經閣已在歲月中坍塌,但那些飄散在虛空亂流中的每一頁金書玉冊,都記載著足以引發修真界血雨腥風的無上神通。唯有金丹巔峰修士,方能勉強抵禦那股來自遠古的威壓,窺探一絲仙機。"
# Misfortune System
msgid "misfortune_event_format"
msgstr "遭遇黴運({theme}{result}"
msgid "misfortune_story_prompt"
msgstr "請據此寫100~300字小故事。只描述倒黴事件本身不要描述角色的心理活動或者愈挫愈勇不要有數值。"
msgid "misfortune_result_loss_spirit_stone"
msgstr "{name} 損失靈石 {amount} 枚"
msgid "misfortune_result_injury"
msgstr "{name} 受到傷害 {damage} 點剩餘HP {current}/{max}"
msgid "misfortune_result_backlash"
msgstr "{name} 修爲倒退 {amount} 點"
msgid "misfortune_theme_pickpocket"
msgstr "遭遇扒手"
msgid "misfortune_theme_fake_goods"
msgstr "誤買假貨"
msgid "misfortune_theme_blackmail"
msgstr "遭人勒索"
msgid "misfortune_theme_theft"
msgstr "洞府失竊"
msgid "misfortune_theme_gambling_loss"
msgstr "賭石慘敗"
msgid "misfortune_theme_bad_investment"
msgstr "投資失敗"
msgid "misfortune_theme_cultivation_accident"
msgstr "修煉岔氣"
msgid "misfortune_theme_trip_fall"
msgstr "出門摔傷"
msgid "misfortune_theme_beast_ambush"
msgstr "妖獸偷襲"
msgid "misfortune_theme_enemy_attack"
msgstr "仇家悶棍"
msgid "misfortune_theme_trap"
msgstr "誤觸機關"
msgid "misfortune_theme_disaster"
msgstr "天降橫禍"
msgid "misfortune_theme_heart_demon"
msgstr "心魔滋生"
msgid "misfortune_theme_qi_deviation"
msgstr "靈氣逆行"
msgid "misfortune_theme_confusion"
msgstr "感悟錯亂"
msgid "misfortune_theme_anxiety"
msgstr "急火攻心"

View File

@@ -115,7 +115,7 @@ function handleClick(key: string) {
aria-modal="true"
>
<n-form>
<n-form-item :label="t('ui.language')">
<n-form-item label="语言 / Language">
<n-select
v-model:value="settingStore.locale"
:options="languageOptions"