示例#1
0
    def incrementExp(self, trackIndex, track, newValue):
        bar = self.trackBars[trackIndex]
        nextExp = GagGlobals.getMaxExperienceValue(newValue, track.name)
        oldValue = bar['value']
        color = GagGlobals.TrackColorByName.get(track.name)

        bar['text'] = '%d/%d' % (newValue, nextExp)
        bar['range'] = nextExp if not nextExp == -1 else newValue
        bar['value'] = newValue
        bar['barColor'] = (color[0], color[1], color[2], 1)
    def __init__(self, avatar):
        self.avatar = avatar
        self.avatarName = None if not self.avatar else avatar.getName()
        self.notify = directNotify.newCategory(
            'RPToonData[%s]' %
            self.avatarName if self.avatarName else 'Undefined')
        self.favoriteGag = GagGlobals.Cupcake

        # All the gag tracks
        self.tracks = OrderedDict()

        if not self.avatar:
            for track in GagGlobals.TrackNameById.values():
                self.tracks[track] = Track(track, 0, 0, 0)
        else:
            for track, exp in self.avatar.trackExperience.iteritems():
                self.tracks[track] = Track(
                    track, exp, GagGlobals.getMaxExperienceValue(exp, track),
                    0)
    def parseToonData(self):
        blobs = []
        for avId, data in self.avatarData.iteritems():
            avatar = base.air.doId2do.get(avId, None)
            deadCogData = data[1]
            favGagId = 0  # Make it whole cream pie by default
            favGagUses = 0
            gagUnlocked = False

            if avatar:
                rpData = RPToonData(avatar)
                trackIncrements = {}

                for track in avatar.trackExperience.keys():
                    trackIncrements[track] = 0

                for gagId, uses in data[0].iteritems():
                    gagName = self.air.attackMgr.getAttackName(gagId)
                    gagData = GagGlobals.gagData.get(gagName)
                    track = gagData['track']
                    if uses > favGagUses:
                        favGagId = gagId

                    trackGags = GagGlobals.TrackGagNamesByTrackName.get(track)

                    incr = (trackGags.index(gagName) + 1) * uses
                    if track in trackIncrements.keys():
                        incr = incr + trackIncrements[track]
                    trackIncrements[track] = incr

                rpData.favoriteGag = self.air.attackMgr.getAttackName(favGagId)

                for track, exp in avatar.trackExperience.iteritems():
                    rpDataTrack = rpData.getTrackByName(track)
                    increment = trackIncrements.get(track)
                    maxExp = GagGlobals.getMaxExperienceValue(exp, track)
                    incrMaxExp = GagGlobals.getMaxExperienceValue(
                        exp + increment, track)
                    rpDataTrack.exp = exp
                    rpDataTrack.maxExp = maxExp
                    rpDataTrack.increment = increment
                    avatar.trackExperience[track] = (exp +
                                                     rpDataTrack.increment)

                    if incrMaxExp != maxExp:
                        # We've unlocked a gag.
                        maxExpIndex = GagGlobals.TrackExperienceAmounts.get(
                            track).index(incrMaxExp)
                        newGagName = GagGlobals.TrackGagNamesByTrackName.get(
                            track)[maxExpIndex]
                        gagId = self.air.attackMgr.getAttackIDByName(
                            newGagName)
                        avatar.backpack.addGag(gagId, 1)
                        gagUnlocked = True
                avatar.b_setTrackExperience(
                    GagGlobals.trackExperienceToNetString(
                        avatar.trackExperience))

                if gagUnlocked:
                    netString = avatar.getBackpackAmmo()
                    avatar.d_setBackpackAmmo(netString)

                # Let's update quest stuff for this avatar.
                questManager = avatar.questManager

                objectiveProgresses = []

                for quest in questManager.quests.values():
                    objectiveProgress = []
                    for i, objective in enumerate(quest.accessibleObjectives):
                        objectiveProgress.append(objective.progress)
                        if objective.type == DefeatCog:
                            progress = objective.progress
                            for killData in deadCogData:
                                if not (
                                        progress == objective.goal
                                ) and objective.isNeededCogFromDeadCogData(
                                        killData):
                                    progress += 1
                                elif (progress == objective.goal):
                                    break
                            objectiveProgress[i] = progress
                        elif objective.type == DefeatCogBuilding and self.isCogOffice(
                        ) and objective.isAcceptable(self.hood, self.dept,
                                                     self.numFloors):
                            objectiveProgress[i] = objectiveProgress[i] + 1
                        elif objective.type == RecoverItem:
                            for killData in deadCogData:
                                objective.handleProgressFromDeadCogData(
                                    killData)

                    objectiveProgresses.append(objectiveProgress)
                questManager.updateQuestData(
                    objectiveProgresses=objectiveProgresses)

                blobs.append(rpData.toNetString(avId))

        return blobs