Пример #1
0
 def __init__(self, tmanInvID):
     super(CrewSkinsProcessorBase, self).__init__()
     self._tmanInvID = tmanInvID
     self.__compensationPriceObject = None
     self.__compensationRequired = False
     lobbyContext = dependency.instance(ILobbyContext)
     equippedSkinID = self.itemsCache.items.getTankman(tmanInvID).skinID
     if equippedSkinID != NO_CREW_SKIN_ID and lobbyContext.getServerSettings().isCrewSkinsEnabled():
         crewSkinItem = self.itemsCache.items.getCrewSkin(equippedSkinID)
         self.__compensationPriceObject = crewSkinItem.getBuyPrice()
         self.__compensationRequired = not crewSkinItem.isStorageAvailable()
         self.addPlugin(plugins.CrewSkinsCompensationDialogConfirmator('crewSkins/skinWillBeDeleted', plugins.CrewSkinsRemovalCompensationDialogMeta.OUT_OF_STORAGE_SUFFIX, ctx={'price': self.__compensationPriceObject,
          'action': None,
          'items': [crewSkinItem]}, isEnabled=not crewSkinItem.isStorageAvailable()))
     return
Пример #2
0
 def __init__(self, tankman, role, vehTypeCompDescr):
     self.__roleIdx = SKILL_INDICES[role]
     self.__vehTypeCompDescr = vehTypeCompDescr
     self.__changeRoleCost = self.itemsCache.items.shop.changeRoleCost
     vehicle = self.itemsCache.items.getItemByCD(self.__vehTypeCompDescr)
     super(TankmanChangeRole, self).__init__(
         tankman,
         (plugins.TankmanLockedValidator(tankman),
          plugins.VehicleCrewLockedValidator(vehicle),
          plugins.MessageConfirmator('tankmanChageRole/unknownVehicle',
                                     ctx={'tankname': vehicle.userName},
                                     isEnabled=not vehicle.isInInventory),
          plugins.VehicleValidator(vehicle, False),
          plugins.VehicleRoleValidator(vehicle, role, tankman),
          plugins.MoneyValidator(Money(gold=self.__changeRoleCost))))
     self.__compensationPriceObject = None
     self.__compensationRequired = False
     lobbyContext = dependency.instance(ILobbyContext)
     equippedSkinID = tankman.skinID
     if equippedSkinID != NO_CREW_SKIN_ID and lobbyContext.getServerSettings(
     ).isCrewSkinsEnabled():
         crewSkinItem = self.itemsCache.items.getCrewSkin(equippedSkinID)
         roleMismatch = crewSkinItem.getRoleID(
         ) is not None and crewSkinItem.getRoleID() != role
         self.__compensationPriceObject = crewSkinItem.getBuyPrice()
         self.__compensationRequired = roleMismatch and not crewSkinItem.isStorageAvailable(
         )
         self.addPlugins(
             (plugins.CrewSkinsRoleChangeRemovalConfirmator(
                 'crewSkins/skinWillBeRemoved',
                 ctx={'items': [crewSkinItem]},
                 isEnabled=roleMismatch
                 and crewSkinItem.isStorageAvailable()),
              plugins.CrewSkinsCompensationDialogConfirmator(
                  'crewSkins/skinWillBeDeleted',
                  plugins.CrewSkinsRemovalCompensationDialogMeta.
                  ROLE_MISMATCH_SUFFIX,
                  ctx={
                      'price': self.__compensationPriceObject,
                      'items': [crewSkinItem]
                  },
                  isEnabled=self.__compensationRequired)))
     return
Пример #3
0
 def __init__(self, tankman):
     vehicle = None
     if tankman.vehicleInvID > 0:
         vehicle = self.itemsCache.items.getVehicle(tankman.vehicleInvID)
     confirmator = plugins.TankmanOperationConfirmator(
         'protectedDismissTankman', tankman)
     super(TankmanDismiss, self).__init__(tankman, [
         plugins.TankmanLockedValidator(tankman), confirmator,
         plugins.VehicleValidator(vehicle,
                                  isEnabled=tankman.vehicleInvID > 0)
     ])
     deletedTankmen = self.restore.getTankmenBeingDeleted()
     if deletedTankmen and tankman.isRestorable():
         self.addPlugin(
             plugins.BufferOverflowConfirmator({
                 'dismissed': tankman,
                 'deleted': deletedTankmen[0]
             }))
     self.__compensationPriceObject = None
     self.__compensationRequired = False
     lobbyContext = dependency.instance(ILobbyContext)
     equippedSkinID = tankman.skinID
     if equippedSkinID != NO_CREW_SKIN_ID and lobbyContext.getServerSettings(
     ).isCrewSkinsEnabled():
         crewSkinItem = self.itemsCache.items.getCrewSkin(equippedSkinID)
         self.__compensationPriceObject = crewSkinItem.getBuyPrice()
         self.__compensationRequired = not crewSkinItem.isStorageAvailable()
         self.addPlugin(
             plugins.CrewSkinsCompensationDialogConfirmator(
                 'crewSkins/skinWillBeDeleted',
                 plugins.CrewSkinsRemovalCompensationDialogMeta.
                 OUT_OF_STORAGE_SUFFIX,
                 ctx={
                     'price': self.__compensationPriceObject,
                     'action': None,
                     'items': [crewSkinItem]
                 },
                 isEnabled=self.__compensationRequired))
     return
