def __getDirectionBuildings(self, direction):
        buildings = [None, None]
        for buildingID, buildingData in self.__item.getDictBuildingsBrief().iteritems():
            dir = getDirectionFromDirPos(buildingData['dirPosByte'])
            if direction == dir:
                pos = getPositionFromDirPos(buildingData['dirPosByte'])
                level = buildingData['level']
                buildings[pos] = {'uid': self.getBuildingUIDbyID(buildingID),
                 'progress': self._getProgress(buildingID, level),
                 'buildingLevel': level}

        return buildings
Пример #2
0
    def __getDirectionBuildings(self, direction):
        buildings = [None, None]
        for buildingID, buildingData in self.__item.getDictBuildingsBrief().iteritems():
            dir = getDirectionFromDirPos(buildingData['dirPosByte'])
            if direction == dir:
                pos = getPositionFromDirPos(buildingData['dirPosByte'])
                level = buildingData['level']
                uid = self.getBuildingUIDbyID(buildingID)
                buildings[pos] = {'uid': uid,
                 'progress': self._getProgress(buildingID, level),
                 'buildingLevel': level,
                 'iconSource': FortViewHelper.getSmallIconSource(uid, level)}

        return buildings
    def _updateDirections(self):
        directions = []
        selectedDirection = -1
        fort = self.fortCtrl.getFort()
        inProcess, _ = fort.getDefenceHourProcessing()
        isDefenceOn = fort.isDefenceHourEnabled() or inProcess
        enemyBuildings = [None, None]
        for buildingID, buildingData in self.__item.getDictBuildingsBrief(
        ).iteritems():
            dirId = getDirectionFromDirPos(buildingData['dirPosByte'])
            if self.__direction == dirId:
                pos = getPositionFromDirPos(buildingData['dirPosByte'])
                level = buildingData['level']
                if 0 <= level < 5:
                    isAvailable = False
                else:
                    isAvailable = self.__isBuildingAvailableForAttack(
                        buildingData['hp'],
                        g_fortCache.buildings[buildingID].levels[level].hp)
                uid = self.getBuildingUIDbyID(buildingID)
                enemyBuildings[pos] = {
                    'uid':
                    uid,
                    'progress':
                    self._getProgress(buildingID, level),
                    'buildingLevel':
                    level,
                    'isAvailable':
                    isAvailable,
                    'iconSource':
                    FortViewHelper.getSmallIconSource(uid, level, isDefenceOn)
                }

        enemyDirection = {
            'name':
            _ms('#fortifications:General/directionName%d' % self.__direction),
            'isMine':
            False,
            'buildings':
            enemyBuildings
        }
        for direction in range(1, g_fortCache.maxDirections + 1):
            isOpened = fort.isDirectionOpened(direction)
            isBusy = False
            availableTime = None
            name = _ms('#fortifications:General/directionName%d' % direction)
            ttHeader = _ms(
                FORTIFICATIONS.
                FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_HEADER)
            ttBody = _ms(
                FORTIFICATIONS.
                FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_BODY)
            infoMessage = ''
            allieBuildings = []
            if isOpened:
                for building in fort.getBuildingsByDirections().get(
                        direction, ()):
                    data = None
                    if building is not None:
                        buildingTypeId = building.typeID
                        uid = self.getBuildingUIDbyID(buildingTypeId)
                        level = building.level
                        data = {
                            'uid':
                            uid,
                            'progress':
                            self._getProgress(buildingTypeId, level),
                            'buildingLevel':
                            level,
                            'isAvailable':
                            self.__isBuildingAvailableForAttack(
                                building.hp, building.levelRef.hp),
                            'iconSource':
                            FortViewHelper.getSmallIconSource(
                                uid, level, isDefenceOn)
                        }
                    allieBuildings.append(data)

                eventTypeID = FORT_EVENT_TYPE.DIR_OPEN_ATTACKS_BASE + direction
                availableTime, _, _ = fort.events.get(eventTypeID,
                                                      (None, None, None))
                if availableTime <= self.__selectedDayStart:
                    availableTime = None
                if availableTime is None:
                    attackerClanName = None
                    todayAttacks = fort.getAttacks(
                        filterFunc=lambda a: self.__selectedDayStart <= a.
                        getStartTime(
                        ) <= self.__selectedDayFinish and a.isPlanned())
                    roamingDateAttacks = fort.getAttacks(
                        filterFunc=lambda a: a.getStartTime() - time_utils.
                        ONE_DAY < self.__defHourStart < a.getStartTime(
                        ) + time_utils.ONE_DAY and a.isPlanned())
                    for attack in todayAttacks + roamingDateAttacks:
                        if direction == attack.getDirection():
                            isBusy = True
                            _, defClanAbbrev, _ = attack.getOpponentClanInfo()
                            attackerClanName = '[%s]' % defClanAbbrev

                    if isBusy:
                        ttHeader = _ms(
                            FORTIFICATIONS.
                            FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_HEADER
                        )
                        ttBody = _ms(
                            FORTIFICATIONS.
                            FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_BODY,
                            clanName=attackerClanName)
                    else:
                        clanForAttackTag = '[%s]' % self.__item.getClanAbbrev()
                        ttHeader = _ms(
                            FORTIFICATIONS.
                            FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_HEADER,
                            direction=name)
                        ttBody = _ms(
                            FORTIFICATIONS.
                            FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_BODY,
                            direction=name,
                            clanName=clanForAttackTag)
                else:
                    infoMessage = _ms(
                        FORTIFICATIONS.
                        FORTDECLARATIONOFWARWINDOW_DIRECTION_NOTAVAILABLE,
                        date=BigWorld.wg_getShortDateFormat(availableTime))
                    ttHeader = _ms(
                        FORTIFICATIONS.
                        FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_HEADER
                    )
                    ttBody = _ms(
                        FORTIFICATIONS.
                        FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_BODY,
                        date=BigWorld.wg_getShortDateFormat(availableTime))
                if not isBusy and selectedDirection == -1:
                    selectedDirection = direction
            directions.append({
                'leftDirection': {
                    'name': name,
                    'uid': direction,
                    'isOpened': isOpened,
                    'isBusy': isBusy or availableTime is not None,
                    'buildings': allieBuildings,
                    'ttHeader': ttHeader,
                    'ttBody': ttBody,
                    'infoMessage': infoMessage
                },
                'rightDirection':
                enemyDirection,
                'connectionIcon':
                RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_OFFENCE
            })

        self.as_setDirectionsS(directions)
        self.as_selectDirectionS(selectedDirection)
        return
    def _updateDirections(self):
        directions = []
        selectedDirection = -1
        enemyBuildings = [None, None]
        for buildingID, buildingData in self.__item.getDictBuildingsBrief().iteritems():
            dirId = getDirectionFromDirPos(buildingData['dirPosByte'])
            if self.__direction == dirId:
                pos = getPositionFromDirPos(buildingData['dirPosByte'])
                level = buildingData['level']
                if 0 <= level < 5:
                    isAvailable = False
                else:
                    isAvailable = self.__isBuildingAvailableForAttack(buildingData['hp'], g_fortCache.buildings[buildingID].levels[level].hp)
                enemyBuildings[pos] = {'uid': self.getBuildingUIDbyID(buildingID),
                 'progress': self._getProgress(buildingID, level),
                 'buildingLevel': level,
                 'isAvailable': isAvailable}

        enemyDirection = {'name': _ms('#fortifications:General/directionName%d' % self.__direction),
         'isMine': False,
         'buildings': enemyBuildings}
        fort = self.fortCtrl.getFort()
        for direction in range(1, g_fortCache.maxDirections + 1):
            isOpened = fort.isDirectionOpened(direction)
            isBusy = False
            availableTime = None
            name = _ms('#fortifications:General/directionName%d' % direction)
            ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_HEADER)
            ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTOPENED_TOOLTIP_BODY)
            infoMessage = ''
            allieBuildings = []
            if isOpened:
                for building in fort.getBuildingsByDirections().get(direction, ()):
                    data = None
                    if building is not None:
                        buildingTypeId = building.typeID
                        data = {'uid': self.getBuildingUIDbyID(buildingTypeId),
                         'progress': self._getProgress(buildingTypeId, building.level),
                         'buildingLevel': building.level,
                         'isAvailable': self.__isBuildingAvailableForAttack(building.hp, building.levelRef.hp)}
                    allieBuildings.append(data)

                eventTypeID = FORT_EVENT_TYPE.DIR_OPEN_ATTACKS_BASE + direction
                availableTime, _, _ = fort.events.get(eventTypeID, (None, None, None))
                if availableTime <= self.__selectedDayStart:
                    availableTime = None
                if availableTime is None:
                    attackerClanName = None
                    todayAttacks = fort.getAttacks(filterFunc=lambda a: self.__selectedDayStart <= a.getStartTime() <= self.__selectedDayFinish and a.isPlanned())
                    roamingDateAttacks = fort.getAttacks(filterFunc=lambda a: a.getStartTime() - time_utils.ONE_DAY < self.__defHourStart < a.getStartTime() + time_utils.ONE_DAY and a.isPlanned())
                    for attack in todayAttacks + roamingDateAttacks:
                        if direction == attack.getDirection():
                            isBusy = True
                            _, defClanAbbrev, _ = attack.getOpponentClanInfo()
                            attackerClanName = '[%s]' % defClanAbbrev

                    if isBusy:
                        ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_HEADER)
                        ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_BUSY_TOOLTIP_BODY, clanName=attackerClanName)
                    else:
                        clanForAttackTag = '[%s]' % self.__item.getClanAbbrev()
                        ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_HEADER, direction=name)
                        ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_ATTACK_TOOLTIP_BODY, direction=name, clanName=clanForAttackTag)
                else:
                    infoMessage = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_DIRECTION_NOTAVAILABLE, date=BigWorld.wg_getShortDateFormat(availableTime))
                    ttHeader = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_HEADER)
                    ttBody = _ms(FORTIFICATIONS.FORTDECLARATIONOFWARWINDOW_ITEM_NOTAVAILABLE_TOOLTIP_BODY, date=BigWorld.wg_getShortDateFormat(availableTime))
                if not isBusy and selectedDirection == -1:
                    selectedDirection = direction
            directions.append({'leftDirection': {'name': name,
                               'uid': direction,
                               'isOpened': isOpened,
                               'isBusy': isBusy or availableTime is not None,
                               'buildings': allieBuildings,
                               'ttHeader': ttHeader,
                               'ttBody': ttBody,
                               'infoMessage': infoMessage},
             'rightDirection': enemyDirection,
             'connectionIcon': RES_ICONS.MAPS_ICONS_LIBRARY_FORTIFICATION_OFFENCE})

        self.as_setDirectionsS(directions)
        self.as_selectDirectionS(selectedDirection)
        return