def init(self, ctx=None):
     self.storage.release()
     self.__watcher = EpicVehiclesWatcher()
     self.__watcher.start()
     result = super(EpicEntity, self).init(ctx)
     if not result & FUNCTIONAL_FLAG.LOAD_PAGE:
         result |= self.__processWelcome()
     return result
 def init(self, ctx=None):
     self.storage.release()
     epicSquadEntity = super(EpicSquadEntity, self).init(ctx)
     self._maxSpgCount = self.getMaxSPGCount()
     self.lobbyContext.getServerSettings().onServerSettingsChange += self._onServerSettingChanged
     self.eventsCache.onSyncCompleted += self._onServerSettingChanged
     g_clientUpdateManager.addCallbacks({'inventory.1': self._onInventoryVehiclesUpdated})
     self.__watcher = EpicVehiclesWatcher()
     self.__watcher.start()
     return epicSquadEntity
Exemple #3
0
class EpicSquadEntity(SquadEntity):
    eventsCache = dependency.descriptor(IEventsCache)
    lobbyContext = dependency.descriptor(ILobbyContext)

    def __init__(self):
        self._isBalancedSquad = False
        self._isUseSPGValidateRule = True
        self._maxSpgCount = False
        self.__watcher = None
        self.storage = prequeue_storage_getter(QUEUE_TYPE.EPIC)()
        super(EpicSquadEntity, self).__init__(FUNCTIONAL_FLAG.EPIC,
                                              PREBATTLE_TYPE.EPIC)
        return

    def init(self, ctx=None):
        self.storage.release()
        epicSquadEntity = super(EpicSquadEntity, self).init(ctx)
        self._maxSpgCount = self.getMaxSPGCount()
        self.lobbyContext.getServerSettings(
        ).onServerSettingsChange += self._onServerSettingChanged
        self.eventsCache.onSyncCompleted += self._onServerSettingChanged
        g_clientUpdateManager.addCallbacks(
            {'inventory.1': self._onInventoryVehiclesUpdated})
        self.__watcher = EpicVehiclesWatcher()
        self.__watcher.start()
        return epicSquadEntity

    def fini(self, ctx=None, woEvents=False):
        self.lobbyContext.getServerSettings(
        ).onServerSettingsChange -= self._onServerSettingChanged
        self.eventsCache.onSyncCompleted -= self._onServerSettingChanged
        g_clientUpdateManager.removeObjectCallbacks(self, force=True)
        self._isUseSPGValidateRule = False
        if self.__watcher is not None:
            self.__watcher.stop()
            self.__watcher = None
        self.invalidateVehicleStates()
        return super(EpicSquadEntity, self).fini(ctx=ctx, woEvents=woEvents)

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

    def getQueueType(self):
        return QUEUE_TYPE.EPIC

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

    def getMaxSPGCount(self):
        return self.lobbyContext.getServerSettings().getMaxSPGinSquads()

    def hasSlotForSPG(self):
        accountDbID = account_helpers.getAccountDatabaseID()
        return self.getMaxSPGCount() > 0 and (
            self.getCurrentSPGCount() < self.getMaxSPGCount()
            or self.isCommander(accountDbID))

    def getCurrentSPGCount(self):
        enableSPGCount = 0
        unitMgrId, unit = self.getUnit(safe=True)
        if unit is None:
            return enableSPGCount
        else:
            enableSPGCount = sum(
                (slot.player is not None and slot.player.isReady
                 and slot.vehicle is not None
                 and slot.vehicle.vehClassIdx == VEHICLE_CLASS_INDICES['SPG']
                 for slot in self.getSlotsIterator(unitMgrId, unit)))
            return enableSPGCount

    def unit_onUnitVehiclesChanged(self, dbID, vehicles):
        super(EpicSquadEntity, self).unit_onUnitVehiclesChanged(dbID, vehicles)
        self._onUnitMemberVehiclesChanged(dbID)

    def unit_onUnitVehicleChanged(self, dbID, vehInvID, vehTypeCD):
        super(EpicSquadEntity,
              self).unit_onUnitVehicleChanged(dbID, vehInvID, vehTypeCD)
        self._onUnitMemberVehiclesChanged(dbID)

    def unit_onUnitPlayerRoleChanged(self, playerID, prevRoleFlags,
                                     nextRoleFlags):
        super(EpicSquadEntity,
              self).unit_onUnitPlayerRoleChanged(playerID, prevRoleFlags,
                                                 nextRoleFlags)
        if playerID == account_helpers.getAccountDatabaseID():
            self.unit_onUnitRosterChanged()

    def unit_onUnitPlayerRemoved(self, playerID, playerData):
        super(EpicSquadEntity,
              self).unit_onUnitPlayerRemoved(playerID, playerData)
        if playerID == account_helpers.getAccountDatabaseID():
            self.unit_onUnitRosterChanged()

    def _createActionsHandler(self):
        return BalancedSquadActionsHandler(self)

    def _createActionsValidator(self):
        return EpicSquadActionsValidator(self)

    def _vehicleStateCondition(self, v):
        result = True
        if self._isUseSPGValidateRule and v.type == VEHICLE_CLASS_NAME.SPG:
            isHaveSPG = False
            accountDbID = account_helpers.getAccountDatabaseID()
            spgDifferenceCount = self.getMaxSPGCount(
            ) - self.getCurrentSPGCount()
            if self.getMaxSPGCount() == 0:
                return (False, None)
            elif self.isCommander(accountDbID):
                return (result, None)
            elif spgDifferenceCount == 0:
                _, _ = self.getUnit()
                vInfos = self.getVehiclesInfo()
                for vInfo in vInfos:
                    if vInfo.vehClassIdx == VEHICLE_CLASS_INDICES['SPG']:
                        isHaveSPG = True

                if isHaveSPG:
                    return (result, None)
                return (False, None)
            elif spgDifferenceCount > 0:
                return (result, None)
            else:
                return (False, None)
        return super(EpicSquadEntity, self)._vehicleStateCondition(v)

    def _onServerSettingChanged(self, *args, **kwargs):
        self._maxSpgCount = self.getMaxSPGCount()
        self._switchActionsValidator()
        self.unit_onUnitRosterChanged()

    def _onInventoryVehiclesUpdated(self, diff):
        self.invalidateVehicleStates()

    def _onUnitMemberVehiclesChanged(self, accoundDbID):
        self.invalidateVehicleStates()
        if accoundDbID != account_helpers.getAccountDatabaseID():
            self.unit_onUnitRosterChanged()
 def init(self, ctx=None):
     self.storage.release()
     self.__watcher = EpicVehiclesWatcher()
     self.__watcher.start()
     result = super(EpicEntity, self).init(ctx)
     return result
