示例#1
0
 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
示例#2
0
    def buyAndInstallItem(self, itemCD, state, inInventory = False):
        itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD)
        assert itemTypeID in GUI_ITEM_TYPE.VEHICLE_MODULES
        vehicle = self._data.getRootItem()
        assert vehicle.isInInventory, 'Vehicle must be in inventory'
        item = self._data.getItem(itemCD)
        conflictedEqs = item.getConflictedEquipments(vehicle)
        if not inInventory:
            Waiting.show('buyItem')
            buyResult = yield ModuleBuyer(item, count=1, buyForCredits=True, conflictedEqs=conflictedEqs, install=True).request()
            Waiting.hide('buyItem')
            if len(buyResult.userMsg):
                SystemMessages.g_instance.pushI18nMessage(buyResult.userMsg, type=buyResult.sysMsgType)
            if buyResult.success:
                item = self._data.getItem(itemCD)
            else:
                return
        else:
            RequestState.sent(state)
        if item.isInInventory:
            Waiting.show('applyModule')
            result = yield getInstallerProcessor(vehicle, item, conflictedEqs=conflictedEqs).request()
            if result and result.auxData:
                for m in result.auxData:
                    SystemMessages.g_instance.pushI18nMessage(m.userMsg, type=m.sysMsgType)

            if result and len(result.userMsg):
                SystemMessages.g_instance.pushI18nMessage(result.userMsg, type=result.sysMsgType)
            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)
示例#3
0
    def buyAndInstallItem(self, itemCD, state, inInventory = False):
        itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD)
        raise itemTypeID in _RESEARCH_ITEMS or AssertionError
        oldStyleVehicle = self._data.getInvItem(self._data.getRootCD())
        if not oldStyleVehicle is not None:
            raise AssertionError, 'Vehicle has be in inventory'
            eqs = functions.findConflictedEquipments(itemCD, itemTypeID, oldStyleVehicle)
            item = g_itemsCache.items.getItemByCD(itemCD)
            vehicle = g_itemsCache.items.getItemByCD(self._data.getRootCD())
            if not inInventory:
                Waiting.show('buyItem')
                buyResult = yield ModuleBuyer(item, count=1, buyForCredits=True, conflictedEqs=eqs, install=True).request()
                if len(buyResult.userMsg):
                    SystemMessages.g_instance.pushI18nMessage(buyResult.userMsg, type=buyResult.sysMsgType)
                Waiting.hide('buyItem')
            else:
                RequestState.sent(state)
            item = g_itemsCache.items.getItemByCD(itemCD)
            if item is not None and item.isInInventory:
                Waiting.show('applyModule')
                result = yield getInstallerProcessor(vehicle, item).request()
                success = result.success
                if result and result.auxData:
                    for m in result.auxData:
                        SystemMessages.g_instance.pushI18nMessage(m.userMsg, type=m.sysMsgType)

                if result and len(result.userMsg):
                    SystemMessages.g_instance.pushI18nMessage(result.userMsg, type=result.sysMsgType)
                success and itemTypeID in (_GUN, _TURRET) and self.tryLoadShells()
            Waiting.hide('applyModule')
        RequestState.received(state)
        return
示例#4
0
 def __cb_onUnlock(self, itemCD, costCtx, resultID):
     Waiting.hide('research')
     RequestState.received('unlock')
     ctx = {'xpCost': BigWorld.wg_getIntegralFormat(costCtx['xpCost']),
      'freeXP': BigWorld.wg_getIntegralFormat(costCtx['freeXP']),
      'vehXP': BigWorld.wg_getIntegralFormat(costCtx['vehXP'])}
     if RES_SUCCESS == resultID:
         self._showUnlockItemMsg(itemCD, ctx)
     else:
         self._showMessage(self.MSG_SCOPE.Unlocks, 'server_error', itemCD)
示例#5
0
 def _doUnlockItem(self, unlockCD, vehCD, unlockIdx, xpCost, result):
     if result and self._validateItem2Unlock(unlockCD, vehCD, unlockIdx,
                                             xpCost):
         costCtx = self._getXPCostCtx(self._data.getVehXP(vehCD), xpCost)
         Waiting.show('research')
         RequestState.sent('unlock')
         BigWorld.player().stats.unlock(vehCD,
                                        unlockIdx,
                                        callback=partial(
                                            self.__cb_onUnlock, unlockCD,
                                            costCtx))
示例#6
0
 def __cb_onUnlock(self, itemCD, costCtx, resultID):
     Waiting.hide('research')
     RequestState.received('unlock')
     ctx = {
         'xpCost': BigWorld.wg_getIntegralFormat(costCtx['xpCost']),
         'freeXP': BigWorld.wg_getIntegralFormat(costCtx['freeXP']),
         'vehXP': BigWorld.wg_getIntegralFormat(costCtx['vehXP'])
     }
     if RES_SUCCESS == resultID:
         self._showUnlockItemMsg(itemCD, ctx)
     else:
         self._showMessage(self.MSG_SCOPE.Unlocks, 'server_error', itemCD)
