def calculateTrophies(self, avId, won, qualify, time):
     if won:
         messenger.send('topToonsManager-event', [avId, TopToonsGlobals.CAT_RACE_WON, 1])
     av = self.air.doId2do[avId]
     kartingHistory = av.getKartingHistory()
     avTrophies = av.getKartingTrophies()
     numTrophies = 0
     for i in xrange(30):
         if avTrophies[i] != 0:
             numTrophies += 1
     oldLaffBoost = int(numTrophies/10)
     genre = RaceGlobals.getTrackGenre(self.trackId)
     trophies = []
     if won:
         kartingHistory[genre] += 1
         kartingHistory[3] += 1
         if kartingHistory[3] > RaceGlobals.TotalWonRaces:
             avTrophies[RaceGlobals.TotalWins] = 1
             trophies.append(RaceGlobals.TotalWins)
         for i in xrange(3):
             if kartingHistory[genre] >= RaceGlobals.WonRaces[i] and avTrophies[RaceGlobals.AllWinsList[genre][i]] != 1:
                 avTrophies[RaceGlobals.AllWinsList[genre][i]] = 1
                 trophies.append(RaceGlobals.AllWinsList[genre][i])
     if qualify:
         kartingHistory[genre + 4] += 1
         kartingHistory[7] += 1
         if kartingHistory[7] >= RaceGlobals.TotalQualifiedRaces and avTrophies[RaceGlobals.TotalQuals] != 1:
             avTrophies[RaceGlobals.TotalQuals] = 1
             trophies.append(RaceGlobals.TotalQuals)
         for i in xrange(3):
             if kartingHistory[genre + 4] >= RaceGlobals.QualifiedRaces[i] and avTrophies[RaceGlobals.AllQualsList[genre][i]] != 1:
                 avTrophies[RaceGlobals.AllQualsList[genre][i]] = 1
                 trophies.append(RaceGlobals.AllQualsList[genre][i])
     for i, history in enumerate(kartingHistory):
         if history > 255:
             kartingHistory[i] = 255
     av.b_setKartingHistory(kartingHistory)
     pKartingBest = av.getKartingPersonalBestAll()
     trackIndex = TTLocalizer.KartRace_TrackNames.keys().index(self.trackId)
     if pKartingBest[trackIndex] > time or not pKartingBest[trackIndex]:
         pKartingBest[trackIndex] = time
         av.b_setKartingPersonalBest(pKartingBest)
     gTourTrophy = True
     for bestTime in pKartingBest:
         if not bestTime:
             gTourTrophy = False
     if gTourTrophy:
         if avTrophies[RaceGlobals.GrandTouring] != 1:
             avTrophies[RaceGlobals.GrandTouring] = 1
             trophies.append(RaceGlobals.GrandTouring)
     newLaffBoost = int((len(trophies) + numTrophies)/10)
     if newLaffBoost - oldLaffBoost != 0:
         for i in xrange(newLaffBoost):
             if avTrophies[RaceGlobals.TrophyCups[i]] != 1:
                 avTrophies[RaceGlobals.TrophyCups[i]] = 1
                 trophies.append(RaceGlobals.TrophyCups[i])
         av.b_setMaxHp(av.getMaxHp() + newLaffBoost - oldLaffBoost)
         av.toonUp(av.getMaxHp())
     av.b_setKartingTrophies(avTrophies)
     return trophies
