示例#1
0
    def __init__(self, strCompactDescr=None, component=None, vehicleCD='', vehicleType=None):
        super(Outfit, self).__init__(strCompactDescr)
        self._containers = {}
        self._vehicleCD = vehicleCD
        if strCompactDescr is not None and component is not None:
            raise SoftException("'strCompactDescr' and 'component' arguments are mutually exclusive!")
        if strCompactDescr:
            component = parseOutfitDescr(strCompactDescr)
        elif component is None:
            component = CustomizationOutfit()
        self._id = component.styleId
        self.__styleProgressionLevel = component.styleProgressionLevel
        self.__styleSerialNumber = component.serial_number
        self._styleDescr = None
        if self._id:
            intCD = makeIntCompactDescrByID('customizationItem', CustomizationType.STYLE, self._id)
            if not IS_EDITOR:
                self._styleDescr = getItemByCompactDescr(intCD)
            else:
                from items.vehicles import g_cache
                if g_cache.customization20(createNew=False):
                    self._styleDescr = getItemByCompactDescr(intCD)
        self._construct(vehicleType=vehicleType)
        for container in self._containers.itervalues():
            container.unpack(component)

        self.__itemsCounter = None
        self.invalidate()
        return
    def __init__(self,
                 strCompactDescr=None,
                 component=None,
                 vehicleCD='',
                 vehicleType=None):
        super(Outfit, self).__init__(strCompactDescr)
        self._containers = {}
        self._vehicleCD = vehicleCD
        if strCompactDescr is not None and component is not None:
            raise SoftException(
                "'strCompactDescr' and 'component' arguments are mutually exclusive!"
            )
        if strCompactDescr:
            component = parseOutfitDescr(strCompactDescr)
        elif component is None:
            component = CustomizationOutfit()
        self._id = component.styleId
        if self._id:
            intCD = makeIntCompactDescrByID('customizationItem',
                                            CustomizationType.STYLE, self._id)
            self._styleDescr = getItemByCompactDescr(intCD)
        else:
            self._styleDescr = None
        self._construct(vehicleType=vehicleType)
        for container in self._containers.itervalues():
            container.unpack(component)

        self.__itemsCounter = None
        self.invalidate()
        return
示例#3
0
    def canBeEditedForVehicle(self, vehicleIntCD):
        if not self.isEditable:
            return EditingStyleReason(EDITING_STYLE_REASONS.NOT_EDITABLE)
        else:
            ctx = self._service.getCtx()
            if ctx is not None and self.isProgression:
                season = ctx.mode.season
                diff = ctx.stylesDiffsCache.getDiff(self, season)
                if diff is not None:
                    vehicleItem = self._service.itemsCache.items.getItemByCD(
                        vehicleIntCD)
                    diffOutfit = parseOutfitDescr(outfitDescr=diff)
                    modifiedProgression = diffOutfit.styleProgressionLevel
                    progressionChanged = modifiedProgression != self.getLatestOpenedProgressionLevel(
                        vehicleItem)
                    if progressionChanged and not self.isProgressionPurchasable(
                            modifiedProgression):
                        return EditingStyleReason(
                            EDITING_STYLE_REASONS.NOT_REACHED_LEVEL)
            if not self.isProgressionRequired:
                return EditingStyleReason(EDITING_STYLE_REASONS.IS_EDITABLE)
            progressionStorage = self._itemsCache.items.inventory.getC11nProgressionDataForVehicle(
                vehicleIntCD)
            for itemIntCD, progressionData in progressionStorage.iteritems():
                if not progressionData.currentLevel:
                    continue
                item = self._service.getItemByCD(itemIntCD)
                if self.descriptor.isItemInstallable(item.descriptor):
                    return EditingStyleReason(
                        EDITING_STYLE_REASONS.IS_EDITABLE)

            return EditingStyleReason(
                EDITING_STYLE_REASONS.NOT_HAVE_ANY_PROGRESIIVE_DECALS)
