def confirmJoinGroup(self, groupId, buttonTuple):
     doneStatus = self.joinDialog.doneStatus
     self.joinDialog.cleanup()
     del self.joinDialog
     if doneStatus is not 'ok':
         return
     for gid in base.cr.groupManager.id2type.keys():
         if base.cr.groupManager.isInGroup(base.localAvatar.doId, gid):
             self.rejectGroup(4)
             return
     #if len(base.cr.groupManager.getGroupPlayers(groupId)) >= 8:
     #    self.rejectGroup(3)
     #    return
     suitIdx = -1
     gids = {10000:0, 11000:1, 12000:2, 13000:3}
     suitIdx = gids.get(groupId)
     if suitIdx is not None:
         merits = base.localAvatar.cogMerits[suitIdx]
         if CogDisguiseGlobals.getTotalMerits(base.localAvatar, suitIdx) > merits:
             self.rejectGroup(2, suitIdx)
             return
         parts = base.localAvatar.getCogParts()
         if not CogDisguiseGlobals.isSuitComplete(parts, suitIdx):
             self.rejectGroup(1)
             return
     base.cr.groupManager.d_addPlayerToGroup(groupId, base.localAvatar.doId)
     self.currentGroupJoined = groupId
     try:
         place = base.cr.playGame.getPlace()
     except:
         try:
             place = base.cr.playGame.hood.loader.place
         except:
             place = base.cr.playGame.hood.place
     place.requestTeleport(groupId, groupId, base.localAvatar.defaultShard, -1)
