def __clearCache(self):
        self.__questsDossierBonuses.clear()
        self.__actionsCache.clear()
        for storage in self.__cache.itervalues():
            storage.clear()

        clearModifiersCache()
    def update(self, diff=None, callback=None):
        clearModifiersCache()
        yield self.getPersonalMissions().questsProgressRequest()
        if not self.getPersonalMissions().isQuestsProgressSynced():
            callback(False)
            return
        else:
            yield self.__questsProgressRequester.request()
            if not self.__questsProgressRequester.isSynced():
                callback(False)
                return
            isNeedToInvalidate = True
            isNeedToClearItemsCaches = False
            isQPUpdated = False

            def _cbWrapper(*args):
                callback(*args)
                self.__personalMissions.update(self, diff)

            if diff is not None:
                isQPUpdated = 'quests' in diff or 'potapovQuests' in diff or 'pm2_progress' in diff
                if not isQPUpdated and 'tokens' in diff:
                    for tokenID in diff['tokens'].iterkeys():
                        if all((not tokenID.startswith(t)
                                for t in NOT_FOR_PERSONAL_MISSIONS_TOKENS)):
                            isQPUpdated = True
                            break

                isEventsDataUpdated = ('eventsData', '_r') in diff or diff.get(
                    'eventsData', {})
                isNeedToInvalidate = isQPUpdated or isEventsDataUpdated
                hasVehicleUnlocks = False
                for intCD in diff.get('stats', {}).get('unlocks', set()):
                    if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE:
                        hasVehicleUnlocks = True
                        break

                isNeedToClearItemsCaches = hasVehicleUnlocks or 'inventory' in diff and GUI_ITEM_TYPE.VEHICLE in diff[
                    'inventory']
            if isNeedToInvalidate:
                self.__invalidateData(_cbWrapper)
            else:
                if isNeedToClearItemsCaches:
                    self.__clearQuestsItemsCache()
                if isQPUpdated:
                    _cbWrapper(True)
                else:
                    callback(True)
            return
    def update(self, diff=None, callback=None):
        clearModifiersCache()
        yield self.randomQuestsProgress.request()
        if not self.randomQuestsProgress.isSynced():
            callback(False)
            return
        else:
            yield self.__questsProgress.request()
            if not self.__questsProgress.isSynced():
                callback(False)
                return
            isNeedToInvalidate = True
            isNeedToClearItemsCaches = False

            def _cbWrapper(*args):
                self.__personalMissions.update(self, diff)
                callback(*args)

            if diff is not None:
                isQPUpdated = 'quests' in diff or 'tokens' in diff
                isEventsDataUpdated = ('eventsData', '_r') in diff or diff.get(
                    'eventsData', {})
                isNeedToInvalidate = isQPUpdated or isEventsDataUpdated
                hasVehicleUnlocks = False
                for intCD in diff.get('stats', {}).get('unlocks', set()):
                    if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE:
                        hasVehicleUnlocks = True
                        break

                isNeedToClearItemsCaches = hasVehicleUnlocks or 'inventory' in diff and GUI_ITEM_TYPE.VEHICLE in diff[
                    'inventory']
            if isNeedToInvalidate:
                self.__invalidateData(_cbWrapper)
                return
            if isNeedToClearItemsCaches:
                self.__clearQuestsItemsCache()
            _cbWrapper(True)
            return
Пример #4
0
    def update(self, diff=None, callback=None):
        clearModifiersCache()
        yield self.getPersonalMissions().questsProgressRequest()
        if not self.getPersonalMissions().isQuestsProgressSynced():
            callback(False)
            return
        else:
            yield self.__questsProgressRequester.request()
            if not self.__questsProgressRequester.isSynced():
                callback(False)
                return
            isNeedToInvalidate = True
            isNeedToClearItemsCaches = False
            isQPUpdated = False
            isQuestConditionUpdated = False

            def _cbWrapper(*args):
                callback(*args)
                self.__personalMissions.update(self, diff)

            if diff is not None:
                tokenIDs = sorted(diff.get('tokens', {}).keys())
                if len(tokenIDs) % 2 == 0:
                    if tokenIDs:
                        isQuestConditionUpdated = True
                        for idx, tokenID in enumerate(tokenIDs[::2]):
                            validator = first([
                                validator for prefix, validator in
                                UPDATABLE_CONDITION_TOKEN_TO_VALIDATOR.items()
                                if tokenID.startswith(prefix)
                            ])
                            if not validator or not validator(
                                    tokenID, tokenIDs[idx * 2 + 1]):
                                isQuestConditionUpdated = False
                                break

                isQPUpdated = 'quests' in diff or 'potapovQuests' in diff or 'pm2_progress' in diff
                if not isQPUpdated and 'tokens' in diff and not isQuestConditionUpdated:
                    for tokenID in diff['tokens'].iterkeys():
                        if all((not tokenID.startswith(t)
                                for t in NOT_FOR_PERSONAL_MISSIONS_TOKENS)):
                            isQPUpdated = True
                            break

                isEventsDataUpdated = ('eventsData', '_r') in diff or diff.get(
                    'eventsData', {})
                isNeedToInvalidate = isQPUpdated or isEventsDataUpdated
                hasVehicleUnlocks = False
                for intCD in diff.get('stats', {}).get('unlocks', set()):
                    if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE:
                        hasVehicleUnlocks = True
                        break

                isNeedToClearItemsCaches = hasVehicleUnlocks or 'inventory' in diff and GUI_ITEM_TYPE.VEHICLE in diff[
                    'inventory']
            if isNeedToInvalidate:
                self.__invalidateData(_cbWrapper)
            else:
                if isNeedToClearItemsCaches:
                    self.__clearQuestsItemsCache()
                if isQuestConditionUpdated:
                    self.onQuestConditionUpdated()
                if isQPUpdated:
                    _cbWrapper(True)
                else:
                    callback(True)
            return