def getOutfitComponent(outfitCD, vehicleDescriptor=None):
    if outfitCD:
        outfitComponent = parseOutfitDescr(outfitCD)
        season = _currentMapSeason()
        if outfitComponent.styleId != 0 and season is not None:
            intCD = makeIntCompactDescrByID('customizationItem', CustomizationType.STYLE, outfitComponent.styleId)
            styleDescr = getItemByCompactDescr(intCD)
            if IS_EDITOR:
                if hasattr(outfitComponent, 'edSeasonsMask'):
                    enyOutfit = styleDescr.outfits[season]
                    season = enyOutfit.edSeasonsMask
            baseOutfitComponent = deepcopy(styleDescr.outfits[season])
            if vehicleDescriptor and ItemTags.ADD_NATIONAL_EMBLEM in styleDescr.tags:
                emblems = createNationalEmblemComponents(vehicleDescriptor)
                baseOutfitComponent.decals.extend(emblems)
            if isEditedStyle(outfitComponent):
                outfitComponent = baseOutfitComponent.applyDiff(outfitComponent)
            else:
                outfitComponent = baseOutfitComponent
        return outfitComponent
    else:
        return CustomizationOutfit()
def getOutfitComponent(outfitCD, vehicleDescriptor=None, seasonType=None):
    if outfitCD:
        outfitComponent = parseOutfitDescr(outfitCD)
        if seasonType is None:
            seasonType = _currentMapSeason()
        if outfitComponent.styleId != 0 and outfitComponent.styleId != EMPTY_ITEM_ID and seasonType is not None:
            intCD = makeIntCompactDescrByID('customizationItem',
                                            CustomizationType.STYLE,
                                            outfitComponent.styleId)
            styleDescr = getItemByCompactDescr(intCD)
            if IS_EDITOR:
                if hasattr(outfitComponent, 'edSeasonsMask'):
                    if styleDescr.outfits is not None and bool(
                            styleDescr.outfits):
                        anyOutfit = styleDescr.outfits[
                            styleDescr.outfits.keys()[0]]
                        seasonType = anyOutfit.edSeasonsMask
                    else:
                        return outfitComponent
            baseOutfitComponent = deepcopy(styleDescr.outfits[seasonType])
            if styleDescr.isProgression or IS_EDITOR:
                if IS_EDITOR:
                    baseOutfitComponent.styleId = styleDescr.id
                outfit = Outfit(component=baseOutfitComponent,
                                vehicleCD=vehicleDescriptor.makeCompactDescr())
                if outfit and outfit.style and outfit.style.styleProgressions:
                    outfit = getStyleProgressionOutfit(
                        outfit, outfitComponent.styleProgressionLevel,
                        seasonType)
                    baseOutfitComponent = outfit.pack()
                baseOutfitComponent.styleProgressionLevel = outfitComponent.styleProgressionLevel
            if styleDescr.isWithSerialNumber:
                baseOutfitComponent.serial_number = outfitComponent.serial_number
            if vehicleDescriptor and ItemTags.ADD_NATIONAL_EMBLEM in styleDescr.tags:
                emblems = createNationalEmblemComponents(vehicleDescriptor)
                baseOutfitComponent.decals.extend(emblems)
            if isEditedStyle(outfitComponent):
                outfitComponent = baseOutfitComponent.applyDiff(
                    outfitComponent)
            else:
                outfitComponent = baseOutfitComponent
            if IS_EDITOR:

                def setupAlternateItem(itemType, outfit, sourceOutfit,
                                       collectionName):
                    alternateItem = outfit.editorData.alternateItems[itemType]
                    if alternateItem != 0:
                        sourceComponents = getattr(sourceOutfit,
                                                   collectionName)
                        if sourceComponents is not None:
                            if itemType != CustomizationType.MODIFICATION:
                                for componentItem in sourceComponents:
                                    componentItem.id = alternateItem

                            else:
                                for index, _ in enumerate(sourceComponents):
                                    sourceComponents[index] = alternateItem

                                setattr(sourceOutfit, collectionName,
                                        sourceComponents)
                    return

                anyOutfit = styleDescr.outfits[seasonType]
                setupAlternateItem(CustomizationType.DECAL, anyOutfit,
                                   outfitComponent, 'decals')
                setupAlternateItem(CustomizationType.PROJECTION_DECAL,
                                   anyOutfit, outfitComponent,
                                   'projection_decals')
                setupAlternateItem(CustomizationType.PAINT, anyOutfit,
                                   outfitComponent, 'paints')
                setupAlternateItem(CustomizationType.CAMOUFLAGE, anyOutfit,
                                   outfitComponent, 'camouflages')
                setupAlternateItem(CustomizationType.MODIFICATION, anyOutfit,
                                   outfitComponent, 'modifications')
                setupAlternateItem(CustomizationType.PERSONAL_NUMBER,
                                   anyOutfit, outfitComponent,
                                   'personal_numbers')
        return outfitComponent
    else:
        return CustomizationOutfit()