class EpicEntity(PreQueueEntity):
    __settingsCore = dependency.descriptor(ISettingsCore)
    __epicController = dependency.descriptor(IEpicBattleMetaGameController)

    def __init__(self):
        super(EpicEntity, self).__init__(FUNCTIONAL_FLAG.EPIC, QUEUE_TYPE.EPIC,
                                         EpicSubscriber())
        self.__watcher = None
        return

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

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

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

    def leave(self, ctx, callback=None):
        self.storage.suspend()
        super(EpicEntity, self).leave(ctx, callback)

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

    def getQueueType(self):
        return QUEUE_TYPE.EPIC

    @vehicleAmmoCheck
    def queue(self, ctx, callback=None):
        super(EpicEntity, self).queue(ctx, callback=callback)

    def doSelectAction(self, action):
        name = action.actionName
        if name in (PREBATTLE_ACTION_NAME.EPIC,
                    PREBATTLE_ACTION_NAME.EPIC_FORCED):
            return SelectResult(True)
        return SelectResult(
            True, EpicSquadEntryPoint(accountsToInvite=action.accountsToInvite)
        ) if name == PREBATTLE_ACTION_NAME.SQUAD else super(
            EpicEntity, self).doSelectAction(action)

    def _createActionsValidator(self):
        return EpicActionsValidator(self)

    def _createScheduler(self):
        return EpicMetaScheduler(self)

    def _doQueue(self, ctx):
        BigWorld.player().enqueueEpic(ctx.getVehicleInventoryID())
        LOG_DEBUG('Sends request on queuing to the epic battle', ctx)

    def _doDequeue(self, ctx):
        BigWorld.player().dequeueEpic()
        LOG_DEBUG('Sends request on dequeuing from the epic battle')

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

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

    def _exitFromQueueUI(self):
        g_eventDispatcher.loadHangar()