Exemplo n.º 2
0
    def addAvBlock(self, avId, block, paid):
        """
        Purpose: The addAvBlock Method updates the starting block of the
        avatar that has requested entry to the block.

        Params: avId - the id of the avatar entering the block.
                block - the Starting Block object that the avatar will enter.
        Return: None
        """

        # Grab the avatar and make certain its valid
        av = self.air.doId2do.get(avId, None)
        if (not av):
            self.notify.warning("addAvBlock: Avatar not found with id %s" %
                                (avId))
            return KartGlobals.ERROR_CODE.eGeneric

        # Make sure this track is open
        #if (self.trackId in (RaceGlobals.RT_Urban_1, RaceGlobals.RT_Urban_1_rev) and
        #    not simbase.config.GetBool('test-urban-track', 0)):
        #    return KartGlobals.ERROR_CODE.eTrackClosed

        grandPrixWeekendRunning = self.air.holidayManager.isHolidayRunning(
            ToontownGlobals.CIRCUIT_RACING_EVENT)

        # trialer restriction - only Speedway Practice races
        if not paid and not grandPrixWeekendRunning:
            genre = RaceGlobals.getTrackGenre(self.trackId)
            if not ((genre == RaceGlobals.Speedway) and
                    (self.trackType == RaceGlobals.Practice)):
                return KartGlobals.ERROR_CODE.eUnpaid

        if not (self.state == 'WaitEmpty' or self.state == 'WaitCountdown'):
            #you can only join a racepad in one of these states
            return KartGlobals.ERROR_CODE.eTooLate

        # Only check for non-practice races
        if (av.hasKart() and (not self.trackType == RaceGlobals.Practice)):
            # Check if the toon owns enough tickets for the race
            raceFee = RaceGlobals.getEntryFee(self.trackId, self.trackType)
            avTickets = av.getTickets()

            if (avTickets < raceFee):
                self.notify.debug(
                    "addAvBlock: Avatar %s does not own enough tickets for the race!"
                )
                return KartGlobals.ERROR_CODE.eTickets

        # Call the Super Class Method
        success = DistributedKartPadAI.addAvBlock(self, avId, block, paid)
        if (success != KartGlobals.ERROR_CODE.success):
            return success

        # A valid avatar has entered a starting block, now enter wait
        # countdown state. If already in the WaitCountdown state this
        # will not cause any harm.
        if (self.isOccupied()):
            self.request('WaitCountdown')

        return success
 def calculateTrophies(self, avId, won, qualify, time):
     av = self.air.doId2do[avId]
     kartingHistory = av.getKartingHistory()
     avTrophies = av.getKartingTrophies()
     numTrophies = 0
     for i in range(30):
         if avTrophies[i] != 0:
             numTrophies += 1
     oldLaffBoost = int(numTrophies / 10)
     genre = RaceGlobals.getTrackGenre(self.trackId)
     trophies = []
     if won:
         kartingHistory[genre] += 1
         kartingHistory[3] += 1
         if kartingHistory[3] > RaceGlobals.TotalWonRaces:
             avTrophies[RaceGlobals.TotalWins] = 1
             trophies.append(RaceGlobals.TotalWins)
         for i in range(3):
             if kartingHistory[genre] >= RaceGlobals.WonRaces[
                     i] and avTrophies[RaceGlobals.AllWinsList[genre][i]] != 1:
                 avTrophies[RaceGlobals.AllWinsList[genre][i]] = 1
                 trophies.append(RaceGlobals.AllWinsList[genre][i])
     if qualify:
         kartingHistory[genre + 4] += 1
         kartingHistory[7] += 1
         if kartingHistory[7] >= RaceGlobals.TotalQualifiedRaces and avTrophies[
                 RaceGlobals.TotalQuals] != 1:
             avTrophies[RaceGlobals.TotalQuals] = 1
             trophies.append(RaceGlobals.TotalQuals)
         for i in range(3):
             if kartingHistory[
                     genre +
                     4] >= RaceGlobals.QualifiedRaces[i] and avTrophies[
                     RaceGlobals.AllQualsList[genre][i]] != 1:
                 avTrophies[RaceGlobals.AllQualsList[genre][i]] = 1
                 trophies.append(RaceGlobals.AllQualsList[genre][i])
     av.b_setKartingHistory(kartingHistory)
     pKartingBest = av.getKartingPersonalBestAll()
     trackIndex = TTLocalizer.KartRace_TrackNames.keys().index(self.trackId)
     if pKartingBest[trackIndex] > time or not pKartingBest[trackIndex]:
         pKartingBest[trackIndex] = time
         av.b_setKartingPersonalBest(pKartingBest)
     gTourTrophy = True
     for bestTime in pKartingBest:
         if not bestTime:
             gTourTrophy = False
     if gTourTrophy:
         if avTrophies[RaceGlobals.GrandTouring] != 1:
             avTrophies[RaceGlobals.GrandTouring] = 1
             trophies.append(RaceGlobals.GrandTouring)
     newLaffBoost = int((len(trophies) + numTrophies) / 10)
     if newLaffBoost - oldLaffBoost != 0:
         for i in range(newLaffBoost):
             if avTrophies[RaceGlobals.TrophyCups[i]] != 1:
                 avTrophies[RaceGlobals.TrophyCups[i]] = 1
                 trophies.append(RaceGlobals.TrophyCups[i])
         av.b_setMaxHp(av.getMaxHp() + newLaffBoost - oldLaffBoost)
         av.toonUp(av.getMaxHp())
     av.b_setKartingTrophies(avTrophies)
     return trophies
    def avatarFinished(self, avId):
        if not avId in self.avatars:
            self.air.writeServerEvent(
                'suspicious', avId,
                'Toon tried to finish in a race they\'re not in!')
            return

        if avId in self.finishedAvatars:
            self.air.writeServerEvent('suspicious', avId,
                                      'Toon tried to finish in a race twice!')
            return
        self.finishedAvatars.append(avId)

        av = self.air.doId2do.get(avId)
        place = len(self.finishedAvatars)
        entryFee = RaceGlobals.getEntryFee(self.trackId, self.raceType)
        bonus = 0
        totalTime = globalClockDelta.networkToLocalTime(
            globalClockDelta.getRealNetworkTime()) - self.startTime
        qualify = False
        if totalTime < RaceGlobals.getQualifyingTime(self.trackId):
            qualify = True
        if self.raceType == RaceGlobals.Practice:
            winnings = RaceGlobals.PracticeWinnings
            trophies = []
        elif qualify:
            offset = 4 - len(
                self.avatarProgress
            )  # self.avatarProgress contains the amount of STARTING players.
            winnings = entryFee * RaceGlobals.Winnings[(place + offset) - 1]
            trophies = self.calculateTrophies(avId, place == 1, qualify,
                                              totalTime)
        else:
            winnings = 0
            trophies = []
        av.b_setTickets(av.getTickets() + winnings)
        if av.getTickets() > RaceGlobals.MaxTickets:
            av.b_setTickets(RaceGlobals.MaxTickets)

        # LEADER BOARD # NJF
        genre = RaceGlobals.getTrackGenre(self.trackId)
        av = self.air.doId2do[avId]
        timeStamp = time.time()

        av = str(av)  # NJF
        av = av.split("/")[1]

        self.air.leaderBoardMgr.appendNewRaceEntry(self.trackId, 0, av,
                                                   totalTime, timeStamp)
        self.air.leaderBoardMgr.appendNewRaceEntry(self.trackId, 1, av,
                                                   totalTime, timeStamp)
        self.air.leaderBoardMgr.appendNewRaceEntry(self.trackId, 2, av,
                                                   totalTime, timeStamp)

        self.sendUpdate('setPlace', [
            avId, totalTime, place, entryFee, qualify,
            max((winnings - entryFee), 0), bonus, trophies, [], 0
        ])