Пример #4
0
    def __init__(self, vehicle, shells=None, eqs=None, optDevs=None, inventory=None, customizationItems=None, boosters=None, isCrewDismiss=False, itemsForDemountKit=None):
        shells = shells or []
        eqs = eqs or []
        boosters = boosters or []
        optDevs = optDevs or []
        inventory = inventory or []
        customizationItems = customizationItems or []
        itemsForDemountKit = itemsForDemountKit or []
        nationGroupVehs = vehicle.getAllNationGroupVehs(self.itemsCache.items)
        self.vehicle = vehicle
        self.nationGroupVehs = nationGroupVehs
        self.shells = shells
        self.eqs = eqs
        self.optDevs = optDevs
        self.gainMoney, self.spendMoney = self.__getGainSpendMoney(vehicle, nationGroupVehs, shells, eqs, boosters, optDevs, inventory, customizationItems, itemsForDemountKit)
        self.inventory = set((m.intCD for m in inventory))
        self.customizationItems = set(customizationItems)
        self.boosters = boosters
        self.itemsForDemountKit = itemsForDemountKit
        barracksBerthsNeeded = getCrewCount(nationGroupVehs)
        bufferOverflowCtx = {}
        isBufferOverflowed = False
        crewSkinsNeedDeletion = []
        self.__compensationAmount = ItemPrice(Money(), Money())
        if isCrewDismiss:
            tankmenGoingToBuffer, deletedTankmen = self.__restore.getTankmenDeletedBySelling(*nationGroupVehs)
            countOfDeleted = len(deletedTankmen)
            if countOfDeleted > 0:
                isBufferOverflowed = True
                bufferOverflowCtx['deleted'] = deletedTankmen[-1]
                bufferOverflowCtx['dismissed'] = tankmenGoingToBuffer[-1]
                if countOfDeleted > 1:
                    bufferOverflowCtx['multiple'] = True
                    bufferOverflowCtx['extraCount'] = countOfDeleted - 1
            if self.__lobbyContext.getServerSettings().isCrewSkinsEnabled():
                freeCountByItem = {}
                for veh in nationGroupVehs:
                    for _, tankman in veh.crew:
                        if tankman is not None and tankman.skinID != NO_CREW_SKIN_ID:
                            crewSkinItem = self.itemsCache.items.getCrewSkin(tankman.skinID)
                            if freeCountByItem.setdefault(crewSkinItem.getID(), crewSkinItem.getFreeCount()) < crewSkinItem.getMaxCount():
                                freeCountByItem[crewSkinItem.getID()] += 1
                            else:
                                crewSkinsNeedDeletion.append(crewSkinItem)
                                self.__compensationAmount += crewSkinItem.getBuyPrice()

        self.__compensationRequired = bool(crewSkinsNeedDeletion)
        plugins = [proc_plugs.VehicleValidator(vehicle, False, prop={'isBroken': True,
          'isLocked': True}),
         proc_plugs.VehicleSellValidator(vehicle),
         proc_plugs.MoneyValidator(self.spendMoney - self.gainMoney),
         proc_plugs.VehicleSellsLeftValidator(vehicle, not (vehicle.isRented and vehicle.rentalIsOver)),
         proc_plugs.BarracksSlotsValidator(barracksBerthsNeeded, isEnabled=not isCrewDismiss),
         proc_plugs.BufferOverflowConfirmator(bufferOverflowCtx, isEnabled=isBufferOverflowed),
         proc_plugs.BattleBoosterValidator(boosters),
         proc_plugs.DismountForDemountKitValidator(vehicle, itemsForDemountKit),
         _getUniqueVehicleSellConfirmator(vehicle)]
        if self.__lobbyContext.getServerSettings().isCrewSkinsEnabled():
            ctx = {'price': self.__compensationAmount,
             'action': None,
             'items': crewSkinsNeedDeletion}
            skinsPlugin = proc_plugs.CrewSkinsCompensationDialogConfirmator('crewSkins/skinWillBeDeleted', proc_plugs.CrewSkinsRemovalCompensationDialogMeta.OUT_OF_STORAGE_SUFFIX, ctx=ctx, isEnabled=bool(crewSkinsNeedDeletion))
            plugins.append(skinsPlugin)
        super(VehicleSeller, self).__init__(vehicle, plugins)
        self.isCrewDismiss = isCrewDismiss
        self.isDismantlingForMoney = bool(self.spendMoney)
        self.isRemovedAfterRent = vehicle.isRented
        self.usedDemountKitsCount = len(itemsForDemountKit)
        self.__hasPairModification = any((step.action.getPurchasedID() is not None for step in vehicle.postProgression.iterUnorderedSteps() if step.action.isMultiAction()))
        return