示例#7
0
 def request4Install(self, itemCD):
     if RequestState.inProcess('install'):
         SystemMessages.pushI18nMessage(
             '#system_messages:inventory/item/equip_in_processing',
             type=SystemMessages.SM_TYPE.Warning)
     itemCD = int(itemCD)
     self.buyAndInstallItem(itemCD, 'install', inInventory=True)
示例#8
0
 def request4Buy(self, itemCD):
     itemCD = int(itemCD)
     if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE:
         self.buyVehicle(itemCD)
     else:
         if RequestState.inProcess('buyAndInstall'):
             SystemMessages.pushI18nMessage('#system_messages:shop/item/buy_and_equip_in_processing', type=SystemMessages.SM_TYPE.Warning)
         self.buyAndInstallItem(itemCD, 'buyAndInstall')
示例#9
0
 def installItem(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)
         RequestState.sent(state)
         if item.isInInventory:
             Waiting.show('applyModule')
             result = yield getInstallerProcessor(vehicle, item, conflictedEqs=conflictedEqs).request()
             processMsg(result)
             vehicle = result.success and item.itemTypeID in (GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN) and g_itemsCache.items.getItemByCD(vehicle.intCD)
             yield tryToLoadDefaultShellsLayout(vehicle)
         Waiting.hide('applyModule')
     RequestState.received(state)
     yield lambda callback = None: callback
     return
示例#10
0
 def request4Buy(self, itemCD):
     itemCD = int(itemCD)
     itemTypeID, _, _ = vehicles.parseIntCompactDescr(itemCD)
     if itemTypeID == _VEHICLE:
         self.buyVehicle(itemCD)
     else:
         if RequestState.inProcess('buyAndInstall'):
             SystemMessages.pushI18nMessage(
                 '#system_messages:shop/item/buy_and_equip_in_processing',
                 type=SystemMessages.SM_TYPE.Warning)
         self.buyAndInstallItem(itemCD, 'buyAndInstall')
示例#11
0
    def buyAndInstallItem(self, itemCD, state, inInventory=False):
        itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD)
        raise itemTypeID in _RESEARCH_ITEMS or AssertionError
        oldStyleVehicle = self._data.getInvItem(self._data.getRootCD())
        if not oldStyleVehicle is not None:
            raise AssertionError, 'Vehicle has be in inventory'
            eqs = functions.findConflictedEquipments(itemCD, itemTypeID,
                                                     oldStyleVehicle)
            item = g_itemsCache.items.getItemByCD(itemCD)
            vehicle = g_itemsCache.items.getItemByCD(self._data.getRootCD())
            if not inInventory:
                Waiting.show('buyItem')
                buyResult = yield ModuleBuyer(item,
                                              count=1,
                                              buyForCredits=True,
                                              conflictedEqs=eqs,
                                              install=True).request()
                if len(buyResult.userMsg):
                    SystemMessages.g_instance.pushI18nMessage(
                        buyResult.userMsg, type=buyResult.sysMsgType)
                Waiting.hide('buyItem')
            else:
                RequestState.sent(state)
            item = g_itemsCache.items.getItemByCD(itemCD)
            if item is not None and item.isInInventory:
                Waiting.show('applyModule')
                result = yield getInstallerProcessor(vehicle, item).request()
                success = result.success
                if result and result.auxData:
                    for m in result.auxData:
                        SystemMessages.g_instance.pushI18nMessage(
                            m.userMsg, type=m.sysMsgType)

                if result and len(result.userMsg):
                    SystemMessages.g_instance.pushI18nMessage(
                        result.userMsg, type=result.sysMsgType)
                success and itemTypeID in (_GUN,
                                           _TURRET) and self.tryLoadShells()
            Waiting.hide('applyModule')
        RequestState.received(state)
        return
