Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def ensure_dungeon_count(s=None):
created = 0
known = s.query(TavernDungeon).filter(TavernDungeon.secret == False).count()
for i in range(constants.DUNGEONS_MIN_KNOWN - known):
dungeon = dungeon_controller.create_new_dungeon(random.randint(
constants.DUNGEONS_MIN_FLOORS, constants.DUNGEONS_MAX_FLOORS), s=s)
created += 1
dungeon_controller.discover_dungeon(dungeon, s=s)
dungeon_controller.populate_dungeon(dungeon)
return created
def reset_pool(s=None):
unhired = set(s.query(TavernHero).filter(TavernHero.activity.in_([
HeroActivity.VisitingTavern, HeroActivity.CommonPool
]), TavernHero.patron == None).all())
for hero in unhired:
pool_controller.degrade_cost(hero)
available = set(s.query(TavernHero).filter(TavernHero.activity.in_([
HeroActivity.VisitingTavern, HeroActivity.CommonPool, HeroActivity.Elsewhere
]), TavernHero.patron == None).all())
taverns = hq_controller.get_taverns(s=s)
# Divide heroes into three groups: those visiting taverns, those in the pool, and those elsewhere.
visitors = random.sample(available, len(taverns))
available = available - set(visitors)
pool_heroes = random.sample(available, min(constants.POOL_SIZE, len(available)))
available = available - set(pool_heroes)
random.shuffle(taverns)
for hero, tavern in zip(visitors, taverns):
pool_controller.change_hero_activity(hero, HeroActivity.VisitingTavern, tavern=tavern, s=s)
s.add(logs.hero_visiting(hero, tavern))
for hero in pool_heroes:
pool_controller.change_hero_activity(hero, HeroActivity.CommonPool, s=s)
for hero in available:
pool_controller.change_hero_activity(hero, HeroActivity.Elsewhere, s=s)
s.add(logs.pool_refreshed(visitors, pool_heroes))
def ensure_hero_count(s=None):
alive = s.query(TavernHero).filter(TavernHero.activity != HeroActivity.Dead, TavernHero.patron == None).count()
idle = s.query(TavernHero).filter(TavernHero.activity.in_(
[HeroActivity.CommonPool, HeroActivity.Elsewhere]), TavernHero.patron == None).count()
to_create = max(constants.HEROES_MIN_ALIVE - alive, constants.HEROES_MIN_IDLE -
idle, hq_controller.count_taverns(s=s) - idle)
created = 0
for i in range(to_create):
hero = pool_controller.generate_hero(s=s)
created += 1
s.add(logs.make_arrival_log(hero))
return created
def populate_dungeon(dungeon):
traits = map(lambda t: dungeon_raws.types[t.name], dungeon.traits)
required = set()
optional = set()
for trait in traits:
required |= trait.monster_reqs
optional |= trait.monster_opts
optional |= required
options = monster_raws.get_monster_options(required, optional)
num_monsters = len(dungeon.floors) * constants.MONSTERS_PER_FLOOR
monsters = generate_monsters(num_monsters, options)
monsters.sort(key=monster_rank_func(constants.MONSTER_SORT_VARIATION))
print(dungeon.floors)
for floor in range(len(dungeon.floors)):
dungeon.floors[floor].monsters = monsters[
floor * constants.MONSTERS_PER_FLOOR:(floor + 1) * constants.MONSTERS_PER_FLOOR]
def populate_dungeon(dungeon):
traits = map(lambda t: dungeon_raws.types[t.name], dungeon.traits)
required = set()
optional = set()
for trait in traits:
required |= trait.monster_reqs
optional |= trait.monster_opts
optional |= required
options = monster_raws.get_monster_options(required, optional)
num_monsters = len(dungeon.floors) * constants.MONSTERS_PER_FLOOR
monsters = generate_monsters(num_monsters, options)
monsters.sort(key=monster_rank_func(constants.MONSTER_SORT_VARIATION))
print(dungeon.floors)
for floor in range(len(dungeon.floors)):
dungeon.floors[floor].monsters = monsters[
floor * constants.MONSTERS_PER_FLOOR:(floor + 1) * constants.MONSTERS_PER_FLOOR]
def ensure_dungeon_count(s=None):
created = 0
known = s.query(TavernDungeon).filter(TavernDungeon.secret == False).count()
for i in range(constants.DUNGEONS_MIN_KNOWN - known):
dungeon = dungeon_controller.create_new_dungeon(random.randint(
constants.DUNGEONS_MIN_FLOORS, constants.DUNGEONS_MAX_FLOORS), s=s)
created += 1
dungeon_controller.discover_dungeon(dungeon, s=s)
dungeon_controller.populate_dungeon(dungeon)
return created
def hide_emptied_dungeons(s=None):
for dungeon in dungeon_controller.get_known_dungeons(s=s):
empty_floors = len(list(filter(lambda f: len(f.monsters) == 0, dungeon.floors)))
if empty_floors / len(dungeon.floors) > constants.DUNGEON_EMPTY_THRESHHOLD:
dungeon_controller.hide_dungeon(dungeon, s=s)