def __makeFakeDescriptor(self):
     vehType = vehicles.VehicleDescr(typeID=(0, 0)).type
     skills = self._getSkillsForDescr()
     freeSkills = self._getFreeSkillsForDescr()
     tmanDescr = tankmen.TankmanDescr(tankmen.generateCompactDescr(tankmen.generatePassport(vehType.id[0], False), vehType.id[1], vehType.crewRoles[0][0], self._roleLevel, skills=skills, freeSkills=freeSkills, lastSkillLevel=self._lastSkillLevel))
     tmanDescr.addXP(self._freeXP)
     return tmanDescr
예제 #2
0
    def _calcCrewBonuses(self, crew, proxy):
        bonuses = dict()
        bonuses['equipment'] = 0
        for eq in self.eqs:
            if eq is not None:
                bonuses['equipment'] += eq.crewLevelIncrease

        bonuses['optDevices'] = self.descriptor.miscAttrs['crewLevelIncrease']
        bonuses['commander'] = 0
        commanderEffRoleLevel = 0
        bonuses['brotherhood'] = tankmen.getSkillsConfig()['brotherhood']['crewLevelIncrease']
        femalesCount = 0
        for tankmanID in crew:
            if tankmanID is None:
                bonuses['brotherhood'] = 0
                continue
            tmanInvData = proxy.inventory.getItems(GUI_ITEM_TYPE.TANKMAN, tankmanID)
            if not tmanInvData:
                continue
            tdescr = tankmen.TankmanDescr(compactDescr=tmanInvData['compDescr'])
            if tdescr.isFemale:
                femalesCount += 1
            if 'brotherhood' not in tdescr.skills or tdescr.skills.index('brotherhood') == len(tdescr.skills) - 1 and tdescr.lastSkillLevel != tankmen.MAX_SKILL_LEVEL:
                bonuses['brotherhood'] = 0
            if tdescr.role == Tankman.ROLES.COMMANDER:
                factor, addition = tdescr.efficiencyOnVehicle(self.descriptor)
                commanderEffRoleLevel = round(tdescr.roleLevel * factor + addition)

        if femalesCount and len(crew) != femalesCount:
            bonuses['brotherhood'] = 0
        bonuses['commander'] += round((commanderEffRoleLevel + bonuses['brotherhood'] + bonuses['equipment']) / tankmen.COMMANDER_ADDITION_RATIO)
        return bonuses
 def __validateInventoryTankmen(self):
     tmenInvData = self.itemsCache.items.inventory.getCacheValue(GUI_ITEM_TYPE.TANKMAN, {})
     for invID, tmanCompDescr in tmenInvData.get('compDescr', {}).iteritems():
         try:
             tankmen.TankmanDescr(tmanCompDescr)
         except Exception as e:
             raise ValidateException(e.message, self.CODES.INVENTORY_TANKMEN_MISMATCH, self.__packItemData(GUI_ITEM_TYPE.TANKMAN, (invID, tmanCompDescr)))
예제 #4
0
 def validateCrewSlot(self, compactDescr):
     result = CrewSlotValidationResult()
     if not compactDescr:
         result.isEmpty = True
     else:
         result.tManValidRes = self._isTankmanOk(
             tankmen.TankmanDescr(compactDescr))
     return result
예제 #5
0
def __makeFakeTankmanDescr(startRoleLevel, freeXpValue, typeID):
    vehType = vehicles.VehicleDescr(typeID=typeID).type
    tmanDescr = tankmen.TankmanDescr(
        tankmen.generateCompactDescr(
            tankmen.generatePassport(vehType.id[0], False), vehType.id[1],
            vehType.crewRoles[0][0], startRoleLevel))
    tmanDescr.addXP(freeXpValue)
    return tmanDescr
