Beispiel #1
0
 def init(self, ctx=None):
     self.__restrictedSPGDataProvider.init(self)
     self.storage.release()
     mapboxSquadEntity = super(MapboxSquadEntity, self).init(ctx)
     self.__lobbyContext.getServerSettings().onServerSettingsChange += self._onServerSettingChanged
     self.__eventsCache.onSyncCompleted += self._onServerSettingChanged
     g_clientUpdateManager.addCallbacks({'inventory.1': self._onInventoryVehiclesUpdated})
     self.__watcher = MapboxVehiclesWatcher()
     self.__watcher.start()
     return mapboxSquadEntity
 def init(self, ctx=None):
     self.storage.release()
     self.__watcher = MapboxVehiclesWatcher()
     self.__watcher.start()
     result = super(MapboxEntity, self).init(ctx)
     return result
Beispiel #3
0
class MapboxSquadEntity(SquadEntity):
    __eventsCache = dependency.descriptor(IEventsCache)
    __lobbyContext = dependency.descriptor(ILobbyContext)

    def __init__(self):
        self._isBalancedSquad = False
        self._isUseSPGValidateRule = True
        self.__watcher = None
        self.__restrictedSPGDataProvider = RestrictedSPGDataProvider()
        super(MapboxSquadEntity, self).__init__(FUNCTIONAL_FLAG.MAPBOX, PREBATTLE_TYPE.MAPBOX)
        return

    def init(self, ctx=None):
        self.__restrictedSPGDataProvider.init(self)
        self.storage.release()
        mapboxSquadEntity = super(MapboxSquadEntity, self).init(ctx)
        self.__lobbyContext.getServerSettings().onServerSettingsChange += self._onServerSettingChanged
        self.__eventsCache.onSyncCompleted += self._onServerSettingChanged
        g_clientUpdateManager.addCallbacks({'inventory.1': self._onInventoryVehiclesUpdated})
        self.__watcher = MapboxVehiclesWatcher()
        self.__watcher.start()
        return mapboxSquadEntity

    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()
        self.__restrictedSPGDataProvider.fini()
        return super(MapboxSquadEntity, self).fini(ctx=ctx, woEvents=woEvents)

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

    def getQueueType(self):
        return QUEUE_TYPE.MAPBOX

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

    def getMaxSPGCount(self):
        return self.__restrictedSPGDataProvider.getMaxVehiclesOfClass()

    def hasSlotForSPG(self):
        return self.__restrictedSPGDataProvider.hasSlotForVehicleClass()

    def getCurrentSPGCount(self):
        return self.__restrictedSPGDataProvider.getCurrentVheiclesOfClassCount()

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

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

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

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

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

    def _createActionsHandler(self):
        return MapboxSquadActionsHandler(self)

    def _createActionsValidator(self):
        return MapboxSquadActionsValidator(self)

    def _vehicleStateCondition(self, v):
        return self.__restrictedSPGDataProvider.isVehcleOfClassAvailable() if self._isUseSPGValidateRule and v.type == VEHICLE_CLASS_NAME.SPG else super(MapboxSquadEntity, self)._vehicleStateCondition(v)

    def _onServerSettingChanged(self, *args, **kwargs):
        self.invalidateVehicleStates()
        self._switchActionsValidator()
        self.unit_onUnitRosterChanged()
        if self.__watcher is not None:
            self.__watcher.updateValidLevels(self.__lobbyContext.getServerSettings().mapbox.levels)
        return

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

    def _onUnitMemberVehiclesChanged(self, accoundDbID):
        self.invalidateVehicleStates()
        if accoundDbID != account_helpers.getAccountDatabaseID():
            self.unit_onUnitRosterChanged()

    def _createScheduler(self):
        return MapboxScheduler(self)
class MapboxEntity(PreQueueEntity):
    def __init__(self):
        super(MapboxEntity, self).__init__(FUNCTIONAL_FLAG.MAPBOX,
                                           QUEUE_TYPE.MAPBOX,
                                           PreQueueSubscriber())
        self.__watcher = None
        self.storage = prequeue_storage_getter(QUEUE_TYPE.MAPBOX)()
        return

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

    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
        self.storage.suspend()
        return super(MapboxEntity, self).fini(ctx, woEvents)

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

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

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

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

    def _createActionsValidator(self):
        return MapboxActionsValidator(self)

    def _createScheduler(self):
        return MapboxScheduler(self)

    def _doQueue(self, ctx):
        BigWorld.player().enqueueMapbox(ctx.getVehicleInventoryID())
        LOG_DEBUG('Sends request on queuing to Mapbox', ctx)

    def _doDequeue(self, ctx):
        BigWorld.player().dequeueMapbox()
        LOG_DEBUG('Sends request on dequeuing from Mapbox')

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

    def _exitFromQueueUI(self):
        g_eventDispatcher.loadHangar()