Example #1
0
 def __readHeader(self, eventType, questSection, gStartTime, gFinishTime, curTime):
     id = questSection.readString('id', '')
     if not id:
         raise Exception, 'Quest id must be specified.'
     if questSection.has_key('name'):
         questName = self.__readMetaSection(questSection['name'])
     else:
         questName = ''
     if questSection.has_key('description'):
         description = self.__readMetaSection(questSection['description'])
     else:
         description = ''
     progressExpiryTime = readUTC(questSection, 'progressExpiryTime', gFinishTime)
     startTime = readUTC(questSection, 'startTime', gStartTime)
     finishTime = readUTC(questSection, 'finishTime', gFinishTime)
     weekDayNames = questSection.readString('weekDays', '').split()
     weekDays = set([ _WEEKDAYS[val] for val in weekDayNames ])
     intervalsInString = questSection.readString('activeTimeIntervals', '').split()
     makeHM = lambda hm: tuple((int(v) for v in hm.split(':')))
     makeIntervals = lambda intervals: tuple((makeHM(v) for v in intervals.split('_')))
     activeTimeIntervals = [ makeIntervals(i) for i in intervalsInString ]
     if startTime < gStartTime:
         raise Exception, 'Invalid start time. startTime:%s < gStartTime:%s' % (startTime, gStartTime)
     if finishTime > gFinishTime:
         raise Exception, 'Invalid finish time. finishTime:%s > gFinishTime:%s' % (finishTime, gFinishTime)
     if progressExpiryTime < gFinishTime:
         raise Exception, 'Invalid progress expiry time. progressExpiryTime:%s < gFinishTime:%s' % (progressExpiryTime, gFinishTime)
     requiredToken = questSection.readString('requiredToken', '')
     if eventType == EVENT_TYPE.PERSONAL_QUEST:
         if not requiredToken:
             raise Exception, 'Personal quest must contain tag <requiredToken> with not empty token'
     if eventType == EVENT_TYPE.FORT_QUEST:
         if FORT_QUEST_SUFFIX not in id:
             raise Exception, 'Fort quest must contain "stronghold" in its id.'
     elif FORT_QUEST_SUFFIX in id:
         raise Exception, 'Quest must not contain "stronghold" in its id.'
     tOption = curTime > time.localtime()
     info = {'id': id,
      'hidden': questSection.readBool('hidden', False),
      'serverOnly': questSection.readBool('serverOnly', False),
      'name': questName,
      'type': eventType,
      'description': description,
      'progressExpiryTime': progressExpiryTime,
      'weekDays': weekDays,
      'activeTimeIntervals': activeTimeIntervals,
      'startTime': startTime if not tOption else time.time() - 300,
      'finishTime': finishTime,
      'gStartTime': gStartTime,
      'gFinishTime': gFinishTime,
      'disableGui': questSection.readBool('disableGui', False),
      'requiredToken': requiredToken,
      'Toption': None if not tOption else startTime,
      'priority': questSection.readInt('priority', 0),
      'uiDecoration': questSection.readInt('uiDecoration', 0)}
     return info
    def __readHeader(self, eventType, questSection, gStartTime, gFinishTime,
                     curTime):
        id = questSection.readString('id', '')
        if not id:
            raise Exception('Quest id must be specified.')
        if questSection.has_key('name'):
            questName = self.__readMetaSection(questSection['name'])
        else:
            questName = ''
        if questSection.has_key('description'):
            description = self.__readMetaSection(questSection['description'])
        else:
            description = ''
        progressExpiryTime = readUTC(questSection, 'progressExpiryTime',
                                     gFinishTime)
        startTime = readUTC(questSection, 'startTime', gStartTime)
        finishTime = readUTC(questSection, 'finishTime', gFinishTime)
        weekDayNames = questSection.readString('weekDays', '').split()
        weekDays = set([_WEEKDAYS[val] for val in weekDayNames])
        intervalsInString = questSection.readString('activeTimeIntervals',
                                                    '').split()
        makeHM = lambda hm: tuple((int(v) for v in hm.split(':')))
        makeIntervals = lambda intervals: tuple(
            (makeHM(v) for v in intervals.split('_')))
        activeTimeIntervals = [makeIntervals(i) for i in intervalsInString]
        if startTime < gStartTime:
            raise Exception(
                'Invalid start time. startTime:%s < gStartTime:%s' %
                (startTime, gStartTime))
        if finishTime > gFinishTime:
            raise Exception(
                'Invalid finish time. finishTime:%s > gFinishTime:%s' %
                (finishTime, gFinishTime))
        if progressExpiryTime < gFinishTime:
            raise Exception(
                'Invalid progress expiry time. progressExpiryTime:%s < gFinishTime:%s'
                % (progressExpiryTime, gFinishTime))
        requiredToken = questSection.readString('requiredToken', '')
        if eventType == EVENT_TYPE.PERSONAL_QUEST:
            if not requiredToken:
                raise Exception(
                    'Personal quest must contain tag <requiredToken> with not empty token'
                )
        if eventType == EVENT_TYPE.FORT_QUEST:
            if FORT_QUEST_SUFFIX not in id:
                raise Exception(
                    'Fort quest must contain "stronghold" in its id.')
        elif FORT_QUEST_SUFFIX in id:
            raise Exception('Quest must not contain "stronghold" in its id.')
        tOption = curTime > time.gmtime()
        showCongrats = questSection.readBool(
            'showCongrats', eventType in (EVENT_TYPE.POTAPOV_QUEST, ))
        info = {
            'id': id,
            'hidden': questSection.readBool('hidden', False),
            'serverOnly': questSection.readBool('serverOnly', False),
            'name': questName,
            'type': eventType,
            'description': description,
            'progressExpiryTime': progressExpiryTime,
            'weekDays': weekDays,
            'activeTimeIntervals': activeTimeIntervals,
            'startTime': startTime if not tOption else time.time() - 300,
            'finishTime': finishTime,
            'gStartTime': gStartTime,
            'gFinishTime': gFinishTime,
            'disableGui': questSection.readBool('disableGui', False),
            'showCongrats': showCongrats,
            'requiredToken': requiredToken,
            'Toption': None if not tOption else startTime,
            'priority': questSection.readInt('priority', 0),
            'uiDecoration': questSection.readInt('uiDecoration', 0)
        }
        if eventType == EVENT_TYPE.MOTIVE_QUEST:
            extraSubsectionsNames = ('advice', 'requirements',
                                     'congratulation')
            for subsectionName in extraSubsectionsNames:
                if questSection.has_key(subsectionName):
                    info[subsectionName] = self.__readMetaSection(
                        questSection[subsectionName])

        return info
    def __readHeader(self, eventType, questSection, curTime, gStartTime, gFinishTime):
        id = questSection.readString('id', '')
        if not id:
            raise SoftException('Quest id must be specified.')
        if questSection.has_key('name'):
            questName = self.__readMetaSection(questSection['name'])
        else:
            questName = ''
        if questSection.has_key('description'):
            description = self.__readMetaSection(questSection['description'])
        else:
            description = ''
        startTime = readUTC(questSection, 'startTime', gStartTime)
        finishTime = readUTC(questSection, 'finishTime', gFinishTime)
        progressExpiryTime = readUTC(questSection, 'progressExpiryTime', finishTime)
        defaultAnnounceTime = gStartTime if gStartTime != DEFAULT_QUEST_START_TIME else startTime
        announceTime = readUTC(questSection, 'announceTime', defaultAnnounceTime)
        weekDayNames = questSection.readString('weekDays', '').split()
        weekDays = set([ _WEEKDAYS[val] for val in weekDayNames ])
        intervalsInString = questSection.readString('activeTimeIntervals', '').split()
        makeHM = lambda hm: tuple((int(v) for v in hm.split(':')))
        makeIntervals = lambda intervals: tuple((makeHM(v) for v in intervals.split('_')))
        activeTimeIntervals = [ makeIntervals(i) for i in intervalsInString ]
        if announceTime < gStartTime:
            raise SoftException('Invalid announce time. announceTime:%s < gStartTime:%s' % (announceTime, gStartTime))
        if startTime < announceTime:
            raise SoftException('Invalid announce time. startTime:%s < announceTime:%s' % (startTime, announceTime))
        if startTime < gStartTime:
            raise SoftException('Invalid start time. startTime:%s < gStartTime:%s' % (startTime, gStartTime))
        if finishTime > gFinishTime:
            raise SoftException('Invalid finish time. finishTime:%s > gFinishTime:%s' % (finishTime, gFinishTime))
        if progressExpiryTime < finishTime:
            raise SoftException('Invalid progress expiry time. progressExpiryTime:%s < finishTime:%s' % (progressExpiryTime, finishTime))
        requiredToken = questSection.readString('requiredToken', '')
        if eventType == EVENT_TYPE.PERSONAL_QUEST:
            if not requiredToken:
                raise SoftException('Personal quest must contain tag <requiredToken> with not empty token')
        runFlags = []
        if questSection.has_key('run'):
            for flagName, flagValue in questSection['run'].items():
                if flagName == 'on':
                    runFlags.append(QUEST_RUN_FLAGS.NAME_TO_TYPE[flagValue.asString])

        tOption = curTime > time.time()
        showCongrats = questSection.readBool('showCongrats', eventType in (EVENT_TYPE.PERSONAL_MISSION,))
        onlyForPeripheriesList = questSection.readString('peripheryIDs', '')
        info = {'id': id,
         'hidden': questSection.readBool('hidden', False),
         'serverOnly': questSection.readBool('serverOnly', False),
         'name': questName,
         'type': eventType,
         'description': description,
         'progressExpiryTime': progressExpiryTime,
         'weekDays': weekDays,
         'activeTimeIntervals': activeTimeIntervals,
         'startTime': startTime if not tOption else time.time() - 300,
         'finishTime': finishTime,
         'announceTime': announceTime,
         'disableGui': questSection.readBool('disableGui', False),
         'showCongrats': showCongrats,
         'requiredToken': requiredToken,
         'Toption': None if not tOption else startTime,
         'priority': questSection.readInt('priority', 0),
         'uiDecoration': questSection.readInt('uiDecoration', 0),
         'peripheryIDs': {int(p) for p in onlyForPeripheriesList.split()} if onlyForPeripheriesList else set(),
         'runFlags': runFlags,
         'showPostBattleStat': questSection.readBool('showPostBattleStat', False)}
        if eventType == EVENT_TYPE.MOTIVE_QUEST:
            extraSubsectionsNames = ('advice', 'requirements', 'congratulation')
            for subsectionName in extraSubsectionsNames:
                if questSection.has_key(subsectionName):
                    info[subsectionName] = self.__readMetaSection(questSection[subsectionName])

        if eventType == EVENT_TYPE.RANKED_QUEST:
            if finishTime > curTime + _YEAR:
                raise SoftException("'finishTime' section is missing or too far into the future", info['id'])
            seasonSectionName = 'conditions/common/season'
            if questSection.has_key(seasonSectionName):
                season = questSection[seasonSectionName].asInt
            else:
                raise SoftException("'season' condition is compulsory", info['id'])
            cycleSectionName = 'conditions/common/cycle'
            if questSection.has_key(cycleSectionName):
                cycle = questSection[cycleSectionName].asInt
            else:
                cycle = None
            info['subtype'] = questSection['subtype'].asString
            info['ranked'] = (season, cycle)
        if eventType in EVENT_TYPE.QUESTS_WITH_SHOP_BUTTON:
            info['shopButton'] = questSection.readString('shopButton', 'hide')
        return info