File size: 786 Bytes
bcf0302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import random

class DisasterPlugin:
    def __init__(self, disaster_frequency, disaster_prob):
        self.disaster_frequency = disaster_frequency
        self.disaster_prob = disaster_prob

    def trigger_disaster(self, characters, character_die_callback):
        print("发生自然灾难...")
        num_killed = int(len(characters) * self.disaster_prob)
        killed = random.sample(characters, num_killed)
        for c in killed:
            c.history.append(f"{c.real_age}岁,死于自然灾难")
            character_die_callback(c)

    def execute(self, characters, round_num, character_die_callback):
        if round_num % self.disaster_frequency == 0 and random.random() < self.disaster_prob:
            self.trigger_disaster(characters, character_die_callback)