当前位置: 首页>>代码示例>>Python>>正文


Python Cart.buyItem方法代码示例

本文整理汇总了Python中cart.Cart.buyItem方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.buyItem方法的具体用法?Python Cart.buyItem怎么用?Python Cart.buyItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cart.Cart的用法示例。


在下文中一共展示了Cart.buyItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Slots

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import buyItem [as 别名]

#.........这里部分代码省略.........
            isInDossier = item['object'].isInDossier
            bonus = self.__getSlotBonusString(item['object'].qualifier, isInDossier)
        typedData = self.__data['data'][cType]['data']
        if len(typedData) == 2:
            thisItemSlotIdx = slotIdx
            anotherSlotIdx = 1 - slotIdx
            if item['id'] < 0:
                if typedData[thisItemSlotIdx]['itemID'] == typedData[anotherSlotIdx]['itemID']:
                    typedData[anotherSlotIdx]['price'] = self.getSlotItem(cType=cType, slotIdx=anotherSlotIdx).getPrice(typedData[anotherSlotIdx]['duration'])
            elif item['id'] == typedData[anotherSlotIdx]['itemID']:
                if duration == 0:
                    typedData[anotherSlotIdx]['price'] = 0
                elif typedData[anotherSlotIdx]['duration'] == 0:
                    price = 0
            else:
                itemInAnotherSlot = self.getSlotItem(cType=cType, slotIdx=anotherSlotIdx)
                if itemInAnotherSlot is not None:
                    typedData[anotherSlotIdx]['price'] = itemInAnotherSlot.getPrice(typedData[anotherSlotIdx]['duration'])
        currentSlotItem = self.__data['data'][cType]['data'][slotIdx]
        newSlotItem = {'itemID': item['id'],
         'img': img,
         'purchaseTypeIcon': RES_ICONS.MAPS_ICONS_LIBRARY_GOLDICON_2 if duration == 0 else RES_ICONS.MAPS_ICONS_LIBRARY_CREDITSICON_2,
         'bonus': bonus,
         'duration': duration,
         'spot': currentSlotItem['spot'],
         'price': price,
         'isInDossier': isInDossier,
         'slotTooltip': makeTooltip(_ms(TOOLTIPS.CUSTOMIZATION_SLOT_HEADER, groupName=_ms(_SLOT_TOOLTIP_MAPPING[self.__currentType])), TOOLTIPS.CUSTOMIZATION_SLOT_BODY),
         'removeBtnTooltip': makeTooltip(TOOLTIPS.CUSTOMIZATION_SLOTREMOVE_HEADER, TOOLTIPS.CUSTOMIZATION_SLOTREMOVE_BODY)}
        self.__updateViewModel(cType, slotIdx, newSlotItem)
        initialSlotItem = self.__initialData['data'][cType]['data'][slotIdx]
        if newSlotItem['itemID'] < 0 or initialSlotItem['itemID'] == newSlotItem['itemID']:
            if currentSlotItem['isInDossier']:
                self.cart.buyItem(cType, newSlotItem['spot'], self.calculateVehicleIndex(slotIdx, cType), currentSlotItem['itemID'], 0, price=-1)
            else:
                initialSlotItem = copy.deepcopy(initialSlotItem)
                self.__setSlotAndUpdateView(cType, slotIdx, initialSlotItem)
        elif newSlotItem['isInDossier']:
            numberOfDays = item['object'].numberOfDays
            if numberOfDays is not None:
                itemDuration = numberOfDays if numberOfDays == 30 else 7
                price = -2
            else:
                itemDuration = 0
                price = 0
            self.cart.buyItem(cType, newSlotItem['spot'], self.calculateVehicleIndex(slotIdx, cType), newSlotItem['itemID'], itemDuration, price=price)
        else:
            self.__setSlotAndUpdateView(cType, slotIdx, newSlotItem)
        return

    def calculateVehicleIndex(self, initialIndex, cType):
        if initialIndex == 1:
            slotItem = self.__data['data'][cType]['data'][initialIndex]
            adjacentSlotItem = self.__data['data'][cType]['data'][0]
            if slotItem['spot'] != adjacentSlotItem['spot']:
                return initialIndex - 1
            else:
                return initialIndex
        return initialIndex

    def __setSlotAndUpdateView(self, cType, slotIdx, itemToSet):
        self.__data['data'][cType]['data'][slotIdx] = itemToSet
        self.cart.update(self.__data)
        self.bonusPanel.update(self.__data)
        self.updated({'type': cType,
         'idx': slotIdx,
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:70,代码来源:slots.py


注:本文中的cart.Cart.buyItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。