def change(self, vehInvID, section, isAlreadyPurchased): if self._newItemID is None: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_NOT_SELECTED) self.onCustomizationChangeFailed(message) return if self._rentalPackageDP.selectedPackage is None: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_DAYS_NOT_SELECTED) self.onCustomizationChangeFailed(message) return cost, isGold = self._itemsDP.getCost(self._newItemID) if cost < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_COST_NOT_FOUND) self.onCustomizationChangeFailed(message) return if isAlreadyPurchased: daysToWear = 0 cost = 0 elif CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, self._newItemID, self._nationID, self._itemsDP.position): hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION_TYPE, self._newItemID) daysToWear = 0 if hangarItem.get('isPermanent') else 7 else: daysToWear = self._rentalPackageDP.selectedPackage.get('periodDays') newIdToSend = 0 isNewInDefaultSetup = False isCurrIgr = self._itemsDP.isIGRItem(self._currentItemID) if isCurrIgr: isNewInDefaultSetup = CustomizationHelper.isIdInDefaultSetup(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, self._newItemID) if self._currentItemID is None or not isCurrIgr or isCurrIgr and not isNewInDefaultSetup or isCurrIgr and isNewInDefaultSetup and daysToWear > 0: newIdToSend = self._newItemID BigWorld.player().inventory.changeVehicleInscription(vehInvID, self.getRealPosition(), newIdToSend, daysToWear, 1, lambda resultID: self.__onChangeVehicleInscription(resultID, (cost, isGold)))
def change(self, vehInvID, section, isAlreadyPurchased): if self._newItemID is None: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_NOT_SELECTED) self.onCustomizationChangeFailed(message) return elif self._rentalPackageDP.selectedPackage is None: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_DAYS_NOT_SELECTED) self.onCustomizationChangeFailed(message) return else: cost, isGold = self._itemsDP.getCost(self._newItemID) if cost < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_COST_NOT_FOUND) self.onCustomizationChangeFailed(message) return if isAlreadyPurchased: daysToWear = 0 cost = 0 elif CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, self._newItemID, self._nationID, self._itemsDP.position): hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION_TYPE, self._newItemID, self._nationID, self._itemsDP.position) daysToWear = 0 if hangarItem.get('isPermanent') else 7 else: daysToWear = self._rentalPackageDP.selectedPackage.get('periodDays') newIdToSend = 0 isNewInDefaultSetup = False isCurrIgr = self._itemsDP.isIGRItem(self._currentItemID) if isCurrIgr: isNewInDefaultSetup = CustomizationHelper.isIdInDefaultSetup(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, self._newItemID) if self._currentItemID is None or not isCurrIgr or isCurrIgr and not isNewInDefaultSetup or isCurrIgr and isNewInDefaultSetup and daysToWear > 0: newIdToSend = self._newItemID BigWorld.player().inventory.changeVehicleInscription(vehInvID, self.getRealPosition(), newIdToSend, daysToWear, 1, lambda resultID: self.__onChangeVehicleInscription(resultID, (cost, isGold))) return
def change(self, vehInvID, section, isAlreadyPurchased): if self._rentalPackageDP.selectedPackage is None: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DAYS_NOT_SELECTED) self.onCustomizationChangeFailed(message) return else: isNewItemFound = False for kind, item in self.currentItemsByKind.iteritems(): newItemID = item.get("newItemID", None) currItemId = item.get("id", None) if newItemID is None: continue elif not isNewItemFound: isNewItemFound = True price = self.getItemCost(newItemID, item.get("packageIdx")) cost = price.get("cost", 0) isGold = price.get("isGold", False) if cost < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_COST_NOT_FOUND) self.onCustomizationChangeFailed(message) return localKind = kind if CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, newItemID, self._nationID): hangarItem = CustomizationHelper.getItemFromHangar( CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, newItemID, self._nationID ) daysToWear = 0 if hangarItem.get("isPermanent") else 7 else: daysToWear = self._rentalPackageDP.pyRequestItemAt(item.get("packageIdx")).get("periodDays") newIdToSend = 0 isNewInDefaultSetup = False isCurrIgr = self._itemsDP.isIGRItem(currItemId) if isCurrIgr: isNewInDefaultSetup = CustomizationHelper.isIdInDefaultSetup( CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, newItemID ) if ( currItemId is None or not isCurrIgr or isCurrIgr and not isNewInDefaultSetup or isCurrIgr and isNewInDefaultSetup and daysToWear > 0 ): newIdToSend = newItemID BigWorld.player().inventory.changeVehicleCamouflage( vehInvID, localKind, newIdToSend, daysToWear, functools.partial(self.__onChangeVehicleCamouflage, (cost, isGold), localKind), ) if not isNewItemFound: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_NOT_SELECTED) self.onCustomizationChangeFailed(message) return
def __onIGRTypeChanged(self, roomType, xpFactor): LOG_DEBUG('__onIGRTypeChanged', roomType, xpFactor) if not g_currentVehicle.isPresent(): return self.__steps = len(_VEHICLE_CUSTOMIZATIONS) vehType = vehicles.g_cache.vehicle(*g_currentVehicle.item.descriptor.type.id) vehDescr = CustomizationHelper.getUpdatedDescriptor(g_currentVehicle.item.descriptor) VehicleCustomizationModel.resetVehicleDescriptor(vehDescr) for interface in self.__interfaces.itervalues(): interface.update(CustomizationHelper.getUpdatedDescriptor(g_currentVehicle.item.descriptor)) interface.refreshViewData(vehType, refresh=True) self.as_refreshDataS() self.as_onResetNewItemS() self.__isIgrChanged = True
def buildList(self): hiddenInscriptions = g_itemsCache.items.shop.getInscriptionsGroupHiddens(self._nationID) customization = vehicles.g_cache.customization(self._nationID) result = [] if customization is not None: igrRoomType = gui.game_control.g_instance.igr.getRoomType() groups = customization.get('inscriptionGroups', {}) for name, group in groups.iteritems(): inscriptionIDs, groupUserString, igrType, allow, deny = group isHasNew = self._hasNewItems(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION_TYPE, inscriptionIDs) isHiddenGroup = name in hiddenInscriptions currVehIntD = g_currentVehicle.item.intCD canBeUsedOnVehicle = currVehIntD not in deny and (len(allow) == 0 or currVehIntD in allow) hasItemsInHangar = False if isHiddenGroup: hasItemsInHangar = CustomizationHelper.areItemsInHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, inscriptionIDs, self._nationID) if canBeUsedOnVehicle and (isHasNew or hasItemsInHangar or not isHiddenGroup) and (gui.GUI_SETTINGS.igrEnabled or not gui.GUI_SETTINGS.igrEnabled and igrType == constants.IGR_TYPE.NONE): result.append({'name': name, 'userString': groupUserString, 'hasNew': isHasNew, 'isIGR': igrType != constants.IGR_TYPE.NONE, 'enabled': igrType == constants.IGR_TYPE.NONE or igrType <= igrRoomType, 'tooltip': TOOLTIPS.CUSTOMIZATION_INSCRIPTION_IGR}) self._list = sorted(result, cmp=self.__comparator) return
def buildList(self): hiddenEmblems = g_itemsCache.items.shop.getEmblemsGroupHiddens() groups, emblems, names = vehicles.g_cache.playerEmblems() result = [] if groups is not None: igrRoomType = gui.game_control.g_instance.igr.getRoomType() for name, group in groups.iteritems(): emblemIDs, groupUserString, igrType, nations, allow, deny = group isHasNew = self._hasNewItems(CUSTOMIZATION_ITEM_TYPE.EMBLEM_TYPE, emblemIDs) isHiddenGroup = name in hiddenEmblems hasItemsInHangar = False currVehIntD = g_currentVehicle.item.intCD canBeUsedOnVehicle = currVehIntD not in deny and (len(allow) == 0 or currVehIntD in allow) if isHiddenGroup: hasItemsInHangar = CustomizationHelper.areItemsInHangar(CUSTOMIZATION_ITEM_TYPE.EMBLEM, emblemIDs, self._nationID) if canBeUsedOnVehicle and (isHasNew or hasItemsInHangar or not isHiddenGroup) and (gui.GUI_SETTINGS.igrEnabled or not gui.GUI_SETTINGS.igrEnabled and igrType == constants.IGR_TYPE.NONE) and (nations is None or g_currentVehicle.item.nationID in nations): result.append({'name': name, 'userString': groupUserString, 'hasNew': isHasNew, 'isIGR': igrType != constants.IGR_TYPE.NONE, 'enabled': igrType == constants.IGR_TYPE.NONE or igrType <= igrRoomType, 'tooltip': TOOLTIPS.CUSTOMIZATION_EMBLEM_IGR}) self._list = sorted(result, cmp=self.__comparator) return
def __onDropVehicleInscription(self, resultID): if resultID < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return else: newID = None newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: inscriptions = g_currentVehicle.item.descriptor.playerInscriptions inscr = inscriptions[self.getRealPosition()] if inscr[0] is not None: newID = inscr[0] newLifeCycle = (inscr[1], inscr[2]) hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION_TYPE, self._currentItemID, self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_DROP_SUCCESS) self._currentItemID = newID self._currentLifeCycle = newLifeCycle self._itemsDP.currentItemID = newID self.updateVehicleCustomization(newID) self.onCustomizationDropSuccess(message) return
def __onDropVehicleCamouflage(self, resultID, kind): if resultID < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return else: item = self.currentItemsByKind.get(kind) hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, item.get('id'), self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SUCCESS) if g_tankActiveCamouflage.has_key(g_currentVehicle.item.intCD): del g_tankActiveCamouflage[g_currentVehicle.item.intCD] newID = None newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: camouflages = g_currentVehicle.item.descriptor.camouflages camo = camouflages[kind] if camo[0] is not None: newID = camo[0] newLifeCycle = (camo[1], camo[2]) item['id'] = newID item['lifeCycle'] = newLifeCycle if CAMOUFLAGE_KINDS.get(self._itemsDP.currentGroup) == kind: self._itemsDP.currentItemID = newID self.onCustomizationDropSuccess(message) return
def _dispose(self): CustomizationHelper.updateVisitedItems(CUSTOMIZATION_ITEM_TYPE.CI_TYPES[self._type], self.__newIds) self.__newIds = None if self._newItemID is not None: self.updateVehicleCustomization(self._currentItemID) self._rentalPackageDP.onDataInited -= self._onRentalPackagesDataInited self._rentalPackageDP.onRentalPackageChange -= self.__handleRentalPackageChange self._rentalPackageDP._dispose() self._groupsDP._dispose() self._itemsDP._dispose() self._rentalPackageDP = None self._groupsDP = None self._itemsDP = None self._eventManager.clear() LOG_DEBUG('BaseTimedCustomizationInterface _dispose', self._name) super(BaseTimedCustomizationInterface, self)._dispose()
def __onDropVehicleEmblem(self, resultID): if resultID < 0: message = i18n.makeString( SYSTEM_MESSAGES.CUSTOMIZATION_EMBLEM_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return else: newID = self.defaultPlayerEmblemID newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: emblems = g_currentVehicle.item.descriptor.playerEmblems emblem = emblems[self.getRealPosition()] if emblem[0] is not None: newID = emblem[0] newLifeCycle = (emblem[1], emblem[2]) hangarItem = CustomizationHelper.getItemFromHangar( CUSTOMIZATION_ITEM_TYPE.EMBLEM_TYPE, self._currentItemID, self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString( SYSTEM_MESSAGES.CUSTOMIZATION_EMBLEM_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString( SYSTEM_MESSAGES.CUSTOMIZATION_EMBLEM_DROP_SUCCESS) self._currentItemID = newID self._currentLifeCycle = newLifeCycle self._itemsDP.currentItemID = newID self.updateVehicleCustomization(newID) self.onCustomizationDropSuccess(message) self.onCurrentItemChange(self._name) return
def onRequestList(self, groupName): if not groupName: return else: customization = vehicles.g_cache.customization(self.nationID) result = [] hiddenItems = g_itemsCache.items.shop.getInscriptionsGroupHiddens(self.nationID) if customization is not None: groups = customization.get('inscriptionGroups', {}) group = groups.get(groupName, {}) inscriptions = customization.get('inscriptions', {}) if group is not None: inscriptionIDs, groupUserString, igrType, allow, deny = group isHasNew = self._hasNewItems(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION_TYPE, inscriptionIDs) isHiddenGroup = groupName in hiddenItems hasItemsInHangar = False if isHiddenGroup: hasItemsInHangar = CustomizationHelper.areItemsInHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, inscriptionIDs, self.nationID) self._isIGR = igrType != constants.IGR_TYPE.NONE if isHasNew or hasItemsInHangar or not isHiddenGroup: for id in inscriptionIDs: itemInfo = self._constructInscription(id, groups, inscriptions, self.currentItemID == id, False if self.isIGRItem(id) else CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, id, self.nationID, self.position), False) if itemInfo is not None: if not self._isIGR or self._isIGR and itemInfo.get('igrType') != constants.IGR_TYPE.NONE: result.append(itemInfo) return sorted(result, cmp=self.__comparator)
def __onDropVehicleCamouflage(self, resultID, kind): if resultID < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return item = self.currentItemsByKind.get(kind) hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, item.get('id'), self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SUCCESS) if g_tankActiveCamouflage.has_key(g_currentVehicle.item.intCD): del g_tankActiveCamouflage[g_currentVehicle.item.intCD] newID = None newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: camouflages = g_currentVehicle.item.descriptor.camouflages camo = camouflages[kind] if camo[0] is not None: newID = camo[0] newLifeCycle = (camo[1], camo[2]) item['id'] = newID item['lifeCycle'] = newLifeCycle if CAMOUFLAGE_KINDS.get(self._itemsDP.currentGroup) == kind: self._itemsDP.currentItemID = newID self.onCustomizationDropSuccess(message)
def _hasNewItems(self, type, itemsInGroupIDs): newItemsIds = CustomizationHelper.getNewIdsByType(type, self._nationID) if type == CUSTOMIZATION_ITEM_TYPE.EMBLEM_TYPE: groupIdsSet = set(itemsInGroupIDs) else: groupIdsSet = set(((self._nationID, id) for id in itemsInGroupIDs)) result = groupIdsSet.intersection(newItemsIds) return len(result) > 0
def _getPriceFactor(self, itemID): priceFactor = 0 groups, emblems, names = vehicles.g_cache.playerEmblems() emblem = emblems.get(itemID) if emblem is not None: groupName, igrType, texture, bumpFile, emblemUserString, isMirrored = emblem[0:6] if not CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.EMBLEM, itemID, self.nationID, self.position): priceFactor = g_itemsCache.items.shop.getEmblemsGroupPriceFactors().get(groupName) return priceFactor
def __refreshData(self): vehType = vehicles.g_cache.vehicle(*g_currentVehicle.item.descriptor.type.id) updatedDescr = CustomizationHelper.getUpdatedDescriptor(g_currentVehicle.item.descriptor) for interface in self.__interfaces.itervalues(): interface.update(updatedDescr) interface.fetchCurrentItem(updatedDescr) interface.refreshViewData(vehType, refresh=True) self.as_refreshDataS()
def _populate(self): BigWorld.player().resyncDossiers() self.fireEvent(LobbySimpleEvent(LobbySimpleEvent.HIDE_HANGAR, True)) View._populate(self) credits, gold = g_itemsCache.items.stats.money self.as_setCreditsS(credits) self.as_setGoldS(gold) g_playerEvents.onDossiersResync += self.__pe_onDossiersResync g_clientUpdateManager.addCallbacks({ 'stats.gold': self.onGoldUpdate, 'stats.credits': self.onCreditsUpdate, 'cache.mayConsumeWalletResources': self.onGoldUpdate, 'account.attrs': self.onCameraUpdate, 'inventory.1.compDescr': self.onVehiclesUpdate, 'cache.vehsLock': self.__cv_onChanged }) g_itemsCache.onSyncCompleted += self.__pe_onShopResync game_control.g_instance.igr.onIgrTypeChanged += self.__onIGRTypeChanged g_currentVehicle.onChanged += self.__cv_onChanged g_hangarSpace.onSpaceCreate += self.__hs_onSpaceCreate g_eventsCache.onSyncCompleted += self.__onEventsCacheSyncCompleted vehDescr = None vehType = None if g_currentVehicle.isPresent(): vehDescr = CustomizationHelper.getUpdatedDescriptor( g_currentVehicle.item.descriptor) vehType = vehDescr.type VehicleCustomizationModel.setVehicleDescriptor(vehDescr) self.__steps = len(_VEHICLE_CUSTOMIZATIONS) for customization in _VEHICLE_CUSTOMIZATIONS: sectionName = customization['sectionName'] interface = customization['interface']( sectionName, vehDescr.type.customizationNationID, customization['type'], customization['position']) interface.onDataInited += self.__ci_onDataInited interface.onCustomizationChangeSuccess += self.__ci_onCustomizationChangeSuccess interface.onCustomizationChangeFailed += self.__ci_onCustomizationChangeFailed interface.onCustomizationDropSuccess += self.__ci_onCustomizationDropSuccess interface.onCustomizationDropFailed += self.__ci_onCustomizationDropFailed interface.onCurrentItemChange += self.__ci_onCurrentItemChanged self.__interfaces[sectionName] = interface interface.updateSlotsPosition(vehDescr) interface.setFlashObject(self.flashObject, setScript=False) interface.fetchCurrentItem(vehDescr) interface.invalidateViewData(vehType) if not self.__steps: self.__finishInitData() self.setupContextHints(TUTORIAL.CUSTOMIZATION) return
def __init__(self, name, nationId, type, position = -1): super(BaseTimedCustomizationInterface, self).__init__(name, nationId, type, position) self._currentItemID = None self._currentLifeCycle = None self._newItemID = None self._rentalPackageDP = None self._groupsDP = None self._itemsDP = None self._flashObject = None self.__newIds = CustomizationHelper.getNewIdsByType(CUSTOMIZATION_ITEM_TYPE.CI_TYPES[type], nationId)
def __onIGRTypeChanged(self, roomType, xpFactor): LOG_DEBUG('__onIGRTypeChanged', roomType, xpFactor) if not g_currentVehicle.isPresent(): return self.__steps = len(_VEHICLE_CUSTOMIZATIONS) vehType = vehicles.g_cache.vehicle( *g_currentVehicle.item.descriptor.type.id) vehDescr = CustomizationHelper.getUpdatedDescriptor( g_currentVehicle.item.descriptor) VehicleCustomizationModel.resetVehicleDescriptor(vehDescr) for interface in self.__interfaces.itervalues(): interface.update( CustomizationHelper.getUpdatedDescriptor( g_currentVehicle.item.descriptor)) interface.refreshViewData(vehType, refresh=True) self.as_refreshDataS() self.as_onResetNewItemS() self.__isIgrChanged = True
def onVehiclesUpdate(self, vehicles): if vehicles is None or self.__lockUpdate: return vehCompDescr = vehicles.get(g_currentVehicle.invID) if vehCompDescr is not None: vehDescr = VehicleDescr(compactDescr=vehCompDescr) for interface in self.__interfaces.itervalues(): interface.update(CustomizationHelper.getUpdatedDescriptor(vehDescr)) self.as_refreshItemsDataS()
def __refreshData(self): vehType = vehicles.g_cache.vehicle( *g_currentVehicle.item.descriptor.type.id) updatedDescr = CustomizationHelper.getUpdatedDescriptor( g_currentVehicle.item.descriptor) for interface in self.__interfaces.itervalues(): interface.update(updatedDescr) interface.fetchCurrentItem(updatedDescr) interface.refreshViewData(vehType, refresh=True) self.as_refreshDataS()
def onVehiclesUpdate(self, vehicles): if vehicles is None or self.__lockUpdate: return vehCompDescr = vehicles.get(g_currentVehicle.invID) if vehCompDescr is not None: vehDescr = VehicleDescr(compactDescr=vehCompDescr) for interface in self.__interfaces.itervalues(): interface.update( CustomizationHelper.getUpdatedDescriptor(vehDescr)) self.as_refreshItemsDataS()
def _getPriceFactor(self, itemID): priceFactor = 0 customization = vehicles.g_cache.customization(self.nationID) if customization is not None: inscriptions = customization.get('inscriptions', {}) inscription = inscriptions.get(itemID) if inscription is not None: groupName, igrType, texture, bumpMap, inscriptionUserString, isFeatured = inscription[0:6] if not CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, itemID, self.nationID, self.position): priceFactor = g_itemsCache.items.shop.getInscriptionsGroupPriceFactors(self.nationID).get(groupName) return priceFactor
def change(self, vehInvID, section, isAlreadyPurchased): if self._rentalPackageDP.selectedPackage is None: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DAYS_NOT_SELECTED) self.onCustomizationChangeFailed(message) return else: isNewItemFound = False for kind, item in self.currentItemsByKind.iteritems(): newItemID = item.get('newItemID', None) currItemId = item.get('id', None) if newItemID is None: continue elif not isNewItemFound: isNewItemFound = True price = self.getItemCost(newItemID, item.get('packageIdx')) cost = price.get('cost', 0) isGold = price.get('isGold', False) if cost < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_COST_NOT_FOUND) self.onCustomizationChangeFailed(message) return localKind = kind if CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, newItemID, self._nationID): hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, newItemID, self._nationID) daysToWear = 0 if hangarItem.get('isPermanent') else 7 else: daysToWear = self._rentalPackageDP.pyRequestItemAt(item.get('packageIdx')).get('periodDays') newIdToSend = 0 isNewInDefaultSetup = False isCurrIgr = self._itemsDP.isIGRItem(currItemId) if isCurrIgr: isNewInDefaultSetup = CustomizationHelper.isIdInDefaultSetup(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, newItemID) if currItemId is None or not isCurrIgr or isCurrIgr and not isNewInDefaultSetup or isCurrIgr and isNewInDefaultSetup and daysToWear > 0: newIdToSend = newItemID BigWorld.player().inventory.changeVehicleCamouflage(vehInvID, localKind, newIdToSend, daysToWear, functools.partial(self.__onChangeVehicleCamouflage, (cost, isGold), localKind)) if not isNewItemFound: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_NOT_SELECTED) self.onCustomizationChangeFailed(message) return
def _dispose(self): self.fireEvent(LobbySimpleEvent(LobbySimpleEvent.HIDE_HANGAR, False)) self.__resetPreviewMode() for interface in self.__interfaces.itervalues(): interface.destroy() interface.onDataInited -= self.__ci_onDataInited interface.onCustomizationChangeSuccess -= self.__ci_onCustomizationChangeSuccess interface.onCustomizationChangeFailed -= self.__ci_onCustomizationChangeFailed interface.onCustomizationDropSuccess -= self.__ci_onCustomizationDropSuccess interface.onCustomizationDropFailed -= self.__ci_onCustomizationDropFailed interface.onCurrentItemChange -= self.__ci_onCurrentItemChanged self.__interfaces.clear() self.__onceDataInited = False g_itemsCache.onSyncCompleted -= self.__pe_onShopResync game_control.g_instance.igr.onIgrTypeChanged -= self.__onIGRTypeChanged g_currentVehicle.onChanged -= self.__cv_onChanged g_hangarSpace.onSpaceCreate -= self.__hs_onSpaceCreate g_playerEvents.onDossiersResync -= self.__pe_onDossiersResync g_clientUpdateManager.removeObjectCallbacks(self) CustomizationHelper.clearStoredCustomizationData() View._dispose(self)
def _dispose(self): self.fireEvent(LobbySimpleEvent(LobbySimpleEvent.HIDE_HANGAR, False)) self.__resetPreviewMode() for interface in self.__interfaces.itervalues(): interface.destroy() interface.onDataInited -= self.__ci_onDataInited interface.onCustomizationChangeSuccess -= self.__ci_onCustomizationChangeSuccess interface.onCustomizationChangeFailed -= self.__ci_onCustomizationChangeFailed interface.onCustomizationDropSuccess -= self.__ci_onCustomizationDropSuccess interface.onCustomizationDropFailed -= self.__ci_onCustomizationDropFailed interface.onCurrentItemChange -= self.__ci_onCurrentItemChanged self.__interfaces.clear() self.__onceDataInited = False g_itemsCache.onSyncCompleted -= self.__pe_onShopResync game_control.g_instance.igr.onIgrTypeChanged -= self.__onIGRTypeChanged g_currentVehicle.onChanged -= self.__cv_onChanged g_hangarSpace.onSpaceCreate -= self.__hs_onSpaceCreate g_eventsCache.onSyncCompleted -= self.__onEventsCacheSyncCompleted g_playerEvents.onDossiersResync -= self.__pe_onDossiersResync g_clientUpdateManager.removeObjectCallbacks(self) CustomizationHelper.clearStoredCustomizationData() View._dispose(self)
def _populate(self): BigWorld.player().resyncDossiers() self.fireEvent(LobbySimpleEvent(LobbySimpleEvent.HIDE_HANGAR, True)) View._populate(self) credits, gold = g_itemsCache.items.stats.money self.as_setCreditsS(credits) self.as_setGoldS(gold) g_playerEvents.onDossiersResync += self.__pe_onDossiersResync g_clientUpdateManager.addCallbacks({'stats.gold': self.onGoldUpdate, 'stats.credits': self.onCreditsUpdate, 'cache.mayConsumeWalletResources': self.onGoldUpdate, 'account.attrs': self.onCameraUpdate, 'inventory.1.compDescr': self.onVehiclesUpdate, 'cache.vehsLock': self.__cv_onChanged}) g_itemsCache.onSyncCompleted += self.__pe_onShopResync game_control.g_instance.igr.onIgrTypeChanged += self.__onIGRTypeChanged g_currentVehicle.onChanged += self.__cv_onChanged g_hangarSpace.onSpaceCreate += self.__hs_onSpaceCreate g_eventsCache.onSyncCompleted += self.__onEventsCacheSyncCompleted vehDescr = None vehType = None if g_currentVehicle.isPresent(): vehDescr = CustomizationHelper.getUpdatedDescriptor(g_currentVehicle.item.descriptor) vehType = vehDescr.type VehicleCustomizationModel.setVehicleDescriptor(vehDescr) self.__steps = len(_VEHICLE_CUSTOMIZATIONS) for customization in _VEHICLE_CUSTOMIZATIONS: sectionName = customization['sectionName'] interface = customization['interface'](sectionName, vehDescr.type.customizationNationID, customization['type'], customization['position']) interface.onDataInited += self.__ci_onDataInited interface.onCustomizationChangeSuccess += self.__ci_onCustomizationChangeSuccess interface.onCustomizationChangeFailed += self.__ci_onCustomizationChangeFailed interface.onCustomizationDropSuccess += self.__ci_onCustomizationDropSuccess interface.onCustomizationDropFailed += self.__ci_onCustomizationDropFailed interface.onCurrentItemChange += self.__ci_onCurrentItemChanged self.__interfaces[sectionName] = interface interface.updateSlotsPosition(vehDescr) interface.setFlashObject(self.flashObject, setScript=False) interface.fetchCurrentItem(vehDescr) interface.invalidateViewData(vehType) if not self.__steps: self.__finishInitData() self.setupContextHints(TUTORIAL.CUSTOMIZATION) return
def onRequestList(self, groupName): groups, emblems, names = vehicles.g_cache.playerEmblems() group = groups.get(groupName) result = [] hiddenItems = g_itemsCache.items.shop.getEmblemsGroupHiddens() if group is not None: emblemIDs, groupUserString, igrType, nations, allow, deny = group self._isIGR = igrType != constants.IGR_TYPE.NONE isHasNew = self._hasNewItems(CUSTOMIZATION_ITEM_TYPE.EMBLEM_TYPE, emblemIDs) isHiddenGroup = groupName in hiddenItems hasItemsInHangar = False if isHiddenGroup: hasItemsInHangar = CustomizationHelper.areItemsInHangar(CUSTOMIZATION_ITEM_TYPE.EMBLEM, emblemIDs, self.nationID) if isHasNew or hasItemsInHangar or not isHiddenGroup: for id in emblemIDs: itemInfo = self._constructEmblem(id, groups, emblems, self.position, self.currentItemID == id, False if self.isIGRItem(id) else CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.EMBLEM, id, self.nationID, self.position), False) if itemInfo is not None: if not self._isIGR or self._isIGR and itemInfo.get('igrType') != constants.IGR_TYPE.NONE: result.append(itemInfo) return sorted(result, cmp=self.__comparator)
def hasNewItems(self): type = CUSTOMIZATION_ITEM_TYPE.CI_TYPES[self._type] newItemIDs = CustomizationHelper.getNewIdsByType(type, self._nationID) return len(newItemIDs) > 0
def getDrorStr(self, sectionName, kind): items = CustomizationHelper.getItemsOnVehicle(self._type) itemIdx = kind if self._type == CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE else self.getRealPosition() item = items[itemIdx] return 'customization/{0:>s}{1:>s}'.format(sectionName, 'Drop' if item[2] > 0 else 'Dismount')
def makeItem(self, itemID, isCurrent, lifeCycle, timeLeftString): groups, emblems, names = vehicles.g_cache.playerEmblems() itemInfo = None if emblems is not None: itemInfo = self._constructEmblem(itemID, groups, emblems, self.position, isCurrent, CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.EMBLEM, itemID, self.nationID, self.position)) if itemInfo is not None: itemInfo['timeLeft'] = timeLeftString else: itemInfo = {'id': itemID, 'texturePath': None, 'description': '', 'userString': '', 'igrType': 0, 'position': self.position, 'price': {'cost': 0, 'isGold': False}, 'action': None, 'current': isCurrent, 'isInHangar': False, 'timeLeft': timeLeftString} itemInfo['type'] = CUSTOMIZATION_ITEM_TYPE.EMBLEM return itemInfo
def onRequestList(self, groupName): self.currentGroup = groupName customization = vehicles.g_cache.customization(self.nationID) result = [] if customization is not None: groups = customization.get('camouflageGroups', {}) group = groups.get(groupName, {}) camouflages = customization.get('camouflages', {}) armorColor = customization.get('armorColor', 0) ids = group.get('ids', []) currIntDescr = g_currentVehicle.item.intCD for id in ids: camouflageInfo = self._constructCamouflage(id, groups, camouflages, armorColor, isCurrent=self.currentItemID == id, isInHangar=CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, id, self.nationID), withoutCheck=False, currVehIntD=currIntDescr) if camouflageInfo is not None: if not self._isIGR and camouflageInfo.get('igrType') == constants.IGR_TYPE.NONE or self._isIGR and camouflageInfo.get('igrType') == constants.IGR_TYPE.PREMIUM: result.append(camouflageInfo) if gui.GUI_SETTINGS.igrEnabled: for name, group in groups.iteritems(): if name not in CAMOUFLAGE_KINDS: ids = group.get('ids', []) for cID in ids: camouflage = camouflages.get(cID, None) if camouflage.get('kind', 0) == CAMOUFLAGE_KINDS.get(groupName, 0): camouflageInfo = self._constructCamouflage(cID, groups, camouflages, armorColor, isCurrent=self.currentItemID == cID, isInHangar=CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, cID, self.nationID), withoutCheck=False, currVehIntD=currIntDescr) if camouflageInfo is not None and camouflageInfo: if not self._isIGR and camouflageInfo.get('igrType') == constants.IGR_TYPE.NONE or self._isIGR and camouflageInfo.get('igrType') == constants.IGR_TYPE.PREMIUM: result.append(camouflageInfo) return sorted(result, cmp=self.__comparator)
def getCostForPackagePrice(self, camouflageID, packagePrice, isGold): if CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, camouflageID, self.nationID): priceFactor = 0 else: priceFactor = g_itemsCache.items.shop.getCamouflagesPriceFactors(self.nationID).get(camouflageID) return (self._makeCost(packagePrice, self._vehPriceFactor, priceFactor), isGold)
def _constructCamouflage(self, cID, groups, camouflages, armorColor, lifeCycle = None, isCurrent = False, isInHangar = False, withoutCheck = True, currVehIntD = None): camouflageInfo = None camouflage = camouflages.get(cID, None) hiddenCamos = g_itemsCache.items.shop.getCamouflagesHiddens(self.nationID) if camouflage is not None and (withoutCheck or cID not in hiddenCamos or isInHangar or camouflage.get('igrType', 0) != constants.IGR_TYPE.NONE and cID not in hiddenCamos): denyCD = camouflage.get('deny') allowCD = camouflage.get('allow') if currVehIntD not in denyCD and (len(allowCD) == 0 or currVehIntD in allowCD) or currVehIntD is None: invisibilityFactor = camouflage.get('invisibilityFactor', 1) invisibilityPercent = int(round((invisibilityFactor - 1) * 100)) invisibilityLbl = gui.makeHtmlString('html_templates:lobby/customization', 'camouflage-hint', {'percents': invisibilityPercent}, sourceKey=self.__getKindById(camouflage.get('kind', 0))) price = self._makeCost(self._cost, self._vehPriceFactor, self._getPriceFactor(cID)) if not isInHangar else 0 defaultPrice = self._makeCost(self._defCost, self._defVehPriceFactor, self._getDefaultCamoPriceFactor(cID)) if not isInHangar else 0 action = None if price != defaultPrice: isPremium = self._isGold == 1 newPrice = (0, price) if isPremium else (price, 0) oldPrice = (0, defaultPrice) if isPremium else (defaultPrice, 0) state = (None, ACTION_TOOLTIPS_STATE.DISCOUNT) if isPremium else (ACTION_TOOLTIPS_STATE.DISCOUNT, None) key = 'camouflagePacket7Cost' if self._period == 0: key = 'camouflagePacketInfCost' elif self._period == 30: key = 'camouflagePacket30Cost' action = {'type': ACTION_TOOLTIPS_TYPE.CAMOUFLAGE, 'key': cPickle.dumps((currVehIntD, key)), 'isBuying': True, 'state': state, 'newPrice': newPrice, 'oldPrice': oldPrice} timeLeftStr = '' days = 0 isPermanent = False value = 0 timeLeft = 0 if self._isGold else self._period * 86400 if isInHangar: item = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, cID, self.nationID) if item: isPermanent = item.get('isPermanent') value = item.get('quantity') timeLeft = value * 86400 if not item.get('isPermanent') else 0 timeLeftStr = CustomizationHelper.getTimeLeftText(timeLeft) if isCurrent: updatedDescr = CustomizationHelper.getUpdatedDescriptor(g_currentVehicle.item.descriptor) item = updatedDescr.camouflages[camouflage.get('kind', 0)] _, startTime, days = item if days: timeLeft = startTime + days * 86400 - time.time() timeLeftStr = CustomizationHelper.getTimeLeftText(timeLeft) camouflageInfo = {'id': cID, 'texturePath': self._makeSmallTextureUrl(camouflage.get('texture'), camouflage.get('colors', (0, 0, 0, 0)), armorColor, lifeCycle), 'description': self._makeDescription(groups, camouflage.get('groupName', ''), camouflage.get('description', '')), 'price': {'cost': price, 'isGold': self._isGold == 1}, 'action': action, 'isNew': self.isNewID(cID), 'invisibilityLbl': invisibilityLbl, 'igrType': camouflage.get('igrType', 0), 'current': isCurrent, 'isInHangar': isInHangar, 'timeLeftStr': timeLeftStr, 'type': CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, 'nationId': self.nationID, 'isSpecialTooltip': True, 'timeLeftValue': timeLeft, 'isPermanent': isPermanent, 'value': value} return camouflageInfo
def getDrorStr(self, sectionName, kind): items = CustomizationHelper.getItemsOnVehicle(self._type) itemIdx = kind if self._type == CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE else self.getRealPosition() item = items[itemIdx] return 'customization/{0:>s}{1:>s}'.format(sectionName, 'Drop' if item[2] > 0 else 'Dismount')
def makeItem(self, camouflageID, isCurrent, lifeCycle, timeLeftString, kind): customization = vehicles.g_cache.customization(self.nationID) camouflageInfo = None if customization is not None: groups = customization.get('camouflageGroups', {}) armorColor = customization.get('armorColor', 0) camouflageInfo = self._constructCamouflage(camouflageID, groups, customization.get('camouflages', {}), armorColor, lifeCycle, isCurrent, CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE, camouflageID, self.nationID)) if camouflageInfo is not None: camouflageInfo['timeLeft'] = timeLeftString else: camouflageInfo = {'timeLeft': timeLeftString, 'id': camouflageID, 'texturePath': None, 'description': self.getDefaultDescription(kind), 'price': {'cost': 0, 'isGold': False}, 'action': None, 'isNew': False, 'invisibilityLbl': '', 'current': False} return camouflageInfo
def hasNewItems(self): type = CUSTOMIZATION_ITEM_TYPE.CI_TYPES[self._type] newItemIDs = CustomizationHelper.getNewIdsByType(type, self._nationID) return len(newItemIDs) > 0
def _constructInscription(self, itemID, groups, inscriptions, isCurrent = False, isInHangar = False, withoutCheck = True): itemInfo = None inscription = inscriptions.get(itemID, None) priceFactors = g_itemsCache.items.shop.getInscriptionsGroupPriceFactors(self.nationID) defPriceFactors = g_itemsCache.items.shop.defaults.getInscriptionsGroupPriceFactors(self.nationID) hiddens = g_itemsCache.items.shop.getInscriptionsGroupHiddens(self.nationID) if inscription is not None: groupName, igrType, texture, bumpMap, inscriptionUserString, isFeatured = inscription[0:6] inscriptionIDs, groupUserString, igrType, allow, deny = groups.get(groupName) isNewItem = self.isNewID(itemID) if withoutCheck or isNewItem or isInHangar or groupName not in hiddens: price = self._makeCost(self._cost, self._vehPriceFactor, priceFactors.get(groupName)) if not isInHangar else 0 defaultPrice = self._makeCost(self._defCost, self._defVehPriceFactor, defPriceFactors.get(groupName, 1)) if not isInHangar else 0 action = None if price != defaultPrice: isPremium = self._isGold == 1 newPrice = (0, price) if isPremium else (price, 0) oldPrice = (0, defaultPrice) if isPremium else (defaultPrice, 0) state = (None, ACTION_TOOLTIPS_STATE.DISCOUNT) if isPremium else (ACTION_TOOLTIPS_STATE.DISCOUNT, None) key = 'inscriptionPacket7Cost' if self._period == 0: key = 'inscriptionPacketInfCost' elif self._period == 30: key = 'inscriptionPacket30Cost' action = {'type': ACTION_TOOLTIPS_TYPE.ECONOMICS, 'key': key, 'isBuying': True, 'state': state, 'newPrice': newPrice, 'oldPrice': oldPrice} timeLeftStr = '' days = 0 isPermanent = False value = 0 timeLeft = 0 if self._isGold else self._period * 86400 canUse = True if isInHangar: item = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION_TYPE, itemID, self.nationID, self.position) if item: isPermanent = item.get('isPermanent') value = item.get('quantity') timeLeft = value * 86400 if not item.get('isPermanent') else 0 timeLeftStr = CustomizationHelper.getTimeLeftText(timeLeft) if not isPermanent: _, selectedInscriptions = VehicleCustomizationModel.getVehicleModel() for selectedInscription in selectedInscriptions: if selectedInscriptions.index(selectedInscription) != self.position and selectedInscription[0] == itemID: canUse = False if isCurrent: updatedDescr = CustomizationHelper.getUpdatedDescriptor(g_currentVehicle.item.descriptor) item = updatedDescr.playerInscriptions[self.position] _, startTime, days, _ = item if days: timeLeft = startTime + days * 86400 - time.time() timeLeftStr = CustomizationHelper.getTimeLeftText(timeLeft) itemInfo = {'id': itemID, 'texturePath': self._makeSmallTextureUrl(texture, None, None), 'description': self._makeDescription(groupUserString, inscriptionUserString), 'igrType': igrType, 'price': {'cost': price, 'isGold': days == 0 if isCurrent else self._isGold == 1}, 'action': action, 'current': isCurrent, 'position': self.position, 'isInHangar': isInHangar, 'isFeatured': isFeatured, 'isNew': isNewItem, 'timeLeftStr': timeLeftStr, 'type': CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, 'nationId': self.nationID, 'isSpecialTooltip': True, 'timeLeftValue': timeLeft, 'isPermanent': isPermanent, 'value': value, 'canUse': canUse} return itemInfo
def makeItem(self, itemID, isCurrent, lifeCycle, timeLeftString): customization = vehicles.g_cache.customization(self.nationID) itemInfo = None if customization is not None: groups = customization.get('inscriptionGroups', {}) inscriptions = customization.get('inscriptions', {}) if inscriptions is not None: itemInfo = self._constructInscription(itemID, groups, inscriptions, isCurrent, CustomizationHelper.isItemInHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION, itemID, self.nationID, self.position)) if itemInfo is not None: itemInfo['timeLeft'] = timeLeftString else: itemInfo = {'timeLeft': timeLeftString, 'id': itemID, 'texturePath': None, 'description': '', 'price': {'cost': 0, 'isGold': False}, 'action': None, 'current': isCurrent, 'position': self.position} itemInfo['type'] = CUSTOMIZATION_ITEM_TYPE.INSCRIPTION return itemInfo
def isNewID(self, itemID): return CustomizationHelper.checkIsNewItem(self._currentType, itemID, self.nationID)