Exemplo n.º 1
0
    def avatarFinished(self, avId):
        if not avId in self.avatars:
            self.air.writeServerEvent('suspicious', avId=avId, issue='Toon tried to finish in a race they\'re not in!')
            return

        if avId in self.finishedAvatars:
            self.air.writeServerEvent('suspicious', avId=avId, issue='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)
        self.sendUpdate('setPlace', [avId, totalTime, place, entryFee, qualify, (winnings-entryFee), bonus, trophies, [], 0])
 def createRace(self):
     self.raceZone = self.air.allocateZone()
     avatars = []
     for block in self.startingBlocks:
         if block.avId != 0:
             avatars.append(block.avId)
             self.sendUpdateToAvatarId(block.avId, 'setRaceZone', [self.raceZone])
     race = DistributedRaceAI(self.air)
     race.setZoneId(self.raceZone)
     race.setTrackId(self.trackId)
     race.setRaceType(self.trackType)
     race.setAvatars(avatars)
     if self.trackType == RaceGlobals.Circuit:
         race.setCircuitLoop(RaceGlobals.getCircuitLoop(self.trackId))
     else:
         race.setCircuitLoop([])
     race.setStartingPlaces(range(len(avatars)))
     race.setLapCount(3)
     race.generateWithRequired(self.raceZone)
     for avId in avatars:
         if avId in self.air.doId2do:
             av = self.air.doId2do[avId]
             entryFee = RaceGlobals.getEntryFee(self.trackId, self.trackType)
             if av.getTickets() < entryFee:
                 self.air.writeServerEvent('suspicious', avId, 'Toon somehow lost tickets between entering a race and it leaving!')
                 av.b_setTickets(0)
             else:
                 av.b_setTickets(av.getTickets() - entryFee)
     self.b_setState('WaitEmpty', globalClockDelta.getRealNetworkTime())
Exemplo n.º 3
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
Exemplo n.º 4
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)
        self.sendUpdate('setPlace', [avId, totalTime, place, entryFee, qualify, max((winnings-entryFee), 0), bonus, trophies, [], 0])
 def createRace(self):
     self.raceZone = self.air.allocateZone()
     avatars = []
     for block in self.startingBlocks:
         if block.avId != 0:
             avatars.append(block.avId)
             self.sendUpdateToAvatarId(block.avId, 'setRaceZone',
                                       [self.raceZone])
     race = DistributedRaceAI(self.air)
     race.setZoneId(self.raceZone)
     race.setTrackId(self.trackId)
     race.setRaceType(self.trackType)
     race.setAvatars(avatars)
     if self.trackType == RaceGlobals.Circuit:
         race.setCircuitLoop(RaceGlobals.getCircuitLoop(self.trackId))
     else:
         race.setCircuitLoop([])
     race.setStartingPlaces(range(len(avatars)))
     race.setLapCount(3)
     race.generateWithRequired(self.raceZone)
     for avId in avatars:
         if avId in self.air.doId2do:
             av = self.air.doId2do[avId]
             entryFee = RaceGlobals.getEntryFee(self.trackId,
                                                self.trackType)
             if av.getTickets() < entryFee:
                 self.air.writeServerEvent(
                     'suspicious', avId,
                     'Toon somehow lost tickets between entering a race and it leaving!'
                 )
                 av.b_setTickets(0)
             else:
                 av.b_setTickets(av.getTickets() - entryFee)
     self.b_setState('WaitEmpty', globalClockDelta.getRealNetworkTime())
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)
        listPlace = place + (4 - len(self.avatarProgress)) - 1
        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
            self.air.leaderboardMgr.submitRace(self.trackId, av.getName(), totalTime)
        if self.raceType == RaceGlobals.Practice:
            winnings = RaceGlobals.PracticeWinnings
            trophies = []
        elif qualify:
            winnings = entryFee * RaceGlobals.Winnings[listPlace]
            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)
        av.addStat(ToontownGlobals.STAT_RACING)
        points = []
        if self.circuitPoints:
            avIndex = self.avatars.index(avId)
            points = self.circuitPoints[avIndex]
            points[0] += points[1]
            points[1] = RaceGlobals.CircuitPoints[place - 1]
        self.sendUpdate(
            "setPlace",
            [avId, totalTime, place, entryFee, qualify, max((winnings - entryFee), 0), bonus, trophies, points, 0],
        )
        if self.circuitPoints:
            self.circuitWinnings[avIndex] += winnings
            self.sendUpdate("setCircuitPlace", [avId, place, entryFee, self.circuitWinnings[avIndex], bonus, trophies])

            if len(self.finishedAvatars) == len(self.avatars):
                del self.circuitLoop[0]
                self.sendUpdate("setCircuitLoop", [self.circuitLoop])
                self.sendUpdate("endCircuitRace")
    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)
        listPlace = place + (4 - len(self.avatarProgress)) - 1
        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
            self.air.leaderboardMgr.submitRace(self.trackId, av.getName(), totalTime)
        if self.raceType == RaceGlobals.Practice:
            winnings = RaceGlobals.PracticeWinnings
            trophies = []
        elif qualify:
            winnings = entryFee * RaceGlobals.Winnings[listPlace]
            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)
        av.addStat(ToontownGlobals.STAT_RACING)
        points = []
        if self.circuitPoints:
            avIndex = self.avatars.index(avId)
            points = self.circuitPoints[avIndex]
            points[0] += points[1]
            points[1] = RaceGlobals.CircuitPoints[place - 1]
        self.sendUpdate('setPlace', [avId, totalTime, place, entryFee, qualify, max((winnings-entryFee), 0), bonus, trophies, points, 0])
        if self.circuitPoints:
            self.circuitWinnings[avIndex] += winnings
            self.sendUpdate('setCircuitPlace', [avId, place, entryFee, self.circuitWinnings[avIndex], bonus, trophies])
            
            if len(self.finishedAvatars) == len(self.avatars):
                del self.circuitLoop[0]
                self.sendUpdate('setCircuitLoop', [self.circuitLoop])
                self.sendUpdate('endCircuitRace')
