def buyAndInstallItem(self, itemCD, rootCD, state): itemTypeID, _, __ = vehicles.parseIntCompactDescr(itemCD) if itemTypeID not in GUI_ITEM_TYPE.VEHICLE_MODULES: raise SoftException('Specified type (itemTypeID={}) is not type of module'.format(itemTypeID)) vehicle = self.itemsCache.items.getItemByCD(rootCD) if not vehicle.isInInventory: raise SoftException('Vehicle (intCD={}) must be in inventory'.format(rootCD)) item = self.itemsCache.items.getItemByCD(itemCD) conflictedEqs = item.getConflictedEquipments(vehicle) if not self._mayObtainForMoney(item) and self._mayObtainWithMoneyExchange(item): isOk, _ = yield DialogsInterface.showDialog(ExchangeCreditsMeta(itemCD, vehicle.intCD)) if not isOk: return if self._mayObtainForMoney(item): Waiting.show('buyAndInstall') vehicle = self.itemsCache.items.getItemByCD(rootCD) gunCD = getGunCD(item, vehicle) result = yield BuyAndInstallItemProcessor(vehicle, item, 0, gunCD, conflictedEqs=conflictedEqs, skipConfirm=self.skipConfirm).request() processMsg(result) if result.success and item.itemTypeID in (GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN): item = self.itemsCache.items.getItemByCD(itemCD) vehicle = self.itemsCache.items.getItemByCD(rootCD) if item.isInstalled(vehicle): yield tryToLoadDefaultShellsLayout(vehicle) Waiting.hide('buyAndInstall') RequestState.received(state) yield lambda callback=None: callback return
def _response(self, code, callback, errStr='', ctx=None): LOG_DEBUG('Server response', code, errStr, ctx) RequestState.received('unlock') return callback( self._errorHandler(code, errStr='server_error', ctx=ctx)) if code < 0 else callback( self._successHandler(code, ctx=ctx))
def installItem(self, itemCD, rootCD, state): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) raise itemTypeID in GUI_ITEM_TYPE.VEHICLE_MODULES or AssertionError vehicle = self.itemsCache.items.getItemByCD(rootCD) if not vehicle.isInInventory: raise AssertionError('Vehicle must be in inventory') item = self.itemsCache.items.getItemByCD(itemCD) conflictedEqs = item.getConflictedEquipments(vehicle) RequestState.sent(state) if item.isInInventory: Waiting.show('applyModule') result = yield getInstallerProcessor( vehicle, item, conflictedEqs=conflictedEqs, skipConfirm=self.skipConfirm).request() processMsg(result) vehicle = result.success and item.itemTypeID in ( GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN) and self.itemsCache.items.getItemByCD( vehicle.intCD) yield tryToLoadDefaultShellsLayout(vehicle) Waiting.hide('applyModule') RequestState.received(state) yield lambda callback=None: callback return
def installItem(self, itemCD, rootCD, state): itemTypeID, _, __ = vehicles.parseIntCompactDescr(itemCD) if itemTypeID not in GUI_ITEM_TYPE.VEHICLE_MODULES: raise SoftException( 'Specified type (itemTypeID={}) is not type of module'.format( itemTypeID)) vehicle = self.itemsCache.items.getItemByCD(rootCD) if not vehicle.isInInventory: raise SoftException( 'Vehicle (intCD={}) must be in inventory'.format(rootCD)) item = self.itemsCache.items.getItemByCD(itemCD) conflictedEqs = item.getConflictedEquipments(vehicle) RequestState.sent(state) if item.isInInventory: Waiting.show('applyModule') result = yield getInstallerProcessor( vehicle, item, conflictedEqs=conflictedEqs, skipConfirm=self.skipConfirm).request() processMsg(result) if result.success and item.itemTypeID in (GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN): vehicle = self.itemsCache.items.getItemByCD(vehicle.intCD) yield tryToLoadDefaultShellsLayout(vehicle) Waiting.hide('applyModule') RequestState.received(state) yield lambda callback=None: callback return
def buyAndInstallItem(self, itemCD, rootCD, state): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) raise itemTypeID in GUI_ITEM_TYPE.VEHICLE_MODULES or AssertionError vehicle = g_itemsCache.items.getItemByCD(rootCD) if not vehicle.isInInventory: raise AssertionError('Vehicle must be in inventory') item = g_itemsCache.items.getItemByCD(itemCD) conflictedEqs = item.getConflictedEquipments(vehicle) if not self._canBuy(item) and self._canBuyWithExchange(item): isOk, args = yield DialogsInterface.showDialog(ExchangeCreditsMeta(itemCD, vehicle.intCD)) if not isOk: return if self._canBuy(item): Waiting.show('buyAndInstall') vehicle = g_itemsCache.items.getItemByCD(rootCD) gunCD = getGunCD(item, vehicle) result = yield BuyAndInstallItemProcessor(vehicle, item, 0, gunCD, conflictedEqs=conflictedEqs).request() processMsg(result) if result.success and item.itemTypeID in (GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN): item = g_itemsCache.items.getItemByCD(itemCD) vehicle = g_itemsCache.items.getItemByCD(rootCD) item.isInstalled(vehicle) and (yield tryToLoadDefaultShellsLayout(vehicle)) Waiting.hide('buyAndInstall') RequestState.received(state) yield lambda callback = None: callback return
def buyAndInstallItem(self, itemCD, rootCD, state): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) assert itemTypeID in GUI_ITEM_TYPE.VEHICLE_MODULES vehicle = g_itemsCache.items.getItemByCD(rootCD) assert vehicle.isInInventory, 'Vehicle must be in inventory' item = g_itemsCache.items.getItemByCD(itemCD) conflictedEqs = item.getConflictedEquipments(vehicle) if not self._canBuy(item) and self._canBuyWithExchange(item): isOk, args = yield DialogsInterface.showDialog(ExchangeCreditsMeta(itemCD, vehicle.intCD)) if not isOk: return if self._canBuy(item): Waiting.show('buyAndInstall') vehicle = g_itemsCache.items.getItemByCD(rootCD) gunCD = getGunCD(item, vehicle) result = yield BuyAndInstallItemProcessor(vehicle, item, 0, gunCD, conflictedEqs=conflictedEqs).request() processMsg(result) if result.success and item.itemTypeID in (GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN): item = g_itemsCache.items.getItemByCD(itemCD) vehicle = g_itemsCache.items.getItemByCD(rootCD) if item.isInstalled(vehicle): yield tryToLoadDefaultShellsLayout(vehicle) Waiting.hide('buyAndInstall') RequestState.received(state) yield lambda callback = None: callback
def installItem(self, itemCD, rootCD, state): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) assert itemTypeID in GUI_ITEM_TYPE.VEHICLE_MODULES vehicle = g_itemsCache.items.getItemByCD(rootCD) assert vehicle.isInInventory, 'Vehicle must be in inventory' item = g_itemsCache.items.getItemByCD(itemCD) conflictedEqs = item.getConflictedEquipments(vehicle) RequestState.sent(state) if item.isInInventory: Waiting.show('applyModule') result = yield getInstallerProcessor(vehicle, item, conflictedEqs=conflictedEqs).request() processMsg(result) if result.success and item.itemTypeID in (GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN): vehicle = g_itemsCache.items.getItemByCD(vehicle.intCD) yield tryToLoadDefaultShellsLayout(vehicle) Waiting.hide('applyModule') RequestState.received(state) yield lambda callback = None: callback
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 doAction(self): if RequestState.inProcess('buyAndInstall'): SystemMessages.pushI18nMessage('#system_messages:shop/item/buy_and_equip_in_processing', type=SystemMessages.SM_TYPE.Warning) self.buyAndInstallItem(self._itemCD, self._rootCD, 'buyAndInstall')
def doAction(self): if RequestState.inProcess('install'): SystemMessages.pushI18nMessage('#system_messages:inventory/item/equip_in_processing', type=SystemMessages.SM_TYPE.Warning) self.installItem(self._itemCD, self._rootCD, 'install')
def _response(self, code, callback, errStr = '', ctx = None): LOG_DEBUG('Server response', code, errStr, ctx) RequestState.received('unlock') if code < 0: return callback(self._errorHandler(code, errStr='server_error', ctx=ctx)) return callback(self._successHandler(code, ctx=ctx))
def _request(self, callback): RequestState.sent('unlock') BigWorld.player().stats.unlock(self.vehTypeCD, self.unlockIdx, lambda code: self._response(code, callback))