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.setCircuitLoop([]) race.setAvatars(avatars) race.setStartingPlaces(list(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())
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)
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.setCircuitLoop([]) race.setAvatars(avatars) 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())
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)
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 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 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 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)
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 __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)
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)
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')
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 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 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 endCircuitRace(self, race, bonus=0): self.notify.debug('endCircuitRace') pointTotals = [] for avId in race.circuitPoints: pointTotals.append([avId, sum(race.circuitPoints[avId])]) numVals = len(pointTotals) finalStandings = [] def swap(x, y): t = pointTotals[x] pointTotals[x] = pointTotals[y] pointTotals[y] = t for i in range(numVals - 1, 0, -1): for j in range(i): if pointTotals[j][1] < pointTotals[j + 1][1]: swap(j, j + 1) elif pointTotals[j][1] == pointTotals[j + 1][1]: avId1 = pointTotals[j][0] avId2 = pointTotals[j + 1][0] if race.circuitTimes[avId1] > race.circuitTimes[avId2]: swap(j, j + 1) for i in range(numVals): finalStandings.append(pointTotals[i][0]) self.notify.debug('Final standings %s' % finalStandings) for avId in finalStandings: self.notify.debug('avId %s' % avId) place = finalStandings.index(avId) + 1 places = len(finalStandings) winnings = 0 trophies = [] if race.isLastRace(): self.notify.debug('isLastRace') av = self.air.doId2do.get(avId) if av and avId in race.playersFinished: self.air.writeServerEvent('kartingCircuitFinished', avId, '%s|%s' % (place, places)) print('kartingCircuitFinished', avId, '%s|%s' % (place, places)) entryFee = RaceGlobals.getEntryFee(race.trackId, race.raceType) placeMultiplier = RaceGlobals.Winnings[ place - 1 + (RaceGlobals.MaxRacers - places)] winnings = int(entryFee * placeMultiplier) newHistory = self.getNewCircuitHistory(race, avId, place) if newHistory: self.notify.debug('history %s' % newHistory) trophies = self.checkForCircuitTrophies( race, avId, newHistory) av.b_setKartingHistory(newHistory) if trophies: self.updateTrophiesFromList(avId, trophies) else: self.notify.debug('no new history') trophies = self.checkForNonRaceTrophies(avId) oldTickets = av.getTickets() self.notify.debug('endCircuitRace: old tickets: %s' % oldTickets) newTickets = oldTickets + winnings + entryFee self.air.writeServerEvent('kartingTicketsWonCircuit', 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('new tickets: %s' % newTickets) self.notify.debug('trophies: %s' % trophies) self.notify.debug('bonus: %s' % bonus) av.b_setTickets(newTickets) finalBonus = 0 if avId in race.circuitTotalBonusTickets: finalBonus = race.circuitTotalBonusTickets[avId] race.d_setCircuitPlace(avId, place, entryFee, winnings, finalBonus, trophies) race.playersFinished = finalStandings race.d_endCircuitRace()