Example #1
0
    def __onBuyFullCollection(self, *_):
        collectionStrID = YEARS_INFO.getCollectionSettingID(
            self._collectionType, self._collectionBuilder.YEAR_NAME)
        collectionID = YEARS_INFO.getCollectionIntID(collectionStrID)
        builder = AlbumCollectionDialogBuilder(collectionID)
        self.__confirmationWindow = builder.build(withBlur=True)
        result = yield BuyCollectionProcessor(
            collectionID, self.__confirmationWindow).request()
        self.__confirmationWindow = None
        if result.userMsg:
            SystemMessages.pushI18nMessage(
                result.userMsg,
                type=result.sysMsgType,
                priority=NotificationPriorityLevel.MEDIUM)
        if not self.isLoaded or not result.success:
            return
        else:
            with self.viewModel.transaction() as model:
                for toyRenderer in model.getToys():
                    if not toyRenderer.getIsInCollection():
                        toyRenderer.setIsNew(True)
                        toyRenderer.setIsInCollection(True)

                model.setCollectedToysCount(model.getTotalToysCount())
                model.setCurrentRankToysCount(model.getTotalRankToysCount())
                model.setIsCollectionFull(True)
                self.__updateShards()
            return
Example #2
0
def getCollectionByStrID(collectionStrID):
    year, settingID = YEARS_INFO.splitCollectionStrID(collectionStrID)
    if settingID < 0:
        return (None, None)
    else:
        collectionName = YEARS_INFO.getCollectionTypesByYear(year)[settingID]
        return (year, collectionName)
Example #3
0
    def getCollectionSettingsIDs(cls, useMega=False):
        result = []
        for settingName in YEARS_INFO.getCollectionTypesByYear(
                cls._YEAR, useMega=useMega):
            result.append(
                YEARS_INFO.getCollectionIntID(
                    YEARS_INFO.getCollectionSettingID(settingName, cls._YEAR)))

        return result
Example #4
0
 def getCollectionLevelByName(cls, collectionName):
     config = getBonusConfig()
     requester = cls._itemsCache.items.festivity
     collectionDistrs = requester.getCollectionDistributions()
     collectionStrID = YEARS_INFO.getCollectionSettingID(
         collectionName, YEARS_INFO.CURRENT_YEAR_STR)
     collectionID = YEARS_INFO.getCollectionIntID(collectionStrID)
     return config.getCollectionLevel(
         collectionDistrs[collectionID]) if requester.isSynced() else 0
Example #5
0
    def getCollectionsFactor(cls):
        result = 0
        for name in YEARS_INFO.getCollectionTypesByYear(
                YEARS_INFO.CURRENT_YEAR, useMega=False):
            result += cls.getCollectionFactor(name)

        return result
Example #6
0
 def __invalidate(self, year, collection):
     self.__yearName = year
     self.__collectionName = collection or YEARS_INFO.getCollectionTypesByYear(
         year, useMega=True)[0]
     with self.viewModel.transaction() as model:
         self.__updateState(model)
         self.__updateStyleInfo(model)