Exemplo n.º 5
0
    def getNewCircuitHistory(self, race, avId, positionFinished):
        newHistory = 0
        av = self.air.doId2do.get(avId)
        if not av:
            return []
        history = av.getKartingHistory()
        trackGenre = RaceGlobals.getTrackGenre(race.trackId)
        historyIndex = RaceGlobals.CircuitWins
        trophyReqList = RaceGlobals.WonCircuitRaces
        sweepIndices = RaceGlobals.CircuitSweepsList
        sweepReqList = RaceGlobals.SweptCircuitRaces
        self.notify.debug(
            'getNewCircuitHistory: avId=%d positionFinished=%d history =%s' %
            (avId, positionFinished, history))
        if history[historyIndex] < trophyReqList[-1] and positionFinished == 1:
            history[historyIndex] += 1
            self.notify.debug('New History Won!')
            newHistory = 1
        swept = 0
        totalPoints = sum(race.circuitPoints[avId])
        if totalPoints == len(
                race.circuitPoints[avId]) * RaceGlobals.CircuitPoints[0]:
            swept = 1
        if swept:
            if history[RaceGlobals.CircuitSweeps] < sweepReqList[-1]:
                if not history[RaceGlobals.CircuitSweeps]:
                    history[RaceGlobals.CircuitSweeps] = 0
                history[RaceGlobals.CircuitSweeps] += 1
                self.notify.debug('New History Swept!')
                newHistory = 1
        qualified = 0
        self.notify.debug('qual times %s' % race.qualTimes)
        self.notify.debug('avatar times %s' % race.circuitTimeList[avId])
        qualified = 1
        self.notify.debug('End Race Circuit Time List %s' %
                          race.circuitTimeList)
        self.notify.debug('check for qualify')
        for qual in race.circuitTimeList[avId]:
            self.notify.debug('qual %s' % qual)
            if qual[1] == -1:
                qualified = 0
                self.notify.debug('not qualified')

        if qualified:
            self.notify.debug('qualified has %s needs %s' %
                              (history[RaceGlobals.CircuitQuals],
                               RaceGlobals.QualifiedCircuitRaces[-1]))
            if history[RaceGlobals.
                       CircuitQuals] < RaceGlobals.QualifiedCircuitRaces[-1]:
                history[RaceGlobals.CircuitQuals] += 1
                self.notify.debug('New History qualified!')
                newHistory = 1
        if newHistory:
            return history
