def __calculateDefencePeriod(self):
     currentDefencePeriod = time_utils.getTimeForLocal(
         self.__selectedDayStart,
         *adjustDefenceHourToLocal(self.__item.getStartDefHour()))
     self.__selectedDefencePeriodStart = time_utils.getTimeForLocal(
         self.__selectedDayStart,
         *self.__item.getDefHourFor(currentDefencePeriod))
     self.__selectedDefencePeriodEnd = self.__selectedDefencePeriodStart + time_utils.ONE_HOUR
    def canPlanAttackOn(self, dayTimestamp, clanFortInfo):
        if self.isFrozen():
            return ATTACK_PLAN_RESULT.MY_FROZEN
        currentDefHourTimestamp = time_utils.getTimeForLocal(dayTimestamp, clanFortInfo.getStartDefHour())
        enemyDefHour = clanFortInfo.getDefHourFor(currentDefHourTimestamp)
        enemyDefHourTimestamp = time_utils.getTimeForLocal(dayTimestamp, enemyDefHour)
        if enemyDefHourTimestamp - time_utils.getCurrentTimestamp() <= fortified_regions.g_cache.attackPreorderTime:
            return ATTACK_PLAN_RESULT.PREORDER_TIME
        if self.isOnVacationAt(enemyDefHourTimestamp):
            return ATTACK_PLAN_RESULT.MY_VACATION
        (vacationStart, vacationEnd,) = clanFortInfo.getVacationPeriod()
        if vacationStart <= enemyDefHourTimestamp <= vacationEnd:
            return ATTACK_PLAN_RESULT.OPP_VACATION
        dayDate = time_utils.getDateTimeInLocal(dayTimestamp)
        localOffDay = clanFortInfo.getLocalOffDayFor(currentDefHourTimestamp)
        if dayDate.weekday() == localOffDay:
            return ATTACK_PLAN_RESULT.OPP_OFF_DAY
        if self.defenceHour == clanFortInfo.getStartDefHour():
            return ATTACK_PLAN_RESULT.DEFENCE_HOUR_SAME

        def filterInFight(item):
            if enemyDefHourTimestamp <= item.getStartTime() < enemyDefHourTimestamp + time_utils.ONE_HOUR:
                return True
            return False


        attacksInFight = self.getAttacks(clanFortInfo.getClanDBID(), filterInFight)
        if attacksInFight:
            return ATTACK_PLAN_RESULT.WAR_DECLARED
        if clanFortInfo.closestAttackInCooldown is not None and dayTimestamp < clanFortInfo.closestAttackInCooldown.getStartTime() + time_utils.ONE_DAY * 7 and not clanFortInfo.counterAttacked:
            return ATTACK_PLAN_RESULT.IN_COOLDOWN
        (hasAvailableDirections, hasFreeDirections,) = (False, False)
        for direction in self.getOpenedDirections():
            eventTypeID = FORT_EVENT_TYPE.DIR_OPEN_ATTACKS_BASE + direction
            (availableTime, _, _,) = self.events.get(eventTypeID, (None, None, None))
            if availableTime <= enemyDefHourTimestamp:
                hasAvailableDirections = True

                def filterAttacks(item):
                    if enemyDefHourTimestamp <= item.getStartTime() <= enemyDefHourTimestamp + time_utils.ONE_HOUR and direction == item.getDirection() and not item.isEnded():
                        return True
                    return False


                if not self.getAttacks(filterFunc=filterAttacks):
                    hasFreeDirections = True
                    break

        if not hasAvailableDirections:
            return ATTACK_PLAN_RESULT.MY_NO_DIR
        if not hasFreeDirections:
            return ATTACK_PLAN_RESULT.MY_BUSY
        (isBusy, isAvailable,) = clanFortInfo.isAvailableForAttack(enemyDefHourTimestamp)
        if not isAvailable:
            return ATTACK_PLAN_RESULT.OPP_NO_DIR
        if isBusy:
            return ATTACK_PLAN_RESULT.OPP_BUSY
        return ATTACK_PLAN_RESULT.OK