def gainedLevels(tankmanInvId, crewBookCD, itemsCache=None):
    result = {}
    if crewBookCD is None:
        return result
    else:

        def _newSkillsCount(descr):
            if tankman.role == tankman.ROLES.COMMANDER:
                skillsList = list(skills_constants.ACTIVE_SKILLS)
            else:
                skillsList = list(tankman._NON_COMMANDER_SKILLS)
            i = 0
            while descr.roleLevel == 100 and (descr.lastSkillLevel == 100 or
                                              not descr.skills) and skillsList:
                skillName = skillsList.pop()
                if skillName not in descr.skills:
                    descr.addSkill(skillName)
                    i += 1

            return i

        def _calculateSurplus(xp, surplus, descr, result):
            if surplus == 0:
                xpCost = descr.levelUpXpCost(
                    descr.lastSkillLevel,
                    descr.lastSkillNumber - descr.freeSkillsNumber)
                result[XpGainResult.SURPLUS_LEVELS] = round(
                    xp / (xpCost * 1.0), 2)
                if result[XpGainResult.SURPLUS_LEVELS] == 0:
                    result[XpGainResult.SURPLUS_LEVELS] = format(
                        result[XpGainResult.SURPLUS_LEVELS], '.2f')
            else:
                result[XpGainResult.SURPLUS_LEVELS] = surplus

        def _fillResult(newSkillsCount, descr, levelBeforeAdd, bookXP, result):
            if newSkillsCount:
                result[XpGainResult.NEW_SKILLS] = newSkillsCount
                surplus = descr.lastSkillLevel
                _calculateSurplus(descr.freeXP, surplus, descr, result)
            else:
                surplus = descr.lastSkillLevel - levelBeforeAdd
                _calculateSurplus(bookXP, surplus, descr, result)

        tankman = itemsCache.items.getTankman(tankmanInvId)
        descr = tankmen.TankmanDescr(tankman.strCD)
        xp = itemsCache.items.getItemByCD(crewBookCD).getXP()
        roleLevel = descr.roleLevel
        if roleLevel < tankmen.MAX_SKILL_LEVEL:
            descr.addXP(xp)
            newSkillsCount = _newSkillsCount(descr)
            _fillResult(newSkillsCount, descr, 0, xp, result)
        else:
            _newSkillsCount(descr)
            levelBeforeAdd = descr.lastSkillLevel
            descr.addXP(xp)
            newSkillsCount = _newSkillsCount(descr)
            _fillResult(newSkillsCount, descr, levelBeforeAdd, xp, result)
        return result
예제 #7
0
 def isOn(self, tankmanDescr):
     if tankmanDescr is None:
         return False
     else:
         tankman = tankmen.TankmanDescr(tankmanDescr)
         result = len(tankman.skills) > 0
         if result:
             self.setVar(tankman.skills[0])
         return result
예제 #8
0
    def getTankmenData(self):
        result = []
        if self._value is not None:
            for tankmanData in self._value:
                if type(tankmanData) is str:
                    result.append(self._makeTmanInfoByDescr(tankmen.TankmanDescr(compactDescr=tankmanData)))
                else:
                    result.append(makeTupleByDict(self._TankmanInfoRecord, tankmanData))

        return result
