예제 #1
0
    def resurrect(self, bot):
        stats = DATABASE.get_attr_by_id(self.id, ('max_health', ))
        max_health = stats['max_health']

        health = int(max_health * 0.1)
        is_death = False

        DATABASE.update_by_id(self.id, 'health', health)
        DATABASE.update_by_id(self.id, 'is_death', is_death)

        bot.send_message(self.id, 'Вы возродились')
예제 #2
0
    def heal(self):
        stats = DATABASE.get_attr_by_id(
            self.id, ('health', 'max_health', 'health_per_second'))
        health = stats['health']
        max_health = stats['max_health']
        health_per_second = stats['health_per_second']

        if health < max_health:
            health += health_per_second
            if health > max_health:
                health = max_health

        DATABASE.update_by_id(self.id, 'health', health)
예제 #3
0
    def mob_attack(self, other, bot):
        stats = DATABASE.get_attr_by_id(
            self.id, ('health', 'armor', 'user_level', 'current_exp'))
        health = stats['health']
        armor = stats['armor']
        level = stats['user_level']
        current_exp = stats['current_exp']
        # Цикл битвы до смерти
        while other.health > 0 and health > 0:
            health -= int(other.damage * (1 - calculate_armor(armor)))
            other.attack(self.damage)

        else:
            # Проверка на смерть кого-либо
            if health <= 0:
                health = 0
                is_death = True

                DATABASE.update_by_id(self.id, 'health', health)
                DATABASE.update_by_id(self.id, 'is_death', is_death)

                self.resurrect_timer(bot)
                return 'death', 0, 0

            elif other.health <= 0:
                DATABASE.update_by_id(self.id, 'health', health)
                add_exp = other.get_exp(level)
                current_exp += add_exp
                DATABASE.update_by_id(self.id, 'current_exp', current_exp)
                next_level = levels.next_level(self)
                return 'kill', add_exp, next_level
예제 #4
0
def next_level(player):
    user_stats = DATABASE.get_attr_by_id(player.id,
                                         ('user_level', 'current_exp'))
    level = user_stats['user_level']
    current_exp = user_stats['current_exp']
    if level >= 100:
        return False
    if current_exp >= levels[level]:
        current_exp -= levels[level]
        DATABASE.update_by_id(player.id, 'current_exp', current_exp)
        stats = player.next_level()
        return stats
    else:
        return False
예제 #5
0
    def resurrect_timer(self, bot):
        stats = DATABASE.get_attr_by_id(self.id, ('time_for_resurrect', ))
        time_for_resurrect = stats['time_for_resurrect']

        time_to_start_resurrect = time.time()
        timer = Timer(time_for_resurrect, self.resurrect, [bot])

        DATABASE.update_by_id(self.id, 'time_to_start_resurrect',
                              time_to_start_resurrect)

        try:
            timer.start()

        except Exception as e:
            timer.cancel()
            self.resurrect(bot)
            print(e)
예제 #6
0
    def next_level(self):
        stats = DATABASE.get_attr_by_id(
            self.id,
            ('user_level', 'agility', 'strength', 'intelligence', 'class'))
        level = stats['user_level']
        agility = stats['agility']
        strength = stats['strength']
        intelligence = stats['intelligence']
        user_class = stats['class']

        strength_const = []
        agility_const = []
        intelligence_const = []
        if user_class == 'Воин':
            strength_const = [2, 1.05]
            agility_const = [1.3, 1.03]
            intelligence_const = [1.1, 1.01]
        elif user_class == 'Лучник':
            strength_const = [1.1, 1.01]
            agility_const = [2, 1.05]
            intelligence_const = [1.3, 1.03]
        elif user_class == 'Маг':
            strength_const = [1.3, 1.03]
            agility_const = [1.1, 1.01]
            intelligence_const = [2, 1.05]

        add_strength = calculate_exponential_grow_with_round(
            strength_const[0], strength_const[1], level, 2)
        add_agility = calculate_exponential_grow_with_round(
            agility_const[0], agility_const[1], level, 2)
        add_intelligence = calculate_exponential_grow_with_round(
            intelligence_const[0], intelligence_const[1], level, 2)

        strength += add_strength
        agility += add_agility
        intelligence += add_intelligence

        DATABASE.update_by_id(self.id, 'strength', strength)
        DATABASE.update_by_id(self.id, 'agility', agility)
        DATABASE.update_by_id(self.id, 'intelligence', intelligence)

        level += 1
        DATABASE.update_by_id(self.id, 'user_level', level)
        return add_strength, add_agility, add_intelligence
예제 #7
0
 def change_keyboard(self, name):
     DATABASE.update_by_id(self.id, 'current_keyboard', f"'{name}'")
예제 #8
0
 def change_name(self, message, bot):
     DATABASE.update_by_id(self.id, 'user_name', f"'{message.text}'")
     bot.send_message(message.chat.id, 'Имя изменено')