Esempio n. 1
0
    def getItems(self, types):
        items = {}
        for v in self.__vehicles:
            for type in types:
                currents = self.__getItemsByType(v, type)
                for current in currents:
                    if current:
                        current = items.setdefault(
                            current, VehicleItem(compactDescr=current))
                        current.count += 1
                        current.vehicles.append(v)

        return items.values()
Esempio n. 2
0
 def __init__(self,
              vehicle,
              item,
              itemType,
              slotIdx,
              install=True,
              conflictedEqs=None,
              plugs=tuple()):
     """
     Ctor.
     
     @param vehicle: vehicle
     @param item: module to install
     @param slotIdx: vehicle equipment slot index to install
     @param itemType: item type
     @param install: flag to designated process
     @param conflictedEqs: conflicted items
     @param plugs: plugins list
     """
     opType = 'apply' if install else 'remove'
     if not conflictedEqs:
         conflictedEqs = tuple()
         ModuleProcessor.__init__(self,
                                  item=item,
                                  opType=opType,
                                  plugs=plugs)
         VehicleItemProcessor.__init__(self,
                                       vehicle=vehicle,
                                       module=item,
                                       allowableTypes=itemType)
         addPlugins = []
         install and addPlugins += (plugins.CompatibilityInstallValidator(
             vehicle, item, slotIdx),
                                    plugins.MessageConfirmator(
                                        'removeIncompatibleEqs',
                                        ctx={
                                            'name':
                                            "', '".join([
                                                VehicleItem(
                                                    descriptor=eq).name
                                                for eq in conflictedEqs
                                            ])
                                        },
                                        isEnabled=bool(conflictedEqs)))
     else:
         addPlugins += (plugins.CompatibilityRemoveValidator(vehicle,
                                                             item), )
     self.install = install
     self.slotIdx = slotIdx
     self.addPlugins(addPlugins)
Esempio n. 3
0
    def _successHandler(self, code, ctx=None):
        additionalMessages = []
        removedItems = []
        for eqKd in ctx.get('incompatibleEqs', []):
            item = VehicleItem(compactDescr=eqKd)
            removedItems.append(item.name)

        if removedItems:
            additionalMessages.append(
                makeI18nSuccess(self._formMessage('incompatibleEqs'),
                                items="', '".join(removedItems),
                                type=SM_TYPE.Information))
        additionalMessages.append(
            makeI18nSuccess(self._formMessage('success'),
                            type=SM_TYPE.Information,
                            auxData=additionalMessages,
                            **self._getMsgCtx()))
        return makeSuccess(auxData=additionalMessages)
Esempio n. 4
0
 def __init__(self,
              vehicle,
              item,
              itemType,
              install=True,
              conflictedEqs=None,
              plugs=tuple()):
     """
     Ctor.
     
     @param vehicle: vehicle
     @param item: equipment to install
     @param itemType: vehicle module type
     @param install: flag to designated process
     @param conflictedEqs: conflicted items
     @param plugs: plugins list
     """
     opType = 'apply' if install else 'remove'
     if not conflictedEqs:
         conflictedEqs = tuple()
         ModuleProcessor.__init__(self,
                                  item=item,
                                  opType=opType,
                                  plugs=plugs)
         VehicleItemProcessor.__init__(self,
                                       vehicle=vehicle,
                                       module=item,
                                       allowableTypes=itemType)
         install and self.addPlugin(
             plugins.MessageConfirmator(
                 'removeIncompatibleEqs',
                 ctx={
                     'name':
                     "', '".join([
                         VehicleItem(descriptor=eq).name
                         for eq in conflictedEqs
                     ])
                 },
                 isEnabled=bool(conflictedEqs)))
     self.install = install
Esempio n. 5
0
 def _getValue(self):
     result = list()
     shell = self._tooltip.item
     configuration = self._tooltip.context.getParamsConfiguration(shell)
     vehicle = configuration.vehicle
     params = configuration.params
     historicalBattleID = configuration.historicalBattleID
     battle = g_eventsCache.getHistoricalBattles().get(historicalBattleID)
     vDescr = vehicle.descriptor if vehicle is not None else None
     vCompDescr = vehicle.intCD if vehicle is not None else None
     if vehicle is not None and battle is not None and battle.canParticipateWith(
             vCompDescr):
         vDescr = battle.getVehicleModifiedDescr(vehicle)
     result.append([])
     if params:
         result = [
             ItemsParameters.g_instance.getParameters(
                 shell.descriptor, vDescr)
         ]
     result.append([])
     if vehicle is not None:
         gun = VehicleItem(vDescr.gun)
         vehicleShell = findFirst(lambda s: s.intCD == shell.intCD,
                                  vehicle.shells)
         shellCount = vehicleShell.count if vehicleShell else getattr(
             shell, 'count', 0)
         if battle is not None and battle.canParticipateWith(vCompDescr):
             _, shellCount = findFirst(lambda x: x[0].intCD == shell.intCD,
                                       battle.getShellsLayout(vCompDescr),
                                       (None, 0))
         result[-1].append({
             'label': 'ammo',
             'current': shellCount,
             'total': gun.descriptor['maxAmmo']
         })
     return result