Exemplo n.º 6
0
    def avatarFinished(self, avId):
        if not avId in self.avatars:
            self.air.writeServerEvent('suspicious', avId, 'Toon tried to finish in a race they\'re not in!')
            return

        if avId in self.finishedAvatars:
            self.air.writeServerEvent('suspicious', avId, 'Toon tried to finish in a race twice!')
            return
        self.finishedAvatars.append(avId)

        av = self.air.doId2do.get(avId)
        place = len(self.finishedAvatars)
        entryFee = RaceGlobals.getEntryFee(self.trackId, self.raceType)
        bonus = 0
        totalTime = globalClockDelta.networkToLocalTime(globalClockDelta.getRealNetworkTime()) - self.startTime
        qualify = False
        if totalTime < RaceGlobals.getQualifyingTime(self.trackId):
            qualify = True
        if self.raceType == RaceGlobals.Practice:
            winnings = RaceGlobals.PracticeWinnings
            trophies = []
        elif qualify:
            offset = 4 - len(self.avatarProgress) # self.avatarProgress contains the amount of STARTING players.
            winnings = entryFee * RaceGlobals.Winnings[(place+offset)-1]
            trophies = self.calculateTrophies(avId, place == 1, qualify, totalTime)
        else:
            winnings = 0
            trophies = []
        av.b_setTickets(av.getTickets() + winnings)
        if av.getTickets() > RaceGlobals.MaxTickets:
            av.b_setTickets(RaceGlobals.MaxTickets)


        genre = RaceGlobals.getTrackGenre(self.trackId)
        av = self.air.doId2do[avId]
        timeStamp = time.time()


        print (self.trackId)
        print (genre)
        print (totalTime)
        print (av)
        av = str(av)
        av = av.split("/")[1]


        self.air.leaderBoardMgr.appendNewRaceEntry(self.trackId, 0, av, totalTime, timeStamp)
        self.air.leaderBoardMgr.appendNewRaceEntry(self.trackId, 1, av, totalTime, timeStamp)
        self.air.leaderBoardMgr.appendNewRaceEntry(self.trackId, 2, av, totalTime, timeStamp)

        print ("TRACK INDEX!!!")

        self.sendUpdate('setPlace', [avId, totalTime, place, entryFee, qualify, max((winnings-entryFee), 0), bonus, trophies, [], 0])
