Exemplo n.º 1
0
def get_members(guild):
    """
    Returns all members from a guild (discord server).
    """
    players = read_query(create_db_connection(),
                         DBQueries.select_player(condition('guild', guild)))
    return players
Exemplo n.º 2
0
 def save(self):
     """
     Save current attributes to permanet file on database.
     """
     con = create_db_connection()
     execute_query(
         con, DBQueries.update_player(self.id, self.get_attributes_data()))
Exemplo n.º 3
0
def get_member(member_id):
    """
    Returns a member data from database.
    param : member_id : <str>
    return: <list>
    """
    player = read_query(
        create_db_connection(),
        DBQueries.select_player(condition('member_id', member_id)))
    return next(iter(player), None)
Exemplo n.º 4
0
    def lv_up(self):
        """
        Levels up a member, if possible.
        """
        while self.messages >= self.next_lv and self.lv < config.MAXIMUM_LV:
            self.lv += 1
            self.next_lv = next_lv(self.lv)

            self.max_hp += randint(10, 50)
            self.max_mp += randint(5, 25)
            self.strength += randint(0, 2)
            self.defense += randint(0, 2)
            self.magic += randint(0, 2)
            self.skill_points += 2

            #pply  maximum restrictions
            if self.max_hp > config.MAXIMUM_HP:
                self.max_hp = config.MAXIMUM_HP

            if self.max_mp > config.MAXIMUM_MP:
                self.max_mp = config.MAXIMUM_MP

            if self.strength > config.MAXIMUM_STATS:
                self.strength = config.MAXIMUM_STATS

            if self.magic > config.MAXIMUM_STATS:
                self.magic = config.MAXIMUM_STATS

            if self.defense > config.MAXIMUM_STATS:
                self.defense = config.MAXIMUM_STATS

            # 50% chance learning a skill on level up

            if choice([True, False]):
                skills_data = read_query(
                    create_db_connection(),
                    DBQueries.select_skill(
                        condition('skill_rank', self.get_skill_rank())))
                new_skill = choice([s[0] for s in skills_data])
                skills = convert(self.learned_skills)

                # skip if member already knows this skill
                if new_skill not in skills:
                    skills.append(new_skill)
                    self.learned_skills = str(skills)

        self.save()
        return self
Exemplo n.º 5
0
 def __init__(self, reference, resolver='skill_id'):
     # resolve from db
     skill = next(
         iter(
             read_query(
                 create_db_connection(),
                 DBQueries.select_skill(condition(resolver, reference)))),
         None)
     # TODO raise exception if not skill
     self.skill_id = skill[0]
     self.name = skill[1]
     self.type = skill[2]
     self.power = skill[3]
     self.cost = skill[4]
     self.effect = skill[5]
     self.rank = skill[6]