def takeRewardForLevel(self, level): chapter = self.getChapterByLevel(level - 1) isBought = self.isBought(chapter=chapter) awardType = BattlePassConsts.REWARD_BOTH if isBought else BattlePassConsts.REWARD_FREE isOfferEnabled = self.isOfferEnabled() bonuses = self.getSingleAward(level, awardType) rewardsToChoose = [] stylesToChoose = [] for bonus in bonuses: bonusName = bonus.getName() if bonusName == BATTLE_PASS_SELECT_BONUS_NAME and isOfferEnabled: for tokenID in bonus.getTokens().iterkeys(): if self.__itemsCache.items.tokens.getToken( tokenID ) is not None and self.__offersProvider.getOfferByToken( getOfferTokenByGift(tokenID)) is not None: rewardsToChoose.append(tokenID) if bonusName == BATTLE_PASS_STYLE_PROGRESS_BONUS_NAME: for tokenID in bonus.getTokens().iterkeys(): if self.__itemsCache.items.tokens.getToken( tokenID) is not None: chapter = bonus.getChapter() if chapter not in stylesToChoose: stylesToChoose.append(chapter) rewardsToChoose.sort( key=lambda x: (int(x.split(':')[-1]), x.split(':')[-2])) self.getRewardLogic().startManualFlow(rewardsToChoose, stylesToChoose) return
def getValue(cls, bonus): giftTokenName = first(bonus.getTokens().keys()) offer = cls.__offersProvider.getOfferByToken(getOfferTokenByGift(giftTokenName)) if offer is None: return bonus.getCount() else: gift = first(offer.getAllGifts()) return bonus.getCount() if gift is None else gift.giftCount * bonus.getCount()
def takeAllRewards(self): if self.isOfferEnabled(): rewardsToChoose = [ token for token in self.__itemsCache.items.tokens.getTokens().iterkeys() if token.startswith(BATTLE_PASS_CHOICE_REWARD_OFFER_GIFT_TOKENS ) and self.__offersProvider. getOfferByToken(getOfferTokenByGift(token)) is not None ] rewardsToChoose.sort( key=lambda x: (int(x.split(':')[-1]), x.split(':')[-2])) else: rewardsToChoose = [] chapter = self.getCurrentChapter() stylesToChoose = getStylesToChooseUntilChapter(chapter + 1) self.getRewardLogic().startManualFlow(rewardsToChoose, stylesToChoose) return
def isChooseRewardEnabled(self, awardType, level): if level > self.getCurrentLevel(): return False else: bonuses = self.getSingleAward(level, awardType) for bonus in bonuses: if bonus.getName() == BATTLE_PASS_STYLE_PROGRESS_BONUS_NAME: return True if bonus.getName() == BATTLE_PASS_SELECT_BONUS_NAME: for tokenID in bonus.getTokens().iterkeys(): if self.__itemsCache.items.tokens.getToken( tokenID) is not None: return self.isOfferEnabled( ) and self.__offersProvider.getOfferByToken( getOfferTokenByGift(tokenID)) is not None return False
def __setMainData(self): offerToken = getOfferTokenByGift(self.__battlePassController.getRewardLogic().getNextRewardToChoose()) self.__offer = self.__offersProvider.getOfferByToken(offerToken) offerTokenPrefix, _, level = self.__offer.token.rsplit(':', 2) level = int(level) self.__rewardType = _OFFER_MAIN_TOKEN_TO_REWARD_TYPE[offerTokenPrefix + ':'] with self.viewModel.transaction() as model: model.setRewardType(backport.text(R.strings.battle_pass.rewardChoice.rewardType.dyn(self.__rewardType.value)())) model.setLevel(level) chapter = self.__battlePassController.getChapterByLevel(level - 1) model.setChapter(backport.text(R.strings.battle_pass.chapter.name.num(chapter)())) model.setChapterNumber(chapter) model.setSelectedGiftId(-1) leftRewardsCount = self.__battlePassController.getRewardLogic().getLeftRewardsCount() model.setNotChooseRewardsCount(leftRewardsCount) model.setIsOptionsSequence(bool(leftRewardsCount - 1)) self.__fillRewards(model=model) switchHangarOverlaySoundFilter(on=True)
def buildItem(self, tokenID, **kwargs): self.__hasOffer = True result = [] shortName = tokenID.split(':')[2] offerToken = getOfferTokenByGift(tokenID) offer = self.__offersProvider.getOfferByToken(offerToken) if offer is None: self.__hasOffer = False return result else: if shortName in ('brochure_gift', 'guide_gift'): gift = first(offer.getAllGifts()) if gift is not None: result.append(gift.bonus.displayedItem.getXP()) else: for gift in offer.getAllGifts(): result.append(gift.title) return result
def replaceOfferByReward(self, bonuses): result = [] for bonus in bonuses: if bonus.getName() == BATTLE_PASS_SELECT_BONUS_NAME: bonus.updateContext({'isReceived': False}) hasGift = False for tokenID in bonus.getTokens().iterkeys(): offerToken = getOfferTokenByGift(tokenID) offer = self.__offersProvider.getOfferByToken(offerToken) if offer is not None: receivedGifts = self.__offersProvider.getReceivedGifts(offer.id) if receivedGifts: for giftId, count in receivedGifts.iteritems(): if count > 0: gift = offer.getGift(giftId) if gift is not None: hasGift = True result.extend(gift.bonuses) if not hasGift: result.append(bonus) result.append(bonus) return result
def __getBonusOffer(cls, bonus): giftTokenName = first(bonus.getValue().keys()) return cls.__offersProvider.getOfferByToken( getOfferTokenByGift(giftTokenName))
def _getOfferByGiftToken(token, offers=None): return offers.getOfferByToken(getOfferTokenByGift(token))
def getNotChosenRewardCount(self): return sum((token.startswith(BATTLE_PASS_CHOICE_REWARD_OFFER_GIFT_TOKENS) for token in self.__itemsCache.items.tokens.getTokens().iterkeys() if self.__offersProvider.getOfferByToken(getOfferTokenByGift(token)) is not None))
def canChooseAnyReward(self): return self.isOfferEnabled() and any((token.startswith(BATTLE_PASS_CHOICE_REWARD_OFFER_GIFT_TOKENS) for token in self.__itemsCache.items.tokens.getTokens().iterkeys() if self.__offersProvider.getOfferByToken(getOfferTokenByGift(token)) is not None))