import random class CultivationPlugin: def __init__(self, cultivation_speed=1.0): self.cultivation_speed = cultivation_speed def cultivate_characters(self, characters, world_spiritual_energy, init_world_spiritual_energy, consume_spiritual_energy_callback): for character in characters: if sum(character.spiritual_roots) > 0: cultivation_speed = self.cultivation_speed * [0, 1.2, 1, 0.8, 0.6, 0.5][sum(character.spiritual_roots)] # 灵根数量惩罚 # 根据特殊体质修炼速度进行调整 if character.special_constitution[2] == 1: # 灵龟体质 cultivation_speed *= 0.5 elif character.special_constitution[3] == 1: # 蜉蝣体质 cultivation_speed *= 2 # 消耗buff if character.buff: cultivation_speed *= 1.5 character.buff = False if world_spiritual_energy > 0: cultivation_speed *= world_spiritual_energy / init_world_spiritual_energy success_rate = 1 - 0.2 * random.random() character.cultivate(1000 * cultivation_speed * success_rate) consume_amount = 10 * cultivation_speed * success_rate consume_spiritual_energy_callback(consume_amount) # 消耗灵气 character.consume_spiritual_energy += consume_amount else: # 没有灵气,无法修炼了 pass def execute(self, characters, world_spiritual_energy, init_world_spiritual_energy, consume_spiritual_energy): self.cultivate_characters(characters, world_spiritual_energy, init_world_spiritual_energy, consume_spiritual_energy)