def _readBookItem(pricesCache, cache, xmlCtx, section, storage): bookID = _xml.readInt(xmlCtx, section, 'id', 1) priceGroup = section.readString('priceGroup') tags = _readGroupTags((xmlCtx, 'tags'), section, 'tags') nameID = _xml.readStringOrEmpty(xmlCtx, section, 'name') descriptionID = _xml.readStringOrEmpty(xmlCtx, section, 'description') iconID = _xml.readNonEmptyString(xmlCtx, section, 'icon') type = _xml.readNonEmptyString(xmlCtx, section, 'type') if type not in crew_books_constants.CREW_BOOK_RARITY.ALL_TYPES: _xml.raiseWrongXml(xmlCtx, 'type', "unknown crew book rarity type '%s'" % type) crewBookItem = cb.CrewBook(bookID, priceGroup, nameID, descriptionID, iconID, type, tags) if section.has_key('filters'): filterSection = _xml.getSubsection(xmlCtx, section, 'filters') if filterSection.has_key('nation'): nation = filterSection.readString('nation', '') if nation and nation not in nations.NAMES: _xml.raiseWrongXml(xmlCtx, 'nation', "unknown nation '%s'" % nation) crewBookItem.nation = nation if nation else None if not crewBookItem.nation and type not in crew_books_constants.CREW_BOOK_RARITY.NO_NATION_TYPES: _xml.raiseWrongXml(xmlCtx, 'nation', "crew book with rarity type '%s' should have nation" % type) storage[bookID] = crewBookItem groupsDict = cache.priceGroups itemToGroup = cache.itemToPriceGroup if crewBookItem.priceGroup: if crewBookItem.priceGroup not in cache.priceGroupNames: _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'unknown price group %s for item %s' % (crewBookItem.priceGroup, crewBookItem.id)) priceGroupId = cache.priceGroupNames[crewBookItem.priceGroup] crewBookItem.priceGroupTags = groupsDict[priceGroupId].tags itemToGroup[crewBookItem.compactDescr] = groupsDict[priceGroupId].compactDescr itemNotInShop = section.readBool('notInShop', False) _copyPriceForItem(pricesCache, groupsDict[priceGroupId].compactDescr, crewBookItem.compactDescr, itemNotInShop) else: _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'no price for item %s' % crewBookItem.id) return
def readSoundSiegeModeStateChange(xmlCtx, section): pcOn = _xml.readStringOrEmpty(xmlCtx, section, 'soundStateChange/on') pcOff = _xml.readStringOrEmpty(xmlCtx, section, 'soundStateChange/off') npcOn = _xml.readStringOrEmpty(xmlCtx, section, 'soundStateChange/npcOn') npcOff = _xml.readStringOrEmpty(xmlCtx, section, 'soundStateChange/npcOff') return sound_components.SoundSiegeModeStateChange( on=pcOn, off=pcOff, npcOn=npcOn, npcOff=npcOff, isEngine=_xml.readBool(xmlCtx, section, 'soundStateChange/isEngine', False))
def _readPerkItem(xmlCtx, section, storage): perkID = _xml.readInt(xmlCtx, section, 'id', 1) name = _xml.readStringOrEmpty(xmlCtx, section, 'name') description = _xml.readNonEmptyString(xmlCtx, section, 'description') icon = _xml.readNonEmptyString(xmlCtx, section, 'icon') branchID = _xml.readInt(xmlCtx, section, 'branchID', 0) ultimative = section.readBool('ultimative', False) maxCount = _xml.readInt(xmlCtx, section, 'maxCount', 1) situational = _xml.readBool(xmlCtx, section, 'situational', False) perkItem = Perk(perkID, name, description, icon, branchID, ultimative, maxCount, situational) storage[perkID] = perkItem
def __readProgress(xmlCtx, section): progress = cc.ProgressForCustomization() itemId = ix.readInt(xmlCtx, section, 'id') if section.has_key('autobound'): progress.autobound = True for sectionName, subSection in section.items(): if sectionName == 'levels': for levelSectionName, levelSection in subSection.items(): level = int(re.findall('\\d+', levelSectionName)[0]) if levelSection['default'] is not None: progress.defaultLvl = level if level > progress.defaultLvl else progress.defaultLvl progress.levels[level] = __readProgressLevel( (xmlCtx, levelSectionName), levelSection) if sectionName == 'autoGrantCount': progress.autoGrantCount = ix.readPositiveInt( xmlCtx, subSection, '') if sectionName == 'bonusType': bonusTypes = ix.readStringOrEmpty(xmlCtx, subSection, '').split() parseArenaBonusType( progress.bonusTypes, bonusTypes, ARENA_BONUS_TYPE_CAPS.CUSTOMIZATION_PROGRESSION) if sectionName == 'priceGroup': progress.priceGroup = ix.readStringOrEmpty(xmlCtx, subSection, '') if len(progress.levels) < 2: ix.raiseWrongXml( xmlCtx, 'tags', 'wrong progression. Minimum count progression = 2. Current count progression %i' % len(progress.levels)) for i in range(1, len(progress.levels) + 1): if i not in progress.levels: ix.raiseWrongXml(xmlCtx, 'tags', 'wrong progression. Skipped level %i' % i) if progress.levels[1].get('notInShop'): ix.raiseWrongXml( xmlCtx, 'tags', 'wrong progression. First level should always be available for purchase.' ) return (itemId, progress)
def readGroundNodesAndGroups(xmlCtx, section, cache): if section['groundNodes'] is None: return (component_constants.EMPTY_TUPLE, component_constants.EMPTY_TUPLE, False, None) else: groundGroups = [] groundNodes = [] for sname, subsection in _xml.getChildren(xmlCtx, section, 'groundNodes'): if sname == 'group': ctx = (xmlCtx, 'groundNodes/group') group = chassis_components.GroundNodeGroup( isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'), nodesTemplate=intern( _xml.readNonEmptyString(ctx, subsection, 'template')), affectedWheelsTemplate=_xml.readStringOrNone( ctx, subsection, 'affectedWheelsTemplate'), nodesCount=_xml.readInt(ctx, subsection, 'count', 1), startIndex=subsection.readInt('startIndex', 0), collisionSamplesCount=subsection.readInt( 'collisionSamplesCount', 1), hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode', False)) groundGroups.append(group) if sname == 'node': ctx = (xmlCtx, 'groundNodes/node') groundNode = chassis_components.GroundNode( nodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'name')), affectedWheelName=_xml.readStringOrEmpty( ctx, subsection, 'affectedWheelName'), isLeft=_xml.readBool(ctx, subsection, 'isLeft'), minOffset=_xml.readFloat(ctx, subsection, 'minOffset'), maxOffset=_xml.readFloat(ctx, subsection, 'maxOffset'), collisionSamplesCount=_xml.readInt( ctx, subsection, 'collisionSamplesCount', 1), hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode', False)) groundNodes.append(groundNode) activePostmortem = _xml.readBool(xmlCtx, section, 'groundNodes/activePostmortem', False) lodSettingsSection = section['groundNodes/lodSettings'] if lodSettingsSection is not None: lodSettings = shared_readers.readLodSettings( xmlCtx, section['groundNodes'], cache) else: lodSettings = None return (tuple(groundGroups), tuple(groundNodes), activePostmortem, lodSettings)
def _readSkinItem(pricesCache, cache, xmlCtx, section, storage): skinID = _xml.readInt(xmlCtx, section, 'id', 1) if skinID in storage: _xml.raiseWrongXml(xmlCtx, 'id', "duplicate id '%s'" % skinID) priceGroup = section.readString('priceGroup') tags = _readGroupTags((xmlCtx, 'tags'), section, 'tags') firstNameID = _xml.readStringOrEmpty(xmlCtx, section, 'firstName') lastNameID = _xml.readNonEmptyString(xmlCtx, section, 'lastName') description = _xml.readNonEmptyString(xmlCtx, section, 'description') iconID = _xml.readNonEmptyString(xmlCtx, section, 'icon') rarity = _xml.readInt(xmlCtx, section, 'rarity', 1) maxCount = _xml.readInt(xmlCtx, section, 'maxCount') soundSetID = section.readString('soundSet', crew_skins_constants.NO_CREW_SKIN_SOUND_SET) historical = _xml.readBool(xmlCtx, section, 'historical', False) realmsStr = section.readString('realms', '') realms = realmsStr.split() unexpectedRealms = set(realms) - REGIONAL_REALMS if unexpectedRealms: _xml.raiseWrongXml(xmlCtx, 'realms', "unknown realms '%s'" % unexpectedRealms) crewSkinItem = cc.CrewSkin(skinID, priceGroup, firstNameID, lastNameID, iconID, description, rarity, maxCount, tags, historical, soundSetID, realms) if section.has_key('filters'): filterSection = _xml.getSubsection(xmlCtx, section, 'filters') if filterSection.has_key('role'): roleName = filterSection.readString('role') if roleName not in skills_constants.ROLES: _xml.raiseWrongXml(xmlCtx, 'role', "unknown tankmanRole '%s'" % roleName) crewSkinItem.roleID = roleName if roleName else None if filterSection.has_key('nation'): nation = filterSection.readString('nation', '') if nation and nation not in nations.NAMES: _xml.raiseWrongXml(xmlCtx, 'nation', "unknown nation '%s'" % nation) crewSkinItem.nation = nation if nation else None if filterSection.has_key('sex'): sex = filterSection.readString('sex', '') if sex not in crew_skins_constants.TANKMAN_SEX.AVAILABLE: _xml.raiseWrongXml(xmlCtx, 'sex', "unknown tankman sex '%s'" % sex) crewSkinItem.sex = sex storage[skinID] = crewSkinItem groupsDict = cache.priceGroups itemToGroup = cache.itemToPriceGroup if crewSkinItem.priceGroup: if crewSkinItem.priceGroup not in cache.priceGroupNames: _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'unknown price group %s for item %s' % (crewSkinItem.priceGroup, crewSkinItem.id)) priceGroupId = cache.priceGroupNames[crewSkinItem.priceGroup] crewSkinItem.priceGroupTags = groupsDict[priceGroupId].tags itemToGroup[crewSkinItem.compactDescr] = groupsDict[priceGroupId].compactDescr itemNotInShop = section.readBool('notInShop', False) _copyPriceForItem(pricesCache, groupsDict[priceGroupId].compactDescr, crewSkinItem.compactDescr, itemNotInShop) else: _xml.raiseWrongXml(xmlCtx, 'priceGroup', 'no price for item %s' % crewSkinItem.id) return
def readLeveredSuspension(xmlCtx, section, cache): leveredSection = section['leveredSuspension'] if leveredSection is None: return else: levers = [] for sname, subsection in _xml.getChildren(xmlCtx, section, 'leveredSuspension'): if sname != 'lever': continue ctx = (xmlCtx, 'leveredSuspension/lever') limits = _xml.readVector2(ctx, subsection, 'limits') lever = chassis_components.SuspensionLever( startNodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'startNode')), jointNodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'jointNode')), trackNodeName=intern( _xml.readNonEmptyString(ctx, subsection, 'trackNode')), minAngle=math.radians(limits.x), maxAngle=math.radians(limits.y), collisionSamplesCount=subsection.readInt( 'collisionSamplesCount', 1), hasLiftMode=_xml.readBool(ctx, subsection, 'hasLiftMode', False), affectedWheelName=_xml.readStringOrEmpty( ctx, subsection, 'affectedWheelName')) levers.append(lever) ctx = (xmlCtx, 'leveredSuspension') leveredSuspensionConfig = chassis_components.LeveredSuspensionConfig( levers=levers, interpolationSpeedMul=_xml.readFloat(ctx, leveredSection, 'interpolationSpeedMul', 10.0), lodSettings=shared_readers.readLodSettings(ctx, leveredSection, cache), activePostmortem=_xml.readBool(ctx, leveredSection, 'activePostmortem', False)) return leveredSuspensionConfig
def __readDebrisParams(xmlCtx, section, cache): result = [None, None] for name, (ctx, subSection) in _xml.getItemsWithContext(xmlCtx, section, 'trackDebris'): isLeft = _xml.readBool(ctx, subSection, 'isLeft') idx = 0 if isLeft else 1 if result[idx] is not None: _xml.raiseWrongXml(ctx, name, 'isLeft is the same') destructionEffect = _xml.readStringOrEmpty(ctx, subSection, 'destructionEffect') physicalParams = None if subSection['physicalParams'] is not None: hingeJointStiffness = _xml.readFloat(ctx, subSection, 'physicalParams/hingeJointStiffness') physicalParams = chassis_components.PhysicalTrackDebrisParams(hingeJointStiffness) nodesRemap = {} for key, value in subSection.items(): if key == 'remapNode': nodeName = _xml.readString(ctx, value, 'from') remapNode = _xml.readString(ctx, value, 'to') nodesRemap[nodeName] = remapNode result[idx] = chassis_components.TrackDebrisParams(destructionEffect, physicalParams, cache.getVehicleEffect(destructionEffect), nodesRemap) return chassis_components.TrackPairDebris(result[0], result[1]) if result[0] and result[1] else None
def _readBookTypeItem(pricesCache, cache, xmlCtx, section, storage): type = _xml.readStringOrEmpty(xmlCtx, section, 'type') if type not in crew_books_constants.CREW_BOOK_RARITY.ALL_TYPES: _xml.raiseWrongXml(xmlCtx, 'type', "unknown crew book rarity type '%s'" % type) exp = _xml.readInt(xmlCtx, section, 'exp', 0) storage[type] = exp
def _readBranchItem(xmlCtx, section, storage): perkID = _xml.readInt(xmlCtx, section, 'id', 1) name = _xml.readStringOrEmpty(xmlCtx, section, 'name') needPoints = section.readInt('needPoints', 0) perkItem = PerksBranch(perkID, name, needPoints) storage[perkID] = perkItem