Exemplo n.º 8
0
    def loadRecords(self):
        try:
            file = open(self.filename + '.bu', 'rb')
            if os.path.exists(self.filename):
                os.remove(self.filename)
        except IOError:
            try:
                file = open(self.filename, 'rb')
            except IOError:
                return self.getRecordTimes()

        file.seek(0)
        records = self.loadFrom(file)
        file.close()
        for trackId in RaceGlobals.TrackIds:
            if trackId not in records:
                records[trackId] = {}
                for i in RaceGlobals.PeriodIds:
                    records[trackId][i] = []
                    for j in range(0, RaceGlobals.NumRecordsPerPeriod):
                        records[trackId][i].append(
                            RaceGlobals.getDefaultRecord(trackId))

        self.resetLeaderboards()
        return records
    def updateTunnelSignText(self):
        self.notify.debugStateCall(self)
        trackNameString = TTLocalizer.KartRace_TrackNames[self.trackId]
        if not self.trackNameNode:
            self.notify.warning("invalid trackNameNode, just returning")
            return

        self.trackNameNode.setText(trackNameString)

        trackTypeString = TTLocalizer.KartRace_RaceNames[self.trackType]
        self.trackTypeNode.setText(trackTypeString)

        deposit = 0
        if self.trackType:
            deposit = RaceGlobals.getEntryFee(self.trackId, self.trackType)
        depositString = TTLocalizer.KartRace_DepositPhrase + str(deposit)

        self.depositNode.setText(depositString)

        time = RaceGlobals.TrackDict[self.trackId][1]
        secs, hundredths = divmod(time, 1)
        min, sec = divmod(secs, 60)
        timeText = "%02d:%02d:%02d" % (min, sec, hundredths * 100)
        qualifyString = TTLocalizer.KartRace_QualifyPhrase + timeText
        self.qualifyNode.setText(qualifyString)
 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.º 11
0
    def __handleSetRaceCountdownTimeout(self, params=[]):
        """
        Comment:
        """
        # set the timer task to off, because raceExit calls removeAvBlock and
        # shouldn't call. SHOULD BREAK UP THOSE CALLS.
        self.timerTask = None
        players = self.avId2BlockDict.keys()
        circuitLoop = []
        if self.trackType == RaceGlobals.Circuit:
            circuitLoop = RaceGlobals.getCircuitLoop(self.trackId)

        raceZone = self.raceMgr.createRace(self.trackId,
                                           self.trackType,
                                           self.numLaps,
                                           players,
                                           circuitLoop[1:], {}, {}, [], {},
                                           circuitTotalBonusTickets={})
        for avId in self.avId2BlockDict.keys():
            if (avId):
                self.notify.debug(
                    "Handling Race Launch Countdown for avatar %s" % (avId))
                # Tell each player that they should enter
                # the mint, and which zone it is in.
                self.sendUpdateToAvatarId(avId, "setRaceZone", [raceZone])
                self.avId2BlockDict[avId].raceExit()

        # Let's now restart for a new race.
        self.request('WaitEmpty')
        return Task.done
 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 __handleEnterSphere(self, collEntry):
        if base.localAvatar.doId == self.lastAvId and globalClock.getFrameCount() <= self.lastFrame + 1:
            self.notify.debug('Ignoring duplicate entry for avatar.')
            return
        if base.localAvatar.hp > 0:

            def handleEnterRequest(self = self):
                self.ignore('stoppedAsleep')
                if hasattr(self.dialog, 'doneStatus') and self.dialog.doneStatus == 'ok':
                    self.d_requestEnter(base.cr.isPaid())
                elif self.cr and not self.isDisabled():
                    self.cr.playGame.getPlace().setState('walk')
                else:
                    self.notify.warning('Warning! Object has already been disabled.')
                self.dialog.ignoreAll()
                self.dialog.cleanup()
                del self.dialog

            self.cr.playGame.getPlace().fsm.request('stopped')
            self.accept('stoppedAsleep', handleEnterRequest)
            doneEvent = 'enterRequest|dialog'
            if self.kartPad.isPractice():
                msg = TTLocalizer.StartingBlock_EnterPractice
            else:
                raceName = TTLocalizer.KartRace_RaceNames[self.kartPad.trackType]
                numTickets = RaceGlobals.getEntryFee(self.kartPad.trackId, self.kartPad.trackType)
                msg = TTLocalizer.StartingBlock_EnterNonPractice % (raceName, numTickets)
            self.dialog = TTGlobalDialog(msg, doneEvent, 4)
            self.dialog.accept(doneEvent, handleEnterRequest)
Exemplo n.º 14
0
    def findRacingPads(self, dnaGroup, zoneId, area, padType='racing_pad'):
        racingPads = []
        racingPadGroups = []
        if isinstance(dnaGroup, DNAGroup) and (padType in dnaGroup.getName()):
            racingPadGroups.append(dnaGroup)

            if padType == 'racing_pad':
                nameInfo = dnaGroup.getName().split('_')
                racingPad = DistributedRacePadAI(simbase.air)
                racingPad.setArea(zoneId)
                racingPad.nameType = nameInfo[3]
                racingPad.index = int(nameInfo[2])
                nextRaceInfo = RaceGlobals.getNextRaceInfo(-1, racingPad.nameType, racingPad.index)
                racingPad.setTrackInfo([nextRaceInfo[0], nextRaceInfo[1]])
                racingPad.generateWithRequired(zoneId)
            elif padType == 'viewing_pad':
                racingPad = DistributedViewPadAI(simbase.air)
                racingPad.setArea(zoneId)
                racingPad.generateWithRequired(zoneId)
            else:
                self.notify.error('Invalid racing pad type: ' + padType)

            racingPads.append(racingPad)
        elif isinstance(dnaGroup, DNAVisGroup):
            zoneId = ZoneUtil.getTrueZoneId(int(dnaGroup.getName().split(':')[0]), zoneId)
        for i in xrange(dnaGroup.getNumChildren()):
            (foundRacingPads, foundRacingPadGroups) = self.findRacingPads(dnaGroup.at(i), zoneId, area, padType=padType)
            racingPads.extend(foundRacingPads)
            racingPadGroups.extend(foundRacingPadGroups)
        return (racingPads, racingPadGroups)
 def requestEnter(self):
     avId = self.air.getAvatarIdFromSender()
     av = self.air.doId2do.get(avId)
     if not av:
         return
     if not av.hasKart():
         self.sendUpdateToAvatarId(avId, 'rejectEnter',
                                   [KartGlobals.ERROR_CODE.eNoKart])
         return
     if av.getTickets() < RaceGlobals.getEntryFee(self.pad.trackId,
                                                  self.pad.trackType):
         self.sendUpdateToAvatarId(avId, 'rejectEnter',
                                   [KartGlobals.ERROR_CODE.eTickets])
         return
     if self.pad.state == 'AllAboard' or self.pad.state == 'WaitBoarding':
         self.sendUpdateToAvatarId(avId, 'rejectEnter',
                                   [KartGlobals.ERROR_CODE.eBoardOver])
         return
     if self.avId != 0:
         if self.avId == avId:
             self.air.writeServerEvent(
                 'suspicious', avId,
                 'Toon tried to board the same starting block twice!')
         self.sendUpdateToAvatarId(avId, 'rejectEnter',
                                   [KartGlobals.ERROR_CODE.eOccupied])
         return
     self.b_setOccupied(avId)
     self.b_setMovie(KartGlobals.ENTER_MOVIE)