示例#12
0
文件: actions.py 项目: webiumsk/WoT
    def buyAndInstallItem(self, itemCD, rootCD, state, inInventory = False):
        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 inInventory:
                if not self._canBuy(item) and self._canBuyWithExchange(item):
                    isOk, args = yield DialogsInterface.showDialog(ExchangeCreditsMeta(itemCD))
                    if not isOk:
                        return
                if self._canBuy(item):
                    Waiting.show('buyItem')
                    buyResult = yield ModuleBuyer(item, count=1, buyForCredits=True, conflictedEqs=conflictedEqs, install=True).request()
                    Waiting.hide('buyItem')
                    if len(buyResult.userMsg):
                        SystemMessages.g_instance.pushI18nMessage(buyResult.userMsg, type=buyResult.sysMsgType)
                    if buyResult.success:
                        item = g_itemsCache.items.getItemByCD(itemCD)
                    else:
                        return
            else:
                RequestState.sent(state)
            if item.isInInventory:
                Waiting.show('applyModule')
                result = yield getInstallerProcessor(vehicle, item, conflictedEqs=conflictedEqs).request()
                if result and result.auxData:
                    for m in result.auxData:
                        SystemMessages.g_instance.pushI18nMessage(m.userMsg, type=m.sysMsgType)

                if result and len(result.userMsg):
                    SystemMessages.g_instance.pushI18nMessage(result.userMsg, type=result.sysMsgType)
                vehicle = result.success and item.itemTypeID in (GUI_ITEM_TYPE.TURRET, GUI_ITEM_TYPE.GUN) and g_itemsCache.items.getItemByCD(vehicle.intCD)
                yield tryToLoadDefaultShellsLayout(vehicle)
            Waiting.hide('applyModule')
        RequestState.received(state)
        yield lambda callback = None: callback
        return
示例#13
0
 def _validateItem2Unlock(self, unlockCD, vehCD, unlockIdx, xpCost):
     itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(vehCD)
     if itemTypeID != _VEHICLE:
         LOG_ERROR('Int compact descriptor is not for vehicle', vehCD)
         return False
     if not self._data.isUnlocked(vehCD):
         LOG_ERROR('Vehicle is not unlocked', unlockCD, vehCD)
         return False
     if self._data.isUnlocked(unlockCD):
         self._showAlreadyUnlockedMsg(vehCD)
         return False
     if not self._data.isNext2Unlock(unlockCD):
         LOG_ERROR('Required items are not unlocked', unlockCD, vehCD)
         return False
     if max(self._data._accFreeXP, 0) + self._data.getVehXP(vehCD) < xpCost:
         LOG_ERROR('XP not enough for unlock', vehCD, unlockIdx, xpCost)
         return False
     if RequestState.inProcess('unlock'):
         SystemMessages.pushI18nMessage('#system_messages:unlocks/in_processing', type=SystemMessages.SM_TYPE.Warning)
         return False
     return True
示例#14
0
 def _validateItem2Unlock(self, unlockCD, vehCD, unlockIdx, xpCost):
     itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(vehCD)
     if itemTypeID != _VEHICLE:
         LOG_ERROR('Int compact descriptor is not for vehicle', vehCD)
         return False
     if not self._data.isUnlocked(vehCD):
         LOG_ERROR('Vehicle is not unlocked', unlockCD, vehCD)
         return False
     if self._data.isUnlocked(unlockCD):
         self._showAlreadyUnlockedMsg(vehCD)
         return False
     if not self._data.isNext2Unlock(unlockCD):
         LOG_ERROR('Required items are not unlocked', unlockCD, vehCD)
         return False
     if max(self._data._accFreeXP, 0) + self._data.getVehXP(vehCD) < xpCost:
         LOG_ERROR('XP not enough for unlock', vehCD, unlockIdx, xpCost)
         return False
     if RequestState.inProcess('unlock'):
         SystemMessages.pushI18nMessage(
             '#system_messages:unlocks/in_processing',
             type=SystemMessages.SM_TYPE.Warning)
         return False
     return True
示例#15
0
文件: unlock.py 项目: webiumsk/WoT
 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()
示例#16
0
文件: unlock.py 项目: webiumsk/WoT
 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))
示例#17
0
文件: unlock.py 项目: webiumsk/WoT
 def _request(self, callback):
     RequestState.sent('unlock')
     BigWorld.player().stats.unlock(self.vehTypeCD, self.unlockIdx, lambda code: self._response(code, callback))
示例#18
0
 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')
示例#19
0
 def _doUnlockItem(self, unlockCD, vehCD, unlockIdx, xpCost, result):
     if result and self._validateItem2Unlock(unlockCD, vehCD, unlockIdx, xpCost):
         costCtx = self._getXPCostCtx(self._data.getVehXP(vehCD), xpCost)
         Waiting.show('research')
         RequestState.sent('unlock')
         BigWorld.player().stats.unlock(vehCD, unlockIdx, callback=partial(self.__cb_onUnlock, unlockCD, costCtx))
示例#20
0
 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')
示例#21
0
 def request4Install(self, itemCD):
     if RequestState.inProcess('install'):
         SystemMessages.pushI18nMessage('#system_messages:inventory/item/equip_in_processing', type=SystemMessages.SM_TYPE.Warning)
     itemCD = int(itemCD)
     self.buyAndInstallItem(itemCD, 'install', inInventory=True)