def _getPlayersStateStats(self, rosterKey): """ Get players state stats Args: rosterKey: roster key mask """ clientPrb = prb_getters.getClientPrebattle() notReadyCount = 0 playersCount = 0 limitMaxCount = 0 haveInBattle = False if clientPrb: players = clientPrb.rosters.get(rosterKey, {}) playersCount = len(players) team, assigned = decodeRoster(rosterKey) teamLimits = self._settings.getTeamLimits(team) limitMaxCount = teamLimits['maxCount'][not assigned] for _, accInfo in players.iteritems(): state = accInfo.get('state', PREBATTLE_ACCOUNT_STATE.UNKNOWN) if not state & PREBATTLE_ACCOUNT_STATE.READY: notReadyCount += 1 if not haveInBattle and state & PREBATTLE_ACCOUNT_STATE.IN_BATTLE: haveInBattle = True return prb_items.PlayersStateStats(notReadyCount, haveInBattle, playersCount, limitMaxCount)
def fini(self, clientPrb=None, woEvents=False): self._hasEntity = False self._settings = None super(PrbDispatcher, self).fini(clientPrb, woEvents) if self._limits is not None: self._limits.clear() self._limits = None if not woEvents: try: self._invokeListeners('onPrbFunctionalFinished') except: LOG_CURRENT_EXCEPTION() self.clear() if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingUpdated -= self.prb_onSettingUpdated clientPrb.onTeamStatesReceived -= self.prb_onTeamStatesReceived clientPrb.onPlayerStateChanged -= self.prb_onPlayerStateChanged clientPrb.onPlayerRosterChanged -= self.prb_onPlayerRosterChanged clientPrb.onPlayerAdded -= self.prb_onPlayerAdded clientPrb.onPlayerRemoved -= self.prb_onPlayerRemoved clientPrb.onKickedFromQueue -= self.prb_onKickedFromQueue return FUNCTIONAL_FLAG.UNDEFINED
def fini(self, clientPrb = None, woEvents = False): if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingsReceived -= self.prb_onSettingsReceived clientPrb.onRosterReceived -= self.prb_onRosterReceived return FUNCTIONAL_FLAG.UNDEFINED
def fini(self, clientPrb = None, woEvents = False): self._hasEntity = False self._settings = None super(PrbDispatcher, self).fini(clientPrb, woEvents) if self._limits is not None: self._limits.clear() self._limits = None if not woEvents: try: self._invokeListeners('onPrbFunctionalFinished') except: LOG_CURRENT_EXCEPTION() self.clear() if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingUpdated -= self.prb_onSettingUpdated clientPrb.onTeamStatesReceived -= self.prb_onTeamStatesReceived clientPrb.onPlayerStateChanged -= self.prb_onPlayerStateChanged clientPrb.onPlayerRosterChanged -= self.prb_onPlayerRosterChanged clientPrb.onPlayerAdded -= self.prb_onPlayerAdded clientPrb.onPlayerRemoved -= self.prb_onPlayerRemoved clientPrb.onKickedFromQueue -= self.prb_onKickedFromQueue return FUNCTIONAL_FLAG.UNDEFINED
def fini(self, clientPrb=None, woEvents=False): if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingsReceived -= self.prb_onSettingsReceived clientPrb.onRosterReceived -= self.prb_onRosterReceived return FUNCTIONAL_FLAG.UNDEFINED
def _canAddPlayers(self): clientPrb = prb_getters.getClientPrebattle() result = False if clientPrb is not None: settings = prb_getters.getPrebattleSettings(prebattle=clientPrb) rosters = prb_getters.getPrebattleRosters(prebattle=clientPrb) result, _ = limits.MaxCount().check(rosters, 1, settings.getTeamLimits(1)) return result
def _canAddPlayers(self): clientPrb = prb_getters.getClientPrebattle() result = False if clientPrb is not None: settings = prb_getters.getPrebattleSettings(prebattle=clientPrb) rosters = prb_getters.getPrebattleRosters(prebattle=clientPrb) result, _ = MaxCount().check(rosters, 1, settings.getTeamLimits(1)) return result
def pe_onPrebattleJoined(self): if prb_getters.getClientPrebattle() is not None: self.__setLegacy(self.__requestCtx.getFlags()) else: LOG_ERROR('ClientPrebattle is not defined') self.__setDefault() g_eventDispatcher.loadHangar() return
def pe_onPrebattleJoined(self): if prb_getters.getClientPrebattle() is not None: flags = self.__requestCtx.getFlags() self.__setFunctional(CreateFunctionalCtx(_CTRL_TYPE.PREBATTLE, flags=flags)) else: LOG_ERROR("ClientPrebattle is not defined") self.__requestCtx.stopProcessing(result=False) return
def pe_onPrebattleJoined(self): if prb_getters.getClientPrebattle() is not None: flags = self.__requestCtx.getFlags() self.__setFunctional( CreateFunctionalCtx(_CTRL_TYPE.PREBATTLE, flags=flags)) else: LOG_ERROR('ClientPrebattle is not defined') self.__requestCtx.stopProcessing(result=False) return
def fini(self, clientPrb=None, ctx=None, woEvents=False): if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingsReceived -= self.prb_onSettingsReceived clientPrb.onRosterReceived -= self.prb_onRosterReceived return super(LegacyInitEntity, self).fini(clientPrb=clientPrb, ctx=ctx, woEvents=woEvents)
def join(self, ctx, callback = None): if prb_getters.getClientPrebattle() is None or ctx.isForced(): ctx.startProcessing(callback=callback) BigWorld.player().prb_join(ctx.getID()) else: LOG_ERROR('First, player has to confirm exit from the current prebattle', prb_getters.getPrebattleType()) if callback: callback(False) return
def _canAddPlayers(self): """ Can new player be added to team according to max limit """ clientPrb = prb_getters.getClientPrebattle() result = False if clientPrb is not None: settings = prb_getters.getPrebattleSettings(prebattle=clientPrb) rosters = prb_getters.getPrebattleRosters(prebattle=clientPrb) result, _ = MaxCount().check(rosters, 1, settings.getTeamLimits(1)) return result
def init(self, clientPrb = None, ctx = None): if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingsReceived += self.prb_onSettingsReceived clientPrb.onRosterReceived += self.prb_onRosterReceived if prb_getters.isPrebattleSettingsReceived(prebattle=clientPrb): self.prb_onSettingsReceived() if prb_getters.getPrebattleRosters(prebattle=clientPrb): self.prb_onRosterReceived() return FUNCTIONAL_FLAG.UNDEFINED
def init(self, clientPrb=None, ctx=None): result = super(EpicBattleTrainingEntity, self).init(clientPrb=clientPrb) g_eventBus.addListener(ViewEventType.LOAD_VIEW, self.__handleViewLoad, scope=EVENT_BUS_SCOPE.LOBBY) if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onPlayerGroupChanged += self.__prb_onPlayerGroupChanged self.__enterTrainingRoom(True) g_eventDispatcher.addEpicTrainingToCarousel(False) result = FUNCTIONAL_FLAG.addIfNot(result, FUNCTIONAL_FLAG.LOAD_WINDOW) result = FUNCTIONAL_FLAG.addIfNot(result, FUNCTIONAL_FLAG.LOAD_PAGE) return result
def init(self, clientPrb=None, ctx=None): result = super(LegacyInitEntity, self).init(clientPrb=clientPrb, ctx=ctx) if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingsReceived += self.prb_onSettingsReceived clientPrb.onRosterReceived += self.prb_onRosterReceived if prb_getters.isPrebattleSettingsReceived(prebattle=clientPrb): self.prb_onSettingsReceived() if prb_getters.getPrebattleRosters(prebattle=clientPrb): self.prb_onRosterReceived() return result
def pe_onPrebattleJoined(self): """ Player event listener for prebattle join. Sets entity to proper legacy or resets to default. """ if prb_getters.getClientPrebattle() is not None: self.__setLegacy(self.__requestCtx.getFlags()) else: LOG_ERROR('ClientPrebattle is not defined') self.__setDefault() g_eventDispatcher.loadHangar() return
def canAssignToTeam(self, team = 1): result = super(BattleSessionPermissions, self).canAssignToTeam(team) if not result: return False else: clientPrb = prb_getters.getClientPrebattle() result = False if clientPrb is not None: settings = prb_getters.getPrebattleSettings(prebattle=clientPrb) rosters = prb_getters.getPrebattleRosters(prebattle=clientPrb) prbType = prb_getters.getPrebattleType(clientPrb, settings) result, _ = TeamNoPlayersInBattle(prbType).check(rosters, team, settings.getTeamLimits(team)) return result
def canAssignToTeam(self, team = 1): result = super(BattleSessionPrbPermissions, self).canAssignToTeam(team) if not result: return False else: clientPrb = prb_getters.getClientPrebattle() result = False if clientPrb is not None: settings = prb_getters.getPrebattleSettings(prebattle=clientPrb) rosters = prb_getters.getPrebattleRosters(prebattle=clientPrb) prbType = prb_getters.getPrebattleType(clientPrb, settings) result, _ = limits.TeamNoPlayersInBattle(prbType).check(rosters, team, settings.getTeamLimits(team)) return result
def create(self, ctx, callback = None): if prb_cooldown.validatePrbCreationCooldown(): if callback is not None: callback(False) elif prb_getters.getClientPrebattle() is None or ctx.isForced(): ctx.startProcessing(callback=callback) BigWorld.player().prb_createCompany(ctx.isOpened(), ctx.getComment(), ctx.getDivision()) prb_cooldown.setPrbCreationCooldown() else: LOG_ERROR('First, player has to confirm exit from the current prebattle', prb_getters.getPrebattleType()) if callback is not None: callback(False) return
def init(self, clientPrb=None, ctx=None): result = super(EpicBattleTrainingEntity, self).init(clientPrb=clientPrb) add = g_eventBus.addListener for event in self.__loadEvents: add(event, self.__handleViewLoad, scope=EVENT_BUS_SCOPE.LOBBY) if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onPlayerGroupChanged += self.__prb_onPlayerGroupChanged self.__enterTrainingRoom(True) result = FUNCTIONAL_FLAG.addIfNot(result, FUNCTIONAL_FLAG.LOAD_WINDOW) result = FUNCTIONAL_FLAG.addIfNot(result, FUNCTIONAL_FLAG.LOAD_PAGE) return result
def __createByAccountState(self, ctx): clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: if prb_getters.isPrebattleSettingsReceived(prebattle=clientPrb): prbSettings = prb_getters.getPrebattleSettings( prebattle=clientPrb) prbType = prb_getters.getPrebattleType(settings=prbSettings) clazz = None clazz = collectLegacyEntity(prbType) if clazz: return clazz(prbSettings) else: return LegacyInitEntity() return self.__createByPrbType(ctx)
def __checkPrebattleLockedVehicle(self): clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: rosters = prb_getters.getPrebattleRosters(prebattle=clientPrb) for rId, roster in rosters.iteritems(): if BigWorld.player().id in roster: vehCompDescr = roster[BigWorld.player().id].get('vehCompDescr', '') if len(vehCompDescr): vehDescr = vehicles.VehicleDescr(vehCompDescr) vehicle = g_itemsCache.items.getItemByCD(vehDescr.type.compactDescr) if vehicle is not None: return vehicle.invID return 0
def __checkPrebattleLockedVehicle(self): from gui.prb_control import prb_getters clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: rosters = prb_getters.getPrebattleRosters(prebattle=clientPrb) for _, roster in rosters.iteritems(): if BigWorld.player().id in roster: vehCompDescr = roster[BigWorld.player().id].get('vehCompDescr', '') if vehCompDescr: vehDescr = VehicleDescr(vehCompDescr) vehicle = self.itemsCache.items.getItemByCD(vehDescr.type.compactDescr) if vehicle is not None: return vehicle.invID return 0
def init(self, clientPrb=None, ctx=None): if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingUpdated += self.prb_onSettingUpdated clientPrb.onRosterReceived += self.prb_onRosterReceived clientPrb.onTeamStatesReceived += self.prb_onTeamStatesReceived clientPrb.onPlayerStateChanged += self.prb_onPlayerStateChanged clientPrb.onPlayerRosterChanged += self.prb_onPlayerRosterChanged clientPrb.onPlayerAdded += self.prb_onPlayerAdded clientPrb.onPlayerRemoved += self.prb_onPlayerRemoved clientPrb.onKickedFromQueue += self.prb_onKickedFromQueue else: LOG_ERROR('ClientPrebattle is not defined') return super(LegacyEntity, self).init(clientPrb, ctx)
def fini(self, clientPrb=None, ctx=None, woEvents=False): super(EpicBattleTrainingEntity, self).fini(clientPrb=clientPrb, ctx=ctx, woEvents=woEvents) clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onPlayerGroupChanged -= self.__prb_onPlayerGroupChanged g_eventBus.removeListener(ViewEventType.LOAD_VIEW, self.__handleViewLoad, scope=EVENT_BUS_SCOPE.LOBBY) if not woEvents: aliasToLoad = [PREBATTLE_ALIASES.EPICBATTLE_LIST_VIEW_PY, PREBATTLE_ALIASES.EPIC_TRAINING_ROOM_VIEW_PY] if not self.canSwitch(ctx) and g_eventDispatcher.needToLoadHangar(ctx, self.getModeFlags(), aliasToLoad): g_eventDispatcher.loadHangar() g_eventDispatcher.removeEpicTrainingFromCarousel(False) self.storage.suspend() else: g_eventDispatcher.removeEpicTrainingFromCarousel(False, closeWindow=False) return FUNCTIONAL_FLAG.UNDEFINED
def create(self, ctx, callback = None): if not isinstance(ctx, prb_ctx.TrainingSettingsCtx): LOG_ERROR('Invalid context to create training', ctx) if callback is not None: callback(False) elif prb_cooldown.validatePrbCreationCooldown(): if callback is not None: callback(False) elif prb_getters.getClientPrebattle() is None or ctx.isForced(): ctx.startProcessing(callback=callback) BigWorld.player().prb_createTraining(ctx.getArenaTypeID(), ctx.getRoundLen(), ctx.isOpened(), ctx.getComment()) prb_cooldown.setPrbCreationCooldown() else: LOG_ERROR('First, player has to confirm exit from the current prebattle', prb_getters.getPrebattleType()) if callback is not None: callback(False) return
def create(self, ctx, callback=None): if prb_cooldown.validatePrbCreationCooldown(): if callback is not None: callback(False) elif prb_getters.getClientPrebattle() is None or ctx.isForced(): ctx.startProcessing(callback=callback) BigWorld.player().prb_createCompany(ctx.isOpened(), ctx.getComment(), ctx.getDivision()) prb_cooldown.setPrbCreationCooldown() else: LOG_ERROR( 'First, player has to confirm exit from the current prebattle', prb_getters.getPrebattleType()) if callback is not None: callback(False) return
def create(self, ctx, callback=None): if not isinstance(ctx, TrainingSettingsCtx): LOG_ERROR('Invalid context to create training', ctx) if callback is not None: callback(False) elif not self.canCreate(): if callback is not None: callback(False) elif prb_getters.getClientPrebattle() is None or ctx.isForced(): ctx.startProcessing(callback=callback) BigWorld.player().prb_createTraining(ctx.getArenaTypeID(), ctx.getRoundLen(), ctx.isOpened(), ctx.getComment()) cooldown.setPrbCreationCooldown() else: LOG_ERROR('First, player has to confirm exit from the current prebattle', prb_getters.getPrebattleType()) if callback is not None: callback(False) return
def init(self, clientPrb = None, ctx = None): self._hasEntity = True if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingUpdated += self.prb_onSettingUpdated clientPrb.onRosterReceived += self.prb_onRosterReceived clientPrb.onTeamStatesReceived += self.prb_onTeamStatesReceived clientPrb.onPlayerStateChanged += self.prb_onPlayerStateChanged clientPrb.onPlayerRosterChanged += self.prb_onPlayerRosterChanged clientPrb.onPlayerAdded += self.prb_onPlayerAdded clientPrb.onPlayerRemoved += self.prb_onPlayerRemoved clientPrb.onKickedFromQueue += self.prb_onKickedFromQueue self._invokeListeners('onPrbFunctionalInited') else: LOG_ERROR('ClientPrebattle is not defined') return FUNCTIONAL_FLAG.UNDEFINED
def fini(self, clientPrb=None, ctx=None, woEvents=False): super(EpicBattleTrainingEntity, self).fini(clientPrb=clientPrb, ctx=ctx, woEvents=woEvents) clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onPlayerGroupChanged -= self.__prb_onPlayerGroupChanged remove = g_eventBus.removeListener for event in self.__loadEvents: remove(event, self.__handleViewLoad, scope=EVENT_BUS_SCOPE.LOBBY) if not woEvents: if not self.canSwitch(ctx): g_eventDispatcher.loadHangar() g_eventDispatcher.removeTrainingFromCarousel(False) self.storage.suspend() else: g_eventDispatcher.removeTrainingFromCarousel(False, closeWindow=False) return FUNCTIONAL_FLAG.UNDEFINED
def fini(self, clientPrb=None, ctx=None, woEvents=False): self._settings = None result = super(LegacyEntity, self).fini(clientPrb, ctx=ctx, woEvents=woEvents) if self._limits is not None: self._limits.clear() self._limits = None self.clear() if clientPrb is None: clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: clientPrb.onSettingUpdated -= self.prb_onSettingUpdated clientPrb.onTeamStatesReceived -= self.prb_onTeamStatesReceived clientPrb.onPlayerStateChanged -= self.prb_onPlayerStateChanged clientPrb.onPlayerRosterChanged -= self.prb_onPlayerRosterChanged clientPrb.onPlayerAdded -= self.prb_onPlayerAdded clientPrb.onPlayerRemoved -= self.prb_onPlayerRemoved clientPrb.onKickedFromQueue -= self.prb_onKickedFromQueue return result
def _getPlayersStateStats(self, rosterKey): clientPrb = prb_getters.getClientPrebattle() notReadyCount = 0 playersCount = 0 limitMaxCount = 0 haveInBattle = False if clientPrb: players = clientPrb.rosters.get(rosterKey, {}) playersCount = len(players) team, assigned = decodeRoster(rosterKey) teamLimits = self._settings.getTeamLimits(team) limitMaxCount = teamLimits['maxCount'][not assigned] for _, accInfo in players.iteritems(): state = accInfo.get('state', PREBATTLE_ACCOUNT_STATE.UNKNOWN) if not state & PREBATTLE_ACCOUNT_STATE.READY: notReadyCount += 1 if not haveInBattle and state & PREBATTLE_ACCOUNT_STATE.IN_BATTLE: haveInBattle = True return prb_items.PlayersStateStats(notReadyCount, haveInBattle, playersCount, limitMaxCount)
def __createByAccountState(self, ctx): """ Tries to create entity by current account state. Args: ctx: creation request context. Returns: new prebattle legacy entity """ clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: if prb_getters.isPrebattleSettingsReceived(prebattle=clientPrb): prbSettings = prb_getters.getPrebattleSettings(prebattle=clientPrb) prbType = prb_getters.getPrebattleType(settings=prbSettings) clazz = None if prbType in _SUPPORTED_ENTITY: clazz = _SUPPORTED_ENTITY[prbType] if clazz: return clazz(prbSettings) else: return LegacyInitEntity() return self.__createByPrbType(ctx)
def _createByAccountState(self, ctx): created = None clientPrb = prb_getters.getClientPrebattle() if clientPrb is not None: if prb_getters.isPrebattleSettingsReceived(prebattle=clientPrb): prbSettings = prb_getters.getPrebattleSettings(prebattle=clientPrb) prbType = prb_getters.getPrebattleType(settings=prbSettings) clazz = None if prbType in _SUPPORTED_FUNCTIONAL: clazz = _SUPPORTED_FUNCTIONAL[prbType] ctx.removeFlags(FUNCTIONAL_FLAG.PREBATTLE_BITMASK) ctx.addFlags(FUNCTIONAL_FLAG.PREBATTLE) if clazz: created = clazz(prbSettings) else: LOG_ERROR('Prebattle with given type is not supported', prbType) created = not_supported.NotSupportedFunctional() elif not ctx.hasFlags(FUNCTIONAL_FLAG.PREBATTLE_INIT): ctx.removeFlags(FUNCTIONAL_FLAG.PREBATTLE_BITMASK) ctx.addFlags(FUNCTIONAL_FLAG.PREBATTLE_INIT) created = default.PrbInitFunctional() else: created = self._createByPrbType(ctx) return created
def prb_onPropertyUpdated(self, propertyName): propertyValue = prb_getters.getClientPrebattle().properties[propertyName] LOG_DEBUG('prb_onPropertyUpdated', propertyName, propertyValue) self._invokeListeners('onPropertyUpdated', self, propertyName, propertyValue)