Exemplo n.º 16
0
    def findRacingPads(self,
                       dnaData,
                       zoneId,
                       area,
                       type='racing_pad',
                       overrideDNAZone=False):
        racingPads, racingPadGroups = [], []
        if type in dnaData.getName():
            if type == 'racing_pad':
                nameSplit = dnaData.getName().split('_')
                racePad = DistributedRacePadAI(self)
                racePad.setArea(area)
                racePad.index = int(nameSplit[2])
                racePad.genre = nameSplit[3]
                trackInfo = RaceGlobals.getNextRaceInfo(
                    -1, racePad.genre, racePad.index)
                racePad.setTrackInfo([trackInfo[0], trackInfo[1]])
                racePad.laps = trackInfo[2]
                racePad.generateWithRequired(zoneId)
                racingPads.append(racePad)
                racingPadGroups.append(dnaData)
            elif type == 'viewing_pad':
                viewPad = DistributedViewPadAI(self)
                viewPad.setArea(area)
                viewPad.generateWithRequired(zoneId)
                racingPads.append(viewPad)
                racingPadGroups.append(dnaData)

        for i in xrange(dnaData.getNumChildren()):
            foundRacingPads, foundRacingPadGroups = self.findRacingPads(
                dnaData.at(i), zoneId, area, type, overrideDNAZone)
            racingPads.extend(foundRacingPads)
            racingPadGroups.extend(foundRacingPadGroups)

        return racingPads, racingPadGroups
    def __handleEnterSphere(self, collEntry):
        if base.localAvatar.doId == self.lastAvId and globalClock.getFrameCount(
        ) <= self.lastFrame + 1:
            self.notify.debug('Ignoring duplicate entry for avatar.')
            return
        if base.localAvatar.hp > 0:

            def handleEnterRequest(self=self):
                self.ignore('stoppedAsleep')
                if hasattr(self.dialog,
                           'doneStatus') and self.dialog.doneStatus == 'ok':
                    self.d_requestEnter()
                elif self.cr and not self.isDisabled():
                    self.cr.playGame.getPlace().setState('walk')
                else:
                    self.notify.warning(
                        'Warning! Object has already been disabled.')
                self.dialog.ignoreAll()
                self.dialog.cleanup()
                del self.dialog

            self.cr.playGame.getPlace().fsm.request('stopped')
            self.accept('stoppedAsleep', handleEnterRequest)
            doneEvent = 'enterRequest|dialog'
            if self.kartPad.isPractice():
                msg = TTLocalizer.StartingBlock_EnterPractice
            else:
                raceName = TTLocalizer.KartRace_RaceNames[
                    self.kartPad.trackType]
                numTickets = RaceGlobals.getEntryFee(self.kartPad.trackId,
                                                     self.kartPad.trackType)
                msg = TTLocalizer.StartingBlock_EnterNonPractice % (raceName,
                                                                    numTickets)
            self.dialog = TTGlobalDialog(msg, doneEvent, 4)
            self.dialog.accept(doneEvent, handleEnterRequest)
Exemplo n.º 18
0
    def findRacingPads(self, dnaGroup, zoneId, area, padType='racing_pad'):
        racingPads = []
        racingPadGroups = []
        if isinstance(dnaGroup, DNAGroup) and (padType in dnaGroup.getName()):
            racingPadGroups.append(dnaGroup)

            if padType == 'racing_pad':
                nameInfo = dnaGroup.getName().split('_')
                racingPad = DistributedRacePadAI(simbase.air)
                racingPad.setArea(zoneId)
                racingPad.nameType = nameInfo[3]
                racingPad.index = int(nameInfo[2])
                nextRaceInfo = RaceGlobals.getNextRaceInfo(-1, racingPad.nameType, racingPad.index)
                racingPad.setTrackInfo([nextRaceInfo[0], nextRaceInfo[1]])
                racingPad.generateWithRequired(zoneId)
            elif padType == 'viewing_pad':
                racingPad = DistributedViewPadAI(simbase.air)
                racingPad.setArea(zoneId)
                racingPad.generateWithRequired(zoneId)
            else:
                self.notify.error('Invalid racing pad type: ' + padType)

            racingPads.append(racingPad)
        elif isinstance(dnaGroup, DNAVisGroup):
            zoneId = ZoneUtil.getTrueZoneId(int(dnaGroup.getName().split(':')[0]), zoneId)
        for i in range(dnaGroup.getNumChildren()):
            (foundRacingPads, foundRacingPadGroups) = self.findRacingPads(dnaGroup.at(i), zoneId, area, padType=padType)
            racingPads.extend(foundRacingPads)
            racingPadGroups.extend(foundRacingPadGroups)
        return (racingPads, racingPadGroups)
 def requestEnter(self, isPaid):
     avId = self.air.getAvatarIdFromSender()
     av = self.air.doId2do.get(avId)
     if not av:
         self.air.writeServerEvent(
             'suspicious', avId=avId,
             issue='Toon tried to board a starting block, but is not on the district!')
         return
     if not av.hasKart():
         self.sendUpdateToAvatarId(
             avId, 'rejectEnter', [
                 KartGlobals.ERROR_CODE.eNoKart])
         return
     if av.getTickets() < RaceGlobals.getEntryFee(
             self.pad.trackId, self.pad.trackType):
         self.sendUpdateToAvatarId(
             avId, 'rejectEnter', [
                 KartGlobals.ERROR_CODE.eTickets])
         return
     if self.pad.state == 'AllAboard' or self.pad.state == 'WaitBoarding':
         self.sendUpdateToAvatarId(
             avId, 'rejectEnter', [
                 KartGlobals.ERROR_CODE.eBoardOver])
         return
     if self.avId != 0:
         if self.avId == avId:
             self.air.writeServerEvent(
                 'suspicious', avId=avId,
                 issue='Toon tried to board the same starting block twice!')
         self.sendUpdateToAvatarId(
             avId, 'rejectEnter', [
                 KartGlobals.ERROR_CODE.eOccupied])
         return
     self.b_setOccupied(avId)
     self.b_setMovie(KartGlobals.ENTER_MOVIE)
