This commit is contained in:
bridge
2025-08-23 22:02:47 +08:00
parent a94ea2bd8b
commit cc9ffc3557
4 changed files with 44 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
import random
from src.classes.calendar import Month, Year
from src.classes.cultivation import Realm
class Age:
@@ -55,6 +56,30 @@ class Age:
判断是否老死
"""
return random.random() < self.get_death_probability(realm)
def calculate_age(self, current_month: Month, current_year: Year, birth_month: Month, birth_year: Year) -> int:
"""
计算准确的年龄(整数年)
Args:
current_month: 当前月份
current_year: 当前年份
birth_month: 出生月份
birth_year: 出生年份
Returns:
整数年龄
"""
age = current_year - birth_year
if current_month.value < birth_month.value:
age -= 1
return max(0, age)
def update_age(self, current_month: Month, current_year: Year, birth_month: Month, birth_year: Year):
"""
更新年龄
"""
self.age = self.calculate_age(current_month, current_year, birth_month, birth_year)
def __str__(self) -> str:
"""返回年龄的字符串表示"""

View File

@@ -97,6 +97,12 @@ class Avatar:
如果老死返回True否则返回False
"""
return self.age.death_by_old_age(self.cultivation_progress.realm)
def update_age(self, current_month: Month, current_year: Year):
"""
更新年龄
"""
self.age.update_age(current_month, current_year, self.birth_month, self.birth_year)
def get_age_info(self) -> dict:
"""

View File

@@ -26,6 +26,7 @@ class Simulator:
death_avatar_ids.append(avatar_id)
event = Event(self.year, self.month, f"{avatar.name} 老死了,时年{avatar.age.get_age()}")
events.append(event)
avatar.update_age(self.month, self.year)
for avatar_id in death_avatar_ids:
self.avatars.pop(avatar_id)