How to use the tavern.pool.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 / pool / commands.py View on Github external
if tavern.hired_hero is not None:
            self.plugin.say(channel, "{}: You've already hired {}. Use .tavern quest to send them somewhere!".format(
                arcuser.base.nick, tavern.hired_hero))
            s.rollback()
            return

        hero_to_hire = pool_controller.search_heroes(name=args, s=s)
        if len(hero_to_hire) is 1:
            hero = hero_to_hire[0]
            if hero.activity == HeroActivity.Elsewhere and tavern.resident_hero.id == hero.id:
                if hero.injured:
                    self.plugin.say(channel, '{}: {} is injured and cannot be hired until they have healed.'.format(
                        arcuser.base.nick, hero))
                    return
                # hiring a resident hero is free
                pool_controller.hire_hero(tavern.id, hero.id, 0, s=s)
                s.commit()
                self.plugin.say(channel, '{}: You hired your resident hero, {}, for free. Use .tavern quest to send them somewhere!'.format(
                    arcuser.base.nick, hero))
                return
            if (hero.activity == HeroActivity.VisitingTavern and hero.visiting.id == tavern.id) or hero.activity == HeroActivity.CommonPool:
                cost = hero.cost  # fix cost since it may change
                if tavern.money < cost:
                    self.plugin.say(channel, '{}: You only have {} gold but {} wants {}!'.format(
                        arcuser.base.nick, tavern.money, hero, cost))
                    return
                pool_controller.hire_hero(tavern.id, hero.id, cost, s=s)
                s.commit()
                self.plugin.say(channel, '{}: You hired {} for {}. Use .tavern quest to send them somewhere!'.format(
                    arcuser.base.nick, hero, cost))
                return
            self.plugin.say(channel, '{}: {} is currently {} and cannot be hired.'.format(
github Arctem / arcbot / tavern / pool / commands.py View on Github external
def hire(self, arcuser, channel, args, s=None):
        tavern = hq_controller.find_tavern(arcuser, s=s)
        if tavern.hired_hero is not None:
            self.plugin.say(channel, "{}: You've already hired {}. Use .tavern quest to send them somewhere!".format(
                arcuser.base.nick, tavern.hired_hero))
            s.rollback()
            return

        hero_to_hire = pool_controller.search_heroes(name=args, s=s)
        if len(hero_to_hire) is 1:
            hero = hero_to_hire[0]
            if hero.activity == HeroActivity.Elsewhere and tavern.resident_hero.id == hero.id:
                if hero.injured:
                    self.plugin.say(channel, '{}: {} is injured and cannot be hired until they have healed.'.format(
                        arcuser.base.nick, hero))
                    return
                # hiring a resident hero is free
                pool_controller.hire_hero(tavern.id, hero.id, 0, s=s)
                s.commit()
                self.plugin.say(channel, '{}: You hired your resident hero, {}, for free. Use .tavern quest to send them somewhere!'.format(
                    arcuser.base.nick, hero))
                return
            if (hero.activity == HeroActivity.VisitingTavern and hero.visiting.id == tavern.id) or hero.activity == HeroActivity.CommonPool:
                cost = hero.cost  # fix cost since it may change
                if tavern.money < cost:
github Arctem / arcbot / tavern / adventure / controller.py View on Github external
def end_adventure(adventure, s=None):
    hero = adventure.hero
    dungeon = adventure.dungeon
    tavern = adventure.employer

    if not adventure.active:
        raise TavernException('Adventure {} is not active.'.format(adventure))
    tavern.money += adventure.money_gained
    hero.money += adventure.money_gained
    pool_controller.increase_cost(hero, adventure.money_gained * constants.MONEY_GAINED_TO_HERO_COST)
    adventure.active = False
    adventure.end_tick = tick.current_tick(s=s)
    s.add(logs.adventure_ended(hero, dungeon, tavern, adventure.money_gained))
github Arctem / arcbot / tavern / pool / tasks.py View on Github external
def heal_heroes(s=None):
    for hero in s.query(TavernHero).filter(TavernHero.activity.in_([
            HeroActivity.Elsewhere, HeroActivity.CommonPool, HeroActivity.VisitingTavern]),
            TavernHero.injured == True):
        if (hero.patron is None and random.random() < constants.HERO_HEAL_CHANCE) or \
                (hero.patron is not None and random.random() < constants.RESIDENT_HERO_HEAL_CHANCE):
            pool_controller.heal_hero(hero, s=s)
github Arctem / arcbot / tavern / hq / commands.py View on Github external
if tavern.hired_hero:
                    messages.append('You have hired {}.'.format(tavern.hired_hero))
                for visitor in tavern.visiting_heroes:
                    messages.append('{} is visiting your tavern.'.format(visitor.name))
                adventures = hq_controller.get_active_adventures(tavern, s=s)
                if len(adventures) > 0:
                    heroes_per_dungeon = {}
                    for adventure in adventures:
                        if adventure.dungeon in heroes_per_dungeon:
                            heroes_per_dungeon[adventure.dungeon].append(adventure.hero)
                        else:
                            heroes_per_dungeon[adventure.dungeon] = [adventure.hero]
                    messages.append('You have sent {}.'.format(
                        ', '.join(['{heroes} to {dungeon}'.format(heroes=', '.join(map(str, heroes_per_dungeon[dungeon])), dungeon=dungeon) for dungeon in heroes_per_dungeon])))
        elif args == 'heroes':
            heroes = pool_controller.get_heroes(s=s)
            heroes = {
                activity: list(map(
                    lambda h: h.name,
                    filter(lambda h: h.activity is activity, heroes)
                )) for activity in HeroActivity
            }
            if len(heroes[HeroActivity.Elsewhere]) > 0:
                messages.append('{} are taking the day off.'.format(', '.join(heroes[HeroActivity.Elsewhere])))

            if len(heroes[HeroActivity.CommonPool]) > 0:
                messages.append('{} are visiting the town square.'.format(
                    ', '.join(heroes[HeroActivity.CommonPool])))
            else:
                messages.append('No one is visiting the town square.')

            if len(heroes[HeroActivity.VisitingTavern]) > 0:
github Arctem / arcbot / tavern / pool / tasks.py View on Github external
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))
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 / hq / controller.py View on Github external
def create_resident_hero(tavern, s=None):
    s.add(tavern)
    tavern.resident_hero = pool.controller.generate_hero(s=s)
    return tavern.resident_hero
github Arctem / arcbot / tavern / pool / tasks.py View on Github external
def pay_tabs(s=None):
    for hero in s.query(TavernHero).filter(TavernHero.activity == HeroActivity.VisitingTavern):
        pool_controller.pay_tab(hero, s=s)