Esempio n. 6
0
 def __init__(self,
              item,
              count,
              buyForCredits,
              conflictedEqs=None,
              install=False):
     """
     Ctor.
     
     @param item: module to install
     @param count: buying count
     @param buyForCredits: buy gold item for credits
     @param conflictedEqs: conflicted items
     """
     super(ModuleBuyer, self).__init__(item, count, 'buy')
     if not conflictedEqs:
         conflictedEqs = []
         conflictMsg = ''
         conflictMsg = conflictedEqs and makeString(
             DIALOGS.BUYINSTALLCONFIRMATION_CONFLICTEDMESSAGE,
             conflicted="', '".join(
                 [VehicleItem(descriptor=eq).name for eq in conflictedEqs]))
     self.buyForCredits = buyForCredits
     self.addPlugins((plugins.MoneyValidator(self._getOpPrice()),
                      plugins.MessageConfirmator('buyInstallConfirmation',
                                                 ctx={
                                                     'name':
                                                     item.userName,
                                                     'kind':
                                                     self.item.userType,
                                                     'conflict':
                                                     conflictMsg,
                                                     'price':
                                                     self._getOpPrice()[0]
                                                 },
                                                 isEnabled=install)))
    def populateTechnicalMaintenance(self):
        shopRqs = yield ShopRequester().request()
        statsRqs = yield StatsRequesterr().request()
        goldShellsForCredits = shopRqs.isEnabledBuyingGoldShellsForCredits
        data = {'gold': statsRqs.gold, 'credits': statsRqs.credits}
        if g_currentVehicle.isPresent():
            iVehicles = yield Requester('vehicle').getFromInventory()
            for v in iVehicles:
                if v.inventoryId == g_currentVehicle.invID:
                    vehicle = v
                    break

            gun = VehicleItem(vehicle.descriptor.gun)
            iAmmo = yield Requester('shell').getFromInventory()
            sAmmo = yield Requester('shell').getFromShop()
            casseteCount = vehicle.descriptor.gun['clip'][0]
            data.update({
                'vehicleId':
                vehicle.pack(),
                'repairCost':
                vehicle.repairCost,
                'maxRepairCost':
                vehicle.descriptor.getMaxRepairCost(),
                'autoRepair':
                vehicle.isAutoRepair,
                'maxAmmo':
                gun.descriptor['maxAmmo'],
                'casseteFieldText':
                '' if casseteCount == 1 else
                makeString('#menu:technicalMaintenance/ammoTitleEx') %
                casseteCount,
                'shells': []
            })
            shells = data.get('shells')
            for shell in vehicle.shells:
                shopShell = sAmmo[sAmmo.index(
                    shell)] if shell in sAmmo else None
                if shopShell:
                    iCount = iAmmo[iAmmo.index(
                        shell)].count if shell in iAmmo else 0
                    sPrice = (yield shopShell.getPrice()
                              ) if shell is not shopShell else (0, 0)
                    if goldShellsForCredits:
                        sPrice = (
                            sPrice[0] +
                            sPrice[1] * shopRqs.exchangeRateForShellsAndEqs,
                            sPrice[1])
                    priceCurrency = 'gold'
                    if sPrice[
                            1] == 0 or goldShellsForCredits and shell.boughtForCredits:
                        priceCurrency = 'credits'
                    buyCount = max(shell.default - iCount - shell.count, 0)
                    shells.append({
                        'id':
                        compactItem(shopShell),
                        'compactDescr':
                        shopShell.compactDescr,
                        'type':
                        shell.type,
                        'icon':
                        '../maps/icons/ammopanel/ammo/%s' %
                        shell.descriptor['icon'][0],
                        'count':
                        shell.count,
                        'userCount':
                        shell.default,
                        'step':
                        casseteCount,
                        'inventoryCount':
                        iCount,
                        'goldShellsForCredits':
                        goldShellsForCredits,
                        'prices':
                        list(sPrice)[:2],
                        'currency':
                        priceCurrency,
                        'ammoName':
                        shell.longName,
                        'tableName':
                        shell.tableName,
                        'maxAmmo':
                        gun.descriptor['maxAmmo']
                    })

            data.update({
                'autoShells': vehicle.isAutoLoad,
                'autoEqip': vehicle.isAutoEquip
            })
        self.as_setDataS(data)
        return