def lvl_up_points(bot, update, user_data): id = update.message.from_user.id player = get_player(id) if player is None: return if update.message.text == "Готово": player.update_stats() update_status(user_data.get('saved_lvl_up_status'), player, user_data) user_data.pop('saved_lvl_up_status') show_general_buttons(bot, update, user_data) player.lvl_check() return else: player.lvl_up_point(update.message.text) player.free_points -= 1 players.update({id: player}) players_need_update.put(player) if(update.message.text == "заряд"): bot.send_message(chat_id=update.message.chat_id, text="Улучшен <b>{0}</b>".format(update.message.text), parse_mode='HTML') else: bot.send_message(chat_id=update.message.chat_id, text="Улучшена <b>{0}</b>".format(update.message.text), parse_mode='HTML') choose_points(bot, update, user_data)
def farm(bot, update, user_data): player = get_player(update.message.from_user.id) update_status("Farming", player, user_data) print(player.status) user_data.update({'Farming_started': time.time(), 'Farming': True}) player.grind_started_time = time.time() grinding_players.append(player) show_general_buttons(bot, update, user_data)
def move_player(bot, job): player = job.context.get('player') user_data = job.context.get('user_data') update_status('In Location', player, user_data) update_location(job.context.get('location_id'), player, user_data) print(player.nickname, "Переместился в новую локацию -", player.location) players_need_update.put(player) travel_jobs.pop(player.id) update = job.context.get('update') show_general_buttons(bot, update, user_data)
def return_from_farm(bot, update, user_data): player = get_player(update.message.from_user.id) update_status("In Location", player, user_data) try: user_data.pop('Farming') user_data.pop('Farming_started') except KeyError: pass while player in grinding_players: grinding_players.remove(player) show_general_buttons(bot, update, user_data)
def choose_points(bot, update, user_data): id = update.message.from_user.id player = get_player(id) if(player is None): return free_points = player.free_points if(free_points < 0): player.free_points = 0 free_points = 0 if(free_points == 0): bot.send_message(chat_id = update.message.chat_id, text = "У вас нет свободных очков\n\n" "Выносливость - <b>{0}</b>\nБроня - <b>{1}</b>\n" "Сила - <b>{2}</b>\nСкорость - <b>{3}</b>\n" "Заряд - <b>{4}</b>".format( player.stats.get("endurance"), player.stats.get("armor"), player.stats.get("power"), player.stats.get("speed"), player.stats.get("charge")), parse_mode = "HTML", reply_markup = ReplyKeyboardRemove()) player.update_stats() players.update({id: player}) players_need_update.put(player) update_status(user_data.get('saved_lvl_up_status'), player, user_data) user_data.pop('saved_lvl_up_status') player.update_stats() show_general_buttons(bot, update, user_data) return update_status("Lvl_up_points", player, user_data) button_list = [ KeyboardButton("Выносливость"), KeyboardButton("Броня"), KeyboardButton("Сила"), KeyboardButton("Скорость"), KeyboardButton("Заряд"), KeyboardButton("Готово") ] buttons = ReplyKeyboardMarkup(build_menu(button_list, n_cols=2), resize_keyboard=True, one_time_keyboard=False) s = '' if free_points == 1: s = "характеристику" elif free_points >= 2 or free_points <= 4: s = "характеристики" elif free_points >= 5: s = "характеристик" bot.send_message(chat_id=update.message.chat_id, text="Вы можете улучшить <b>{5}</b> {6}\n\nВыберите характеристику, которую хотите улучшить\n" "Выносливость - <b>{0}</b>\nБроня - <b>{1}</b>\n" "Сила - <b>{2}</b>\nСкорость - <b>{3}</b>\n" "Заряд- <b>{4}</b>".format(player.stats.get("endurance"), player.stats.get("armor"), player.stats.get("power"), player.stats.get("speed"), player.stats.get("charge"), free_points, s), parse_mode='HTML', reply_markup=buttons) players.update({id: player}) players_need_update.put(player)
def nickname_select(bot, update, user_data): request = "select id from players where nickname = %s" cursor.execute(request, (update.message.text, )) row = cursor.fetchone() if row is not None: bot.send_message( chat_id=update.message.chat_id, text="Это имя уже занято. Попробуйте выбрать другое имя!") return user_data.update(username=update.message.text, type=6) player = Player(update.message.from_user.id, update.message.from_user.username, user_data.get('username'), user_data.get('sex'), user_data.get('race'), user_data.get('fraction'), user_data.get('class')) player.update_skills() player.status = 'In capital' #TODO сделать статус 'starting' и сделать начальный квест if player.race == 'Федералы': player.location = 14 user_data.update({'location_name': locations.get(14).name}) user_data.update({'location': 14}) elif player.race == 'Трибунал': player.location = 15 user_data.update({'location_name': locations.get(15).name}) user_data.update({'location': 15}) elif player.race == 'Стая': player.location = 16 user_data.update({'location_name': locations.get(16).name}) user_data.update({'location': 16}) user_data.update({'status': 'In Location'}) user_data.update({'location': player.location}) player.status = 'In Location' players.update({player.id: player}) #TODO Вывод информации о столице player.add_to_database() bot.send_message(chat_id=update.message.chat_id, text='Вы выбрали имя <b>{0}</b>\n' 'И можете приступить к игре!'.format( user_data.get('username')), parse_mode='HTML') show_general_buttons(bot, update, user_data) user_data.pop('type') user_data.pop('fraction') user_data.pop('race') user_data.pop('class') user_data.pop('sex') user_data.pop('username') print("New player -", player.nickname, user_data) return
def choose_way(bot, update, user_data): if update.message.text == 'Назад': update_status('In Location', get_player(update.message.from_user.id), user_data) show_general_buttons(bot, update, user_data) return player = get_player(update.message.from_user.id) current_location = locations.get(player.location) paths = current_location.roads loc_name = update.message.text new_loc_id = 0 for i in paths.keys(): tmp_location = i if locations.get(tmp_location).name == loc_name: new_loc_id = tmp_location break if new_loc_id == 0: logging.error('ERROR: NO SUCH ID bot.py in choose_way, id = 0') else: update_status('Traveling', player, user_data) bot.send_message( chat_id=update.message.chat_id, text="Вы отправились в локацию: {0}, до нее идти {1} минут".format( locations.get(new_loc_id).name, paths.get(new_loc_id)), reply_markup=traveling_buttons) contexts = { 'chat_id': update.message.chat_id, 'location_id': new_loc_id, 'player': player, 'update': update, 'user_data': user_data } if filter_is_admin(update.message): bot.send_message(chat_id=update.message.chat_id, text="Вы можете использовать /fasttravel") user_data.update({'new_location': new_loc_id}) tmp_job = job.run_once(move_player, paths.get(new_loc_id) * 60, context=contexts) j = MyJob(tmp_job, paths.get(new_loc_id) * 60, update.message.chat_id) travel_jobs.update({player.id: j}) return
def choose_skill(bot, update, user_data): id = update.message.from_user.id player = get_player(id) if player is None: return free_skill = player.free_skill_points if free_skill < 0: player.free_skill_points = 0 free_skill = 0 if free_skill == 0: button_list = [ KeyboardButton("Выносливость"), KeyboardButton("Броня"), KeyboardButton("Сила"), KeyboardButton("Скорость"), KeyboardButton("Заряд"), KeyboardButton("Готово") ] buttons = ReplyKeyboardMarkup(build_menu(button_list, n_cols=2), resize_keyboard=True, one_time_keyboard=False) bot.send_message(chat_id = update.message.chat_id, text = "У вас нет очков навыков\n\n" "{5} - {0}-го уровня\n{6} - {1}-го уровня\n" "{7} - {2}-го уровня\n{8} - {3}-го уровня\n" "{9} - {4}-го уровня".format(list(player.skill_lvl.values())[0], list(player.skill_lvl.values())[1], list(player.skill_lvl.values())[2], list(player.skill_lvl.values())[3], list(player.skill_lvl.values())[4], list(player.skill_lvl)[0], list(player.skill_lvl)[1], list(player.skill_lvl)[2], list(player.skill_lvl)[3], list(player.skill_lvl)[4]), reply_markup = buttons) update_status("Lvl_up_points", player, user_data) player.update_skills() players.update({id: player}) players_need_update.put(player) choose_points(bot, update, user_data) show_general_buttons(bot, update, user_data) player.lvl_check() return update_status("Lvl_up_skill", player, user_data) button_list = [ KeyboardButton("1"), KeyboardButton("2"), KeyboardButton("3"), KeyboardButton("4"), KeyboardButton("5"), KeyboardButton("Готово") ] buttons = ReplyKeyboardMarkup(build_menu(button_list, n_cols=2), resize_keyboard=True, one_time_keyboard = False) s = '' if free_skill == 1: s = "навык" elif free_skill >= 2 and free_skill <= 4: s = "навыка" elif free_skill >= 5: s = "навыков" bot.send_message(chat_id=update.message.chat_id, text="Вы можете улучшить <b>{5}</b> {6}\n\nВыберите навык, который хотите улучшить\n\n" "{7} - {0}-го уровня\n{8} - {1}-го уровня\n" "{9} - {2}-го уровня\n{10} - {3}-го уровня\n" "{11} - {4}-го уровня".format(list(player.skill_lvl.values())[0], list(player.skill_lvl.values())[1], list(player.skill_lvl.values())[2], list(player.skill_lvl.values())[3], list(player.skill_lvl.values())[4], free_skill, s, list(player.skill_lvl)[0], list(player.skill_lvl)[1], list(player.skill_lvl)[2], list(player.skill_lvl)[3], list(player.skill_lvl)[4]), parse_mode='HTML', reply_markup=buttons) players.update({id: player}) players_need_update.put(player)
def interprocess_monitor(): data = interprocess_queue.get() while data is not None: try: keys = list(data.data.keys()) if data.type == "user_data": user_data = dispatcher.user_data.get(data.id) player = get_player(data.id) if 'status' in keys: update_status(data.data.get('status'), player, user_data) data.data.pop('status') keys.remove('status') for user_data_record in keys: user_data.update( {user_data_record: data.data.get(user_data_record)}) #print(user_data) elif data.type == "battles_pending": for record in keys: pending_battles.update({record: data.data.get(record)}) print("put battle") elif data.type == "battle status return": dispatcher.user_data.get(data.id).update({ 'status': dispatcher.user_data.get( data.id).get('saved_battle_status') }) user_data = dispatcher.user_data.get(data.id) if user_data.get('status') == None: dispatcher.user_data.get(data.id).update( {'status': 'In Location'}) list_user_data = list(user_data) if 'saved_battle_status' in list_user_data: user_data.pop('saved_battle_status') if 'chosen skill' in list_user_data: user_data.pop('chosen skill') if 'Battle_waiting_to_count' in list_user_data: user_data.pop('Battle_waiting_to_count') if 'Battle id' in list_user_data: try: pending_battles.pop(user_data.get('Battle id')) except KeyError: pass user_data.pop('Battle id') if 'matchmaking' in list_user_data: user_data.pop('matchmaking') if 'Team' in list_user_data: user_data.pop('Team') if 'stunned' in list_user_data: user_data.pop('stunned') if 'Test' in list_user_data: user_data.pop('Test') player = get_player(data.id) player.saved_battle_status = None show_general_buttons(dispatcher.bot, player.id, user_data) elif data.type == "remove stun": user_data = dispatcher.user_data.get(data.id) list_user_data = list(user_data) if "stunned" in list_user_data: user_data.pop('stunned') elif data.type == "change_player_state": player = get_player(list(data.data)[0]) list_keys = list(data.data)[1:] for key in list_keys: change_value = data.data.get(key) if key == "exp": player.exp += change_value player.lvl_check() elif key == "dead": player.dead = change_value elif key == "resources": for new_key in change_value: delta = change_value.get(new_key) old_value = player.resourses.get(new_key) if old_value is None: continue old_value += delta player.resources.update({new_key: old_value}) elif key == "eq_backpack": for new_key in change_value: delta = change_value.get(new_key) old_value = player.eq_backpack.get(new_key) if old_value is None: continue old_value += delta player.resources.update({new_key: old_value}) elif key == "al_backpack": for new_key in change_value: delta = change_value.get(new_key) old_value = player.al_backpack.get(new_key) if old_value is None: continue old_value += delta player.resources.update({new_key: old_value}) elif key == "res_backpack": for new_key in change_value: delta = change_value.get(new_key) old_value = player.res_backpack.get(new_key) if old_value is None: continue old_value += delta player.resources.update({new_key: old_value}) players_need_update.put(player) except Exception: logging.error(traceback.format_exc()) data = interprocess_queue.get() return 0
def return_from_merchant(bot, update, user_data): player = get_player(update.message.from_user.id) update_status(user_data.get('saved_merchant_status'), player, user_data) user_data.pop('saved_merchant_status') show_general_buttons(bot, update, user_data)