Exemplo n.º 1
0
class BattleRoyaleSquadEntity(SquadEntity):
    __battleRoyaleController = dependency.descriptor(IBattleRoyaleController)
    _VALID_RESTRICTIONS = (UNIT_RESTRICTION.UNIT_NOT_FULL, UNIT_RESTRICTION.NOT_READY_IN_SLOTS)

    def __init__(self):
        super(BattleRoyaleSquadEntity, self).__init__(FUNCTIONAL_FLAG.BATTLE_ROYALE, PREBATTLE_TYPE.BATTLE_ROYALE)
        self.__watcher = None
        return

    def init(self, ctx=None):
        self.storage.release()
        self.__watcher = BattleRoyaleVehiclesWatcher()
        self.__watcher.start()
        result = super(BattleRoyaleSquadEntity, self).init(ctx)
        return result

    def fini(self, ctx=None, woEvents=False):
        if self.__watcher is not None:
            self.__watcher.stop()
            self.__watcher = None
        if isNeedToLoadHangar(ctx):
            g_eventDispatcher.loadHangar()
        return super(BattleRoyaleSquadEntity, self).fini(ctx, woEvents)

    def leave(self, ctx, callback=None):
        if ctx.hasFlags(FUNCTIONAL_FLAG.SWITCH):
            self.storage.suspend()
        super(BattleRoyaleSquadEntity, self).leave(ctx, callback)

    def getQueueType(self):
        return QUEUE_TYPE.BATTLE_ROYALE

    def getConfirmDialogMeta(self, ctx):
        return None if not self.__battleRoyaleController.isEnabled() else super(BattleRoyaleSquadEntity, self).getConfirmDialogMeta(ctx)

    @prequeue_storage_getter(QUEUE_TYPE.BATTLE_ROYALE)
    def storage(self):
        return None

    def doSelectAction(self, action):
        name = action.actionName
        if name in (PREBATTLE_ACTION_NAME.BATTLE_ROYALE_SQUAD, PREBATTLE_ACTION_NAME.BATTLE_ROYALE):
            g_eventDispatcher.showUnitWindow(self._prbType)
            if action.accountsToInvite:
                self._actionsHandler.processInvites(action.accountsToInvite)
            return SelectResult(True)
        return super(BattleRoyaleSquadEntity, self).doSelectAction(action)

    def isVehiclesReadyToBattle(self):
        result = self._actionsValidator.getVehiclesValidator().canPlayerDoAction()
        return result is None or result.isValid or result.restriction in self._VALID_RESTRICTIONS

    def _createActionsValidator(self):
        return BattleRoyaleSquadActionsValidator(self)

    def _createScheduler(self):
        return RoyaleScheduler(self)

    def _createActionsHandler(self):
        return BattleRoyaleSquadActionsHandler(self)
Exemplo n.º 2
0
class BattleRoyaleEntity(PreQueueEntity):
    def __init__(self):
        super(BattleRoyaleEntity, self).__init__(FUNCTIONAL_FLAG.BATTLE_ROYALE,
                                                 QUEUE_TYPE.BATTLE_ROYALE,
                                                 _BattleRoyaleSubscriber())
        self.__watcher = None
        return

    def init(self, ctx=None):
        self.storage.release()
        self.__watcher = BattleRoyaleVehiclesWatcher()
        self.__watcher.start()
        result = super(BattleRoyaleEntity, self).init(ctx)
        return result

    def fini(self, ctx=None, woEvents=False):
        if self.__watcher is not None:
            self.__watcher.stop()
            self.__watcher = None
        self.storage.suspend()
        if isNeedToLoadHangar(ctx):
            g_eventDispatcher.loadHangar()
        return super(BattleRoyaleEntity, self).fini(ctx, woEvents)

    def resetPlayerState(self):
        super(BattleRoyaleEntity, self).resetPlayerState()
        g_eventDispatcher.loadHangar()

    @prequeue_storage_getter(QUEUE_TYPE.BATTLE_ROYALE)
    def storage(self):
        return None

    def _makeQueueCtxByAction(self, action=None):
        invID = g_currentVehicle.invID
        return SpecialModeQueueCtx(self._queueType,
                                   invID,
                                   waitingID='prebattle/join')

    def doSelectAction(self, action):
        name = action.actionName
        return SelectResult(
            True) if name == PREBATTLE_ACTION_NAME.BATTLE_ROYALE else super(
                BattleRoyaleEntity, self).doSelectAction(action)

    def isInQueue(self):
        return prb_getters.isInBattleRoyaleQueue()

    def getPermissions(self, pID=None, **kwargs):
        return BattleRoyalePermissions(self.isInQueue())

    def _createActionsValidator(self):
        return BattleRoyaleActionsValidator(self)

    def _createScheduler(self):
        return RoyaleScheduler(self)

    def _doQueue(self, ctx):
        BigWorld.player().enqueueBattleRoyale(ctx.getVehicleInventoryID())
        _logger.debug('Sends request on queuing to the Battle Royale - %r',
                      ctx)

    def _doDequeue(self, ctx):
        BigWorld.player().dequeueBattleRoyale()
        _logger.debug('Sends request on dequeuing from the Battle Royale')

    def _goToQueueUI(self):
        g_eventDispatcher.loadBattleQueue()
        return FUNCTIONAL_FLAG.LOAD_PAGE

    def _exitFromQueueUI(self):
        g_eventDispatcher.loadHangar()
