def openVehiclePackPreview(self, cmd):
        items = _parseItemsPack(cmd.items)
        price, oldPrice = _parseBuyPrice(cmd.buy_price)
        vehiclesID = []
        for item in items:
            if item.type in ItemPackTypeGroup.VEHICLE:
                vehiclesID.append(item.id)

        if vehiclesID and self.__validVehiclePreviewPack(vehiclesID):
            localEndTime = None
            if cmd.end_date:
                timestamp = getTimestampFromISO(cmd.end_date)
                datetimeInUTC = getDateTimeInUTC(timestamp)
                localDatetime = utcToLocalDatetime(datetimeInUTC)
                localEndTime = (localDatetime -
                                getDateTimeInLocal(0)).total_seconds()
            event_dispatcher.showVehiclePreview(
                vehTypeCompDescr=vehiclesID[0],
                itemsPack=items,
                price=price,
                oldPrice=oldPrice,
                title=cmd.title,
                endTime=localEndTime,
                previewAlias=self._getVehiclePreviewReturnAlias(cmd),
                previewBackCb=self._getVehiclePreviewReturnCallback(cmd),
                buyParams=cmd.buy_params)
        else:
            _pushInvalidPreviewMessage()
        return
Exemple #2
0
    def getPeriodsBetween(self, startTime, endTime):
        """
        Return the periods that includes two timestamps
        :param startTime: start time stamp in UTC
        :param endTime: end time stamp in UTC
        :return: list on periods as (start, end)
        """
        periods = []
        startDateTime = time_utils.getDateTimeInUTC(startTime)
        startTimeDayStart, _ = time_utils.getDayTimeBoundsForUTC(startTime)
        weekDay = startDateTime.isoweekday()
        while startTimeDayStart <= endTime:
            if weekDay in self.__periods:
                for (startH, startM), (endH, endM) in self.__periods[weekDay]:
                    periodStartTime = startTimeDayStart + startH * time_utils.ONE_HOUR + startM * time_utils.ONE_MINUTE
                    periodEndTime = startTimeDayStart + endH * time_utils.ONE_HOUR + endM * time_utils.ONE_MINUTE
                    if startTime < periodEndTime and periodStartTime <= endTime:
                        periods.append((max(startTime, periodStartTime), min(endTime, periodEndTime)))

            if weekDay == time_utils.WEEK_END:
                weekDay = time_utils.WEEK_START
            else:
                weekDay += 1
            startTimeDayStart += time_utils.ONE_DAY

        return collapseIntervals(periods)
    def getPeriodsBetween(self, startTime, endTime, includeBeginning=True, includeEnd=True, preferPeriodBounds=False):
        periods = []
        startDateTime = time_utils.getDateTimeInUTC(startTime)
        startTimeDayStart, _ = time_utils.getDayTimeBoundsForUTC(startTime)
        weekDay = startDateTime.isoweekday()
        while startTimeDayStart <= endTime:
            if weekDay in self.__periods:
                for (startH, startM), (endH, endM) in self.__periods[weekDay]:
                    periodStartTime = startTimeDayStart + startH * time_utils.ONE_HOUR + startM * time_utils.ONE_MINUTE
                    periodEndTime = startTimeDayStart + endH * time_utils.ONE_HOUR + endM * time_utils.ONE_MINUTE
                    if startTime < periodEndTime and periodStartTime <= endTime:
                        if not includeBeginning and startTime > periodStartTime:
                            continue
                        if not includeEnd and endTime < periodEndTime:
                            continue
                        if preferPeriodBounds:
                            periods.append((periodStartTime, periodEndTime))
                        else:
                            periods.append((max(startTime, periodStartTime), min(endTime, periodEndTime)))

            if weekDay == time_utils.WEEK_END:
                weekDay = time_utils.WEEK_START
            else:
                weekDay += 1
            startTimeDayStart += time_utils.ONE_DAY

        return collapseIntervals(periods)
Exemple #4
0
def _getCurrentUTCTime():
    return time_utils.getDateTimeInUTC(time_utils.getServerUTCTime())
