def readQuestsFromFile(filePath, eventType): xmlSource = quest_xml_source.Source() nodes = xmlSource.readFromInternalFile(filePath, int(time.time())) nodes = nodes.get(eventType, None) questIDs = set() if nodes is None: LOG_WARNING(filePath, 'No quests of type {} were found in {}.'.format(_getEventName(eventType), filePath)) return else: for node in nodes: info = node.info questID = info.get('id', None) if not questID: raise Exception('questID is not set for a quest in {}, eventType: {}'.format(filePath, _getEventName(eventType))) if questID in questIDs: raise Exception('duplicate questID: {} in {}, eventType: {}'.format(questID, filePath, _getEventName(eventType))) questIDs.add(questID) questData = info.get('questClientData', None) if questData is None: LOG_WARNING(filePath, '"questClientData" not set for {} in {}'.format(questID, filePath)) continue questName = questData.get('name', None) if questName: questName = makeI18nString(questName['key']) questDescr = questData.get('description', None) if questDescr: questDescr = makeI18nString(questDescr['key']) yield (questID, questName, questDescr, questData, node) return
def __readQuestList(self): xmlPath = _POTAPOV_QUEST_XML_PATH + '/list.xml' section = ResMgr.openSection(xmlPath) if section is None: _xml.raiseWrongXml(None, xmlPath, 'can not open or read') self.__potapovQuestIDToQuestType = idToQuest = {} self.__questUniqueIDToPotapovQuestID = questUniqueNameToPotapovQuestID = {} self.__tileIDchainIDToPotapovQuestID = tileIDchainIDToPotapovQuestID = {} self.__tileIDchainIDToFinalPotapovQuestID = tileIDchainIDToFinalPotapovQuestID = {} self.__tileIDchainIDToInitialPotapovQuestID = tileIDchainIDToInitialPotapovQuestID = {} ids = {} curTime = int(time.time()) xmlSource = quest_xml_source.Source() for qname, qsection in section.items(): splitted = qname.split('_') ctx = (None, xmlPath) if qname in ids: _xml.raiseWrongXml(ctx, '', 'potapov quest name is not unique') potapovQuestID = _xml.readInt(ctx, qsection, 'id', 0, 1023) if potapovQuestID in idToQuest: _xml.raiseWrongXml(ctx, 'id', 'is not unique') questBranchName, tileID, chainID, internalID = splitted tileInfo = g_tileCache.getTileInfo(int(tileID)) if 1 <= chainID <= tileInfo['chainsCount']: _xml.raiseWrongXml( ctx, '', 'quest chainID must be between 1 and %s' % tileInfo['chainsCount']) if 1 <= internalID <= tileInfo['questsInChain']: _xml.raiseWrongXml( ctx, '', 'quest internalID must be between 1 and %s' % tileInfo['chainsCount']) minLevel = _xml.readInt(ctx, qsection, 'minLevel', 1, 10) maxLevel = _xml.readInt(ctx, qsection, 'maxLevel', minLevel, 10) basicInfo = { 'name': qname, 'id': potapovQuestID, 'branch': PQ_BRANCH.NAME_TO_TYPE[questBranchName], 'tileID': int(tileID), 'chainID': int(chainID), 'internalID': int(internalID), 'minLevel': minLevel, 'maxLevel': maxLevel, 'requiredUnlocks': frozenset( map( int, _xml.readString(ctx, qsection, 'requiredUnlocks').split())) } rewardByDemand = qsection.readInt('rewardByDemand', 0) if rewardByDemand != 0 and rewardByDemand not in PQ_REWARD_BY_DEMAND.keys( ): raise Exception('Unexpected value for rewardByDemand') basicInfo['rewardByDemand'] = rewardByDemand tags = _readTags(ctx, qsection, 'tags') basicInfo['tags'] = tags if questBranchName == 'regular': if 0 == len(tags & VEHICLE_CLASS_TAGS): _xml.raiseWrongXml(ctx, 'tags', 'quest vehicle class is not specified') if questBranchName == 'fallout': if 0 == len(tags & _FALLOUT_BATTLE_TAGS): _xml.raiseWrongXml(ctx, 'tags', 'quest fallout type is not specified') if IS_CLIENT or IS_WEB: basicInfo['userString'] = i18n.makeString( qsection.readString('userString')) basicInfo['description'] = i18n.makeString( qsection.readString('description')) basicInfo['advice'] = i18n.makeString( qsection.readString('advice')) basicInfo['condition_main'] = i18n.makeString( qsection.readString('condition_main')) basicInfo['condition_add'] = i18n.makeString( qsection.readString('condition_add')) questPath = ''.join([ _POTAPOV_QUEST_XML_PATH, '/', questBranchName, '/tile_', tileID, '/chain_', chainID, '/', qname, '.xml' ]) questCtx = (None, questPath) nodes = xmlSource.readFromInternalFile(questPath, curTime) nodes = nodes.get(EVENT_TYPE.POTAPOV_QUEST, None) if nodes is None: _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Potapov quests are not specified.') if len(nodes) != 2: _xml.raiseWrongXml( questCtx, 'potapovQuest', 'Main and additional quest should be presented.') qinfo = nodes[0].info if not qinfo['id'].endswith('main'): _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Main quest must be first.') if qinfo['id'] in questUniqueNameToPotapovQuestID: _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Duplicate name detected.') questUniqueNameToPotapovQuestID[qinfo['id']] = potapovQuestID basicInfo['mainQuestID'] = qinfo['id'] if IS_CLIENT or IS_WEB: basicInfo['mainQuestInfo'] = qinfo['questClientData'] qinfo = nodes[1].info if not qinfo['id'].endswith('add'): _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Add quest must be second.') if qinfo['id'] in questUniqueNameToPotapovQuestID: _xml.raiseWrongXml(questCtx, 'potapovQuest', 'Duplicate name detected.') questUniqueNameToPotapovQuestID[qinfo['id']] = potapovQuestID basicInfo['addQuestID'] = qinfo['id'] if IS_CLIENT or IS_WEB: basicInfo['addQuestInfo'] = qinfo['questClientData'] idToQuest[potapovQuestID] = PQType(basicInfo) ids[qname] = potapovQuestID key = (int(tileID), int(chainID)) tileIDchainIDToPotapovQuestID.setdefault(key, set()).add(potapovQuestID) if 'final' in tags: tileIDchainIDToFinalPotapovQuestID[key] = potapovQuestID if 'initial' in tags: tileIDchainIDToInitialPotapovQuestID[key] = potapovQuestID ResMgr.purge(xmlPath, True) return