def update_missions(self): for mission in self.missions: if mission.timeout is None or mission.timeout < self.time: self.finish_mission(mission, 'timeout') while len(self.missions) < 4 and self.mission_pool: mission = random.choice(self.mission_pool.keys()) del self.mission_pool[mission] self.missions.append(mission)
def random_merc(req_traits=()): """Get random merc from the team Optionally, filter only those having all req_traits """ pc = HiredGunsWorld.instance().pc mercs = [merc for merc in [pc]+pc.team if merc.has_all_traits(req_traits)] if mercs: return random.choice(mercs) else: print('WARNING: no random_merc selected') return None
def random_encounter(level=(0, float('inf')), with_tags=set(), without_tags=set()): try: level[0] except TypeError: level = (level, level) encounters = [ encounter for encounter in HiredGunsWorld.instance().encounter_pool if level[0] <= encounter.level <= level[1] and set(with_tags).issubset(encounter.tags) and set(without_tags).isdisjoint(encounter.tags) ] if encounters: return random.choice(encounters)() else: return None