Example #7
0
 def init(self, nofail=True):
     cfg = self.__cfg
     try:
         getToyCollectionID = getToySettingID
         ny18Toys = collectibles.g_cache.ny18.toys
         ny19Toys = collectibles.g_cache.ny19.toys
         ny20Toys = collectibles.g_cache.ny20.toys
         ny21Toys = collectibles.g_cache.ny21.toys
         ny22Toys = collectibles.g_cache.ny22.toys
         cfg['toys'] = ny22Toys
         collections = set((getToyCollectionID(toyDescr=toyDescr) for toyDescr in chain(ny22Toys.itervalues(), ny21Toys.itervalues(), ny20Toys.itervalues(), ny19Toys.itervalues(), ny18Toys.itervalues())))
         cfg['collections'] = {name:YEARS_INFO.getCollectionIntID(name) for name in collections}
         cfg['collectionStrIDs'] = sorted(cfg['collections'].keys(), key=YEARS_INFO.getCollectionIntID)
         cfg['slots'] = readSlots(CONSTS.COLLECTION2022_SLOTS_XML_PATH)
         cfg['levels'] = readLevelRewards(CONSTS.COLLECTION2022_LEVEL_REWARDS_XML_PATH)
         cfg['collectionRewardsByCollectionID'] = dict(chain(readCollectionRewards(CONSTS.COLLECTION2022_REWARDS_XML_PATH).iteritems(), readCollectionRewards(CONSTS.COLLECTION2021_REWARDS_XML_PATH).iteritems(), readCollectionRewards(CONSTS.COLLECTION2020_REWARDS_XML_PATH).iteritems(), readCollectionRewards(CONSTS.COLLECTION2019_REWARDS_XML_PATH).iteritems(), readCollectionRewards(CONSTS.COLLECTION2018_REWARDS_XML_PATH).iteritems()))
         cfg['toyCountByCollectionID'] = _countToysByCollection(chain(ny22Toys.itervalues(), ny21Toys.itervalues(), ny20Toys.itervalues(), ny19Toys.itervalues(), ny18Toys.itervalues()), collectingFunction=getToyCollectionID)
         cfg['variadicDiscounts'] = buildVariadicDiscountsCache(CONSTS.VARIADIC_DISCOUNTS_XML_PATH)
         if IS_CLIENT:
             cfg['toysTransformations'] = readToysTransformations(CONSTS.TOYS_TRANSFORMATIONS_XML_PATH)
         if IS_BASEAPP:
             cfg['collectionIDs'] = dictlike(getToyCollectionID)
             cfg['levelRewardsByID'] = dict(((lr.level, lid) for lid, lr in self.levels.iteritems()))
             cfg['toyGroups'] = _buildToyGroups(self.toys.itervalues())
     except Exception:
         self.ffini()
         if nofail:
             raise
         LOG_CURRENT_EXCEPTION()
Example #8
0
    def getCollectionLevels(cls):
        result = {}
        for collectionName in YEARS_INFO.getCollectionTypesByYear(
                YEARS_INFO.CURRENT_YEAR, useMega=False):
            result[collectionName] = cls.getCollectionLevelByName(
                collectionName)

        return result
Example #9
0
 def markPreviousYearTabVisited(self, yearName, uiFlagKey):
     yearNum = YEARS_INFO.convertYearToNum(yearName)
     isMaxLevel = self._itemsCache.items.festivity.getMaxLevel(
     ) == new_year.CONSTS.MAX_ATMOSPHERE_LVL
     isCurrentYearSelected = yearNum == YEARS_INFO.CURRENT_YEAR
     if isMaxLevel and not isCurrentYearSelected:
         oldCollectionsVisited = AccountSettings.getUIFlag(uiFlagKey)
         oldCollectionsVisited[yearNum] = True
         AccountSettings.setUIFlag(uiFlagKey, oldCollectionsVisited)
Example #10
0
def _readToy(section, collectionName=None):
    cfg = {intern('collection'): collectionName} if collectionName else {}
    toyData = {
        intern(name):
        (section.readInt(name) if name in ('id', 'rank') else intern(
            section.readString(name)))
        for name, subsection in section.items()
    }
    if collectionName and collectionName != 'defaultToys':
        if not MIN_TOY_RANK <= toyData[
                'rank'] <= YEARS_INFO.getMaxToyRankByYear(collectionName):
            raise NYSoftException(
                'Invalid toy rank, toy collection:{}, toy id: {}'.format(
                    collectionName, toyData['id']))
        if toyData['setting'] not in YEARS_INFO.getCollectionTypesByYear(
                collectionName):
            raise NYSoftException(
                'Invalid setting, toy collection:{}, toy id: {}'.format(
                    collectionName, toyData['id']))
    cfg.update(toyData)
    return cfg
Example #11
0
 def __prepareNewData(self):
     isCollectionFull = self.currentCollectionPresenter.isFull()
     self.viewModel.setIsCollectionFull(isCollectionFull)
     settingID = YEARS_INFO.CURRENT_SETTING_IDS_BY_NAME[
         self._collectionType]
     settingStrID = new_year.g_cache.collectionStrIDs[settingID]
     _, stamp, _ = self._itemsCache.items.festivity.getAlbums().get(
         settingStrID, (0, 0, 0))
     isStampShow = stamp != isCollectionFull
     if isStampShow:
         self._nyController.sendViewAlbum(
             settingID,
             YEARS_INFO.getMaxToyRankByYear(YEARS_INFO.CURRENT_YEAR))