Exemplo n.º 20
0
    def resetRecordPeriod(self, period):
        for trackId in RaceGlobals.TrackIds:
            for i in range(0, RaceGlobals.NumRecordsPerPeriod):
                self.trackRecords[trackId][period][
                    i] = RaceGlobals.getDefaultRecord(trackId)

            self.updateLeaderboards(trackId, period)

        self.updateRecordFile()
    def changeTrack(self, task):
        trackInfo = RaceGlobals.getNextRaceInfo(self.trackInfo[0], self.genre,
                                                self.index)
        trackId, raceType = trackInfo[0], trackInfo[1]
        if raceType == RaceGlobals.ToonBattle and bboard.get(
                CircuitRaceHolidayMgr.PostName):
            raceType = RaceGlobals.Circuit

        self.b_setTrackInfo([trackId, raceType])
        self.laps = trackInfo[2]
        return task.again
Exemplo n.º 22
0
    def __handleEnterSphere(self, collEntry):
        """
        comment
        """
        assert self.notify.debug("__handleEnterSphere")

        # Protect against the same toon from re-entering the sphere
        # immediately after exiting. It is most likely a mistake on the
        # toon's part.
        if( base.localAvatar.doId == self.lastAvId and \
            globalClock.getFrameCount() <= self.lastFrame + 1 ):
            self.notify.debug("Ignoring duplicate entry for avatar.")
            return

        # Only toons with hp > 0 and own a kart may enter the sphere.
        if ((base.localAvatar.hp > 0)):

            def handleEnterRequest(self=self):
                self.ignore("stoppedAsleep")
                if hasattr(self.dialog,
                           'doneStatus') and (self.dialog.doneStatus == 'ok'):
                    self.d_requestEnter(base.cr.isPaid())
                else:
                    if self.cr and not self.isDisabled():
                        self.cr.playGame.getPlace().setState("walk")
                    else:
                        self.notify.warning(
                            "Warning! Object has already been disabled.")

                self.dialog.ignoreAll()
                self.dialog.cleanup()
                del self.dialog

            # take the localToon out of walk mode
            self.cr.playGame.getPlace().fsm.request('stopped')

            # make dialog go away if they fall asleep while stopped
            self.accept("stoppedAsleep", handleEnterRequest)

            # A dialog box should prompt the toon for action, to either
            # enter a race or ignore it.
            doneEvent = 'enterRequest|dialog'
            if (self.kartPad.isPractice()):
                msg = TTLocalizer.StartingBlock_EnterPractice
            else:
                raceName = TTLocalizer.KartRace_RaceNames[
                    self.kartPad.trackType]
                numTickets = RaceGlobals.getEntryFee(self.kartPad.trackId,
                                                     self.kartPad.trackType)
                msg = TTLocalizer.StartingBlock_EnterNonPractice % (raceName,
                                                                    numTickets)

            self.dialog = TTGlobalDialog(msg, doneEvent, 4)
            self.dialog.accept(doneEvent, handleEnterRequest)
Exemplo n.º 23
0
    def getRecordTimes(self):
        records = {}
        for trackId in RaceGlobals.TrackIds:
            records[trackId] = {}
            for i in RaceGlobals.PeriodIds:
                records[trackId][i] = []
                for j in range(0, RaceGlobals.NumRecordsPerPeriod):
                    records[trackId][i].append(
                        RaceGlobals.getDefaultRecord(trackId))

        return records
Exemplo n.º 24
0
 def changeTrack(self, task):
     trackInfo = RaceGlobals.getNextRaceInfo(self.trackInfo[0], self.genre,
                                             self.index)
     trackId, raceType = trackInfo[0], trackInfo[1]
     if raceType == RaceGlobals.ToonBattle:
         if ToontownGlobals.CIRCUIT_RACING in self.air.holidayManager.currentHolidays or ToontownGlobals.CIRCUIT_RACING_EVENT in self.air.holidayManager.currentHolidays or ToontownGlobals.SILLY_SATURDAY_CIRCUIT in self.air.holidayManager.currentHolidays:
             raceType = RaceGlobals.Circuit
     self.setTrackInfo([trackId, raceType])
     self.laps = trackInfo[2]
     self.sendUpdate('setTrackInfo', [self.trackInfo])
     return task.again
Exemplo n.º 25
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
    def changeTrack(self, task):
        trackInfo = RaceGlobals.getNextRaceInfo(self.trackInfo[0], self.genre,
                                                self.index)
        trackId, raceType = trackInfo[0], trackInfo[1]
        if raceType == RaceGlobals.ToonBattle:
            if ToontownGlobals.Holidays.CircuitRacing in self.air.holidayManager.currentHolidays or \
                    ToontownGlobals.Holidays.CircuitRacingEvent in self.air.holidayManager.currentHolidays or \
                    ToontownGlobals.Holidays.SillySaturdayCircuit in self.air.holidayManager.currentHolidays:
                raceType = RaceGlobals.Circuit

        self.setTrackInfo([trackId, raceType])
        self.laps = trackInfo[2]
        self.sendUpdate('setTrackInfo', [self.trackInfo])
        return task.again