Example #2
0
 def recoverMerits(self,
                   av,
                   cogList,
                   zoneId,
                   multiplier=1,
                   extraMerits=None):
     avId = av.getDoId()
     meritsRecovered = [0, 0, 0, 0]
     if extraMerits is None:
         extraMerits = [0, 0, 0, 0]
     if self.air.suitInvasionManager.getInvading():
         multiplier *= getInvasionMultiplier()
     for i in xrange(len(extraMerits)):
         if CogDisguiseGlobals.isSuitComplete(av.getCogParts(), i):
             meritsRecovered[i] += extraMerits[i]
             self.notify.debug('recoverMerits: extra merits = %s' %
                               extraMerits[i])
     self.notify.debug('recoverMerits: multiplier = %s' % multiplier)
     for cogDict in cogList:
         dept = SuitDNA.suitDepts.index(cogDict['track'])
         if avId in cogDict['activeToons']:
             if CogDisguiseGlobals.isSuitComplete(
                     av.getCogParts(),
                     SuitDNA.suitDepts.index(cogDict['track'])):
                 self.notify.debug(
                     'recoverMerits: checking against cogDict: %s' %
                     cogDict)
                 rand = random.random() * 100
                 if rand <= self.getPercentChance(
                 ) and not cogDict['isVirtual']:
                     merits = cogDict['level'] * MeritMultiplier
                     merits = int(round(merits))
                     if cogDict['hasRevives']:
                         merits *= 2
                     merits = merits * multiplier
                     merits = int(round(merits))
                     meritsRecovered[dept] += merits
                     self.notify.debug('recoverMerits: merits = %s' %
                                       merits)
                 else:
                     self.notify.debug('recoverMerits: virtual cog!')
     if meritsRecovered != [0, 0, 0, 0]:
         actualCounted = [0, 0, 0, 0]
         merits = av.getCogMerits()
         for i in xrange(len(meritsRecovered)):
             max = CogDisguiseGlobals.getTotalMerits(av, i)
             if max:
                 if merits[i] + meritsRecovered[i] <= max:
                     actualCounted[i] = meritsRecovered[i]
                     merits[i] += meritsRecovered[i]
                 else:
                     actualCounted[i] = max - merits[i]
                     merits[i] = max
                 av.b_setCogMerits(merits)
         if reduce(lambda x, y: x + y, actualCounted):
             self.air.writeServerEvent('merits', avId,
                                       '%s|%s|%s|%s' % tuple(actualCounted))
             self.notify.debug('recoverMerits: av %s recovered merits %s' %
                               (avId, actualCounted))
     return meritsRecovered
    def updateMeritBars(self):
        if not self.meritBars:
            return

        for i in xrange(len(self.meritBars)):
            meritBar = self.meritBars[i]

            if CogDisguiseGlobals.isSuitComplete(base.localAvatar.cogParts, i):
                meritBar.show()
                totalMerits = CogDisguiseGlobals.getTotalMerits(base.localAvatar, i)
                merits = base.localAvatar.cogMerits[i]

                if totalMerits:
                    meritBar['range'] = totalMerits
                    meritBar['value'] = merits

                    if merits == totalMerits:
                        meritBar['text'] = TTLocalizer.RewardPanelMeritAlert
                    else:
                        meritBar['text'] = '%s/%s %s' % (merits, totalMerits, TTLocalizer.RewardPanelMeritBarLabels[i])
                else:
                    meritBar['range'] = 1
                    meritBar['value'] = 1
                    meritBar['text'] = TTLocalizer.RewardPanelMeritsMaxed
            else:
                meritBar.hide()
    def updateMeritBars(self):
        if not self.meritBars:
            return

        for i in xrange(len(self.meritBars)):
            meritBar = self.meritBars[i]

            if CogDisguiseGlobals.isSuitComplete(base.localAvatar.cogParts, i):
                meritBar.show()
                totalMerits = CogDisguiseGlobals.getTotalMerits(
                    base.localAvatar, i)
                merits = base.localAvatar.cogMerits[i]

                if totalMerits:
                    meritBar['range'] = totalMerits
                    meritBar['value'] = merits

                    if merits == totalMerits:
                        meritBar['text'] = TTLocalizer.RewardPanelMeritAlert
                    else:
                        meritBar['text'] = '%s/%s %s' % (
                            merits, totalMerits,
                            TTLocalizer.RewardPanelMeritBarLabels[i])
                else:
                    meritBar['range'] = 1
                    meritBar['value'] = 1
                    meritBar['text'] = TTLocalizer.RewardPanelMeritsMaxed
            else:
                meritBar.hide()
    def getMeritIntervalList(self, toon, dept, origMerits, earnedMerits):
        tickDelay = 1.0 / 60
        intervalList = []
        totalMerits = CogDisguiseGlobals.getTotalMerits(toon, dept)
        neededMerits = 0
        if totalMerits and origMerits != totalMerits:
            neededMerits = totalMerits - origMerits
            intervalList.append(
                Func(self.showMeritIncLabel, dept,
                     min(neededMerits, earnedMerits)))
        barTime = 0.5
        numTicks = int(math.ceil(barTime / tickDelay))
        for i in xrange(numTicks):
            t = (i + 1) / float(numTicks)
            newValue = int(origMerits + t * earnedMerits + 0.5)
            intervalList.append(
                Func(self.incrementMerits, toon, dept, newValue, totalMerits))
            intervalList.append(Wait(tickDelay))

        intervalList.append(Func(self.resetMeritBarColor, dept))
        intervalList.append(Wait(0.1))
        if toon.cogLevels[dept] < ToontownGlobals.MaxCogSuitLevel:
            if neededMerits and toon.readyForPromotion(dept):
                intervalList.append(Wait(0.4))
                intervalList += self.getPromotionIntervalList(toon, dept)
        return intervalList
 def updateMeritBar(self, dept):
     merits = base.localAvatar.cogMerits[dept]
     totalMerits = CogDisguiseGlobals.getTotalMerits(base.localAvatar, dept)
     if totalMerits == 0:
         progress = 1
     else:
         progress = min(merits / float(totalMerits), 1)
     self.updateMeritDial(progress)
     if base.localAvatar.readyForPromotion(dept):
         self.cogMeritRatio['text'] = TTLocalizer.DisguisePageMeritFull
         self.promotionTitle.show()
         self.progressTitle.hide()
     else:
         self.cogMeritRatio['text'] = '%d/%d' % (merits, totalMerits)
         self.promotionTitle.hide()
         self.progressTitle.show()
 def updateMeritBar(self, dept):
     merits = base.localAvatar.cogMerits[dept]
     totalMerits = CogDisguiseGlobals.getTotalMerits(base.localAvatar, dept)
     if totalMerits == 0:
         progress = 1
     else:
         progress = min(merits / float(totalMerits), 1)
     self.updateMeritDial(progress)
     if base.localAvatar.readyForPromotion(dept):
         self.cogMeritRatio['text'] = TTLocalizer.DisguisePageMeritFull
         self.promotionTitle.show()
         self.progressTitle.hide()
     else:
         self.cogMeritRatio['text'] = '%d/%d' % (merits, totalMerits)
         self.promotionTitle.hide()
         self.progressTitle.show()
 def recoverMerits(self, av, cogList, zoneId, multiplier = 1, extraMerits = None):
     avId = av.getDoId()
     meritsRecovered = [0, 0, 0, 0]
     if extraMerits is None:
         extraMerits = [0, 0, 0, 0]
     if self.air.suitInvasionManager.getInvading():
         multiplier *= getInvasionMultiplier()
     for i in xrange(len(extraMerits)):
         if CogDisguiseGlobals.isSuitComplete(av.getCogParts(), i):
             meritsRecovered[i] += extraMerits[i]
             self.notify.debug('recoverMerits: extra merits = %s' % extraMerits[i])
     self.notify.debug('recoverMerits: multiplier = %s' % multiplier)
     for cogDict in cogList:
         dept = SuitDNA.suitDepts.index(cogDict['track'])
         if avId in cogDict['activeToons']:
             if CogDisguiseGlobals.isSuitComplete(av.getCogParts(), SuitDNA.suitDepts.index(cogDict['track'])):
                 self.notify.debug('recoverMerits: checking against cogDict: %s' % cogDict)
                 rand = random.random() * 100
                 if rand <= self.getPercentChance() and not cogDict['isVirtual']:
                     merits = cogDict['level'] * MeritMultiplier
                     merits = int(round(merits))
                     if cogDict['hasRevives']:
                         merits *= 2
                     merits = merits * multiplier
                     merits = int(round(merits))
                     meritsRecovered[dept] += merits
                     self.notify.debug('recoverMerits: merits = %s' % merits)
                 else:
                     self.notify.debug('recoverMerits: virtual cog!')
     if meritsRecovered != [0, 0, 0, 0]:
         actualCounted = [0, 0, 0, 0]
         merits = av.getCogMerits()
         for i in xrange(len(meritsRecovered)):
             max = CogDisguiseGlobals.getTotalMerits(av, i)
             if max:
                 if merits[i] + meritsRecovered[i] <= max:
                     actualCounted[i] = meritsRecovered[i]
                     merits[i] += meritsRecovered[i]
                 else:
                     actualCounted[i] = max - merits[i]
                     merits[i] = max
                 av.b_setCogMerits(merits)
         if reduce(lambda x, y: x + y, actualCounted):
             self.air.writeServerEvent('merits', avId, '%s|%s|%s|%s' % tuple(actualCounted))
             self.notify.debug('recoverMerits: av %s recovered merits %s' % (avId, actualCounted))
     return meritsRecovered
    def getMeritIntervalList(self, toon, dept, origMerits, earnedMerits):
        tickDelay = 1.0 / 60
        intervalList = []
        totalMerits = CogDisguiseGlobals.getTotalMerits(toon, dept)
        neededMerits = 0
        if totalMerits and origMerits != totalMerits:
            neededMerits = totalMerits - origMerits
            intervalList.append(Func(self.showMeritIncLabel, dept, min(neededMerits, earnedMerits)))
        barTime = 0.5
        numTicks = int(math.ceil(barTime / tickDelay))
        for i in xrange(numTicks):
            t = (i + 1) / float(numTicks)
            newValue = int(origMerits + t * earnedMerits + 0.5)
            intervalList.append(Func(self.incrementMerits, toon, dept, newValue, totalMerits))
            intervalList.append(Wait(tickDelay))

        intervalList.append(Func(self.resetMeritBarColor, dept))
        intervalList.append(Wait(0.1))
        if toon.cogLevels[dept] < ToontownGlobals.MaxCogSuitLevel:
            if neededMerits and toon.readyForPromotion(dept):
                intervalList.append(Wait(0.4))
                intervalList += self.getPromotionIntervalList(toon, dept)
        return intervalList
