How to use the tavern.dungeon.controller function in tavern

To help you get started, we’ve selected a few tavern examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Arctem / arcbot / tavern / adventure / tasks.py View on Github external
if not adventure.hero.injured:
                s.add(logs.hero_injured_by_monster(adventure, enemy))
                s.add(logs.hero_injured_by_monster(adventure, enemy, adventure.employer.owner))
                pool_controller.change_hero_activity(adventure.hero, HeroActivity.Elsewhere, s=s)
                adventure_controller.end_adventure(adventure, s=s)
                pool_controller.injure_hero(adventure.hero, s=s)
            else:
                s.add(logs.hero_killed_by_monster(adventure, enemy))
                s.add(logs.hero_killed_by_monster(adventure, enemy, adventure.employer.owner))
                adventure_controller.fail_adventure(adventure, s=s)
                pool_controller.kill_hero(adventure.hero, s=s)
        elif result == BattleOutcome.FLEE:
            s.add(logs.hero_fled_monster(adventure, enemy, player=adventure.employer.owner))
        elif result == BattleOutcome.WIN:
            s.add(logs.hero_defeated_monster(adventure, enemy, player=adventure.employer.owner))
            dungeon_controller.kill_monster(enemy, s=s)
        elif result == BattleOutcome.WIN_LOOT:
            loot = dungeon_controller.monster_gold(enemy, s=s)
            s.add(logs.hero_looted_monster(adventure, enemy, loot, player=adventure.employer.owner))
            adventure.money_gained += loot
            dungeon_controller.kill_monster(enemy, s=s)
        elif result == BattleOutcome.WIN_LEVEL:
            s.add(logs.hero_leveled_monster(adventure, enemy, player=adventure.employer.owner))
            pool_controller.level_hero(adventure.hero, s=s)
            dungeon_controller.kill_monster(enemy, s=s)
        elif result == BattleOutcome.WIN_ADVANCE:
            s.add(logs.hero_defeated_monster(adventure, enemy, player=adventure.employer.owner))
            dungeon_controller.kill_monster(enemy, s=s)
            adventure_controller.advance_floor(adventure, s=s)
github Arctem / arcbot / tavern / hq / commands.py View on Github external
def make_long_description(entity, s=None):
    if isinstance(entity, Tavern):
        return hq_controller.tavern_details(entity, s=s)
    if isinstance(entity, TavernHero):
        return pool_controller.hero_details(entity, s=s)
    if isinstance(entity, TavernDungeon):
        return dungeon_controller.dungeon_details(entity, s=s)
github Arctem / arcbot / tavern / dungeon / tasks.py View on Github external
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
github Arctem / arcbot / tavern / dungeon / tasks.py View on Github external
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
github Arctem / arcbot / tavern / adventure / tasks.py View on Github external
def battle_tier(hero, monster):
    diff = hero.level - dungeon_controller.monster_level(monster)
    while diff not in BATTLE_RESULTS:
        diff = diff + (-1 if diff > 0 else 1)
    return BATTLE_RESULTS[diff]
github Arctem / arcbot / tavern / adventure / controller.py View on Github external
def advance_floor(adventure, s=None):
    next_floor = dungeon_controller.get_floor(adventure.dungeon.id, adventure.floor.number + 1, s=s)
    if next_floor:
        adventure.floor = next_floor
        s.add(logs.adventure_reached_floor(adventure))
    else:
        end_adventure(adventure, s=s)
        dungeon_controller.complete_dungeon(adventure.dungeon, s=s)
github Arctem / arcbot / tavern / adventure / controller.py View on Github external
def start_adventure(hero_id, dungeon_id, hiring_tavern_id=None, s=None):
    hero = s.query(TavernHero).filter(TavernHero.id == hero_id).first()
    dungeon = s.query(TavernDungeon).filter(TavernDungeon.id == dungeon_id).first()
    tavern = None if hiring_tavern_id is None else s.query(Tavern).filter(Tavern.id == hiring_tavern_id).first()

    if not (hero.activity == HeroActivity.Hired and tavern is not None and hero.employer == tavern) and not (tavern is None and hero.activity == HeroActivity.Elsewhere):
        raise TavernException('Hero {} cannot start an adventure with tavern {} from state {}'.format(
            hero, tavern, hero.activity))
    if not dungeon.active:
        raise TavernException('Cannot send hero to adventure in inactive dungeon {}'.format(dungeon))

    adventure = TavernAdventure(hero=hero, dungeon=dungeon, employer=tavern,
                                floor=dungeon_controller.get_floor(dungeon.id, 0, s=s),
                                active=True, money_gained=0, start_tick=tick.current_tick(s=s))
    s.add(adventure)
    pool_controller.change_hero_activity(hero, HeroActivity.Adventuring, s=s)
    s.add(logs.adventure_started(hero, dungeon, tavern))
github Arctem / arcbot / tavern / dungeon / tasks.py View on Github external
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)
github Arctem / arcbot / tavern / hq / commands.py View on Github external
messages.append('No one is visiting the town square.')

            if len(heroes[HeroActivity.VisitingTavern]) > 0:
                messages.append('{} are visiting taverns.'.format(', '.join(heroes[HeroActivity.VisitingTavern])))
            if len(heroes[HeroActivity.Hired]) > 0:
                messages.append('{} have been hired.'.format(', '.join(heroes[HeroActivity.Hired])))
            if len(heroes[HeroActivity.Adventuring]) > 0:
                messages.append('{} are out adventuring.'.format(', '.join(heroes[HeroActivity.Adventuring])))

            injured_heroes = list(
                map(lambda h: h.name,
                    filter(lambda h: h.injured and h.alive, pool_controller.get_heroes(s=s))))
            if len(injured_heroes) > 0:
                messages.append('{} are injured.'.format(', '.join(injured_heroes)))
        elif args == 'dungeons':
            dungeons = dungeon_controller.get_known_dungeons(s=s)
            if len(dungeons) == 0:
                messages.append('No dungeons are known of.')
            for dungeon in dungeons:
                message = '{} has {} floors.'.format(dungeon.name, len(dungeon.floors))
                hero_count = dungeon_controller.get_heroes_in_dungeon(dungeon, s=s)
                if hero_count > 0:
                    message += ' There are {} heroes inside.'.format(hero_count)
                messages.append(message)
        else:
            options = hq_controller.search_taverns(
                args, s=s) + pool_controller.search_heroes(args, s=s) + dungeon_controller.search_dungeons(args, s=s)
            if len(options) == 1:
                messages += make_long_description(options[0])
            elif len(options) == 0:
                messages.append('Could not find {}.'.format(args))
            else: