update
This commit is contained in:
@@ -7,7 +7,7 @@ from src.classes.event import Event
|
||||
from src.classes.cultivation import Realm
|
||||
from src.classes.story_teller import StoryTeller
|
||||
from src.classes.tribulation import TribulationSelector
|
||||
from src.classes.hp_and_mp import HP_MAX_BY_REALM, MP_MAX_BY_REALM
|
||||
from src.classes.hp_and_mp import HP_MAX_BY_REALM
|
||||
from src.classes.effect import _merge_effects
|
||||
|
||||
# —— 配置:哪些"出发境界"会生成突破小故事(global var)——
|
||||
@@ -59,9 +59,9 @@ class Breakthrough(TimedAction):
|
||||
self.avatar.cultivation_progress.break_through()
|
||||
new_realm = self.avatar.cultivation_progress.realm
|
||||
|
||||
# 突破成功时更新HP和MP的最大值
|
||||
# 突破成功时更新HP的最大值
|
||||
if new_realm != old_realm:
|
||||
self._update_hp_mp_on_breakthrough(new_realm)
|
||||
self._update_hp_on_breakthrough(new_realm)
|
||||
# 成功:确保最大寿元至少达到新境界的基线
|
||||
self.avatar.age.ensure_max_lifespan_at_least_realm_base(new_realm)
|
||||
# 记录结果用于 finish 事件
|
||||
@@ -77,25 +77,21 @@ class Breakthrough(TimedAction):
|
||||
# 记录结果用于 finish 事件
|
||||
self._last_result = ("fail", int(reduce_years))
|
||||
|
||||
def _update_hp_mp_on_breakthrough(self, new_realm):
|
||||
def _update_hp_on_breakthrough(self, new_realm):
|
||||
"""
|
||||
突破境界时更新HP和MP的最大值并完全恢复
|
||||
突破境界时更新HP的最大值并完全恢复
|
||||
|
||||
Args:
|
||||
new_realm: 新的境界
|
||||
"""
|
||||
new_max_hp = HP_MAX_BY_REALM.get(new_realm, 100)
|
||||
new_max_mp = MP_MAX_BY_REALM.get(new_realm, 100)
|
||||
|
||||
# 计算增加的最大值
|
||||
hp_increase = new_max_hp - self.avatar.hp.max
|
||||
mp_increase = new_max_mp - self.avatar.mp.max
|
||||
|
||||
# 更新最大值并恢复相应的当前值
|
||||
self.avatar.hp.add_max(hp_increase)
|
||||
self.avatar.hp.recover(hp_increase) # 突破时完全恢复HP
|
||||
self.avatar.mp.add_max(mp_increase)
|
||||
self.avatar.mp.recover(mp_increase) # 突破时完全恢复MP
|
||||
|
||||
def can_start(self) -> tuple[bool, str]:
|
||||
ok = self.avatar.cultivation_progress.can_break_through()
|
||||
|
||||
@@ -33,7 +33,7 @@ from src.classes.auxiliary import Auxiliary
|
||||
from src.classes.weapon_type import WeaponType
|
||||
from src.classes.equipment_grade import EquipmentGrade
|
||||
from src.classes.magic_stone import MagicStone
|
||||
from src.classes.hp_and_mp import HP, MP, HP_MAX_BY_REALM, MP_MAX_BY_REALM
|
||||
from src.classes.hp_and_mp import HP, HP_MAX_BY_REALM
|
||||
from src.utils.id_generator import get_avatar_id
|
||||
from src.utils.config import CONFIG
|
||||
from src.classes.relation import Relation, get_reciprocal
|
||||
@@ -93,7 +93,6 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
magic_stone: MagicStone = field(default_factory=lambda: MagicStone(0)) # 灵石,即货币
|
||||
items: dict[Item, int] = field(default_factory=dict)
|
||||
hp: HP = field(default_factory=lambda: HP(0, 0)) # 将在__post_init__中初始化
|
||||
mp: MP = field(default_factory=lambda: MP(0, 0)) # 将在__post_init__中初始化
|
||||
relations: dict["Avatar", Relation] = field(default_factory=dict)
|
||||
alignment: Alignment | None = None
|
||||
# 所属宗门(可为空,表示散修/无门无派)
|
||||
@@ -120,15 +119,13 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
|
||||
def __post_init__(self):
|
||||
"""
|
||||
在Avatar创建后自动初始化tile和HP/MP
|
||||
在Avatar创建后自动初始化tile和HP
|
||||
"""
|
||||
self.tile = self.world.map.get_tile(self.pos_x, self.pos_y)
|
||||
|
||||
# 根据当前境界初始化HP和MP
|
||||
# 根据当前境界初始化HP
|
||||
max_hp = HP_MAX_BY_REALM.get(self.cultivation_progress.realm, 100)
|
||||
max_mp = MP_MAX_BY_REALM.get(self.cultivation_progress.realm, 100)
|
||||
self.hp = HP(max_hp, max_hp)
|
||||
self.mp = MP(max_mp, max_mp)
|
||||
|
||||
# 最大寿元已在 Age 构造时基于境界初始化
|
||||
|
||||
@@ -152,7 +149,7 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
|
||||
|
||||
|
||||
# 初始化时计算所有长期效果(HP/MP等)
|
||||
# 初始化时计算所有长期效果(HP等)
|
||||
self.recalc_effects()
|
||||
|
||||
@property
|
||||
@@ -249,7 +246,6 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
"性别": str(self.gender),
|
||||
"年龄": str(self.age),
|
||||
"hp": str(self.hp),
|
||||
"mp": str(self.mp),
|
||||
"灵石": magic_stone_info,
|
||||
"关系": relations_info,
|
||||
"宗门": sect_info,
|
||||
@@ -292,7 +288,6 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
"realm": self.cultivation_progress.realm.value,
|
||||
"level": self.cultivation_progress.level,
|
||||
"hp": {"cur": self.hp.cur, "max": self.hp.max},
|
||||
"mp": {"cur": self.mp.cur, "max": self.mp.max},
|
||||
"alignment": str(self.alignment) if self.alignment else "未知",
|
||||
"magic_stone": self.magic_stone.value,
|
||||
"thinking": self.thinking,
|
||||
@@ -690,7 +685,6 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
add_kv(lines, "阵营", self.alignment)
|
||||
add_kv(lines, "境界", str(self.cultivation_progress))
|
||||
add_kv(lines, "HP", self.hp)
|
||||
add_kv(lines, "MP", self.mp)
|
||||
add_kv(lines, "战斗力", int(get_base_strength(self)))
|
||||
add_kv(lines, "宗门", self.get_sect_str())
|
||||
|
||||
@@ -850,26 +844,22 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
- 也会重新计算动态表达式(如 eval(...))
|
||||
|
||||
当前包括:
|
||||
- HP/MP 最大值
|
||||
- HP 最大值
|
||||
- 寿命最大值
|
||||
"""
|
||||
# 计算基础最大值(基于境界)
|
||||
base_max_hp = HP_MAX_BY_REALM.get(self.cultivation_progress.realm, 100)
|
||||
base_max_mp = MP_MAX_BY_REALM.get(self.cultivation_progress.realm, 100)
|
||||
|
||||
# 访问 self.effects 会触发 @property,重新 merge 所有 effects
|
||||
effects = self.effects
|
||||
extra_max_hp = int(effects.get("extra_max_hp", 0))
|
||||
extra_max_mp = int(effects.get("extra_max_mp", 0))
|
||||
extra_max_lifespan = int(effects.get("extra_max_lifespan", 0))
|
||||
|
||||
# 计算新的最大值
|
||||
new_max_hp = base_max_hp + extra_max_hp
|
||||
new_max_mp = base_max_mp + extra_max_mp
|
||||
|
||||
# 更新最大值
|
||||
self.hp.max = new_max_hp
|
||||
self.mp.max = new_max_mp
|
||||
|
||||
# 更新寿命
|
||||
# 如果 effects 中有额外寿命加成,需要加到 base_max_lifespan 上吗?
|
||||
@@ -884,8 +874,6 @@ class Avatar(AvatarSaveMixin, AvatarLoadMixin):
|
||||
# 调整当前值(不超过新的最大值)
|
||||
if self.hp.cur > new_max_hp:
|
||||
self.hp.cur = new_max_hp
|
||||
if self.mp.cur > new_max_mp:
|
||||
self.mp.cur = new_max_mp
|
||||
|
||||
def change_weapon(self, new_weapon: Weapon) -> None:
|
||||
"""
|
||||
|
||||
@@ -82,87 +82,3 @@ HP_MAX_BY_REALM = {
|
||||
Realm.Core_Formation: 300,
|
||||
Realm.Nascent_Soul: 400,
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class MP:
|
||||
"""
|
||||
灵力
|
||||
会因为战斗而消耗cur。
|
||||
会随时间或者服用丹药等补充cur。
|
||||
会因为突破境界,服用丹药等增加max。
|
||||
"""
|
||||
max: int
|
||||
cur: int
|
||||
|
||||
def can_cast(self, value_2_cast:int) -> bool:
|
||||
return self.cur >= value_2_cast
|
||||
|
||||
def reduce(self, value_2_reduce:int) -> bool:
|
||||
self.cur -= value_2_reduce
|
||||
if self.cur < 0:
|
||||
self.cur = 0
|
||||
return True
|
||||
|
||||
def recover(self, value_2_recover:int) -> bool:
|
||||
self.cur += value_2_recover
|
||||
if self.cur > self.max:
|
||||
self.cur = self.max
|
||||
return True
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.cur}/{self.max}"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.__str__()
|
||||
|
||||
# 比较运算符,使用cur进行比较
|
||||
def __eq__(self, other) -> bool:
|
||||
if isinstance(other, MP):
|
||||
return self.cur == other.cur
|
||||
return self.cur == other
|
||||
|
||||
def __ne__(self, other) -> bool:
|
||||
if isinstance(other, MP):
|
||||
return self.cur != other.cur
|
||||
return self.cur != other
|
||||
|
||||
def __lt__(self, other) -> bool:
|
||||
if isinstance(other, MP):
|
||||
return self.cur < other.cur
|
||||
return self.cur < other
|
||||
|
||||
def __le__(self, other) -> bool:
|
||||
if isinstance(other, MP):
|
||||
return self.cur <= other.cur
|
||||
return self.cur <= other
|
||||
|
||||
def __gt__(self, other) -> bool:
|
||||
if isinstance(other, MP):
|
||||
return self.cur > other.cur
|
||||
return self.cur > other
|
||||
|
||||
def __ge__(self, other) -> bool:
|
||||
if isinstance(other, MP):
|
||||
return self.cur >= other.cur
|
||||
return self.cur >= other
|
||||
|
||||
def add_max(self, value_2_add:int) -> bool:
|
||||
self.max += value_2_add
|
||||
return True
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""转换为可序列化的字典"""
|
||||
return {"max": self.max, "cur": self.cur}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> "MP":
|
||||
"""从字典重建MP"""
|
||||
return cls(max=data["max"], cur=data["cur"])
|
||||
|
||||
MP_MAX_BY_REALM = {
|
||||
Realm.Qi_Refinement: 100,
|
||||
Realm.Foundation_Establishment: 200,
|
||||
Realm.Core_Formation: 300,
|
||||
Realm.Nascent_Soul: 400,
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class AvatarLoadMixin:
|
||||
from src.classes.calendar import MonthStamp
|
||||
from src.classes.cultivation import Realm, CultivationProgress
|
||||
from src.classes.age import Age
|
||||
from src.classes.hp_and_mp import HP, MP
|
||||
from src.classes.hp_and_mp import HP
|
||||
from src.classes.technique import techniques_by_id
|
||||
from src.classes.item import items_by_id
|
||||
from src.classes.weapon import weapons_by_id
|
||||
@@ -84,9 +84,8 @@ class AvatarLoadMixin:
|
||||
if technique_id is not None:
|
||||
avatar.technique = techniques_by_id.get(technique_id)
|
||||
|
||||
# 设置HP/MP
|
||||
# 设置HP
|
||||
avatar.hp = HP.from_dict(data["hp"])
|
||||
avatar.mp = MP.from_dict(data["mp"])
|
||||
|
||||
# 设置物品与资源
|
||||
avatar.magic_stone = MagicStone(data.get("magic_stone", 0))
|
||||
|
||||
@@ -71,7 +71,6 @@ class AvatarSaveMixin:
|
||||
"root": self.root.name,
|
||||
"technique_id": self.technique.id if self.technique else None,
|
||||
"hp": self.hp.to_dict(),
|
||||
"mp": self.mp.to_dict(),
|
||||
|
||||
# 物品与资源
|
||||
"magic_stone": self.magic_stone.value,
|
||||
|
||||
@@ -74,7 +74,7 @@ async function handleClearObjective() {
|
||||
<StatItem label="年龄" :value="`${data.age} / ${data.lifespan}`" />
|
||||
|
||||
<StatItem label="HP" :value="formatHp(data.hp.cur, data.hp.max)" />
|
||||
<StatItem label="MP" :value="formatHp(data.mp.cur, data.mp.max)" />
|
||||
<StatItem label="性别" :value="data.gender" />
|
||||
|
||||
<StatItem
|
||||
label="阵营"
|
||||
|
||||
@@ -51,7 +51,6 @@ export interface AvatarDetail extends EntityBase {
|
||||
realm: string;
|
||||
level: number;
|
||||
hp: { cur: number; max: number };
|
||||
mp: { cur: number; max: number };
|
||||
magic_stone: number;
|
||||
|
||||
// 属性与资质
|
||||
|
||||
Reference in New Issue
Block a user