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)
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 unlockVehicle(self): stats = g_itemsCache.items.stats unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP) unlockKwargs = unlockStats._asdict() _, unlockProps = g_techTreeDP.isNext2Unlock(self._nodeCD, **unlockKwargs) ItemsActionsFactory.doAction(ItemsActionsFactory.UNLOCK_ITEM, self._nodeCD, unlockProps.parentID, unlockProps.unlockIdx, unlockProps.xpCost)
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)
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)
def unlockVehicle(self): stats = g_itemsCache.items.stats unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP) unlockKwargs = unlockStats._asdict() _, unlockProps = g_techTreeDP.isNext2Unlock(self._nodeCD, **unlockKwargs) ItemsActionsFactory.doAction( ItemsActionsFactory.UNLOCK_ITEM, self._nodeCD, unlockProps.parentID, unlockProps.unlockIdx, unlockProps.xpCost, )
def getUnlockStats(self): """ Gets statistics to resolve unlock states for nodes. :return: instance of UnlockStats. """ return UnlockStats(self._stats.unlocks, self._stats.vehiclesXPs, self._stats.freeXP)
def isVehicleAvailableToUnlock(self, nodeCD, vehicleLevel=UNKNOWN_VEHICLE_LEVEL): unlocks = self.itemsCache.items.stats.unlocks xps = self.itemsCache.items.stats.vehiclesXPs freeXP = self.itemsCache.items.stats.actualFreeXP unlockProps = g_techTreeDP.getUnlockProps(nodeCD, vehicleLevel) parentID = unlockProps.parentID allPossibleXp = self.getAllVehiclePossibleXP(parentID, UnlockStats(unlocks, xps, freeXP)) isNextToUnlock, props = self.isNext2Unlock(nodeCD, unlocked=set(unlocks), xps=xps, freeXP=freeXP, level=vehicleLevel) return (isNextToUnlock, allPossibleXp >= props.xpCost)
def isVehicleAvailableToUnlock(self, nodeCD): unlocks = g_itemsCache.items.stats.unlocks xps = g_itemsCache.items.stats.vehiclesXPs freeXP = g_itemsCache.items.stats.actualFreeXP allPossibleXp = self.getAllVehiclePossibleXP( nodeCD, UnlockStats(unlocks, xps, freeXP)) isAvailable, props = self.isNext2Unlock(nodeCD, unlocked=set(unlocks), xps=xps, freeXP=freeXP) return (isAvailable and allPossibleXp >= props.xpCost, props.xpCost, allPossibleXp)
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()
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()
def getUnlockStats(self): return UnlockStats(self._stats.unlocks, self._stats.vehiclesXPs, self._stats.freeXP)
def _getCostCtx(self, vehCD, xpCost): stats = self.itemsCache.items.stats return unlock.makeCostCtx(UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP).getVehXP(vehCD), xpCost)
def _isEnoughXpToUnlock(self): stats = self.itemsCache.items.stats unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP) return unlockStats.getVehTotalXP(self.__vehCD) >= self.__xpCost
def _isEnoughXpToUnlock(self): stats = g_itemsCache.items.stats unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP) return unlockStats.getVehTotalXP(self.__vehCD) >= self.__xpCost