def __applyElement(self, element, duration, isInQuest): """ :param element: one of elements from DataAggregator :param duration: duration which user selected for purchase :param isInQuest: element was picked from quest and cannot be bought :return: None """ cType = self.__currentType slotIdx = self.__currentIdx installedSlot = self.__installedSlotsData[cType][slotIdx] installedElement = installedSlot['element'] newSlotData = {'element': element, 'duration': duration, 'spot': self.__currentSlotsData[cType][slotIdx]['spot'], 'isRevertible': installedElement is not None, 'isInDossier': element.isInDossier, 'isInQuest': isInQuest} if installedElement is not None and installedElement.getID() == element.getID(): self.__setSlotAndUpdateView(cType, slotIdx, copy.deepcopy(installedSlot)) elif element.isInDossier: numberOfDays = element.numberOfDays if numberOfDays is not None: itemDuration = numberOfDays if numberOfDays == 30 else 7 installationFlag = INSTALLATION.INVOICED else: itemDuration = 0 installationFlag = INSTALLATION.NORMAL self.__events.onOwnedElementPicked(cType, newSlotData['spot'], getAdjustedSlotIndex(slotIdx, cType, self.__currentSlotsData), element.getID(), itemDuration, installationFlag=installationFlag) else: self.__setSlotAndUpdateView(cType, slotIdx, newSlotData) return
def clearSlot(self, cType, slotIdx): installedSlotData = self.__installedSlotsData[cType][slotIdx] if installedSlotData['element'] is not None: self.__events.onTankSlotCleared(cType, installedSlotData['spot'], getAdjustedSlotIndex(slotIdx, cType, self.__currentSlotsData), installedSlotData['element'].getID(), 0, installationFlag=INSTALLATION.REMOVAL) else: self.dropAppliedItem(cType, slotIdx) return
def __onSlotSelected(self, cType, slotIdx, slotData): self.__selectedSlotIdx = slotIdx if cType == CUSTOMIZATION_TYPE.CAMOUFLAGE and slotData['element']: self._currentModelAttributes[0] = slotData['element'].getID() self.__applyViewModel() if cType != CUSTOMIZATION_TYPE.CAMOUFLAGE: self.__hangarSpace.space.locateCameraOnEmblem( slotData['spot'] == 0, SLOT_TYPE[cType], getAdjustedSlotIndex(slotIdx, cType, self.__slotsData), 0.2) else: self.__hangarSpace.space.locateCameraToPreview()
def purchaseMultiple(self, purchaseWindowItems): self.__processingMultiplePurchase = True self.__events.onMultiplePurchaseStarted() sortedItems = sorted(purchaseWindowItems, key=lambda item: item['price']) self.__elementsToProcess = 0 for item in sortedItems: if item['selected']: self.__elementsToProcess += 1 for item in sortedItems: itemIndex = purchaseWindowItems.index(item) cartItem = self.__purchaseData[itemIndex] isGold = cartItem['duration'] == DURATION.PERMANENT if item['selected']: self.purchaseSingle(item['cType'], cartItem['spot'], getAdjustedSlotIndex(item['slotIdx'], item['cType'], self.__initialSlotsData), item['id'], cartItem['duration'], item['price'], isGold)
def __update(self, updatedSlotData, cType, slotIdx): element = updatedSlotData['element'] if cType == CUSTOMIZATION_TYPE.CAMOUFLAGE: if slotIdx == self.__selectedSlotIdx: if element is None: self._currentModelAttributes[0] = None else: self._currentModelAttributes[0] = element.getID() else: if element is None: elementID = None else: elementID = element.getID() viewModelItem = [elementID, time.time(), 0] if cType == CUSTOMIZATION_TYPE.INSCRIPTION: viewModelItem.append(0) self._currentModelAttributes[cType][updatedSlotData['spot'] + getAdjustedSlotIndex(slotIdx, cType, self.__slotsData)] = viewModelItem self.__applyViewModel() return
def purchaseMultiple(self, purchaseWindowItems): self.__processingMultiplePurchase = True self.__events.onMultiplePurchaseStarted() sortedItems = sorted(zip(purchaseWindowItems, self.__purchaseData), key=lambda (wItem, _): wItem['price']) self.__elementsToProcess = len( filter(lambda (wItem, _): wItem['selected'], sortedItems)) for wItem, cartItem in sortedItems: isGold = cartItem['duration'] == DURATION.PERMANENT if wItem['selected']: yield self.__purchaseSingle( wItem['cType'], cartItem['spot'], getAdjustedSlotIndex(wItem['slotIdx'], wItem['cType'], self.__initialSlotsData), wItem['id'], cartItem['duration'], installationFlag=wItem['price'], isGold=isGold)
def __onSlotSelected(self, cType, slotIdx, slotData): self.__selectedSlotIdx = slotIdx if cType == CUSTOMIZATION_TYPE.CAMOUFLAGE and slotData['element']: self._currentModelAttributes[0] = slotData['element'].getID() self.__applyViewModel() if cType != CUSTOMIZATION_TYPE.CAMOUFLAGE: self.__hangarSpace.space.locateCameraOnEmblem(slotData['spot'] == 0, SLOT_TYPE[cType], getAdjustedSlotIndex(slotIdx, cType, self.__slotsData), 0.2) else: self.__hangarSpace.space.locateCameraToPreview()