import random class CharacterGrowthPlugin: def __init__(self, max_apparent_age): self.max_apparent_age = max_apparent_age def grow_characters(self, characters, character_die_callback): die_count = 0 for character in characters: # 检查角色是否存活 if not character.is_alive: print(f"{character.name}死亡了!") character_die_callback(character) continue # 角色成长 character.grow() # 表观年龄>60岁的角色有死亡风险,年纪越大风险越高,>100岁99%会死亡 if character.apparent_age > 60: death_probability = min(0.01 * (character.apparent_age - 60), 0.99) if random.random() < death_probability: character_die_callback(character) die_count += 1 print(f"{die_count}人寿终正寝了") def execute(self, *args, **kwargs): self.grow_characters(*args, **kwargs)