racing: we got leaderboards

This commit is contained in:
John Cote 2020-01-05 22:09:53 -05:00
parent 22486021aa
commit ec12097b06
3 changed files with 12 additions and 7 deletions

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ whitelist/
*.jpg
.idea
*.buildings
*.trackRecords

View file

@ -35,7 +35,11 @@ class DistributedLeaderBoardAI(DistributedObjectAI):
self.subscriptions.append(subscription)
def handleUpdateRaceRecord(self, record):
self.notify.info('handleUpdateRaceRecord TODO')
trackId, period = record
if trackId not in self.records:
return
self.records[trackId][period] = [(x[0], x[3]) for x in self.air.raceMgr.getRecords(trackId, period)]
def updateDisplay(self):
self.currentIndex += 1

View file

@ -323,7 +323,7 @@ class RaceManagerAI(DirectObject.DirectObject):
self.notify.debug('trophies %s' % trophies)
self.notify.debug('GrandTouring: already has grand touring %s' % trophies[RaceGlobals.GrandTouring])
for i in range(1, RaceGlobals.NumTrophies // RaceGlobals.TrophiesPerCup + 1):
cupNum = (trophies[:RaceGlobals.NumTrophies].count(1) + addTrophyCount) / (i * RaceGlobals.TrophiesPerCup)
cupNum = (trophies[:RaceGlobals.NumTrophies].count(1) + addTrophyCount) // (i * RaceGlobals.TrophiesPerCup)
self.notify.debug('cupNum: %s' % cupNum)
trophyIndex = RaceGlobals.TrophyCups[i - 1]
if cupNum and not trophies[trophyIndex]:
@ -545,8 +545,8 @@ class RaceManagerAI(DirectObject.DirectObject):
newTrophies.append(totalTrophyIndex)
self.air.writeServerEvent('kartingTrophy', avId, '%s' % totalTrophyIndex)
self.notify.debug('trophy: ' + TTLocalizer.KartTrophyDescriptions[totalTrophyIndex])
for i in range(1, RaceGlobals.NumTrophies / RaceGlobals.TrophiesPerCup + 1):
cupNum = trophies[:RaceGlobals.NumTrophies].count(1) / (i * RaceGlobals.TrophiesPerCup)
for i in range(1, RaceGlobals.NumTrophies // RaceGlobals.TrophiesPerCup + 1):
cupNum = trophies[:RaceGlobals.NumTrophies].count(1) // (i * RaceGlobals.TrophiesPerCup)
self.notify.debug('cupNum: %s' % cupNum)
trophyIndex = RaceGlobals.TrophyCups[i - 1]
if cupNum and not trophies[trophyIndex]:
@ -610,7 +610,7 @@ class RaceManagerAI(DirectObject.DirectObject):
backup = self.filename + '.bu'
if os.path.exists(self.filename):
os.rename(self.filename, backup)
file = open(self.filename, 'w')
file = open(self.filename, 'wb')
file.seek(0)
pickle.dump(self.trackRecords, file)
file.close()
@ -624,12 +624,12 @@ class RaceManagerAI(DirectObject.DirectObject):
def loadRecords(self):
try:
file = open(self.filename + '.bu', 'r')
file = open(self.filename + '.bu', 'rb')
if os.path.exists(self.filename):
os.remove(self.filename)
except IOError:
try:
file = open(self.filename, 'r')
file = open(self.filename, 'rb')
except IOError:
return self.getRecordTimes()