Example #3
0
    def canPlanAttackOn(self, dayTimestamp, clanFortInfo):
        if self.isFrozen():
            return ATTACK_PLAN_RESULT.MY_FROZEN
        currentDefHourTimestamp = time_utils.getTimeForLocal(dayTimestamp, *clanFortInfo.getLocalDefHour())
        enemyDefHourTimestamp = time_utils.getTimeForLocal(dayTimestamp, *clanFortInfo.getDefHourFor(currentDefHourTimestamp))
        if enemyDefHourTimestamp - time_utils.getCurrentTimestamp() <= fortified_regions.g_cache.attackPreorderTime:
            return ATTACK_PLAN_RESULT.PREORDER_TIME
        if self.isOnVacationAt(enemyDefHourTimestamp):
            return ATTACK_PLAN_RESULT.MY_VACATION
        vacationStart, vacationEnd = clanFortInfo.getVacationPeriod()
        if vacationStart <= enemyDefHourTimestamp <= vacationEnd:
            return ATTACK_PLAN_RESULT.OPP_VACATION
        dayDate = time_utils.getDateTimeInLocal(dayTimestamp)
        localOffDay = clanFortInfo.getLocalOffDayFor(currentDefHourTimestamp)
        if dayDate.weekday() == localOffDay:
            return ATTACK_PLAN_RESULT.OPP_OFF_DAY
        if self.defenceHour == clanFortInfo.getStartDefHour():
            return ATTACK_PLAN_RESULT.DEFENCE_HOUR_SAME

        def filterInFight(item):
            if enemyDefHourTimestamp <= item.getStartTime() < enemyDefHourTimestamp + time_utils.ONE_HOUR:
                return True
            return False

        attacksInFight = self.getAttacks(clanFortInfo.getClanDBID(), filterInFight)
        if attacksInFight:
            return ATTACK_PLAN_RESULT.WAR_DECLARED
        if clanFortInfo.closestAttackInCooldown is not None and dayTimestamp < clanFortInfo.closestAttackInCooldown.getStartTime() + time_utils.ONE_DAY * 7 and not clanFortInfo.counterAttacked:
            return ATTACK_PLAN_RESULT.IN_COOLDOWN
        hasAvailableDirections, hasFreeDirections = False, False
        for direction in self.getOpenedDirections():
            eventTypeID = FORT_EVENT_TYPE.DIR_OPEN_ATTACKS_BASE + direction
            availableTime, _, _ = self.events.get(eventTypeID, (None, None, None))
            if availableTime is None or availableTime <= enemyDefHourTimestamp:
                hasAvailableDirections = True

                def filterAttacks(item):
                    if enemyDefHourTimestamp <= item.getStartTime() <= enemyDefHourTimestamp + time_utils.ONE_HOUR and direction == item.getDirection() and not item.isEnded():
                        return True
                    return False

                if not self.getAttacks(filterFunc=filterAttacks):
                    hasFreeDirections = True
                    break

        if not hasAvailableDirections:
            return ATTACK_PLAN_RESULT.MY_NO_DIR
        if not hasFreeDirections:
            return ATTACK_PLAN_RESULT.MY_BUSY
        isBusy, isAvailable = clanFortInfo.isAvailableForAttack(enemyDefHourTimestamp)
        if not isAvailable:
            return ATTACK_PLAN_RESULT.OPP_NO_DIR
        if isBusy:
            return ATTACK_PLAN_RESULT.OPP_BUSY
        return ATTACK_PLAN_RESULT.OK
 def _populate(self):
     super(FortIntelligenceClanFilterPopover, self)._populate()
     headerText = text_styles.highTitle(_ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_HEADER))
     clanLevelText = text_styles.standard(_ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_CLANLEVEL))
     startHourRangeText = text_styles.standard(_ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_STARTHOURRANGE))
     self.as_setDescriptionsTextS(headerText, clanLevelText, startHourRangeText)
     defaultButtonText = _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_DEFAULTBUTTONTEXT)
     applyButtonText = _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_APPLYBUTTONTEXT)
     cancelButtonText = _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_CANCELBUTTONTEXT)
     self.as_setButtonsTextS(defaultButtonText, applyButtonText, cancelButtonText)
     defaultButtonTooltip = TOOLTIPS.FORTIFICATION_FORTINTELLIGENCECLANFILTERPOPOVER_DEFAULT
     applyButtonTooltip = TOOLTIPS.FORTIFICATION_FORTINTELLIGENCECLANFILTERPOPOVER_APPLY
     self.as_setButtonsTooltipsS(defaultButtonTooltip, applyButtonTooltip)
     minClanLevel = FORTIFICATION_ALIASES.CLAN_FILTER_MIN_LEVEL
     maxClanLevel = FORTIFICATION_ALIASES.CLAN_FILTER_MAX_LEVEL
     startDefenseHour = FORTIFICATION_ALIASES.CLAN_FILTER_MIN_HOUR
     startDefenseMin = 0
     cache = self.fortCtrl.getPublicInfoCache()
     if cache:
         minClanLevel, maxClanLevel, startDefenseHour, availability = cache.getDefaultFilterData()
         selectedDate = time.localtime(time_utils.getTimeForLocal(time_utils.getCurrentTimestamp(), max(0, startDefenseHour)))
         startDefenseMin = selectedDate.tm_min
     data = {'minClanLevel': minClanLevel,
      'maxClanLevel': maxClanLevel,
      'startDefenseHour': startDefenseHour,
      'startDefenseMinutes': startDefenseMin,
      'isTwelveHoursFormat': self.app.utilsManager.isTwelveHoursFormat(),
      'isWrongLocalTime': self._isWrongLocalTime(),
      'skipValues': adjustDefenceHoursListToLocal(g_lobbyContext.getServerSettings().getForbiddenFortDefenseHours())}
     defenceStart, _ = self.fortCtrl.getFort().getLocalDefenceHour()
     if defenceStart != NOT_ACTIVATED:
         data['yourOwnClanStartDefenseHour'] = defenceStart
     self.as_setDataS(data)
 def _populate(self):
     super(FortIntelligenceClanFilterPopover, self)._populate()
     headerText = text_styles.highTitle(_ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_HEADER))
     clanLevelText = text_styles.standard(_ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_CLANLEVEL))
     startHourRangeText = text_styles.standard(_ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_STARTHOURRANGE))
     self.as_setDescriptionsTextS(headerText, clanLevelText, startHourRangeText)
     defaultButtonText = _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_DEFAULTBUTTONTEXT)
     applyButtonText = _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_APPLYBUTTONTEXT)
     cancelButtonText = _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANFILTERPOPOVER_CANCELBUTTONTEXT)
     self.as_setButtonsTextS(defaultButtonText, applyButtonText, cancelButtonText)
     defaultButtonTooltip = TOOLTIPS.FORTIFICATION_FORTINTELLIGENCECLANFILTERPOPOVER_DEFAULT
     applyButtonTooltip = TOOLTIPS.FORTIFICATION_FORTINTELLIGENCECLANFILTERPOPOVER_APPLY
     self.as_setButtonsTooltipsS(defaultButtonTooltip, applyButtonTooltip)
     minClanLevel = FORTIFICATION_ALIASES.CLAN_FILTER_MIN_LEVEL
     maxClanLevel = FORTIFICATION_ALIASES.CLAN_FILTER_MAX_LEVEL
     startDefenseHour = FORTIFICATION_ALIASES.CLAN_FILTER_MIN_HOUR
     startDefenseMin = 0
     cache = self.fortCtrl.getPublicInfoCache()
     if cache:
         minClanLevel, maxClanLevel, startDefenseHour, availability = cache.getDefaultFilterData()
         selectedDate = time.localtime(time_utils.getTimeForLocal(time_utils.getCurrentTimestamp(), max(0, startDefenseHour)))
         startDefenseMin = selectedDate.tm_min
     data = {'minClanLevel': minClanLevel,
      'maxClanLevel': maxClanLevel,
      'startDefenseHour': startDefenseHour,
      'startDefenseMinutes': startDefenseMin,
      'isTwelveHoursFormat': self.app.utilsManager.isTwelveHoursFormat(),
      'isWrongLocalTime': self._isWrongLocalTime(),
      'skipValues': adjustDefenceHoursListToLocal(g_lobbyContext.getServerSettings().getForbiddenFortDefenseHours())}
     defenceStart, _ = self.fortCtrl.getFort().getLocalDefenceHour()
     if defenceStart != NOT_ACTIVATED:
         data['yourOwnClanStartDefenseHour'] = defenceStart
     self.as_setDataS(data)