Example #12
0
    def isRegularToysCollected(self):
        collectionDistribution = self._itemsCache.items.festivity.getCollectionDistributions(
        )
        for collectionName in YEARS_INFO.getCollectionTypesByYear(
                YEARS_INFO.CURRENT_YEAR_STR, useMega=False):
            collectionID = YEARS_INFO.CURRENT_SETTING_IDS_BY_NAME[
                collectionName]
            expectedToyCount = new_year.g_cache.toyCountByCollectionID[
                collectionID]
            collectedToyCount = sum(collectionDistribution[collectionID])
            if expectedToyCount != collectedToyCount:
                return False

        return True
Example #13
0
    def __isShowBubbleOnTabForYears(self, years, uiFlagKey):
        isMaxLevel = self._itemsCache.items.festivity.getMaxLevel(
        ) == new_year.CONSTS.MAX_ATMOSPHERE_LVL
        if not isMaxLevel:
            return False
        oldCollectionsByYearVisited = AccountSettings.getUIFlag(uiFlagKey)
        for year in years:
            beg, end = YEARS_INFO.getCollectionDistributionsRangeForYear(year)
            isCollectionCompleted = self.isCollectionCompleted(range(beg, end))
            if not isCollectionCompleted and not oldCollectionsByYearVisited[
                    year]:
                return True

        return False
Example #14
0
def _buildToyGroups(toysDescrs):
    groups = {}
    for toy in toysDescrs:
        groupID = getToyGroupID(toyDescr=toy)
        groups.setdefault(groupID, [])
        groups[groupID].append(toy.id)

    if any((len(gv) < 1 for gk, gv in groups.iteritems())):
        raise NYSoftException('Inconsistent toys description. Degenerate group size < 1')
    currYearMaxToyRank = YEARS_INFO.currYearMaxToyRank()
    toysInfos = [(currYearMaxToyRank, CONSTS.ToySettings.NEW, CONSTS.TOY_USUAL_TYPES), (MAX_MEGA_TOY_RANK, CONSTS.ToySettings.MEGA, CONSTS.MEGA_TOY_TYPES)]
    expectedGroupsCount = _calculateExpectedCount(toysInfos)
    if len(groups) == expectedGroupsCount:
        return groups
    missingToys = _findMissingToys(toysInfos, groups)
    raise NYSoftException('Inconsistent toys description. Missing toys (groups len={}, expectedGroupsLen={} toyRank={}): {} of {}'.format(len(groups), expectedGroupsCount, currYearMaxToyRank, len(missingToys), missingToys))
Example #15
0
def __readBonus_nyToy(bonus, _name, section, eventType, year, checkLimit):
    if section.has_key('id'):
        tid = section['id'].asInt
        if year == YEARS_INFO.CURRENT_YEAR:
            cache = new_year.g_cache.toys
        else:
            cache = collectibles.g_cache[YEARS.getYearStrFromYearNum(year)].toys
        if tid not in cache:
            raise SoftException('Unknown NY{} toyID: {}'.format(year, tid))
        count = section['count'].asInt if section.has_key('count') else 0
        pureCount = section['pureCount'].asInt if section.has_key('pureCount') else count
        if pureCount > count:
            raise SoftException('Pure count should be less or equal than count', pureCount, count)
        toysCollectionKey = YEARS_INFO.getCollectionKeyForYear(year)
        nyToys = bonus.setdefault(toysCollectionKey, {})
        nyToys[tid] = {'count': count,
         'pureCount': pureCount}
