def start(self): logger.info(u'Обновляем файл %s...' % items_filename) self.game_item_reader = GameItemReader() self.game_item_reader.download(items_filename) self.game_item_reader.read(items_filename) logger.info(u'Логинимся...') self.api_user_id, game_auth_key, self.api_access_token, self.connection = self.site.get_game_params( ) self.session = Session(self.api_user_id, game_auth_key, client_version=self.CLIENT_VERSION) self.factory = Factory(self.session, None) self.request_sender = RequestSender(self.factory, self.connection) self.timer = GameTimer() logger.info(u'Получаем ключ сессии...') key = self.site.get_time_key() command = GameTIME(key=key) time_response = self.request_sender.send(command) server_time = time_response.time session_key = time_response.key logger.info(u'Синхронизируем время сервера...') client_time = self.timer.get_client_time() start_time = time.time() command = self.site.create_start_command(server_time, client_time) sending_time = (time.time() - start_time) * 1000 self.timer.client_time += sending_time logger.info(u'Загружаем игровые данные...') self.factory.set_request_id(server_time) self.factory.set_session_key(session_key) self.factory.set_master(self.account) start_response = self.request_sender.send(command) self.game_state = GameState(start_response, self.game_item_reader) self.game_events_sender = GameEventsSender(self.request_sender) self.api = vk.api.API(token=self.api_access_token) # Получаем доступ к статистике self.statistic = StatisticAccess(self.account) # Показываем нашу игровую статистику self.show_game_stats()
def start(self): logger.info(u'Обновляем файл %s...' % items_filename) self.game_item_reader = GameItemReader() self.game_item_reader.download(items_filename) self.game_item_reader.read(items_filename) logger.info(u'Логинимся...') self.api_user_id, game_auth_key, self.api_access_token, self.connection = self.site.get_game_params() self.session = Session(self.api_user_id, game_auth_key, client_version=self.CLIENT_VERSION) self.factory = Factory(self.session, None) self.request_sender = RequestSender(self.factory, self.connection) self.timer = GameTimer() logger.info(u'Получаем ключ сессии...') key = self.site.get_time_key() command = GameTIME(key=key) time_response = self.request_sender.send(command) server_time = time_response.time session_key = time_response.key logger.info(u'Синхронизируем время сервера...') client_time = self.timer.get_client_time() start_time = time.time() command = self.site.create_start_command(server_time, client_time) sending_time = (time.time() - start_time) * 1000 self.timer.client_time += sending_time logger.info(u'Загружаем игровые данные...') self.factory.set_request_id(server_time) self.factory.set_session_key(session_key) self.factory.set_master(self.account) start_response = self.request_sender.send(command) self.game_state = GameState(start_response, self.game_item_reader) self.game_events_sender = GameEventsSender(self.request_sender) self.api = vk.api.API(token=self.api_access_token) # Получаем доступ к статистике self.statistic = StatisticAccess(self.account) # Показываем нашу игровую статистику self.show_game_stats()
class GameEngine(object): CLIENT_VERSION = 1385060115L def __init__(self, site, account): self.site = site self.account = account self.api_user_id = None self.api_access_token = None self.request_sender = None self.factory = None self.game_item_reader = None self.game_state = None self.connection = None self.session = None self.api = None self.game_events_sender = None self.timer = None self.statistic = None def start(self): logger.info(u'Обновляем файл %s...' % items_filename) self.game_item_reader = GameItemReader() self.game_item_reader.download(items_filename) self.game_item_reader.read(items_filename) logger.info(u'Логинимся...') self.api_user_id, game_auth_key, self.api_access_token, self.connection = self.site.get_game_params() self.session = Session(self.api_user_id, game_auth_key, client_version=self.CLIENT_VERSION) self.factory = Factory(self.session, None) self.request_sender = RequestSender(self.factory, self.connection) self.timer = GameTimer() logger.info(u'Получаем ключ сессии...') key = self.site.get_time_key() command = GameTIME(key=key) time_response = self.request_sender.send(command) server_time = time_response.time session_key = time_response.key logger.info(u'Синхронизируем время сервера...') client_time = self.timer.get_client_time() start_time = time.time() command = self.site.create_start_command(server_time, client_time) sending_time = (time.time() - start_time) * 1000 self.timer.client_time += sending_time logger.info(u'Загружаем игровые данные...') self.factory.set_request_id(server_time) self.factory.set_session_key(session_key) self.factory.set_master(self.account) start_response = self.request_sender.send(command) self.game_state = GameState(start_response, self.game_item_reader) self.game_events_sender = GameEventsSender(self.request_sender) self.api = vk.api.API(token=self.api_access_token) # Получаем доступ к статистике self.statistic = StatisticAccess(self.account) # Показываем нашу игровую статистику self.show_game_stats() def show_game_stats(self): buyed_brains = 0 for buyed_brain in self.game_state.get_state().buyedBrains: buyed_brains += buyed_brain.count logger.info(u'%s КРАТКАЯ ИНФОРМАЦИЯ %s' % (u'*' * 18, u'*' * 18)) logger.info(u'Аккаунт: %s' % self.account.user_name) logger.info(u'Монеты: %i' % self.game_state.get_state().gameMoney) logger.info(u'Зомбаксы: %i' % self.game_state.get_state().cashMoney) logger.info(u'Опыт: %i' % self.game_state.get_state().experience) logger.info(u'Уровень: %i' % self.game_state.get_state().level) logger.info(u'Мозги: %i (%i/%i закопанных и %i платных)' % (self.game_state.get_state().brainsCount + len([x for x in self.game_state.get_state().burySlots if x.enabled and hasattr(x, u'user')]) + buyed_brains, len([x for x in self.game_state.get_state().burySlots if x.enabled and hasattr(x, u'user')]), len([x for x in self.game_state.get_state().burySlots if x.enabled]), buyed_brains)) logger.info(u'Остров: %s' % self.game_item_reader.get(self.game_state.get_state().locationId).name) for show_item in self.account.params().show_count_on_start: show_item_obj = self.game_item_reader.get(show_item) if show_item_obj.type == u'collection': logger.info(u'%s: %i шт' % (show_item_obj.name, self.game_state.count_collection(show_item_obj.items))) elif show_item_obj.type == u'collectionItem': logger.info(u'%s: %i шт' % (show_item_obj.name, self.game_state.count_collection_item(show_item))) else: logger.info(u'%s: %i шт' % (show_item_obj.name, self.game_state.count_storage(show_item))) for buff in self.game_state.get_state().buffs.list: buff_obj = self.game_item_reader.get(buff.item) if buff.expire.type == u'time' and int(buff.expire.endDate) > 0: logger.info(u'%s: %s' % (buff_obj.name, ' '.join(timestamp_to_str(int(buff.expire.endDate))))) logger.info(u'*' * 56)
class GameEngine(object): CLIENT_VERSION = 1385060115L def __init__(self, site, account): self.site = site self.account = account self.api_user_id = None self.api_access_token = None self.request_sender = None self.factory = None self.game_item_reader = None self.game_state = None self.connection = None self.session = None self.api = None self.game_events_sender = None self.timer = None self.statistic = None def start(self): logger.info(u'Обновляем файл %s...' % items_filename) self.game_item_reader = GameItemReader() self.game_item_reader.download(items_filename) self.game_item_reader.read(items_filename) logger.info(u'Логинимся...') self.api_user_id, game_auth_key, self.api_access_token, self.connection = self.site.get_game_params( ) self.session = Session(self.api_user_id, game_auth_key, client_version=self.CLIENT_VERSION) self.factory = Factory(self.session, None) self.request_sender = RequestSender(self.factory, self.connection) self.timer = GameTimer() logger.info(u'Получаем ключ сессии...') key = self.site.get_time_key() command = GameTIME(key=key) time_response = self.request_sender.send(command) server_time = time_response.time session_key = time_response.key logger.info(u'Синхронизируем время сервера...') client_time = self.timer.get_client_time() start_time = time.time() command = self.site.create_start_command(server_time, client_time) sending_time = (time.time() - start_time) * 1000 self.timer.client_time += sending_time logger.info(u'Загружаем игровые данные...') self.factory.set_request_id(server_time) self.factory.set_session_key(session_key) self.factory.set_master(self.account) start_response = self.request_sender.send(command) self.game_state = GameState(start_response, self.game_item_reader) self.game_events_sender = GameEventsSender(self.request_sender) self.api = vk.api.API(token=self.api_access_token) # Получаем доступ к статистике self.statistic = StatisticAccess(self.account) # Показываем нашу игровую статистику self.show_game_stats() def show_game_stats(self): buyed_brains = 0 for buyed_brain in self.game_state.get_state().buyedBrains: buyed_brains += buyed_brain.count logger.info(u'%s КРАТКАЯ ИНФОРМАЦИЯ %s' % (u'*' * 18, u'*' * 18)) logger.info(u'Аккаунт: %s' % self.account.user_name) logger.info(u'Монеты: %i' % self.game_state.get_state().gameMoney) logger.info(u'Зомбаксы: %i' % self.game_state.get_state().cashMoney) logger.info(u'Опыт: %i' % self.game_state.get_state().experience) logger.info(u'Уровень: %i' % self.game_state.get_state().level) logger.info( u'Мозги: %i (%i/%i закопанных и %i платных)' % (self.game_state.get_state().brainsCount + len([ x for x in self.game_state.get_state().burySlots if x.enabled and hasattr(x, u'user') ]) + buyed_brains, len([ x for x in self.game_state.get_state().burySlots if x.enabled and hasattr(x, u'user') ]), len([ x for x in self.game_state.get_state().burySlots if x.enabled ]), buyed_brains)) logger.info(u'Остров: %s' % self.game_item_reader.get( self.game_state.get_state().locationId).name) for show_item in self.account.params().show_count_on_start: show_item_obj = self.game_item_reader.get(show_item) if show_item_obj.type == u'collection': logger.info( u'%s: %i шт' % (show_item_obj.name, self.game_state.count_collection(show_item_obj.items))) elif show_item_obj.type == u'collectionItem': logger.info(u'%s: %i шт' % (show_item_obj.name, self.game_state.count_collection_item(show_item))) else: logger.info(u'%s: %i шт' % (show_item_obj.name, self.game_state.count_storage(show_item))) for buff in self.game_state.get_state().buffs.list: buff_obj = self.game_item_reader.get(buff.item) if buff.expire.type == u'time' and int(buff.expire.endDate) > 0: logger.info(u'%s: %s' % (buff_obj.name, ' '.join( timestamp_to_str(int(buff.expire.endDate))))) logger.info(u'*' * 56)