How to use the tavern.tavern_models.HeroActivity 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
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(
                arcuser.base.nick, hero, pool_controller.hero_activity_string(hero, s=s)))
            s.rollback()
            return
        elif len(hero_to_hire) > 1:
            self.plugin.say(channel, '{}: Found {} heroes. Please specify: {}'.format(
github Arctem / arcbot / tavern / pool / tasks.py View on Github external
]), 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))
github Arctem / arcbot / tavern / pool / controller.py View on Github external
def hero_activity_string(hero, s=None):
    if hero.activity is HeroActivity.Elsewhere:
        return 'out of town'
    elif hero.activity is HeroActivity.CommonPool:
        return 'in the town square'
    elif hero.activity is HeroActivity.VisitingTavern:
        return 'visiting {tavern}'.format(tavern=hero.visiting)
    elif hero.activity is HeroActivity.Hired:
        return 'waiting for orders from {tavern}'.format(tavern=hero.employer)
    elif hero.activity is HeroActivity.Adventuring:
        for adventure in hero.adventures:
            if adventure.active:
                return 'on floor {floor} of {dungeon}'.format(floor=adventure.floor.number, dungeon=adventure.dungeon)
    elif hero.activity is HeroActivity.Dead:
        return 'dead as a doornail'
github Arctem / arcbot / tavern / hq / commands.py View on Github external
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:
                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])))
github Arctem / arcbot / tavern / pool / controller.py View on Github external
def hero_activity_string(hero, s=None):
    if hero.activity is HeroActivity.Elsewhere:
        return 'out of town'
    elif hero.activity is HeroActivity.CommonPool:
        return 'in the town square'
    elif hero.activity is HeroActivity.VisitingTavern:
        return 'visiting {tavern}'.format(tavern=hero.visiting)
    elif hero.activity is HeroActivity.Hired:
        return 'waiting for orders from {tavern}'.format(tavern=hero.employer)
    elif hero.activity is HeroActivity.Adventuring:
        for adventure in hero.adventures:
            if adventure.active:
                return 'on floor {floor} of {dungeon}'.format(floor=adventure.floor.number, dungeon=adventure.dungeon)
    elif hero.activity is HeroActivity.Dead:
        return 'dead as a doornail'
github Arctem / arcbot / tavern / tavern_models.py View on Github external
name = Column(String, unique=True, nullable=False)
    epithet = Column(String, nullable=False)
    primary_class = Column(String, nullable=False)
    secondary_class = Column(String, nullable=False)

    alive = Column(Boolean, default=True, nullable=False)
    injured = Column(Boolean, default=False, nullable=False)
    level = Column(Integer, nullable=False)
    cost = Column(Integer, nullable=False)
    money = Column(Integer, nullable=False)

    adventures = relationship('TavernAdventure', back_populates='hero')
    patron = relationship('Tavern', back_populates='resident_hero',
                          uselist=False, foreign_keys=[Tavern.resident_hero_id])

    activity = Column(Enum(HeroActivity), nullable=False)
    visiting_id = Column(Integer, ForeignKey('taverns.id'))
    visiting = relationship('Tavern', back_populates='visiting_heroes', foreign_keys=[visiting_id], post_update=True)
    employer = relationship('Tavern', uselist=False, back_populates='hired_hero', foreign_keys=[Tavern.hired_hero_id])

    def __str__(self):
        return '{} the {}'.format(self.name, self.epithet)

    def info_string(self):
        return '{name} | {stats}'.format(name=self.name, stats=self.level_string())

    def level_string(self):
        if self.secondary_class is not None:
            return 'level {lvl} {primary} {secondary}'.format(lvl=self.level, primary=self.primary_class.capitalize(), secondary=self.secondary_class.capitalize())
        return 'level {lvl} {primary}'.format(lvl=self.level, primary=self.primary_class.capitalize())
github Arctem / arcbot / tavern / pool / controller.py View on Github external
def hero_activity_string(hero, s=None):
    if hero.activity is HeroActivity.Elsewhere:
        return 'out of town'
    elif hero.activity is HeroActivity.CommonPool:
        return 'in the town square'
    elif hero.activity is HeroActivity.VisitingTavern:
        return 'visiting {tavern}'.format(tavern=hero.visiting)
    elif hero.activity is HeroActivity.Hired:
        return 'waiting for orders from {tavern}'.format(tavern=hero.employer)
    elif hero.activity is HeroActivity.Adventuring:
        for adventure in hero.adventures:
            if adventure.active:
                return 'on floor {floor} of {dungeon}'.format(floor=adventure.floor.number, dungeon=adventure.dungeon)
    elif hero.activity is HeroActivity.Dead:
        return 'dead as a doornail'
github Arctem / arcbot / tavern / pool / tasks.py View on Github external
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))
github Arctem / arcbot / tavern / pool / controller.py View on Github external
def hero_activity_string(hero, s=None):
    if hero.activity is HeroActivity.Elsewhere:
        return 'out of town'
    elif hero.activity is HeroActivity.CommonPool:
        return 'in the town square'
    elif hero.activity is HeroActivity.VisitingTavern:
        return 'visiting {tavern}'.format(tavern=hero.visiting)
    elif hero.activity is HeroActivity.Hired:
        return 'waiting for orders from {tavern}'.format(tavern=hero.employer)
    elif hero.activity is HeroActivity.Adventuring:
        for adventure in hero.adventures:
            if adventure.active:
                return 'on floor {floor} of {dungeon}'.format(floor=adventure.floor.number, dungeon=adventure.dungeon)
    elif hero.activity is HeroActivity.Dead:
        return 'dead as a doornail'
github Arctem / arcbot / tavern / pool / controller.py View on Github external
def generate_hero(name=None, stat_points=None, s=None):
    if not name:
        print(set(s.query(TavernHero).values(TavernHero.name)))
        name = random.choice(list(set(SHAKESPEARE_NAMES) -
                                  {name[0] for name in s.query(TavernHero).values(TavernHero.name)}))
    primary, secondary = random.sample(job_raws.jobs.keys(), 2)
    epithet = create_epithet(primary, secondary)
    hero = TavernHero(name=name, epithet=epithet, level=1,
                      cost=constants.HERO_START_COST, money=constants.HERO_START_MONEY,
                      activity=HeroActivity.Elsewhere,
                      primary_class=primary, secondary_class=secondary)
    s.add(hero)
    return hero