Exemplo n.º 27
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.º 28
0
    def enterRace(self, task):
        trackId, raceType = self.trackInfo
        circuitLoop = []
        if raceType == RaceGlobals.Circuit:
            circuitLoop = RaceGlobals.getCircuitLoop(trackId)
        raceZone = self.air.raceMgr.createRace(trackId,
                                               raceType,
                                               self.laps,
                                               self.avIds,
                                               circuitLoop=circuitLoop[1:],
                                               circuitPoints={},
                                               circuitTimes={})
        for block in self.startingBlocks:
            self.sendUpdateToAvatarId(block.avId, 'setRaceZone', [raceZone])
            block.raceExit()

        return task.done
Exemplo n.º 29
0
    def cycleTrack(self, task=None):
        self.notify.debug("Cycling track - %s" % self.doId)
        raceInfo = RaceGlobals.getNextRaceInfo(self.trackId, self.tunnelGenre,
                                               self.tunnelId)
        self.trackId = raceInfo[0]
        self.trackType = raceInfo[1]

        #determine if this should be a Circuit race
        if self.trackType == RaceGlobals.ToonBattle:
            if bboard.get(CircuitRaceHolidayMgr.PostName):
                self.trackType = RaceGlobals.Circuit

        self.numLaps = raceInfo[2]
        self.sendUpdate("setTrackInfo", [[self.trackId, self.trackType]])
        self.cycleTrackTask = taskMgr.doMethodLater(
            RaceGlobals.TrackSignDuration, self.cycleTrack,
            self.uniqueName("cycleTrack"))
    def b_startRace(self, avIds):
        self.ignoreBarrier('readRules')
        if self.isDeleted():
            return
        self.notify.debug('Going!!!!!!')
        self.ignoreBarrier(self.waitingForReadyBarrier)
        self.toonCount = len(self.avIds)
        self.baseTime = globalClock.getFrameTime(
        ) + 0.5 + RaceGlobals.RaceCountdown
        for i in self.racers:
            self.racers[i].baseTime = self.baseTime

        self.sendUpdate('startRace',
                        [globalClockDelta.localToNetworkTime(self.baseTime)])
        qualTime = RaceGlobals.getQualifyingTime(self.trackId)
        timeout = qualTime + 60 + 3
        self.kickSlowRacersTask = taskMgr.doMethodLater(
            timeout, self.kickSlowRacers, 'kickSlowRacers')
Exemplo n.º 31
0
 def addAvBlock(self, avId, startingBlock, paid):
     av = self.air.doId2do.get(avId)
     if not av:
         return
     if not av.hasKart():
         return KartGlobals.ERROR_CODE.eNoKart
     if self.state == 'Off':
         return KartGlobals.ERROR_CODE.eTrackClosed
     if self.state in ('AllAboard', 'WaitBoarding'):
         return KartGlobals.ERROR_CODE.eBoardOver
     if startingBlock.avId != 0:
         return KartGlobals.ERROR_CODE.eOcuppied
     if RaceGlobals.getEntryFee(self.trackInfo[0],
                                self.trackInfo[1]) > av.getTickets():
         return KartGlobals.ERROR_CODE.eTickets
     self.avIds.append(avId)
     if not self.state == 'WaitCountdown':
         self.request('WaitCountdown')
     return KartGlobals.ERROR_CODE.success
 def updateTunnelSignText(self):
     self.notify.debugStateCall(self)
     trackNameString = TTLocalizer.KartRace_TrackNames[self.trackId]
     if not self.trackNameNode:
         self.notify.warning('invalid trackNameNode, just returning')
         return
     self.trackNameNode.setText(trackNameString)
     trackTypeString = TTLocalizer.KartRace_RaceNames[self.trackType]
     self.trackTypeNode.setText(trackTypeString)
     deposit = 0
     if self.trackType:
         deposit = RaceGlobals.getEntryFee(self.trackId, self.trackType)
     depositString = TTLocalizer.KartRace_DepositPhrase + str(deposit)
     self.depositNode.setText(depositString)
     time = RaceGlobals.TrackDict[self.trackId][1]
     secs, hundredths = divmod(time, 1)
     min, sec = divmod(secs, 60)
     timeText = '%02d:%02d:%02d' % (min, sec, hundredths * 100)
     qualifyString = TTLocalizer.KartRace_QualifyPhrase + timeText
     self.qualifyNode.setText(qualifyString)
def spawn(air, zone, element, match):
    index = int(match.group(1))
    dest = match.group(2)
    pad = DistributedRacePadAI(air)
    pad.setArea(zone)
    pad.nameType = dest
    pad.index = index
    nri = RaceGlobals.getNextRaceInfo(-1, dest, index)
    pad.setTrackInfo(nri[:2])
    pad.generateWithRequired(zone)
    for child in element.children:
        if isinstance(child, DNAProp) and child.code == 'gs_parkingspot':
            index = int(child.name[15:])
            x, y, z = child.getPos()
            h, p, r = child.getHpr()
            startingBlock = DistributedStartingBlockAI(air)
            startingBlock.setPosHpr(x, y, z, h, p, r)
            startingBlock.setPadDoId(pad.getDoId())
            startingBlock.setPadLocationId(index)
            startingBlock.generateWithRequired(zone)
            pad.addStartingBlock(startingBlock)
Exemplo n.º 34
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
Exemplo n.º 35
0
def spawn(air, zone, element, match):
    index = int(match.group(1))
    dest = match.group(2)
    pad = DistributedRacePadAI(air)
    pad.setArea(zone)
    pad.nameType = dest
    pad.index = index
    nri = RaceGlobals.getNextRaceInfo(-1, dest, index)
    pad.setTrackInfo(nri[:2])
    pad.generateWithRequired(zone)
    for child in element.children:
        if isinstance(child, DNAProp) and child.code == 'gs_parkingspot':
            index = int(child.name[15:])
            x, y, z = child.getPos()
            h, p, r = child.getHpr()
            startingBlock = DistributedStartingBlockAI(air)
            startingBlock.setPosHpr(x, y, z, h, p, r)
            startingBlock.setPadDoId(pad.getDoId())
            startingBlock.setPadLocationId(index)
            startingBlock.generateWithRequired(zone)
            pad.addStartingBlock(startingBlock)