예제 #9
0
def __readBonus_tankmen(bonus, vehTypeCompDescr, section, eventType):
    lst = []
    for subsection in section.values():
        tmanDescr = subsection.asString
        if tmanDescr:
            try:
                tman = tankmen.TankmanDescr(tmanDescr)
                if type(vehTypeCompDescr) == int:
                    _, vehNationID, vehicleTypeID = vehicles.parseIntCompactDescr(
                        vehTypeCompDescr)
                    if vehNationID != tman.nationID or vehicleTypeID != tman.vehicleTypeID:
                        raise SoftException('Vehicle and tankman mismatch.')
            except Exception as e:
                raise SoftException(
                    'Invalid tankmen compact descr. Error: %s' % (e, ))

            lst.append(tmanDescr)
            continue
        tmanData = {
            'isFemale': subsection.readBool('isFemale', False),
            'firstNameID': subsection.readInt('firstNameID', -1),
            'lastNameID': subsection.readInt('lastNameID', -1),
            'role': subsection.readString('role', ''),
            'iconID': subsection.readInt('iconID', -1),
            'roleLevel': subsection.readInt('roleLevel', 50),
            'freeXP': subsection.readInt('freeXP', 0),
            'fnGroupID': subsection.readInt('fnGroupID', 0),
            'lnGroupID': subsection.readInt('lnGroupID', 0),
            'iGroupID': subsection.readInt('iGroupID', 0),
            'isPremium': subsection.readBool('isPremium', False),
            'nationID': subsection.readInt('nationID', -1),
            'vehicleTypeID': subsection.readInt('vehicleTypeID', -1),
            'skills': subsection.readString('skills', '').split(),
            'freeSkills': subsection.readString('freeSkills', '').split()
        }
        for record in ('firstNameID', 'lastNameID', 'iconID'):
            if tmanData[record] == -1:
                tmanData[record] = None

        try:
            if type(vehTypeCompDescr) == int:
                _, vehNationID, vehicleTypeID = vehicles.parseIntCompactDescr(
                    vehTypeCompDescr)
                if vehNationID != tmanData[
                        'nationID'] or vehicleTypeID != tmanData[
                            'vehicleTypeID']:
                    raise SoftException('Vehicle and tankman mismatch.')
            if eventType != EVENT_TYPE.PERSONAL_MISSION:
                tmanData = tankmen.makeTmanDescrByTmanData(tmanData)
            lst.append(tmanData)
        except Exception as e:
            raise SoftException('%s: %s' % (e, tmanData))

    bonus['tankmen'] = lst
    return
    def newSkillCount(self):
        if self.hasNewSkill(useCombinedRoles=True):
            tmanDescr = tankmen.TankmanDescr(self.strCD)
            i = 0
            skills_list = list(skills_constants.ACTIVE_SKILLS)
            while 1:
                if tmanDescr.roleLevel == 100 and (tmanDescr.lastSkillLevel == 100 or not tmanDescr.skills) and skills_list:
                    skillname = skills_list.pop()
                    skillname not in tmanDescr.skills and tmanDescr.addSkill(skillname)
                    i += 1

            return (i, tmanDescr.lastSkillLevel)
예제 #11
0
    def newSkillCount(self):
        if self.hasNewSkill(useCombinedRoles=True):
            tmanDescr = tankmen.TankmanDescr(self.strCD)
            i = 0
            skills_list = list(tankmen.ACTIVE_SKILLS)
            while tmanDescr.roleLevel == 100 and (tmanDescr.lastSkillLevel == 100 or len(tmanDescr.skills) == 0) and len(skills_list) > 0:
                skillname = skills_list.pop()
                if skillname not in tmanDescr.skills:
                    tmanDescr.addSkill(skillname)
                    i += 1

            return (i, tmanDescr.lastSkillLevel)
        return (0, 0)
예제 #12
0
 def calcDropSkillsParams(self, tmanCompDescrPickle, xpReuseFraction):
     """
     Recalculates tankman skills by given skills reuse fraction
     
     @param tmanCompDescr: tankman string compact descriptor
     @param xpReuseFraction: tankman experience reuse fraction
     @return: (new skills count, last new skill level)
     """
     tmanCompDescr = pickle.loads(tmanCompDescrPickle)
     tmanDescr = tankmen.TankmanDescr(tmanCompDescr)
     tmanDescr.dropSkills(xpReuseFraction)
     tankman = Tankman(tmanDescr.makeCompactDescr())
     return (tankman.roleLevel, ) + tankman.newSkillCount
예제 #13
0
    def __makeTankman(self, tmanInvID):
        cache = self.__itemsCache[GUI_ITEM_TYPE.TANKMAN]
        if tmanInvID in cache:
            return cache[tmanInvID]
        itemsInvData = self.getCacheValue(GUI_ITEM_TYPE.TANKMAN, {})

        def value(key, default = None):
            return itemsInvData.get(key, {}).get(tmanInvID, default)

        compactDescr = value('compDescr')
        if compactDescr is None:
            return
        item = cache[tmanInvID] = self.TMAN_DATA(compactDescr, tankmen.TankmanDescr(compactDescr), value('vehicle', -1), tmanInvID)
        return item
예제 #14
0
 def __tankmanDossierResponse(self, tankmanID, resultID, data):
     if resultID < 0:
         LOG_ERROR(
             'Server return error for inventory tankman dossier request: responseCode=%s'
             % resultID)
         return
     if self.__callback and data is not None:
         dossier = ''
         tankman = data.get('compDescr', None)
         if tankman is not None:
             tmenCompDescr = tankman.get(tankmanID, None)
             if tmenCompDescr is not None:
                 dossier = tankmen.TankmanDescr(
                     tmenCompDescr).dossierCompactDescr
         self.__callback(dossiers2.getTankmanDossierDescr(dossier))