Example #10
0
 def confirmJoinGroup(self, groupId, buttonTuple):
     doneStatus = self.joinDialog.doneStatus
     self.joinDialog.cleanup()
     del self.joinDialog
     if doneStatus is not 'ok':
         return
     for gid in base.cr.groupManager.id2type.keys():
         if base.cr.groupManager.isInGroup(base.localAvatar.doId, gid):
             self.rejectGroup(4)
             return
     #if len(base.cr.groupManager.getGroupPlayers(groupId)) >= 8:
     #    self.rejectGroup(3)
     #    return
     suitIdx = -1
     gids = {10000: 0, 11000: 1, 12000: 2, 13000: 3}
     suitIdx = gids.get(groupId)
     if suitIdx is not None:
         merits = base.localAvatar.cogMerits[suitIdx]
         if CogDisguiseGlobals.getTotalMerits(base.localAvatar,
                                              suitIdx) > merits:
             self.rejectGroup(2, suitIdx)
             return
         parts = base.localAvatar.getCogParts()
         if not CogDisguiseGlobals.isSuitComplete(parts, suitIdx):
             self.rejectGroup(1)
             return
     base.cr.groupManager.d_addPlayerToGroup(groupId, base.localAvatar.doId)
     self.currentGroupJoined = groupId
     try:
         place = base.cr.playGame.getPlace()
     except:
         try:
             place = base.cr.playGame.hood.loader.place
         except:
             place = base.cr.playGame.hood.place
     place.requestTeleport(groupId, groupId, base.localAvatar.defaultShard,
                           -1)
    def initGagFrame(self, toon, expList, meritList, noSkip = False):
        self.avNameLabel['text'] = toon.getName()
        self.endTrackFrame.hide()
        self.gagExpFrame.show()
        self.newGagFrame.hide()
        self.promotionFrame.hide()
        self.questFrame.hide()
        self.itemFrame.hide()
        self.cogPartFrame.hide()
        self.missedItemFrame.hide()
        trackBarOffset = 0
        self.skipButton['state'] = choice(noSkip, DGG.DISABLED, DGG.NORMAL)
        for i in xrange(len(SuitDNA.suitDepts)):
            meritBar = self.meritBars[i]
            meritLabel = self.meritLabels[i]
            totalMerits = CogDisguiseGlobals.getTotalMerits(toon, i)
            merits = meritList[i]
            self.meritIncLabels[i].hide()
            if CogDisguiseGlobals.isSuitComplete(toon.cogParts, i):
                if not self.trackBarsOffset:
                    trackBarOffset = 0.47
                    self.trackBarsOffset = 1
                meritBar.show()
                meritLabel.show()
                meritLabel.show()
                if totalMerits:
                    meritBar['range'] = totalMerits
                    meritBar['value'] = merits
                    if merits == totalMerits:
                        meritBar['text'] = TTLocalizer.RewardPanelMeritAlert
                    else:
                        meritBar['text'] = '%s/%s %s' % (merits, totalMerits, TTLocalizer.RewardPanelMeritBarLabels[i])
                else:
                    meritBar['range'] = 1
                    meritBar['value'] = 1
                    meritBar['text'] = TTLocalizer.RewardPanelMeritsMaxed
                self.resetMeritBarColor(i)
            else:
                meritBar.hide()
                meritLabel.hide()

        for i in xrange(len(expList)):
            curExp = expList[i]
            trackBar = self.trackBars[i]
            trackLabel = self.trackLabels[i]
            trackIncLabel = self.trackIncLabels[i]
            trackBar.setX(trackBar.getX() - trackBarOffset)
            trackLabel.setX(trackLabel.getX() - trackBarOffset)
            trackIncLabel.setX(trackIncLabel.getX() - trackBarOffset)
            trackIncLabel.hide()
            if toon.hasTrackAccess(i):
                trackBar.show()
                if curExp >= ToontownBattleGlobals.regMaxSkill:
                    nextExp = self.getNextExpValueUber(curExp, i)
                    trackBar['range'] = nextExp
                    uberCurrExp = curExp - ToontownBattleGlobals.regMaxSkill
                    trackBar['value'] = uberCurrExp
                    trackBar['text'] = TTLocalizer.InventoryUberTrackExp % {'nextExp': ToontownBattleGlobals.MaxSkill - curExp}
                else:
                    nextExp = self.getNextExpValue(curExp, i)
                    trackBar['range'] = nextExp
                    trackBar['value'] = curExp
                    trackBar['text'] = '%s/%s' % (curExp, nextExp)
                self.resetBarColor(i)
            else:
                trackBar.hide()
 def getNextMeritValue(self, curMerits, toon, dept):
     totalMerits = CogDisguiseGlobals.getTotalMerits(toon, dept)
     retVal = totalMerits
     if curMerits > totalMerits:
         retVal = amount
     return retVal
    def initGagFrame(self, toon, expList, meritList, noSkip=False):
        self.avNameLabel['text'] = toon.getName()
        self.endTrackFrame.hide()
        self.gagExpFrame.show()
        self.newGagFrame.hide()
        self.promotionFrame.hide()
        self.questFrame.hide()
        self.itemFrame.hide()
        self.cogPartFrame.hide()
        self.missedItemFrame.hide()
        trackBarOffset = 0
        self.skipButton['state'] = choice(noSkip, DGG.DISABLED, DGG.NORMAL)
        for i in xrange(len(SuitDNA.suitDepts)):
            meritBar = self.meritBars[i]
            meritLabel = self.meritLabels[i]
            totalMerits = CogDisguiseGlobals.getTotalMerits(toon, i)
            merits = meritList[i]
            self.meritIncLabels[i].hide()
            if CogDisguiseGlobals.isSuitComplete(toon.cogParts, i):
                if not self.trackBarsOffset:
                    trackBarOffset = 0.47
                    self.trackBarsOffset = 1
                meritBar.show()
                meritLabel.show()
                meritLabel.show()
                if totalMerits:
                    meritBar['range'] = totalMerits
                    meritBar['value'] = merits
                    if merits == totalMerits:
                        meritBar['text'] = TTLocalizer.RewardPanelMeritAlert
                    else:
                        meritBar['text'] = '%s/%s %s' % (
                            merits, totalMerits,
                            TTLocalizer.RewardPanelMeritBarLabels[i])
                else:
                    meritBar['range'] = 1
                    meritBar['value'] = 1
                    meritBar['text'] = TTLocalizer.RewardPanelMeritsMaxed
                self.resetMeritBarColor(i)
            else:
                meritBar.hide()
                meritLabel.hide()

        for i in xrange(len(expList)):
            curExp = expList[i]
            trackBar = self.trackBars[i]
            trackLabel = self.trackLabels[i]
            trackIncLabel = self.trackIncLabels[i]
            trackBar.setX(trackBar.getX() - trackBarOffset)
            trackLabel.setX(trackLabel.getX() - trackBarOffset)
            trackIncLabel.setX(trackIncLabel.getX() - trackBarOffset)
            trackIncLabel.hide()
            if toon.hasTrackAccess(i):
                trackBar.show()
                if curExp >= ToontownBattleGlobals.regMaxSkill:
                    nextExp = self.getNextExpValueUber(curExp, i)
                    trackBar['range'] = nextExp
                    uberCurrExp = curExp - ToontownBattleGlobals.regMaxSkill
                    trackBar['value'] = uberCurrExp
                    trackBar['text'] = TTLocalizer.InventoryUberTrackExp % {
                        'nextExp': ToontownBattleGlobals.MaxSkill - curExp
                    }
                else:
                    nextExp = self.getNextExpValue(curExp, i)
                    trackBar['range'] = nextExp
                    trackBar['value'] = curExp
                    trackBar['text'] = '%s/%s' % (curExp, nextExp)
                self.resetBarColor(i)
            else:
                trackBar.hide()
 def getNextMeritValue(self, curMerits, toon, dept):
     totalMerits = CogDisguiseGlobals.getTotalMerits(toon, dept)
     retVal = totalMerits
     if curMerits > totalMerits:
         retVal = amount
     return retVal