Exemplo n.º 36
0
    def __init__(self, air, area, tunnelGenre, tunnelId):
        """
        COMMENT
        """

        # Initialize the KartPadAI and FSM Super Classes
        DistributedKartPadAI.__init__(self, air, area)
        FSM.__init__(self, "RacePad_%s_FSM" % (DistributedRacePadAI.id))

        # Initialize Instance Variables
        self.id = DistributedRacePadAI.id
        DistributedRacePadAI.id += 1

        self.tunnelId = tunnelId
        self.tunnelGenre = tunnelGenre
        self.timerTask = None
        raceInfo = RaceGlobals.getNextRaceInfo(-1, tunnelGenre, tunnelId)
        self.trackId = raceInfo[0]
        self.trackType = raceInfo[1]
        self.numLaps = raceInfo[2]
        self.raceMgr = self.air.raceMgr
    def b_startTutorial(self, avIds):
        self.ignoreBarrier('waitingForReady')
        racersOut = []
        for i in self.avIds:
            if i not in avIds:
                racersOut.append(i)

        if len(avIds) == 0:
            self.exitBarrier = self.beginBarrier('waitingForExit', self.avIds,
                                                 10, self.endRace)
        for i in racersOut:
            self.d_kickRacer(i)

        if len(avIds) == 0:
            return
        for avId in avIds:
            av = self.air.doId2do.get(avId, None)
            if not av:
                self.notify.warning(
                    'b_racersJoined: Avatar not found with id %s' % avId)
            elif not self.raceType == RaceGlobals.Practice:
                if self.isCircuit() and not self.isFirstRace():
                    continue
                raceFee = RaceGlobals.getEntryFee(self.trackId, self.raceType)
                avTickets = av.getTickets()
                if avTickets < raceFee:
                    self.notify.warning(
                        'b_racersJoined: Avatar %s does not own enough tickets for the race!'
                    )
                    av.b_setTickets(0)
                else:
                    av.b_setTickets(avTickets - raceFee)

        self.avIds = avIds
        self.readRulesBarrier = self.beginBarrier('readRules', self.avIds, 10,
                                                  self.b_startRace)
        self.sendUpdate('startTutorial', [])
        return
 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)
Exemplo n.º 39
0
    def _createObjects(self, group, zone):
        if group.getName()[:13] == "fishing_pond_":
            visGroup = group.getVisGroup()
            pondZone = 0
            if visGroup is None:
                pondZone = zone
            else:
                pondZone = int(visGroup.getName().split(":")[0])

            pondIndex = int(group.getName()[13:])
            pond = DistributedFishingPondAI(simbase.air)
            pond.setArea(zone)
            pond.generateWithRequired(pondZone)

            bingoManager = DistributedPondBingoManagerAI(simbase.air)
            bingoManager.setPondDoId(pond.getDoId())
            bingoManager.generateWithRequired(pondZone)
            # temporary, until we have scheduled stuff
            bingoManager.createGame()
            pond.bingoMgr = bingoManager
            simbase.air.fishManager.ponds[zone] = pond

            for i in range(FishingTargetGlobals.getNumTargets(zone)):
                target = DistributedFishingTargetAI(simbase.air)
                target.setPondDoId(pond.getDoId())
                target.generateWithRequired(pondZone)

            for i in range(group.getNumChildren()):
                posSpot = group.at(i)
                if posSpot.getName()[:13] == "fishing_spot_":
                    posSpot = group.atAsNode(i)
                    spot = DistributedFishingSpotAI(simbase.air)
                    spot.setPondDoId(pond.getDoId())
                    x, y, z = posSpot.getPos()
                    h, p, r = posSpot.getHpr()
                    spot.setPosHpr(x, y, z, h, p, r)
                    spot.generateWithRequired(pondZone)

            NPCToons.createNpcsInZone(simbase.air, pondZone)

        elif group.getName()[:10] == "racing_pad":
            index, dest = group.getName()[11:].split("_", 2)
            index = int(index)

            pad = DistributedRacePadAI(simbase.air)
            pad.setArea(zone)
            pad.nameType = dest
            pad.index = index
            nri = RaceGlobals.getNextRaceInfo(-1, dest, index)
            pad.setTrackInfo([nri[0], nri[1]])
            pad.generateWithRequired(zone)
            for i in range(group.getNumChildren()):
                posSpot = group.at(i)
                if posSpot.getName()[:14] == "starting_block":
                    spotIndex = int(posSpot.getName()[15:])
                    posSpot = group.atAsNode(i)
                    x, y, z = posSpot.getPos()
                    h, p, r = posSpot.getHpr()
                    startingBlock = DistributedStartingBlockAI(simbase.air)
                    startingBlock.setPosHpr(x, y, z, h, p, r)
                    startingBlock.setPadDoId(pad.getDoId())
                    startingBlock.setPadLocationId(index)
                    startingBlock.generateWithRequired(zone)
                    pad.addStartingBlock(startingBlock)

        elif group.getName()[:11] == "viewing_pad":
            pad = DistributedViewPadAI(simbase.air)
            pad.setArea(zone)
            pad.generateWithRequired(zone)
            for i in range(group.getNumChildren()):
                posSpot = group.at(i)
                if posSpot.getName()[:14] == "starting_block":
                    spotIndex = int(posSpot.getName()[15:])
                    posSpot = group.atAsNode(i)
                    x, y, z = posSpot.getPos()
                    h, p, r = posSpot.getHpr()
                    startingBlock = DistributedViewingBlockAI(simbase.air)
                    startingBlock.setPosHpr(x, y, z, h, p, r)
                    startingBlock.setPadDoId(pad.getDoId())
                    startingBlock.setPadLocationId(0)
                    startingBlock.generateWithRequired(zone)
                    pad.addStartingBlock(startingBlock)

        elif group.getName()[:13] == "picnic_table_" and zone != 7000:
            pos = group.getPos()
            hpr = group.getHpr()
            nameInfo = group.getName().split("_")
            picnicTable = DistributedPicnicBasketAI.DistributedPicnicBasketAI(
                simbase.air, nameInfo[2], pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]
            )
            picnicTable.generateWithRequired(zone)
            picnicTable.start()

        elif group.getName() == "prop_game_table_DNARoot" and config.GetBool("want-oz-game-tables", True):
            pos = group.getPos()
            hpr = group.getHpr()
            nameInfo = group.getName().split("_")
            tableIndex = int(group.parent.getName().split("_")[-1])
            picnicTable = DistributedPicnicTableAI.DistributedPicnicTableAI(
                simbase.air, zone, nameInfo[2], pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]
            )
            picnicTable.setTableIndex(tableIndex)
            picnicTable.generateOtpObject(
                simbase.air.districtId, zone, ["setX", "setY", "setZ", "setH", "setP", "setR"]
            )

        elif group.getName()[:9] == "golf_kart" and config.GetBool("want-golf-karts", True):
            info = group.getName()[10:].split("_")
            golfCourse = int(info[0])
            kartId = info[1]
            for i in range(group.getNumChildren()):
                prop = group.at(i)
                if prop.getName()[:15] == "starting_block_":
                    pos, hpr = (prop.getPos(), prop.getHpr())

            kart = DistributedGolfKartAI.DistributedGolfKartAI(
                simbase.air, golfCourse, pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]
            )
            kart.generateWithRequired(zone)
            kart.sendUpdate("setGolfCourse", [golfCourse])
            kart.sendUpdate("setPosHpr", [pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]])
            color = kart.getColor()
            kart.sendUpdate("setColor", [color[0], color[1], color[2]])
            kart.start()

        if group.getName()[:15] == "prop_party_gate" and simbase.air.wantParties:
            gate = DistributedPartyGateAI(simbase.air)
            gate.setArea(zone)
            gate.generateWithRequired(zone)

        for i in range(group.getNumChildren()):
            child = group.at(i)
            self._createObjects(child, zone)
