コード例 #1
0
    def buyItems(self, cmd):
        responses = []
        items = self._itemsCache.items
        for spec in parseItemsSpec(cmd.items):
            if spec.type in (ShopItemType.DEVICE, ShopItemType.EQUIPMENT,
                             ShopItemType.BATTLE_BOOSTER):
                item = items.getItemByCD(spec.id)
                currency = item.buyPrices.itemPrice.price.getCurrency()
                buyer = ModuleBuyer(item, spec.count, currency)
            elif spec.type == ShopItemType.BOOSTER:
                item = self._goodiesCache.getBooster(spec.id)
                currency = item.buyPrices.itemPrice.price.getCurrency()
                buyer = BoosterBuyer(item, spec.count, currency)
            elif spec.type == ShopItemType.VEHICLE:
                item = items.getItemByCD(spec.id)
                buyer = VehicleBuyer(item,
                                     buySlot=False,
                                     showNotEnoughSlotMsg=False)
            elif spec.type == ShopItemType.PREMIUM:
                daysCount = spec.count
                buyer = PremiumAccountBuyer(
                    daysCount,
                    price=items.shop.getPremiumCostWithDiscount()[daysCount],
                    requireConfirm=False)
            else:
                raise SoftException('Invalid item type: "{}".'.format(
                    spec.type))
            if buyer:
                response = yield buyer.request()
                responses.append(
                    self.__makeResult(spec.type, spec.id, response))
            responses.append(None)

        results = []
        for response in responses:
            status = response['success']
            if status and status.userMsg:
                if response['type'] == ShopItemType.VEHICLE:
                    showVehicleReceivedResultMessages(status)
                else:
                    SystemMessages.pushI18nMessage(status.userMsg,
                                                   type=status.sysMsgType)
                statusData = status.auxData
                if statusData is None or 'errStr' not in statusData or not statusData[
                        'errStr']:
                    result = 'success'
                else:
                    result = statusData['errStr']
                results.append(
                    self.__makeResult(response['type'], response['id'],
                                      status.success, result))
            results.append(
                self.__makeResult(response['type'], response['id'], False))

        yield results
        return
コード例 #2
0
 def submit(self, count, currency):
     result = yield BoosterBuyer(self.__booster, count, currency).request()
     if len(result.userMsg):
         SystemMessages.pushI18nMessage(result.userMsg,
                                        type=result.sysMsgType)
コード例 #3
0
 def doAction(self):
     result = yield BoosterBuyer(self.__boosterID, self.__count,
                                 self.__currency).request()
     if result.userMsg:
         SystemMessages.pushI18nMessage(result.userMsg,
                                        type=result.sysMsgType)