Exemplo n.º 7
0
    def checkForTrophies(self, place, trackId, raceType, numRacers, avId):
        av = self.air.doId2do.get(avId)
        outHistory = av.getKartingHistory()
        trophies = av.getKartingTrophies()
        trophiesWon = []
        trackGenre = RaceGlobals.getTrackGenre(trackId)
        if place == 1:
            historyIndex = RaceGlobals.WinsList[trackGenre]
            trophyIndices = RaceGlobals.AllWinsList[trackGenre]
            trophyReqList = RaceGlobals.WonRaces
            historyTotalList = RaceGlobals.WinsList
            totalTrophyIndex = RaceGlobals.TotalWins
            totalReq = RaceGlobals.TotalWonRaces
            trophiesWon += self.checkForTrophy(place, trackId, raceType,
                                               numRacers, avId, historyIndex,
                                               trophyIndices, trophyReqList,
                                               historyTotalList,
                                               totalTrophyIndex, totalReq)
        historyIndex = RaceGlobals.QualsList[trackGenre]
        trophyIndices = RaceGlobals.AllQualsList[trackGenre]
        trophyReqList = RaceGlobals.QualifiedRaces
        historyTotalList = RaceGlobals.QualsList
        totalTrophyIndex = RaceGlobals.TotalQuals
        totalReq = RaceGlobals.TotalQualifiedRaces
        trophiesWon += self.checkForTrophy(place, trackId, raceType, numRacers,
                                           avId, historyIndex, trophyIndices,
                                           trophyReqList, historyTotalList,
                                           totalTrophyIndex, totalReq)
        if not trophies[RaceGlobals.GrandTouring]:
            self.notify.debug('checking for grand touring')
            best = av.getKartingPersonalBestAll()
            self.notify.debug('personal best %s' % best)
            counter = 0
            for time in best:
                if not time == 0:
                    counter += 1

            self.notify.debug('counter %s tracks %s' %
                              (counter, len(RaceGlobals.TrackDict)))
            if counter >= len(RaceGlobals.TrackDict):
                trophiesWon.append(RaceGlobals.GrandTouring)
        if outHistory:
            av.b_setKartingHistory(outHistory)
        if len(trophiesWon):
            for trophy in trophiesWon:
                trophies[trophy] = 1

            av.b_setKartingTrophies(trophies)
        trophiesWon.sort()
        return trophiesWon
Exemplo n.º 8
0
 def getNewSingleRaceHistory(self, race, avId, positionFinished):
     newHistory = 0
     av = self.air.doId2do.get(avId)
     if not av:
         return []
     history = av.getKartingHistory()
     trackGenre = RaceGlobals.getTrackGenre(race.trackId)
     winIndex = RaceGlobals.WinsList[trackGenre]
     winReqList = RaceGlobals.WonRaces
     qualIndex = RaceGlobals.QualsList[trackGenre]
     qualReqList = RaceGlobals.QualifiedRaces
     if history[winIndex] < winReqList[-1] and positionFinished == 1:
         history[winIndex] += 1
         self.notify.debug('New History Won!')
         newHistory = 1
     if history[qualIndex] < qualReqList[-1]:
         history[qualIndex] += 1
         self.notify.debug('New History Qualified!')
         newHistory = 1
     if newHistory:
         return history
 def getTunnelSign(self):
     cPadId = RaceGlobals.RaceInfo2RacePadId(self.trackId, self.trackType)
     genreId = RaceGlobals.getTrackGenre(self.trackId)
     tunnelName = RaceGlobals.getTunnelSignName(genreId, cPadId)
     self.tunnelSign = self.cr.playGame.hood.loader.geom.find('**/' +
                                                              tunnelName)
 def getTunnelSign(self):
     cPadId = RaceGlobals.RaceInfo2RacePadId(self.trackId, self.trackType)
     genreId = RaceGlobals.getTrackGenre(self.trackId)
     tunnelName = RaceGlobals.getTunnelSignName(genreId, cPadId)
     self.tunnelSign = self.cr.playGame.hood.loader.geom.find(
         '**/' + tunnelName)