Exemplo n.º 40
0
    def _createObjects(self, group, zone):
        if group.getName()[:13] == 'fishing_pond_':
            visGroup = group.getVisGroup()
            pondZone = 0
            if visGroup is None:
                pondZone = zone
            else:
                pondZone = int(visGroup.getName().split(':')[0])

            pondIndex = int(group.getName()[13:])
            pond = DistributedFishingPondAI(simbase.air)
            pond.setArea(zone)
            pond.generateWithRequired(pondZone)
            #self.ponds[pondIndex] = pond
            
            bingoManager = DistributedPondBingoManagerAI(simbase.air)
            bingoManager.setPondDoId(pond.getDoId())
            bingoManager.generateWithRequired(pondZone)
            #temporary, until we have scheduled stuff
            bingoManager.createGame()
            pond.bingoMgr = bingoManager
            simbase.air.fishManager.ponds[zone] = pond

            for i in range(FishingTargetGlobals.getNumTargets(zone)):
                target = DistributedFishingTargetAI(simbase.air)
                target.setPondDoId(pond.getDoId())
                target.generateWithRequired(pondZone)

            for i in range(group.getNumChildren()):
                posSpot = group.at(i)
                if posSpot.getName()[:13] == 'fishing_spot_':
                    spot = DistributedFishingSpotAI(simbase.air)
                    spot.setPondDoId(pond.getDoId())
                    x, y, z = posSpot.getPos()
                    h, p, r = posSpot.getHpr()
                    spot.setPosHpr(x, y, z, h, p, r)
                    spot.generateWithRequired(pondZone)
                    
            NPCToons.createNpcsInZone(simbase.air, pondZone)
      
        elif group.getName()[:10] == 'racing_pad':
            index, dest = group.getName()[11:].split('_', 2)
            index = int(index)
            
            pad = DistributedRacePadAI(simbase.air)
            pad.setArea(zone)
            pad.nameType = dest
            pad.index = index
            nri = RaceGlobals.getNextRaceInfo(-1, dest, index)
            pad.setTrackInfo([nri[0], nri[1]])
            pad.generateWithRequired(zone)
            for i in range(group.getNumChildren()):
                posSpot = group.at(i)
                if posSpot.getName()[:14] == 'starting_block':
                    spotIndex = int(posSpot.getName()[15:])
                    x, y, z = posSpot.getPos()
                    h, p, r = posSpot.getHpr()
                    startingBlock = DistributedStartingBlockAI(simbase.air)
                    startingBlock.setPosHpr(x, y, z, h, p, r)
                    startingBlock.setPadDoId(pad.getDoId())
                    startingBlock.setPadLocationId(index)
                    startingBlock.generateWithRequired(zone)
                    pad.addStartingBlock(startingBlock)
        elif group.getName()[:11] == 'viewing_pad':
            pad = DistributedViewPadAI(simbase.air)
            pad.setArea(zone)
            pad.generateWithRequired(zone)
            for i in range(group.getNumChildren()):
                posSpot = group.at(i)
                if posSpot.getName()[:14] == 'starting_block':
                    spotIndex = int(posSpot.getName()[15:])
                    x, y, z = posSpot.getPos()
                    h, p, r = posSpot.getHpr()
                    startingBlock = DistributedViewingBlockAI(simbase.air)
                    startingBlock.setPosHpr(x, y, z, h, p, r)
                    startingBlock.setPadDoId(pad.getDoId())
                    startingBlock.setPadLocationId(0)
                    startingBlock.generateWithRequired(zone)
                    pad.addStartingBlock(startingBlock)
        if group.getName()[:15] == 'prop_party_gate':
            gate = DistributedPartyGateAI(simbase.air)
            gate.setArea(zone)
            gate.generateWithRequired(zone)
        for i in range(group.getNumChildren()):
            self._createObjects(group.at(i), zone)