Example #16
0
    def __setRewards(self, collectionStrID, rewards):
        rewards = self.__getRewards(rewards)
        collectionIntID = YEARS_INFO.getCollectionIntID(collectionStrID)
        with self.getViewModel().transaction() as model:
            year, collectionName = getCollectionByIntID(collectionIntID)
            model.setStyleStr('{}_{}'.format(collectionName, year))
            model.setIsMega(collectionName == ToySettings.MEGA_TOYS)
            rewardsList = model.getRewards()
            rewardsList.clear()
            for index, reward in enumerate(rewards):
                incIndex = index + 1
                formatter = getRewardRendererModelPresenter(reward)
                rewardRender = formatter.getModel(reward, incIndex)
                rewardsList.addViewModel(rewardRender)
                self.__tooltipData[incIndex] = createTooltipDataByDict(reward)

            rewardsList.invalidate()
Example #17
0
def readCollectionRewards(xmlPath):
    cache = {}
    with openSection(xmlPath) as section:
        if section is None:
            raise NYSoftException("Can't open '%s'" % xmlPath)
        for reward in section.values():
            rewardID = reward.readString('id')
            collName = reward.readString('collection')
            if rewardID in cache:
                raise NYSoftException("Repeated boxID '%s'" % rewardID)
            prefix = rewardID[:4]
            year = prefix[2:4]
            collectionStrID = YEARS_INFO.getCollectionSettingID(
                collName, prefix)
            cache[rewardID] = collectionStrID
            cache[collectionStrID] = rewardID
            cache[collName + year] = rewardID

    return cache
Example #18
0
 def __buildRegularToyGroups(self):
     for toyID, toyDescr in new_year.g_cache.toys.iteritems():
         if toyDescr.setting in ToySettings.MEGA:
             continue
         if toyDescr.setting not in ToySettings.NEW:
             _logger.error('Wrong toy setting: "%s"', toyDescr.setting)
             continue
         if toyDescr.type not in TOY_TYPES:
             _logger.error('Wrong toy type: "%s"', toyDescr.type)
             continue
         rank = toyDescr.rank
         if rank not in xrange(
                 1,
                 YEARS_INFO.getMaxToyRankByYear(YEARS_INFO.CURRENT_YEAR) +
                 1):
             _logger.error('Wrong toy rank: "%d"', rank)
             continue
         toyTypeID = TOY_TYPE_IDS_BY_NAME[toyDescr.type]
         toySettingID = YEARS_INFO.CURRENT_SETTING_IDS_BY_NAME[
             toyDescr.setting]
         self.__regularToyGroups.setdefault((toyTypeID, toySettingID, rank),
                                            []).append(toyID)
Example #19
0
 def __getCollectionIntID(self):
     collectionStrID = YEARS_INFO.getCollectionSettingID(
         self.__collectionName, self.__yearName)
     return new_year.g_cache.collections[collectionStrID]
Example #20
0
def getToySettingID(toyID=None, toyDescr=None):
    if toyDescr is None:
        toyDescr = g_cache.toys[toyID]
    return YEARS_INFO.getCollectionSettingID(toyDescr.setting, toyDescr.collection)
Example #21
0
 def isInCollection(self):
     toyCollection = self._itemsCache.items.festivity.getToyCollection()
     toyID = self.getID()
     bytePos = YEARS_INFO.getToyCollectionOffsetForYear(self.COLLECTION_NAME) + toyID / 8
     mask = 1 << toyID % 8
     return True if toyCollection[bytePos] & mask else False
Example #22
0
def getToyMask(toyID, year):
    offset = YEARS_INFO.getToyCollectionOffsetForYear(year)
    bytePos = offset + toyID / 8
    mask = 1 << toyID % 8
    return (bytePos, mask)
Example #23
0
 def getDesc(self):
     return R.strings.dyn(self.PREFIX).decorations.dyn(self.getLocalKey()).description() if self.getRank() == YEARS_INFO.getMaxToyRankByYear(self.COLLECTION_NAME) or self.isMega() else R.invalid()
Example #24
0
 def getCollectionTypes(cls):
     return YEARS_INFO.getCollectionTypesByYear(cls._YEAR, useMega=False)
Example #25
0
def _getMaxCollectionLevels():
    toyCollections = YEARS_INFO.getCollectionTypesByYear(
        YEARS_INFO.CURRENT_YEAR, useMega=False)
    maxBonusLevel = len(getBonusConfig().getCollectionLevelsRating()) - 1
    return {collectionName: maxBonusLevel for collectionName in toyCollections}