Example #6
0
 def _makeVO(self, index, item, favorites):
     timestamp = item.getAvailability()
     defHour, defMin = item.getDefHourFor(timestamp)
     defenceStart = time_utils.getTimeForLocal(timestamp, defHour, defMin)
     defenceFinish = defenceStart + time_utils.ONE_HOUR
     defenceTime = '%s - %s' % (BigWorld.wg_getShortTimeFormat(defenceStart), BigWorld.wg_getShortTimeFormat(defenceFinish))
     return {'clanID': item.getClanDBID(),
      'levelIcon': getIconLevel(item.getLevel()),
      'clanTag': '[%s]' % item.getClanAbbrev(),
      'defenceTime': defenceTime,
      'defenceStartTime': int('%02d%02d' % (defHour, defMin)),
      'avgBuildingLvl': round(item.getAvgBuildingLevel(), 1),
      'isFavorite': item.getClanDBID() in favorites,
      'clanLvl': item.getLevel()}
 def __calculateDefencePeriod(self):
     currentDefencePeriod = time_utils.getTimeForLocal(self.__selectedDayStart, *adjustDefenceHourToLocal(self.__item.getStartDefHour()))
     self.__selectedDefencePeriodStart = time_utils.getTimeForLocal(self.__selectedDayStart, *self.__item.getDefHourFor(currentDefencePeriod))
     self.__selectedDefencePeriodEnd = self.__selectedDefencePeriodStart + time_utils.ONE_HOUR