Exemplo n.º 41
0
 def exitedRace(self, race, playerInfo):
     self.notify.debug('exited race: %s' % playerInfo.avId)
     totalTime = playerInfo.totalTime
     entryFee = 0
     bonus = 0
     placeMultiplier = 0
     qualify = 0
     winnings = 0
     trophies = []
     points = []
     newHistory = None
     race.playersFinished.append(playerInfo.avId)
     place = len(race.playersFinished)
     self.notify.debug('place: %s of %s' % (place, race.toonCount))
     self.notify.debug('pre-tie totalTime: %s' % totalTime)
     if totalTime <= race.lastTotalTime:
         totalTime = race.lastTotalTime + 0.01
     race.lastTotalTime = totalTime
     self.notify.debug(
         'totalTime: %s, qualify: %s' %
         (totalTime, RaceGlobals.getQualifyingTime(race.trackId)))
     circuitTime = totalTime + race.circuitTimes.get(playerInfo.avId, 0)
     race.circuitTimes[playerInfo.avId] = circuitTime
     if not race.circuitTimeList.get(playerInfo.avId):
         race.circuitTimeList[playerInfo.avId] = []
     race.circuitTimeList[playerInfo.avId].append([totalTime, 0])
     self.notify.debug('CircuitTimeList %s' % race.circuitTimeList)
     if race.raceType == RaceGlobals.Circuit:
         points = race.circuitPoints.get(playerInfo.avId, [])
         points.append(RaceGlobals.CircuitPoints[place - 1])
         race.circuitPoints[playerInfo.avId] = points
     currentTimeIndex = len(race.circuitTimeList[playerInfo.avId]) - 1
     if totalTime <= RaceGlobals.getQualifyingTime(race.trackId):
         race.circuitTimeList[playerInfo.avId][currentTimeIndex][1] = 1
         self.notify.debug(
             'Racer Qualified time: %s required: %s' %
             (totalTime, RaceGlobals.getQualifyingTime(race.trackId)))
         qualify = 1
         self.checkPersonalBest(race.trackId, totalTime, race.raceType,
                                race.toonCount, playerInfo.avId)
         if race.raceType == RaceGlobals.Practice:
             winnings = RaceGlobals.PracticeWinnings
             self.notify.debug(
                 'GrandTouring: Checking from branch: practice %s' %
                 playerInfo.avId)
             trophies = self.checkForNonRaceTrophies(playerInfo.avId)
             if trophies:
                 self.updateTrophiesFromList(playerInfo.avId, trophies)
         else:
             self.air.writeServerEvent('kartingPlaced', playerInfo.avId,
                                       '%s|%s' % (place, race.toonCount))
             if race.raceType != RaceGlobals.Circuit:
                 entryFee = RaceGlobals.getEntryFee(race.trackId,
                                                    race.raceType)
                 placeMultiplier = RaceGlobals.Winnings[
                     place - 1 + (RaceGlobals.MaxRacers - race.toonCount)]
                 winnings = int(entryFee * placeMultiplier)
                 newHistory = self.getNewSingleRaceHistory(
                     race, playerInfo.avId, place)
                 av = self.air.doId2do.get(playerInfo.avId)
                 if newHistory:
                     self.notify.debug('history %s' % newHistory)
                     av.b_setKartingHistory(newHistory)
                     trophies = self.checkForRaceTrophies(
                         race, playerInfo.avId)
                 else:
                     trophies = self.checkForNonRaceTrophies(
                         playerInfo.avId)
                 if trophies:
                     self.updateTrophiesFromList(playerInfo.avId, trophies)
             bonus = self.checkTimeRecord(race.trackId, totalTime,
                                          race.raceType, race.toonCount,
                                          playerInfo.avId)
             if playerInfo.avId in race.circuitTotalBonusTickets:
                 race.circuitTotalBonusTickets[playerInfo.avId] += bonus
             else:
                 race.circuitTotalBonusTickets[playerInfo.avId] = bonus
         av = self.air.doId2do.get(playerInfo.avId)
         if av:
             oldTickets = av.getTickets()
             self.notify.debug('old tickets: %s' % oldTickets)
             newTickets = oldTickets + winnings + entryFee + bonus
             self.air.writeServerEvent('kartingTicketsWon', playerInfo.avId,
                                       '%s' % (newTickets - oldTickets))
             self.notify.debug('entry fee: %s' % entryFee)
             self.notify.debug('place mult: %s' % placeMultiplier)
             self.notify.debug('winnings: %s' % winnings)
             self.notify.debug('bonus: %s' % bonus)
             self.notify.debug('new tickets: %s' % newTickets)
             self.notify.debug('circuit points: %s' % points)
             self.notify.debug('circuit time: %s' % circuitTime)
             self.notify.debug('circuitTotalBonusTickets: %s' %
                               race.circuitTotalBonusTickets)
             av.b_setTickets(newTickets)
     else:
         race.circuitTimeList[playerInfo.avId][currentTimeIndex][1] = -1
         self.notify.debug(
             'GrandTouring: Checking from branch: Not Qualified %s' %
             playerInfo.avId)
         trophies = self.checkForNonRaceTrophies(playerInfo.avId)
         if trophies:
             self.updateTrophiesFromList(playerInfo.avId, trophies)
     if race in self.races:
         race.d_setPlace(playerInfo.avId, totalTime, place, entryFee,
                         qualify, winnings, bonus, trophies, points,
                         circuitTime)
         if race.isCircuit():
             self.notify.debug('isCircuit')
             if race.everyoneDone():
                 self.notify.debug('everyoneDone')
                 if race.isLastRace():
                     taskMgr.doMethodLater(
                         10, self.endCircuitRace,
                         'DelayEndCircuitRace=%d' % race.doId,
                         (race, bonus))
                 else:
                     self.endCircuitRace(race, bonus)
         else:
             self.notify.debug('not isCircuit')
     return
 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)
Exemplo n.º 43
0
 def changeTrack(self):
     nri = RaceGlobals.getNextRaceInfo(self.trackId, self.nameType, self.index)
     self.b_setTrackInfo([nri[0], nri[1]])
     taskMgr.doMethodLater(30, DistributedRacePadAI.changeTrack, 'changeTrack%i' % self.doId, [self])