def __makeFakeTankmanDescr(startRoleLevel,
                           freeXpValue,
                           typeID,
                           skills=(),
                           freeSkills=(),
                           lastSkillLevel=tankmen.MAX_SKILL_LEVEL):
    vehType = vehicles.VehicleDescr(typeID=typeID).type
    tmanDescr = tankmen.TankmanDescr(
        tankmen.generateCompactDescr(tankmen.generatePassport(
            vehType.id[0], False),
                                     vehType.id[1],
                                     vehType.crewRoles[0][0],
                                     startRoleLevel,
                                     skills=skills,
                                     freeSkills=freeSkills,
                                     lastSkillLevel=lastSkillLevel))
    tmanDescr.addXP(freeXpValue)
    return tmanDescr
예제 #16
0
    def newSkillCount(self):
        """
        Returns number of skills to study and last new skill level.
        
        @return: ( number of new skills, last new skill level )
        """
        if self.hasNewSkill:
            tmanDescr = tankmen.TankmanDescr(self.strCD)
            i = 0
            skills_list = list(tankmen.ACTIVE_SKILLS)
            while tmanDescr.roleLevel == 100 and (
                    tmanDescr.lastSkillLevel == 100
                    or len(tmanDescr.skills) == 0) and len(skills_list) > 0:
                skillname = skills_list.pop()
                if skillname not in tmanDescr.skills:
                    tmanDescr.addSkill(skillname)
                    i += 1

            return (i, tmanDescr.lastSkillLevel)
        return (0, 0)
예제 #17
0
    def __cb_onGetItemsFromInventory(self, resultID, data):
        self._gui.hideWaiting('request-tankman')
        if resultID < RES_SUCCESS:
            LOG_ERROR(
                'Server return error inventory {0:d} items request, responseCode='
                .format(_TANKMAN, resultID))
            self.isRunning = False
            return
        else:
            current = g_currentVehicle.item
            compDescrs = data.get('compDescr', {})
            vehs = data.get('vehicle', {})
            descrs = map(lambda item: (item[0], tankmen.TankmanDescr(item[1])),
                         compDescrs.iteritems())
            descrs = filter(
                lambda item: item[1].nationID == current.nationID and
                (item[1].vehicleTypeID == current.innationID or self.
                 _specVehicleFlagID is not None), descrs)
            isOn = False
            inVehicle = False
            specVehicle = False
            for idx, tankman in descrs:
                if self.isOn(tankman) and not inVehicle:
                    inVehicle = vehs.get(idx, -1) == g_currentVehicle.invID
                    if tankman.vehicleTypeID != current.innationID or not inVehicle and idx in vehs:
                        continue
                    isOn = True
                    specVehicle = True
                    if self._setVarID is not None:
                        self._tutorial.getVars().set(self._setVarID, idx)
                    if inVehicle:
                        break

            self._setFlagValue(self._inVehicleFlagID, inVehicle)
            self._setFlagValue(self._specVehicleFlagID, specVehicle)
            self.toggle(isOn=isOn)
            return
예제 #18
0
 def descriptor(self):
     if self.__descriptor is None or self.__descriptor.dossierCompactDescr != self.strCompactDescr:
         self.__descriptor = tankmen.TankmanDescr(
             compactDescr=self.strCompactDescr)
     return self.__descriptor
예제 #19
0
 def calcDropSkillsParams(self, tmanCompDescrPickle, xpReuseFraction):
     tmanCompDescr = pickle.loads(tmanCompDescrPickle)
     tmanDescr = tankmen.TankmanDescr(tmanCompDescr)
     tmanDescr.dropSkills(xpReuseFraction)
     tankman = Tankman(tmanDescr.makeCompactDescr())
     return (tankman.roleLevel, ) + tankman.newSkillCount
예제 #20
0
 def unpack(tmanCompDescr, dossierCD, extDossierDump):
     return TankmanDossier(tankmen.TankmanDescr(tmanCompDescr),
                           dossiers2.getTankmanDossierDescr(dossierCD),
                           loadDossier(extDossierDump))