fix bug
This commit is contained in:
@@ -33,7 +33,10 @@ def long_action(step_month: int):
|
||||
"""
|
||||
if self.start_monthstamp is None:
|
||||
return False
|
||||
return (self.world.month_stamp - self.start_monthstamp) >= self.step_month
|
||||
# 修正逻辑:使用 >= step_month - 1 而不是 >= step_month
|
||||
# 这样1个月的动作在第1个月完成(时间差0 >= 0),10个月的动作在第10个月完成(时间差9 >= 9)
|
||||
# 避免了原来多执行一个月的bug
|
||||
return (self.world.month_stamp - self.start_monthstamp) >= self.step_month - 1
|
||||
|
||||
# 只添加 is_finished 方法
|
||||
cls.is_finished = is_finished
|
||||
@@ -241,9 +244,7 @@ class Breakthrough(DefineAction, ActualActionMixin):
|
||||
"""
|
||||
突破境界
|
||||
"""
|
||||
# assert self.avatar.cultivation_progress.can_break_through()
|
||||
if not self.avatar.cultivation_progress.can_break_through():
|
||||
print(f"警告,{self.avatar.name} 无法突破境界,其level为 {self.avatar.cultivation_progress.level},无法突破")
|
||||
assert self.avatar.cultivation_progress.can_break_through()
|
||||
success_rate = self.calc_success_rate()
|
||||
if random.random() < success_rate:
|
||||
self.avatar.cultivation_progress.break_through()
|
||||
|
||||
@@ -115,7 +115,7 @@ class CultivationProgress:
|
||||
self.exp += exp_amount
|
||||
|
||||
# 检查是否可以升级
|
||||
while self.can_level_up():
|
||||
if self.is_level_up():
|
||||
required_exp = self.get_exp_required()
|
||||
self.exp -= required_exp
|
||||
self.level += 1
|
||||
@@ -140,12 +140,19 @@ class CultivationProgress:
|
||||
"""
|
||||
return self.level in level_to_break_through.keys()
|
||||
|
||||
def can_level_up(self) -> bool:
|
||||
def can_cultivate(self) -> bool:
|
||||
"""
|
||||
检查是否可以升级
|
||||
可以突破,说明到顶了,说明不能升级。
|
||||
检查是否可以修炼
|
||||
可以突破,说明到顶了,说明不能修炼了,必须突破后才能正常修炼。
|
||||
"""
|
||||
return not self.can_break_through()
|
||||
|
||||
def is_level_up(self) -> bool:
|
||||
"""
|
||||
检查是否可以进入下一级
|
||||
"""
|
||||
exp_required = self.get_exp_required()
|
||||
return self.exp >= exp_required
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.realm.value}{self.stage.value}({self.level}级)。可以突破:{self.can_break_through()}"
|
||||
@@ -151,12 +151,12 @@ class Front:
|
||||
hovered_region = self._draw_region_labels()
|
||||
hovered_avatar = self._draw_avatars_and_pick_hover()
|
||||
|
||||
# 显示tooltip
|
||||
if hovered_region is not None:
|
||||
# 显示tooltip (人物优先级高于region)
|
||||
if hovered_avatar is not None:
|
||||
self._draw_tooltip_for_avatar(hovered_avatar)
|
||||
elif hovered_region is not None:
|
||||
mouse_x, mouse_y = pygame.mouse.get_pos()
|
||||
self._draw_tooltip_for_region(hovered_region, mouse_x, mouse_y)
|
||||
elif hovered_avatar is not None:
|
||||
self._draw_tooltip_for_avatar(hovered_avatar)
|
||||
|
||||
# 状态信息
|
||||
self._draw_status_bar()
|
||||
@@ -481,8 +481,8 @@ class Front:
|
||||
image_path = os.path.join(male_dir, filename)
|
||||
try:
|
||||
image = pygame.image.load(image_path)
|
||||
# 调整头像大小,减小20%
|
||||
avatar_size = max(26, int(self.tile_size * 4 // 3 * 0.8))
|
||||
# 调整头像大小,减小20%后再放大1.2倍
|
||||
avatar_size = max(26, int(self.tile_size * 4 // 3))
|
||||
scaled_image = pygame.transform.scale(image, (avatar_size, avatar_size))
|
||||
self.male_avatars.append(scaled_image)
|
||||
except pygame.error:
|
||||
@@ -497,8 +497,8 @@ class Front:
|
||||
image_path = os.path.join(female_dir, filename)
|
||||
try:
|
||||
image = pygame.image.load(image_path)
|
||||
# 调整头像大小,减小20%
|
||||
avatar_size = max(26, int(self.tile_size * 4 // 3 * 0.8))
|
||||
# 调整头像大小,减小20%后再放大1.2倍
|
||||
avatar_size = max(26, int(self.tile_size * 4 // 3 * 0.8 * 1.2))
|
||||
scaled_image = pygame.transform.scale(image, (avatar_size, avatar_size))
|
||||
self.female_avatars.append(scaled_image)
|
||||
except pygame.error:
|
||||
|
||||
@@ -11,7 +11,7 @@ class Simulator:
|
||||
def __init__(self, world: World):
|
||||
self.avatars = {} # dict of str -> Avatar
|
||||
self.world = world
|
||||
self.brith_rate = 0.01
|
||||
self.brith_rate = 0 # 0表示不出生新角色
|
||||
|
||||
def step(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user