def _getBonusesWithModifyTokens(bonuses, freeTokenName, addTokensCount,
                                hasPawned):
    if addTokensCount > 0:
        newBonuses = []
        hasFreeTokens = False
        ctx = {}
        for bonus in bonuses:
            ctx = bonus.getContext()
            if bonus.getName() == 'freeTokens':
                value = {
                    freeTokenName: {
                        'count': bonus.getCount() + addTokensCount
                    }
                }
                newBonuses.append(
                    FreeTokensBonus(value, ctx=ctx, hasPawned=hasPawned))
                hasFreeTokens = True
            newBonuses.append(bonus)

        if not hasFreeTokens:
            value = {freeTokenName: {'count': addTokensCount}}
            newBonuses.append(
                FreeTokensBonus(value, ctx=ctx, hasPawned=hasPawned))
        bonuses = newBonuses
    return bonuses
Beispiel #2
0
    def getFormattedBonuses(self,
                            bonuses,
                            size=AWARDS_SIZES.SMALL,
                            gap=0,
                            isObtained=False,
                            pawnedTokensCount=0,
                            obtainedImage='',
                            obtainedImageOffset=0,
                            freeTokenName=''):
        if pawnedTokensCount > 0:
            newBonuses = []
            hasFreeTokens = False
            ctx = {}
            for bonus in bonuses:
                ctx = bonus.getContext()
                if bonus.getName() == 'freeTokens':
                    value = {
                        freeTokenName: {
                            'count': bonus.getCount() + pawnedTokensCount
                        }
                    }
                    newBonuses.append(
                        FreeTokensBonus(value, ctx=ctx, hasPawned=True))
                    hasFreeTokens = True
                newBonuses.append(bonus)

            if not hasFreeTokens:
                value = {freeTokenName: {'count': pawnedTokensCount}}
                newBonuses.append(
                    FreeTokensBonus(value, ctx=ctx, hasPawned=True))
            bonuses = newBonuses
        preformattedBonuses = self.getPreformattedBonuses(bonuses)
        return self._packBonuses(preformattedBonuses, size, gap, isObtained,
                                 obtainedImage, obtainedImageOffset)
    def getFormattedBonuses(self,
                            bonuses,
                            size=AWARDS_SIZES.SMALL,
                            gap=0,
                            isObtained=False,
                            areTokensPawned=False,
                            pawnCost=0,
                            obtainedImage='',
                            obtainedImageOffset=0):
        if areTokensPawned:
            newBonuses = []
            context = {'pawnCost': pawnCost, 'areTokensPawned': True}
            hasFreeTokens = False
            for bonus in bonuses:
                if bonus.getName() == 'freeTokens':
                    value = {
                        PERSONAL_QUEST_FREE_TOKEN_NAME: {
                            'count': bonus.getCount() + pawnCost
                        }
                    }
                    newBonuses.append(FreeTokensBonus(value, ctx=context))
                    hasFreeTokens = True
                else:
                    newBonuses.append(bonus)

            if not hasFreeTokens:
                value = {PERSONAL_QUEST_FREE_TOKEN_NAME: {'count': pawnCost}}
                newBonuses.append(FreeTokensBonus(value, ctx=context))
            bonuses = newBonuses
        preformattedBonuses = self.getPreformattedBonuses(bonuses)
        return self._packBonuses(preformattedBonuses, size, gap, isObtained,
                                 obtainedImage, obtainedImageOffset)