Exemplo n.º 3
0
class BattleRoyaleTournamentEntity(PreQueueEntity):
    __battleRoyaleTournamentController = dependency.descriptor(
        IBattleRoyaleTournamentController)
    __gui = dependency.descriptor(IGuiLoader)

    def __init__(self):
        super(BattleRoyaleTournamentEntity,
              self).__init__(FUNCTIONAL_FLAG.BATTLE_ROYALE,
                             QUEUE_TYPE.BATTLE_ROYALE_TOURNAMENT,
                             _BattleRoyaleTournamentSubscriber())
        self.__watcher = None
        self.__prebatleWindow = False
        return

    def init(self, ctx=None):
        self.storage.release()
        self.__watcher = BattleRoyaleVehiclesWatcher()
        self.__watcher.start()
        result = super(BattleRoyaleTournamentEntity, self).init(ctx)
        return result

    def isPlayerJoined(self, ctx):
        return False if ctx.getEntityType(
        ) != PREBATTLE_TYPE.BATTLE_ROYALE_TOURNAMENT else True

    def canInvite(self, prbType):
        return prbType in PREBATTLE_TYPE.SQUAD_PREBATTLES

    def resetPlayerState(self):
        super(BattleRoyaleTournamentEntity, self).resetPlayerState()
        g_eventDispatcher.loadHangar()

    def isInQueue(self):
        return prb_getters.isInBattleRoyaleTournamentQueue()

    def showGUI(self, ctx=None):
        self.__battleRoyaleTournamentController.leaveCurrentAndJoinToAnotherTournament(
            ctx.getID())

    def fini(self, ctx=None, woEvents=False):
        if ctx and self.__battleRoyaleTournamentController.isSelected():
            self.__battleRoyaleTournamentController.leaveBattleRoyaleTournament(
            )
        if self.__watcher is not None:
            self.__watcher.stop()
            self.__watcher = None
        self.storage.suspend()
        if g_currentPreviewVehicle.isPresent():
            reqFlags = FUNCTIONAL_FLAG.LOAD_PAGE | FUNCTIONAL_FLAG.SWITCH | FUNCTIONAL_FLAG.TRAINING
            if ctx and not ctx.hasFlags(reqFlags):
                g_eventDispatcher.loadHangar()
        return super(BattleRoyaleTournamentEntity, self).fini(ctx, woEvents)

    @prequeue_storage_getter(QUEUE_TYPE.BATTLE_ROYALE)
    def storage(self):
        return None

    def _makeQueueCtxByAction(self, action=None):
        invID = g_currentVehicle.invID
        return SpecialModeQueueCtx(self._queueType,
                                   invID,
                                   waitingID='prebattle/join')

    def getPermissions(self, pID=None, **kwargs):
        return BattleRoyaleTournamentPermissions(self.isInQueue())

    def _createActionsValidator(self):
        return BattleRoyaleTournamentActionsValidator(self)

    def _doQueue(self, ctx):
        self.__battleRoyaleTournamentController.ready(
            ctx.getVehicleInventoryID())
        _logger.debug('Sends request on queuing to the Battle Royale - %r',
                      ctx)

    def _doDequeue(self, ctx):
        self.__battleRoyaleTournamentController.notReady()
        _logger.debug('Sends request on dequeuing from the Battle Royale')

    def _goToQueueUI(self):
        if not self.__prebatleWindow:
            from gui.impl.lobby.battle_royale.pre_battle import PreBattleView
            g_eventBus.handleEvent(events.LoadGuiImplViewEvent(
                GuiImplViewLoadParams(
                    R.views.lobby.battle_royale.PreBattleView(), PreBattleView,
                    ScopeTemplates.LOBBY_SUB_SCOPE)),
                                   scope=EVENT_BUS_SCOPE.LOBBY)
            self.__prebatleWindow = True
        return FUNCTIONAL_FLAG.LOAD_PAGE

    def _exitFromQueueUI(self):
        if self.__prebatleWindow:
            self.__prebatleWindow = False
            views = self.__gui.windowsManager.findViews(
                self.__findSpectatorPreBattleView)
            if views:
                views[0].destroyWindow()

    @staticmethod
    def __findSpectatorPreBattleView(view):
        return str(view).find('PreBattleView') != -1