def stop(self, finished=False, reason=TUTORIAL_STOP_REASON.DEFAULT): if self._stopped: return if self.__callbackID is not None: BigWorld.cancelCallback(self.__callbackID) self.__callbackID = None if self._funcScene is not None: self._funcScene.leave() if self._data is not None: self._data.clear() GlobalStorage.clearFlags() if self._sound is not None: self._sound.stop() self._sound = None if self._gui is not None: self._gui.fini( isItemsRevert=self._descriptor.isItemsRevertIfStop(reason)) self._gui = None if finished: self._cache.setFinished(True).write() else: self._cache.update(self._currentChapter, self._flags.getDict() if self._flags else None) self._cache = None g_tutorialWeaver.clear() clearTutorialProxy() self.removeEffectsInQueue() self._nextChapter = False self._stopped = True self._initialized = 0 self._triggeredEffects.clear() self.onStopped()
def run(self, dispatcher, ctx): self._cache = ctx.cache if self._cache is None: LOG_ERROR('Cache is not init.') return False else: self._bonuses = self._ctrlFactory.createBonuses(ctx.bonusCompleted) self._sound = self._ctrlFactory.createSoundPlayer() GlobalStorage.setFlags(ctx.globalFlags) if not self._stopped: LOG_ERROR('Tutorial is already running.') return False self._gui = createTutorialElement(self._settings.gui) self._gui.setDispatcher(dispatcher) self._gui.onGUILoaded += self.__onGUILoaded if not self._gui.init(): self._gui.onGUILoaded -= self.__onGUILoaded self._gui.setDispatcher(None) LOG_ERROR('GUI can not init. Tutorial is stopping.') return False LOG_DEBUG('Start training', ctx) self._stopped = False proxy = weakref.proxy(self) setTutorialProxy(proxy) if self.__resolveInitialChapter(ctx): self._gui.loadConfig(self._descriptor.getGuiFilePath()) self._gui.onGUIInput += self.__onGUIInput self._gui.onPageChanging += self.__onPageChanging self._gui.onItemFound += self.__onItemFound self._gui.onItemLost += self.__onItemLost self.__tryRunFirstState(INITIAL_FLAG.CHAPTER_RESOLVED) self.onStarted() return True
def stop(self, finished = False, reason = TUTORIAL_STOP_REASON.DEFAULT): if self._tutorialStopped: return else: if self.__callbackID is not None: BigWorld.cancelCallback(self.__callbackID) self.__callbackID = None if self._funcScene is not None: self._funcScene.leave() if self._data is not None: self._data.clear() GlobalStorage.clearFlags() if self._sound is not None: self._sound.stop() self._sound = None if self._gui is not None: self._gui.fini(isItemsRevert=self._descriptor.isItemsRevertIfStop(reason)) self._gui = None if finished: self._cache.setFinished(True).write() else: self._cache.update(self._currentChapter, self._flags.getDict() if self._flags else None) self._cache = None g_tutorialWeaver.clear() clearTutorialProxy() self.removeEffectsInQueue() self._nextChapter = False self._tutorialStopped = True self._initialized = 0 return
def run(self, dispatcher, ctx): self._cache = ctx.cache if self._cache is None: LOG_ERROR('Cache is not init.') return False self._bonuses = self._ctrlFactory.createBonuses(ctx.bonusCompleted) self._sound = self._ctrlFactory.createSoundPlayer() GlobalStorage.setFlags(ctx.globalFlags) if not self._stopped: LOG_ERROR('Tutorial is already running.') return False self._gui = createTutorialElement(self._settings.gui) self._gui.setDispatcher(dispatcher) self._gui.onGUILoaded += self.__onGUILoaded if not self._gui.init(): self._gui.onGUILoaded -= self.__onGUILoaded self._gui.setDispatcher(None) LOG_ERROR('GUI can not init. Tutorial is stopping.') return False LOG_DEBUG('Start training', ctx) self._stopped = False proxy = weakref.proxy(self) setTutorialProxy(proxy) if self.__resolveInitialChapter(ctx): self._gui.loadConfig(self._descriptor.getGuiFilePath()) self._gui.onGUIInput += self.__onGUIInput self._gui.onPageChanging += self.__onPageChanging self._gui.onItemFound += self.__onItemFound self._gui.onItemLost += self.__onItemLost self.__tryRunFirstState(INITIAL_FLAG.CHAPTER_RESOLVED) self.onStarted() return True
def run(self, settingsID, state=None): settings = self.__settings.getSettings(settingsID) if settings is None: _logger.error('Can not find settings: %r', settingsID) return False else: if state is None: state = {} reloadIfRun = state.pop('reloadIfRun', False) restoreIfRun = state.pop('restoreIfRun', False) isStopForced = state.pop('isStopForced', False) if self.__tutorial is not None and not self.__tutorial.isStopped(): isCurrent = self.__tutorial.getID() == settings.id if reloadIfRun and isCurrent: if isStopForced: self.__doStop() else: GlobalStorage.setFlags(state.get('globalFlags', {})) _logger.debug('invalidateFlags from TutorialLoader.run') self.__tutorial.invalidateFlags() return True elif restoreIfRun and not isCurrent: self.__restoreID = self.__tutorial.getID() self.__doStop() else: _logger.error('Tutorial already is running: %r', self.__tutorial.getID()) return False state.setdefault('isAfterBattle', self.__afterBattle) state.setdefault('restart', True) state['byRequest'] = True result = self.__doRun(settings, state) if not result: self.__restoreID = None return result
def stop(self, finished=False): if self._tutorialStopped: return else: if self.__callbackID is not None: BigWorld.cancelCallback(self.__callbackID) self.__callbackID = None if self._funcScene is not None: self._funcScene.leave() if self._data is not None: self._data.clear() GlobalStorage.clearFlags() if self._sound is not None: self._sound.stop() self._sound = None if self._gui is not None: self._gui.fini() self._gui = None if finished: self._cache.setFinished(True).write() else: self._cache.update( self._currentChapter, self._flags.getDict() if self._flags else None) self._cache = None g_tutorialWeaver.clear() clearTutorialProxy() self.removeEffectsInQueue() self._nextChapter = False self._tutorialStopped = True self._initialized = 0 return
def __init__(self, **kwargs): super(RunCtx, self).__init__() self.cache = None self.restart = kwargs.get('restart', False) self.isInRandomQueue = kwargs.get('isInRandomQueue', False) self.isInPrebattle = kwargs.get('prebattleID', 0L) > 0L self.isInTutorialQueue = GlobalStorage( GLOBAL_FLAG.IN_QUEUE, kwargs.get('isInTutorialQueue', False)) self.settings = kwargs.get('settings', TUTORIAL_SETTINGS.DEFAULT_SETTINGS) self.bonusCompleted = kwargs.get('bonusCompleted', 0) return
def run(self, settingsID, state = None): """ Try to run tutorial. :param settingsID: string containing settings ID of required tutorial. :param state: dict( reloadIfRun : bool - just reload tutorial if it's running, afterBattle : bool - tutorial should load scenario that is played when player left battle, initialChapter : str - name of initial chapter, restoreIfRun: bool - current tutorial will be started again if required tutorial stop. globalFlags : dict(GLOBAL_FLAG.* : bool,) ) :return: True if tutorial has started, otherwise - False. """ settings = self.__settings.getSettings(settingsID) if settings is None: LOG_ERROR('Can not find settings', settingsID) return False else: if state is None: state = {} reloadIfRun = state.pop('reloadIfRun', False) restoreIfRun = state.pop('restoreIfRun', False) isStopForced = state.pop('isStopForced', False) if self.__tutorial is not None and not self.__tutorial.isStopped(): isCurrent = self.__tutorial.getID() == settings.id if reloadIfRun and isCurrent: if isStopForced: self.__doStop() else: GlobalStorage.setFlags(state.get('globalFlags', {})) self.__tutorial.invalidateFlags() return True elif restoreIfRun and not isCurrent: self.__restoreID = self.__tutorial.getID() self.__doStop() else: LOG_ERROR('Tutorial already is running', self.__tutorial.getID()) return False if self.__dispatcher is None: self.__setDispatcher(settings.dispatcher) cache = _cache.TutorialCache(BigWorld.player().name) cache.read() state.setdefault('isAfterBattle', self.__afterBattle) state.setdefault('restart', True) result = self.__doRun(settings, RunCtx(cache, **state), byRequest=True) if not result: self.__restoreID = None return result
def run(self, settingsID, state=None): """ Try to run tutorial. :param settingsID: string containing settings ID of required tutorial. :param state: dict( reloadIfRun : bool - just reload tutorial if it's running, afterBattle : bool - tutorial should load scenario that is played when player left battle, initialChapter : str - name of initial chapter, restoreIfRun: bool - current tutorial will be started again if required tutorial stop. globalFlags : dict(GLOBAL_FLAG.* : bool,) ) :return: True if tutorial has started, otherwise - False. """ settings = self.__settings.getSettings(settingsID) if settings is None: LOG_ERROR('Can not find settings', settingsID) return False else: if state is None: state = {} reloadIfRun = state.pop('reloadIfRun', False) restoreIfRun = state.pop('restoreIfRun', False) isStopForced = state.pop('isStopForced', False) if self.__tutorial is not None and not self.__tutorial.isStopped(): isCurrent = self.__tutorial.getID() == settings.id if reloadIfRun and isCurrent: if isStopForced: self.__doStop() else: GlobalStorage.setFlags(state.get('globalFlags', {})) self.__tutorial.invalidateFlags() return True elif restoreIfRun and not isCurrent: self.__restoreID = self.__tutorial.getID() self.__doStop() else: LOG_ERROR('Tutorial already is running', self.__tutorial.getID()) return False state.setdefault('isAfterBattle', self.__afterBattle) state.setdefault('restart', True) state['byRequest'] = True result = self.__doRun(settings, state) if not result: self.__restoreID = None return result
class TutorialModeTrigger(Trigger, IGlobalListener): _inAvailable = GlobalStorage(GLOBAL_FLAG.MODE_IS_AVAILABLE, False) def __init__(self, triggerID): super(TutorialModeTrigger, self).__init__(triggerID) self._inMode = False def run(self): if not self.isSubscribed: self.startGlobalListening() self.isSubscribed = True self.__setState() super(TutorialModeTrigger, self).run() def isOn(self, *args): return self._inMode def clear(self): if self.isSubscribed: self.stopGlobalListening() self.isSubscribed = False self._inMode = False super(TutorialModeTrigger, self).clear() def onPrbEntitySwitched(self): self.__setState() self.toggle(isOn=self._inMode) def __setState(self): funcState = self.prbDispatcher.getFunctionalState() self._inMode = funcState.isInPreQueue(QUEUE_TYPE.TUTORIAL) self._inAvailable = funcState.isInPreQueue(QUEUE_TYPE.RANDOMS) or funcState.isInPreQueue(QUEUE_TYPE.SANDBOX)
class TutorialQueueTrigger(Trigger, GlobalListener): _inQueue = GlobalStorage(GLOBAL_FLAG.IN_QUEUE, False) def __init__(self, triggerID, popUpID): super(TutorialQueueTrigger, self).__init__(triggerID) self._event = ContentChangedEvent(popUpID) def run(self): if not self.isSubscribed: self.startGlobalListening() self.isSubscribed = True super(TutorialQueueTrigger, self).run() def isOn(self, *args): return self._inQueue def clear(self): self._gui.hideWaiting('queue') if self.isSubscribed: self.stopGlobalListening() self.isSubscribed = False self._inQueue = False super(TutorialQueueTrigger, self).clear() def onEnqueued(self, queueType, *args): if queueType != QUEUE_TYPE.TUTORIAL: return if len(args) < 3: LOG_ERROR('Number of argument is invalid', args) queueNumber, queueLen, avgWaitingTime = (0, 0, 0) else: queueNumber, queueLen, avgWaitingTime = args[:3] self._event.fire(avgWaitingTime) if not self._inQueue: self._inQueue = True self.toggle(isOn=True) def onDequeued(self, queueType, *args): if queueType != QUEUE_TYPE.TUTORIAL: return if self._inQueue: self._inQueue = False self.toggle(isOn=False) def onEnqueueError(self, queueType, *args): if queueType == QUEUE_TYPE.TUTORIAL: self._tutorial.refuse() def onKickedFromQueue(self, queueType, *args): if queueType == QUEUE_TYPE.TUTORIAL: self._tutorial.refuse() def onKickedFromArena(self, queueType, *args): if queueType == QUEUE_TYPE.TUTORIAL: self._tutorial.refuse() def onArenaJoinFailure(self, queueType, *args): if queueType == QUEUE_TYPE.TUTORIAL: self._tutorial.refuse()
class TutorialQueueTrigger(Trigger): _inQueue = GlobalStorage(GLOBAL_FLAG.IN_QUEUE, False) def __init__(self, triggerID, popUpID): super(TutorialQueueTrigger, self).__init__(triggerID) self._event = ContentChangedEvent(popUpID) def run(self): if not self.isSubscribed: g_playerEvents.onTutorialEnqueued += self.__pe_onTutorialEnqueued g_playerEvents.onTutorialDequeued += self.__pe_onTutorialDequeued g_playerEvents.onTutorialEnqueueFailure += self.__pe_onTutorialEnqueueFailure g_playerEvents.onArenaJoinFailure += self.__pe_onArenaJoinFailure g_playerEvents.onKickedFromArena += self.__pe_onKickedFromArena self.isSubscribed = True super(TutorialQueueTrigger, self).run() def isOn(self, *args): return self._inQueue def clear(self): self._gui.hideWaiting('queue') if self.isSubscribed: g_playerEvents.onTutorialEnqueued -= self.__pe_onTutorialEnqueued g_playerEvents.onTutorialDequeued -= self.__pe_onTutorialDequeued g_playerEvents.onTutorialEnqueueFailure -= self.__pe_onTutorialEnqueueFailure g_playerEvents.onArenaJoinFailure -= self.__pe_onArenaJoinFailure g_playerEvents.onKickedFromArena -= self.__pe_onKickedFromArena self.isSubscribed = False self._inQueue = False super(TutorialQueueTrigger, self).clear() def __pe_onTutorialEnqueued(self, queueNumber, queueLen, avgWaitingTime): self._event.fire(avgWaitingTime) if not self._inQueue: self._inQueue = True self.toggle(isOn=True) def __pe_onTutorialDequeued(self): if self._inQueue: self._inQueue = False self.toggle(isOn=False) def __pe_onTutorialEnqueueFailure(self, errorCode, errorStr): if errorCode in JOIN_FAILURE_NAMES: text = '#system_messages:arena_start_errors/join/{0:>s}'.format( JOIN_FAILURE_NAMES[errorCode]) else: text = errorStr self._gui.showI18nMessage(text, msgType='Error') self._tutorial.refuse() def __pe_onArenaJoinFailure(self, errorCode, errorStr): self._tutorial.refuse() def __pe_onKickedFromArena(self, errorCode): self._tutorial.refuse()
class BattleFinalStatistic(ContentQuery): _isHistory = GlobalStorage(GLOBAL_FLAG.SHOW_HISTORY, False) def invoke(self, content, varID): localCtx = OffBattleClientCtx.fetch(self._cache) descriptor = getBattleDescriptor() if descriptor is None: return else: if self._isHistory: received = self.__getReceivedBonusesInHistory( descriptor, localCtx) else: received = self.getVar(varID, default=0) content['finished'] = descriptor.areAllBonusesReceived( localCtx.completed) content[ 'areAllBonusesReceived'] = descriptor.areAllBonusesReceived( self._bonuses.getCompleted()) content['arenaUniqueID'] = localCtx.arenaUniqueID content['isHistory'] = self._isHistory self.__addTotalResult(localCtx, content) self.__addChaptersProcess(descriptor, localCtx, received, content) if content['areAllBonusesReceived']: self._cache.setPlayerXPLevel(PLAYER_XP_LEVEL.NORMAL) self._cache.setAfterBattle(False).write() return def __addTotalResult(self, ctx, content): totalKey, finishKey = getTrainingResultKeys(content['finished'], ctx) content['totalResult'] = i18n.makeString( '#battle_tutorial:labels/training-result/{0:>s}'.format(totalKey)) content['finishReason'] = i18n.makeString( '#battle_tutorial:labels/finish-reason/{0:>s}'.format(finishKey)) def __addChaptersProcess(self, descriptor, ctx, received, content): content['chapters'] = _getChaptersResults(descriptor, ctx, received) content['progressMask'] = descriptor.getProgress(ctx.completed) content['lastChapter'] = ctx.chapterIdx content['totalChapters'] = descriptor.getNumberOfChapters() return content def __getReceivedBonusesInHistory(self, descriptor, ctx): accCompleted = 0 inBattle = 0 received = 0 if ctx.accCompleted > 0: accCompleted = ctx.accCompleted if ctx.completed > 0: inBattle = ctx.completed for chapter in descriptor: if chapter.hasBonus() and chapter.isBonusReceived(inBattle): bit = 1 << chapter.getBonusID() if accCompleted & bit == 0: received |= bit return received
def __init__(self, **kwargs): super(RunCtx, self).__init__() self.cache = None self.restart = kwargs.get('restart', False) self.isInRandomQueue = kwargs.get('isInRandomQueue', False) self.isInPrebattle = kwargs.get('prebattleID', 0L) > 0L self.isInTutorialQueue = GlobalStorage(GLOBAL_FLAG.IN_QUEUE, kwargs.get('isInTutorialQueue', False)) self.settings = kwargs.get('settings', TUTORIAL_SETTINGS.DEFAULT_SETTINGS) self.bonusCompleted = kwargs.get('bonusCompleted', 0) return
class SfLobbyDispatcher(GUIDispatcher): _lastHistoryID = GlobalStorage(GLOBAL_VAR.LAST_HISTORY_ID, 0) def __init__(self): super(SfLobbyDispatcher, self).__init__() self._exit = None return def __del__(self): LOG_MEMORY('SfLobbyDispatcher deleted') def start(self, loader): if not super(SfLobbyDispatcher, self).start(loader): return False addListener = g_eventBus.addListener addListener(TutorialEvent.START_TRAINING, self.__handleStartTraining, scope=EVENT_BUS_SCOPE.GLOBAL) addListener(TutorialEvent.STOP_TRAINING, self.__handleStopTraining, scope=EVENT_BUS_SCOPE.GLOBAL) addListener(TutorialEvent.SHOW_TUTORIAL_BATTLE_HISTORY, self.__handleShowHistory, scope=EVENT_BUS_SCOPE.DEFAULT) return True def stop(self): if not super(SfLobbyDispatcher, self).stop(): return False removeListener = g_eventBus.removeListener removeListener(TutorialEvent.START_TRAINING, self.__handleStartTraining, scope=EVENT_BUS_SCOPE.GLOBAL) removeListener(TutorialEvent.STOP_TRAINING, self.__handleStopTraining, scope=EVENT_BUS_SCOPE.GLOBAL) removeListener(TutorialEvent.SHOW_TUTORIAL_BATTLE_HISTORY, self.__handleShowHistory, scope=EVENT_BUS_SCOPE.DEFAULT) self.clearGUI() return True def __handleStartTraining(self, event): if not event.settingsID: LOG_ERROR('Name of tutorial is not defined', event.settingsID) return Waiting.show('tutorial-chapter-loading', isSingle=True) self.startTraining(event.settingsID, event.getState()) Waiting.hide('tutorial-chapter-loading') def __handleStopTraining(self, _): self.stopTraining() def __handleShowHistory(self, event): if not event.targetID: LOG_ERROR('Required parameters is not defined to show history', event.targetID) return isNotAvailable = self._lastHistoryID != event.targetID state = {'reloadIfRun': True, 'restoreIfRun': True, 'isAfterBattle': True, 'globalFlags': {GLOBAL_FLAG.SHOW_HISTORY: True, GLOBAL_FLAG.IS_FLAGS_RESET: True, GLOBAL_FLAG.HISTORY_NOT_AVAILABLE: isNotAvailable}} Waiting.show('tutorial-chapter-loading', isSingle=True) self.startTraining(TUTORIAL_SETTINGS.OFFBATTLE.id, state) Waiting.hide('tutorial-chapter-loading')
def getImagePaths(self, varSummary): path = varSummary.get(self._pathRef) originPath = [] altPath = [] if path: originPath.append(path) altPath.append(path) else: return (self._image, self._image) default = varSummary.get(self._defaultRef) if default: from tutorial.control.context import GLOBAL_VAR, GlobalStorage vehTypeName = GlobalStorage(GLOBAL_VAR.PLAYER_VEHICLE_NAME, default).value() if vehTypeName and default != vehTypeName: originPath.append(vehTypeName.replace(':', '_')) originPath.append(self._image) altPath.append(self._image) if originPath != altPath: result = ('/'.join(originPath), '/'.join(altPath)) else: result = ('/'.join(originPath), '') return result
def __init__(self, **kwargs): super(RunCtx, self).__init__() self.cache = None self.isFirstStart = False self.databaseID = kwargs.get('databaseID', 0L) self.restart = kwargs.get('restart', False) self.isInRandomQueue = kwargs.get('isInRandomQueue', False) self.isInPrebattle = isInPrebattle() self.isInTutorialQueue = GlobalStorage(GLOBAL_FLAG.IN_QUEUE, kwargs.get('isInTutorialQueue', False)) self.isInHistoricalQueue = kwargs.get('isInHistoricalQueue', False) self.isInEventBattlesQueue = kwargs.get('isInEventBattles', False) self.settings = kwargs.get('settings', TUTORIAL_SETTINGS.DEFAULT_SETTINGS) self.bonusCompleted = kwargs.get('bonusCompleted', 0)
def getImagePaths(self, varSummary): path = varSummary.get(self._pathRef) originPath = [] altPath = [] if path and len(path): originPath.append(path) altPath.append(path) else: return (self._image, self._image) default = varSummary.get(self._defaultRef) if default and len(default): from tutorial.control.context import GLOBAL_VAR, GlobalStorage vehTypeName = GlobalStorage(GLOBAL_VAR.PLAYER_VEHICLE_NAME, default).value() if vehTypeName and default != vehTypeName: originPath.append(vehTypeName.replace(':', '_')) originPath.append(self._image) altPath.append(self._image) if originPath != altPath: result = ('/'.join(originPath), '/'.join(altPath)) else: result = ('/'.join(originPath), '') return result
def stop(self, finished=False): """ Stops the process of training. :param finished: if it equals True than training completed. """ if self._stopped: return else: if self.__callbackID is not None: BigWorld.cancelCallback(self.__callbackID) self.__callbackID = None if self._funcScene is not None: self._funcScene.leave() if self._data is not None: self._data.clear() GlobalStorage.clearFlags() if self._sound is not None: self._sound.stop() self._sound = None if self._gui is not None: self._gui.fini() self._gui = None if finished: self._cache.setFinished(True).write() else: self._cache.update( self._currentChapter, self._flags.getDict() if self._flags else None) self._cache = None g_tutorialWeaver.clear() clearTutorialProxy() self.removeEffectsInQueue() self._nextChapter = False self._stopped = True self._initialized = 0 self._triggeredEffects.clear() self.onStopped() return
def stop(self, finished = False): """ Stops the process of training. :param finished: if it equals True than training completed. """ if self._stopped: return else: if self.__callbackID is not None: BigWorld.cancelCallback(self.__callbackID) self.__callbackID = None if self._funcScene is not None: self._funcScene.leave() if self._data is not None: self._data.clear() GlobalStorage.clearFlags() if self._sound is not None: self._sound.stop() self._sound = None if self._gui is not None: self._gui.fini() self._gui = None if finished: self._cache.setFinished(True).write() else: self._cache.update(self._currentChapter, self._flags.getDict() if self._flags else None) self._cache = None g_tutorialWeaver.clear() clearTutorialProxy() self.removeEffectsInQueue() self._nextChapter = False self._stopped = True self._initialized = 0 self._triggeredEffects.clear() self.onStopped() return
class FunctionalShowMessage4QueryEffect(FunctionalEffect): _messagesIDs = GlobalStorage(GLOBAL_VAR.SERVICE_MESSAGES_IDS, []) def triggerEffect(self): target = self.getTarget() if target is not None: content = {} query = self._tutorial._ctrlFactory.createContentQuery(target.getType()) query.invoke(content, target.getVarRef()) messageID = self._gui.showServiceMessage(content, target.getExtra()) if messageID: ids = self._messagesIDs if isinstance(ids, collections.Iterable): ids.append(messageID) else: LOG_ERROR('Target not found', self._effect.getTargetID())
class BattleResultMessage(ContentQuery): _lastHistoryID = GlobalStorage(GLOBAL_VAR.LAST_HISTORY_ID, 0) def invoke(self, content, varID): received = self.getVar(varID, default=0) localCtx = OffBattleClientCtx.fetch(self._cache) self._lastHistoryID = localCtx.arenaUniqueID descriptor = getBattleDescriptor() if descriptor is None: return content.update(localCtx._asdict()) resultKey, finishKey = getTrainingResultKeys(descriptor.areAllBonusesReceived(localCtx.completed), localCtx) content['resultKey'] = resultKey content['finishKey'] = finishKey content['chapters'] = _getChaptersResults(descriptor, localCtx, received) content['areAllBonusesReceived'] = descriptor.areAllBonusesReceived(self._bonuses.getCompleted())
def _isConditionActive(self, result, condition, flags): condType = condition.getType() baseType = chapter.Condition if condType == baseType.FLAG_CONDITION: result = condition.isActiveState() == flags.isActiveFlag( condition.getID()) elif condType == baseType.GLOBAL_FLAG_CONDITION: result = condition.isActiveState() == GlobalStorage( condition.getID(), False).value() elif condType == baseType.VEHICLE_CONDITION: result = condition.isValueEqual( game_vars.vehicle(condition.getID())) elif condType == baseType.WINDOW_ON_SCENE_CONDITION: result = condition.isActiveState( ) == self._gui.isTutorialWindowDisplayed(condition.getID()) return result
def __cb_onGetTutorialsCompleted(self, resultID, completed): ctx = self._ctx loader = self._loader tutorial = loader.tutorial if resultID < RES_SUCCESS: LOG_ERROR('Server return error on request tutorialsCompleted', resultID, completed) loader._clear() self._clear() return else: ctx.bonusCompleted = completed cache = ctx.cache battleDesc = _getBattleDescriptor() if battleDesc is None: LOG_ERROR('Battle tutorial is not defined.') loader._clear() self._clear() return finishReason = OffBattleClientCtx.fetch(cache).finishReason isHistory = GlobalStorage(GLOBAL_FLAG.SHOW_HISTORY, False).value() if isHistory or not cache.isRefused( ) and loader.isAfterBattle and finishReason not in [ -1, FINISH_REASON.FAILURE ]: cache.setAfterBattle(True) else: cache.setAfterBattle(False) if not battleDesc.areAllBonusesReceived(completed): if cache.getPlayerXPLevel() == PLAYER_XP_LEVEL.NEWBIE: BigWorld.player().stats.get('dossier', self.__cb_onGetDossier) else: self._clear() self._resolveTutorialState(loader, ctx) else: cache.setPlayerXPLevel(PLAYER_XP_LEVEL.NORMAL) self._clear() self._resolveTutorialState(loader, ctx) return
class RunCtx(object): __slots__ = [ 'cache', 'afterBattle', 'restart', 'isInRandomQueue', 'isInPrebattle', 'isInTutorialQueue', 'settings', 'bonusCompleted' ] def __init__(self, **kwargs): super(RunCtx, self).__init__() self.cache = None self.restart = kwargs.get('restart', False) self.isInRandomQueue = kwargs.get('isInRandomQueue', False) self.isInPrebattle = kwargs.get('prebattleID', 0L) > 0L self.isInTutorialQueue = GlobalStorage( GLOBAL_FLAG.IN_QUEUE, kwargs.get('isInTutorialQueue', False)) self.settings = kwargs.get('settings', TUTORIAL_SETTINGS.DEFAULT_SETTINGS) self.bonusCompleted = kwargs.get('bonusCompleted', 0) return def __repr__(self): return 'RunCtx(settings = {0:>s}, bonuses = {1:n}, cache = {2!r:s}, inPrb = {3!r:s}, inQueue = {4!r:s})'.format( self.settings, self.bonusCompleted, self.cache, self.isInPrebattle, self.isInTutorialQueue.value())
def triggerEffect(self): GlobalStorage.setValue(self._effect.getTargetID(), False)
def isConditionOk(self, condition): result = GlobalStorage(condition.getID(), False).value() if condition.isPositiveState(): return result else: return not result
def prepare(self, ctx): clientCtx = BattleClientCtx.fetch() ctx.bonusCompleted = clientCtx.completed GlobalStorage.clearVars()
def process(self): loader, ctx = self._flush() clientCtx = BattleClientCtx.fetch() ctx.bonusCompleted = clientCtx.completed GlobalStorage.clearVars() loader._doRun(ctx)
class FunctionalBattleScene(FunctionalScene): _vehTypeName = GlobalStorage(GLOBAL_VAR.PLAYER_VEHICLE_NAME, None) def __init__(self, scene): super(FunctionalBattleScene, self).__init__(scene) self._exitTime = 0 self._exitEntity = None self._arenaFinished = False return def enter(self): g_playerEvents.onArenaPeriodChange += self.__pe_onArenaPeriodChange arena = getattr(BigWorld.player(), 'arena', None) if arena is not None and arena.period is ARENA_PERIOD.BATTLE: self.__requestRequiredData() if self._vehTypeName is None: vehType = getattr(BigWorld.player(), 'vehicleTypeDescriptor', None) if vehType is not None: self._vehTypeName = vehType.name else: LOG_ERROR('Player\\s vehicle not found') for item in self._scene.getGuiItems(): self._gui.setItemProps(item.getTargetID(), item.getProps(), revert=False) self._gui.show() return def leave(self): super(FunctionalBattleScene, self).leave() _MarkersStorage.clear() g_playerEvents.onArenaPeriodChange -= self.__pe_onArenaPeriodChange self._cache.setLocalCtx(ExtendedBattleClientCtx.fetch().makeRecord()) self._exitTime = 0 self._exitEntity = None return def reload(self): _MarkersStorage.clear() def update(self): super(FunctionalBattleScene, self).update() if _MarkersStorage.hasMarkers(): tManager = TriggersManager.g_manager if tManager is None or not tManager.isEnabled(): LOG_ERROR('TriggersManager is not defined or is not enabled') return _MarkersStorage.updateMarkers(tManager) if self._arenaFinished and self.__isDelayPerformed(): avatar_getter.leaveArena() return def setExit(self, exitEntity): self._exitEntity = exitEntity if exitEntity.isSpeakOver(): self._exitTime = 0 else: self._exitTime = BigWorld.time() + exitEntity.getFinishDelay() def __isDelayPerformed(self): result = True if self._exitEntity and self._exitEntity.isSpeakOver(): result = not self._sound.isPlaying(SOUND_EVENT.SPEAKING) if result: self._sound.setMuted(True) self._exitTime = BigWorld.time( ) + self._exitEntity.getFinishDelay() self._exitEntity = None if self._exitTime > 0: result = self._exitTime < BigWorld.time() return result def __requestRequiredData(self): localCtx = BattleClientCtx.fetch() if localCtx.startedAt == 0.0: localCtx.setStartedAt(time.time()) if localCtx.accCompleted < 0: player = BigWorld.player() if player is None or not hasattr(player, 'requestAccountStats'): LOG_DEBUG('Stats method not found', player) return LOG_REQUEST('Avatar.requestAccountStats') player.requestAccountStats(['tutorialsCompleted'], self.__onReceiveAccountStats) return def __onReceiveAccountStats(self, stats): BattleClientCtx.fetch().setAccCompleted( stats.get('tutorialsCompleted', 0)) def __pe_onArenaPeriodChange(self, period, *args): if period is ARENA_PERIOD.BATTLE: self.__requestRequiredData() elif period is ARENA_PERIOD.AFTERBATTLE: self._arenaFinished = True if self.__isDelayPerformed(): avatar_getter.leaveArena()
class RunCtx(object): __slots__ = ['cache', 'isFirstStart', 'databaseID', 'afterBattle', 'restart', 'isInRandomQueue', 'isInPrebattle', 'isInTutorialQueue', 'settings', 'bonusCompleted', 'isInHistoricalQueue', 'isInEventBattlesQueue'] def __init__(self, **kwargs): super(RunCtx, self).__init__() self.cache = None self.isFirstStart = False self.databaseID = kwargs.get('databaseID', 0L) self.restart = kwargs.get('restart', False) self.isInRandomQueue = kwargs.get('isInRandomQueue', False) self.isInPrebattle = isInPrebattle() self.isInTutorialQueue = GlobalStorage(GLOBAL_FLAG.IN_QUEUE, kwargs.get('isInTutorialQueue', False)) self.isInHistoricalQueue = kwargs.get('isInHistoricalQueue', False) self.isInEventBattlesQueue = kwargs.get('isInEventBattles', False) self.settings = kwargs.get('settings', TUTORIAL_SETTINGS.DEFAULT_SETTINGS) self.bonusCompleted = kwargs.get('bonusCompleted', 0) return def __repr__(self): return 'RunCtx(settings = {0:>s}, bonuses = {1:n}, cache = {2!r:s}, inPrb = {3!r:s}, inQueue = {4!r:s})'.format(self.settings, self.bonusCompleted, self.cache, self.isInPrebattle, self.isInTutorialQueue.value())
def triggerEffect(self): GlobalStorage.setValue(self._effect.getTargetID(), True) return True