Пример #1
0
 def _getResourceToExchange(self):
     item = self.itemsCache.items.getItemByCD(self.getTypeCompDescr())
     stats = self.itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs,
                               stats.freeXP)
     return 0 if item.isUnlocked else self._xpCost - unlockStats.getVehTotalXP(
         self._parentCD)
Пример #2
0
 def _getResourceToExchange(self):
     item = self._items.getItemByCD(self.getTypeCompDescr())
     stats = self._items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)
     if item.isUnlocked:
         return 0
     else:
         return self._xpCost - unlockStats.getVehTotalXP(self._parentCD)
    def _getResourceToExchange(self):

        def _getUnlockState(itemCD):
            item = self.itemsCache.items.getItemByCD(itemCD)
            return item.isUnlocked

        unlockState = self._exchangeItem.doAction(_getUnlockState, bool)
        if unlockState:
            return 0
        stats = self.itemsCache.items.stats
        unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)
        return self._xpCost - unlockStats.getVehTotalXP(self._parentCD)
Пример #4
0
 def _getResourceToExchange(self):
     """
     # calculate necessary xp for exchange
     :return: <int>
     """
     item = self.itemsCache.items.getItemByCD(self.getTypeCompDescr())
     stats = self.itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs,
                               stats.freeXP)
     if item.isUnlocked:
         return 0
     return self._xpCost - unlockStats.getVehTotalXP(self._parentCD)
Пример #5
0
 def _validate(self):
     unlockCD, vehCD, unlockIdx, xpCost = self._unlockCtx[:]
     itemGetter = g_itemsCache.items.getItemByCD
     vehicle = itemGetter(vehCD)
     item = itemGetter(unlockCD)
     if vehicle.itemTypeID != GUI_ITEM_TYPE.VEHICLE:
         LOG_ERROR('Int compact descriptor is not for vehicle', vehCD)
         return plugins.makeError('vehicle_invalid')
     if not vehicle.isUnlocked:
         LOG_ERROR('Vehicle is not unlocked', unlockCD, vehCD)
         return plugins.makeError('vehicle_locked')
     if item.isUnlocked:
         return plugins.makeError('already_unlocked')
     stats = g_itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs,
                               stats.freeXP)
     if item.itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         result, _ = g_techTreeDP.isNext2Unlock(unlockCD,
                                                **unlockStats._asdict())
         if not result:
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     else:
         _xpCost, _itemCD, required = vehicle.getUnlocksDescr(
             self._unlockCtx.unlockIdx)
         if _itemCD != unlockCD:
             LOG_ERROR('Item is invalid', self._unlockCtx)
             return plugins.makeError('item_invalid')
         if _xpCost != xpCost:
             LOG_ERROR('XP cost is invalid', self._unlockCtx)
             return plugins.makeError('xp_cost_invalid')
         if not unlockStats.isSeqUnlocked(required):
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     if unlockStats.getVehTotalXP(vehCD) < xpCost:
         LOG_ERROR('XP not enough for unlock', self._unlockCtx)
         return plugins.makeError()
     if RequestState.inProcess('unlock'):
         return plugins.makeError('in_processing')
     return plugins.makeSuccess()
Пример #6
0
 def _validate(self):
     unlockCD, vehCD, unlockIdx, xpCost = self._unlockCtx[:]
     itemGetter = g_itemsCache.items.getItemByCD
     vehicle = itemGetter(vehCD)
     item = itemGetter(unlockCD)
     if vehicle.itemTypeID != GUI_ITEM_TYPE.VEHICLE:
         LOG_ERROR('Int compact descriptor is not for vehicle', vehCD)
         return plugins.makeError('vehicle_invalid')
     if not vehicle.isUnlocked:
         LOG_ERROR('Vehicle is not unlocked', unlockCD, vehCD)
         return plugins.makeError('vehicle_locked')
     if item.isUnlocked:
         return plugins.makeError('already_unlocked')
     stats = g_itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)
     if item.itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         result, _ = g_techTreeDP.isNext2Unlock(unlockCD, **unlockStats._asdict())
         if not result:
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     else:
         _xpCost, _itemCD, required = vehicle.getUnlocksDescr(self._unlockCtx.unlockIdx)
         if _itemCD != unlockCD:
             LOG_ERROR('Item is invalid', self._unlockCtx)
             return plugins.makeError('item_invalid')
         if _xpCost != xpCost:
             LOG_ERROR('XP cost is invalid', self._unlockCtx)
             return plugins.makeError('xp_cost_invalid')
         if not unlockStats.isSeqUnlocked(required):
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     if unlockStats.getVehTotalXP(vehCD) < xpCost:
         LOG_ERROR('XP not enough for unlock', self._unlockCtx)
         return plugins.makeError()
     if RequestState.inProcess('unlock'):
         return plugins.makeError('in_processing')
     return plugins.makeSuccess()
Пример #7
0
 def _isEnoughXpToUnlock(self):
     stats = self.itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)
     return unlockStats.getVehTotalXP(self.__vehCD) >= self.__xpCost
Пример #8
0
 def _isEnoughXpToUnlock(self):
     stats = g_itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)
     return unlockStats.getVehTotalXP(self.__vehCD) >= self.__xpCost