Exemple #5
0
 def __doClockworkLogic(self, mode):
     if not self.isStrongholdSettingsValid():
         if mode & self.CWL_RETURN_MATCHING_BUTTON_STATUS == self.CWL_RETURN_MATCHING_BUTTON_STATUS:
             return True
         return
     isInBattle = self._hasInArenaMembers()
     isInQueue = self._isInQueue()
     dtime = None
     peripheryStartTimestampUTC = 0
     currentTimestampUTC = 0
     matchmakerNextTick = None
     inactiveMatchingButton = True
     forceUpdateBuildings = mode & self.CWL_FORCE_UPDATE_BUILDINGS == self.CWL_FORCE_UPDATE_BUILDINGS
     currentTimeUTC, clientTimeUTC = self._getCurrentUTCTime()
     timer = self.__strongholdSettings.getTimer()
     peripheryStartTimeUTC = currentTimeUTC.replace(hour=0, minute=0, second=0, microsecond=0)
     peripheryEndTimeUTC = currentTimeUTC.replace(hour=0, minute=0, second=0, microsecond=0)
     if timer.getBattlesStartTime() and timer.getBattlesEndTime():
         isInactivePeriphery = False
         peripheryStartTimeUTC, peripheryEndTimeUTC = self.__calculatePeripheryTimeHelper(currentTimeUTC)
         peripheryStartTimestampUTC = int(time_utils.getTimestampFromUTC(peripheryStartTimeUTC.timetuple()))
         currentTimestampUTC = int(time_utils.getTimestampFromUTC(currentTimeUTC.timetuple()))
     else:
         peripheryEndTimeUTC -= datetime.timedelta(days=1)
         peripheryStartTimeUTC -= datetime.timedelta(days=1)
         isInactivePeriphery = True
         dtime = 0
     if self.__strongholdSettings.isSortie():
         textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_UNAVAILABLE
         if isInQueue:
             textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINQUEUE
             dtime = peripheryStartTimestampUTC - currentTimestampUTC
             if dtime < 0 or dtime > timer.getSortiesBeforeStartLag():
                 dtime = 0
         elif isInBattle:
             textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINBATTLE
         elif self.isStrongholdUnitWaitingForData():
             textid = TOOLTIPS.STRONGHOLDS_TIMER_WAITINGFORDATA
         elif peripheryStartTimeUTC <= currentTimeUTC <= peripheryEndTimeUTC:
             dtime = int((peripheryEndTimeUTC - currentTimeUTC).total_seconds())
             inactiveMatchingButton = False
             if dtime <= timer.getSortiesBeforeEndLag():
                 textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_ENDOFBATTLESOON
             else:
                 textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_AVAILABLE
         elif isInactivePeriphery:
             dtime = 0
         else:
             dtime = peripheryStartTimestampUTC - currentTimestampUTC
             if dtime <= timer.getSortiesBeforeStartLag():
                 if dtime < 0:
                     dtime = 0
                 textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON
                 if dtime <= self.MATCHMAKING_BATTLE_BUTTON_SORTIE:
                     inactiveMatchingButton = False
             else:
                 peripheryStartTimeUTC, _ = self.__calculatePeripheryTimeHelper(clientTimeUTC)
                 peripheryStartTimestampUTC = int(time_utils.getTimestampFromUTC(peripheryStartTimeUTC.timetuple()))
                 currentTimestampUTC = int(time_utils.getTimestampFromUTC(clientTimeUTC.timetuple()))
                 peripheryStartTimestamp = self._convertUTCStructToLocalTimestamp(peripheryStartTimeUTC)
                 currentTimestamp = self._convertUTCStructToLocalTimestamp(clientTimeUTC)
                 dtime = peripheryStartTimestampUTC - currentTimestampUTC
                 currDayStart, currDayEnd = time_utils.getDayTimeBoundsForLocal(peripheryStartTimestamp)
                 if currDayStart - time_utils.ONE_DAY <= currentTimestamp <= currDayEnd - time_utils.ONE_DAY:
                     textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETOMORROW
                 elif currDayStart <= currentTimestamp <= currDayEnd:
                     textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETODAY
     else:
         textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_UNAVAILABLE
         if not isInactivePeriphery:
             dtime = time_utils.ONE_YEAR
             matchmakerNextTick = timer.getTimeToReady()
             if matchmakerNextTick is not None:
                 dtime = int(matchmakerNextTick - currentTimestampUTC)
             else:
                 matchmakerNextTick = timer.getMatchmakerNextTick()
                 if matchmakerNextTick is not None:
                     dtime = int(matchmakerNextTick - currentTimestampUTC)
             battlesBeforeStartLag = timer.getFortBattlesBeforeStartLag()
             if self.__prevMatchmakingTimerState == FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON and 0 <= int(dtime - battlesBeforeStartLag) < self.MATCHMAKING_ZERO_TIME_WAITING_FOR_DATA and mode & self.CWL_REGULAR_MODE == self.CWL_REGULAR_MODE:
                 dtime = battlesBeforeStartLag
             if isInQueue:
                 textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINQUEUE
                 if dtime < 0 or dtime > battlesBeforeStartLag:
                     dtime = 0
             elif isInBattle:
                 textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINBATTLE
             elif self.isStrongholdUnitWaitingForData():
                 textid = TOOLTIPS.STRONGHOLDS_TIMER_WAITINGFORDATA
             elif dtime > battlesBeforeStartLag:
                 textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_UNAVAILABLE
                 if matchmakerNextTick is not None:
                     peripheryStartTimeUTC, _ = self.__calculatePeripheryTimeHelper(clientTimeUTC)
                     peripheryStartTimestampUTC = int(time_utils.getTimestampFromUTC(peripheryStartTimeUTC.timetuple()))
                     currentTimestampUTC = int(time_utils.getTimestampFromUTC(clientTimeUTC.timetuple()))
                     currentTimestamp = self._convertUTCStructToLocalTimestamp(clientTimeUTC)
                     dtime = int(matchmakerNextTick - currentTimestampUTC)
                     matchmakerNextTickLocal = time_utils.getDateTimeInUTC(matchmakerNextTick)
                     matchmakerNextTickLocal = self._convertUTCStructToLocalTimestamp(matchmakerNextTickLocal)
                     currDayStart, currDayEnd = time_utils.getDayTimeBoundsForLocal(matchmakerNextTickLocal)
                     if currDayStart - time_utils.ONE_DAY <= currentTimestamp <= currDayEnd - time_utils.ONE_DAY:
                         textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETOMORROW
                     elif currDayStart <= currentTimestamp <= currDayEnd:
                         textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETODAY
             elif dtime >= 0:
                 textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON
                 if dtime <= self.MATCHMAKING_BATTLE_BUTTON_BATTLE or not self.__strongholdSettings.isFirstBattle():
                     inactiveMatchingButton = False
             else:
                 dtimeWD = dtime + self.MATCHMAKING_ZERO_TIME_WAITING_FOR_DATA
                 if dtimeWD >= 0:
                     textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON
                 dtime = 0
     if mode & self.CWL_REGULAR_MODE == self.CWL_REGULAR_MODE:
         self.__prevMatchmakingTimerState = textid
     if mode & self.CWL_INVOKE_LISTENERS == self.CWL_INVOKE_LISTENERS:
         header = self.__strongholdSettings.getHeader()
         g_eventDispatcher.strongholdsOnTimer({'peripheryStartTimestamp': peripheryStartTimestampUTC,
          'matchmakerNextTick': matchmakerNextTick,
          'clan': header.getClan(),
          'enemyClan': header.getEnemyClan(),
          'textid': textid,
          'dtime': dtime,
          'isSortie': self.__strongholdSettings.isSortie(),
          'isFirstBattle': self.__strongholdSettings.isFirstBattle(),
          'currentBattle': header.getCurrentBattle(),
          'maxLevel': header.getMaxLevel(),
          'direction': header.getDirection(),
          'forceUpdateBuildings': forceUpdateBuildings})
     if mode & self.CWL_RETURN_MATCHING_BUTTON_STATUS == self.CWL_RETURN_MATCHING_BUTTON_STATUS:
         return inactiveMatchingButton
     elif mode & self.CWL_RETURN_MATCHMAKER_NEXT_TICK == self.CWL_RETURN_MATCHMAKER_NEXT_TICK:
         return matchmakerNextTick
     else:
         return
Exemple #6
0
 def _getCurrentUTCTime(self):
     return (time_utils.getDateTimeInUTC(time_utils.getServerUTCTime()), datetime.datetime.utcnow())