def setPetAvatar(bot, message): username = message.from_user.username.replace("@", "") try: target_pet_id = message.text.split()[1] target_value = message.text.split()[2] if len(database.getListPetsByUserName(username)) != 0: if database.isPetExist(username, target_pet_id) is not None: user_money = int(database.getDBValue(username, "eco", "money")) change_name_cost = config.global_economic[ "pet_change_avatar_cost"] UI = "" if user_money < change_name_cost: UI = "У вас не достаточно денег для смены аватара!\n" UI += "Цена смены составляет: " + str( change_name_cost) + "💵\n" UI += "💰 Ваш баланс: " + str(user_money) + "\n" bf.ReplyTo(bot, message, UI, stack=False, timeout=10) return lost_current = int( database.getDBValue(username, "stats", "money_lost_in_pet")) lost = lost_current + ( config.global_economic["pet_change_avatar_cost"]) database.setDBValue(username, "stats", "money_lost_in_pet", str(lost)) user_money = user_money - change_name_cost database.setDBValue(username, "eco", "money", str(user_money)) database.setPetValueByPos(username, target_pet_id, "pet_avatar", target_value) UI += "Изменено:\n" UI += "▫ Аватар питомца: " + str( database.getPetValue(username, target_pet_id, "pet_avatar")) + "\n" bf.ReplyTo(bot, message, UI, stack=False, timeout=10) else: bf.ReplyTo( bot, message, "Такого питомца не существует, посмотреть список питомцев /mypets", stack=False, timeout=3) else: bf.ReplyTo( bot, message, "У вас нет ни одного питомца, купить /buy_pet [ид питомца] [имя питомца]", stack=False, timeout=3) except: bf.ReplyTo(bot, message, "Команда введена не правильно. /pet_setavatar [ид] [смайл]", stack=False, timeout=3)
def getUserPets(bot, message): username = message.from_user.username.replace("@", "") UI = "Ваши питомцы: \n\n" if len(database.getListPetsByUserName(username)) == 0: bf.ReplyTo( bot, message, "У вас нет питомцев, купить /buy_pet [ид питомца] [имя питомца]", stack=False, timeout=3) return for pet in database.getListPetsByUserName(username): UI += "ID[" + pet[0] + "] " + str( database.getPetValue(username, str(pet[0]), "pet_avatar")) + " " + str(pet[1]) + "\n" bf.ReplyTo(bot, message, UI, stack=False, timeout=10)
def buyPet(bot, message): username = message.from_user.username.replace("@", "") if fileio.isUserExist(username): user_money = int(database.getDBValue(username, "eco", "money")) pet_cost = config.global_economic["pet_cost"] if user_money < pet_cost: UI = "У вас не достаточно денег для покупки!\n" UI += "Цена нового питомца составляет: " + str(pet_cost) + "💵\n" UI += "💰Ваш баланс: " + str(user_money) + "\n" bf.ReplyTo(bot, message, UI, stack=False, timeout=10) return try: target_pet_id = message.text.split()[1] target_pet_name = message.text.split()[2] pet_count = len(database.getListPetsByUserName(username)) if pet_count == 0: pet_count = 1 user_money = user_money - (pet_cost * pet_count) database.setDBValue(username, "user", "money", str(user_money)) database.addPet(username, target_pet_name, target_pet_id) time.sleep(1) UI = "Вы успешно купили нового питомца 👍\n" UI += "💵 Списано со счета " + str((pet_cost * pet_count)) + " \n\n" UI += "💵 Цена = количество * стандартная цена (3000💵 ) \n" UI += "💰 Баланс " + str(database.getDBValue(username, "money")) + " \n" UI += "Состояние \n\n" UI += "Владелец: @" + str(username) + "\n" UI += "▫️Аватар питомца: " + str( database.getPetValue(username, target_pet_id, "pet_avatar")) + "\n" UI += "▫️Имя питомца: " + str( database.getPetValue(username, target_pet_id, "pet_name")) + "\n" UI += "🍗 Еда питомца: " + str( database.getPetValue(username, target_pet_id, "pet_food")) + "\n" UI += "💧 Вода питомца: " + str( database.getPetValue(username, target_pet_id, "pet_water")) + "\n" UI += "🍗🍗🍗 Избыток еды: " + str( database.getPetValue(username, target_pet_id, "pet_food_auto")) + "\n" UI += "💧💧💧 Избыток воды: " + str( database.getPetValue(username, target_pet_id, "pet_water_auto")) + "\n" UI += "🏠 У питомца есть дом: " + str( database.getPetValue(username, target_pet_id, "pet_have_house")) + "\n" UI += "🏠📊 Уровень дома питомца: " + str( database.getPetValue(username, target_pet_id, "pet_house_level")) + "\n" UI += "💵 Пассивный доход с питомца: " + str( database.getPetValue(username, target_pet_id, "pet_passive_produce")) + "\n" UI += "⏱💵 Тайм-аут дохода в минутах: " + str( database.getPetValue(username, target_pet_id, "pet_passive_produce_timeout_m")) + "\n" UI += "📊 Уровень питомца: " + str( database.getPetValue(username, target_pet_id, "pet_level")) + "\n" UI += "🌟 Опыт питомца: " + str( database.getPetValue(username, target_pet_id, "pet_exp")) + "\n" UI += "💎 Найдено сокровищ питомцем: " + str( database.getPetValue(username, target_pet_id, "pet_unique_treasure")) + "\n" bf.ReplyTo(bot, message, UI, stack=False, timeout=10) except: bf.ReplyTo( bot, message, "Команда введена не правильно. /buy_pet [ид питомца] [имя питомца]\n ID используется для обращения к конкретному питомцу", stack=False, timeout=3)
def getPetStat(bot, message): username = message.from_user.username.replace("@", "") try: target_pet_id = message.text.split()[1] if len(database.getListPetsByUserName(username)) != 0: if database.isPetExist(username, target_pet_id) is not None: UI = "Состояние \n\n" UI += "Владелец: @" + str(username) + "\n" UI += "▫️Аватар питомца: " + str( database.getPetValue(username, target_pet_id, "pet_avatar")) + "\n" UI += "▫️Имя питомца: " + str( database.getPetValue(username, target_pet_id, "pet_name")) + "\n" UI += "🍗 Еда питомца: " + str( database.getPetValue(username, target_pet_id, "pet_food")) + "\n" UI += "💧 Вода питомца: " + str( database.getPetValue(username, target_pet_id, "pet_water")) + "\n" UI += "🍗🍗🍗 Избыток еды: " + str( database.getPetValue(username, target_pet_id, "pet_food_auto")) + "\n" UI += "💧💧💧 Избыток воды: " + str( database.getPetValue(username, target_pet_id, "pet_water_auto")) + "\n" UI += "🏠 У питомца есть дом: " + str( database.getPetValue(username, target_pet_id, "pet_have_house")) + "\n" UI += "🏠📊 Уровень дома питомца: " + str( database.getPetValue(username, target_pet_id, "pet_house_level")) + "\n" UI += "💵 Пассивный доход с питомца: " + str( database.getPetValue(username, target_pet_id, "pet_passive_produce")) + "\n" UI += "⏱💵 Тайм-аут дохода в минутах: " + str( database.getPetValue( username, target_pet_id, "pet_passive_produce_timeout_m")) + "\n" UI += "📊 Уровень питомца: " + str( database.getPetValue(username, target_pet_id, "pet_level")) + "\n" UI += "🌟 Опыт питомца: " + str( database.getPetValue(username, target_pet_id, "pet_exp")) + "\n" UI += "💎 Найдено сокровищ питомцем: " + str( database.getPetValue(username, target_pet_id, "pet_unique_treasure")) + "\n" bf.ReplyTo(bot, message, UI, stack=False, timeout=10) else: bf.ReplyTo( bot, message, "Такого питомца не существует, посмотреть список питомцев /mypets", stack=False, timeout=3) else: bf.ReplyTo( bot, message, "У вас нет ни одного питомца, купить /buy_pet [ид питомца] [имя питомца]", stack=False, timeout=3) except: bf.ReplyTo(bot, message, "Команда введена не правильно. /pet [ид]", stack=False, timeout=3)
def gameLoop(): global counter counter += 1 if counter >= 10: for users in os.listdir(fileio.pets_database_folder): if "xml" in users: username = users.replace(".xml", "") for pet in database.getListPetsByUserName(username): petID = pet[0] pet_food = int( database.getPetValue(username, petID, "pet_food")) pet_food_auto = int( database.getPetValue(username, petID, "pet_food_auto")) pet_water = int( database.getPetValue(username, petID, "pet_water")) pet_water_auto = int( database.getPetValue(username, petID, "pet_water_auto")) pet_have_house = int( database.getPetValue(username, petID, "pet_have_house")) pet_house_level = int( database.getPetValue(username, petID, "pet_house_level")) pet_passive_produce = int( database.getPetValue(username, petID, "pet_passive_produce")) pet_passive_produce_timeout_m = int( database.getPetValue(username, petID, "pet_passive_produce_timeout_m")) pet_exp = int( database.getPetValue(username, petID, "pet_exp")) pet_level = int( database.getPetValue(username, petID, "pet_level")) pet_unique_treasure = int( database.getPetValue(username, petID, "pet_unique_treasure")) pet_died = int( database.getPetValue(username, petID, "pet_died")) UI = "\n\n Pet " + str(petID) + " for " + username + "\n" UI += "pet_food: " + str(pet_food) + "\n" UI += "pet_food_auto: " + str(pet_food_auto) + "\n" UI += "pet_water: " + str(pet_water) + "\n" UI += "pet_water_auto: " + str(pet_water_auto) + "\n" UI += "pet_have_house: " + str(pet_have_house) + "\n" UI += "pet_house_level: " + str(pet_house_level) + "\n" UI += "pet_passive_produce: " + str( pet_passive_produce) + "\n" UI += "pet_passive_produce_timeout_m: " + str( pet_passive_produce_timeout_m) + "\n" UI += "pet_exp: " + str(pet_exp) + "\n" UI += "pet_level: " + str(pet_level) + "\n" UI += "pet_unique_treasure: " + str( pet_unique_treasure) + "\n" #print(UI) #database.getPetValue() pass counter = 0 print("game loop") pass