mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2025-01-09 17:53:50 +00:00
DANIEL: Leaderboards are done 8======D
This commit is contained in:
parent
9db517cfb3
commit
4cda455edc
9 changed files with 142 additions and 31 deletions
2
dependencies/astron/dclass/stride.dc
vendored
2
dependencies/astron/dclass/stride.dc
vendored
|
@ -2625,7 +2625,7 @@ dclass DistributedViewingBlock : DistributedStartingBlock {
|
|||
|
||||
struct LeaderboardResult {
|
||||
string name;
|
||||
uint32 time;
|
||||
uint16 time;
|
||||
};
|
||||
|
||||
dclass DistributedLeaderBoard : DistributedObject {
|
||||
|
|
|
@ -44,6 +44,7 @@ from toontown.hood import OZHoodAI
|
|||
from toontown.hood import SellbotHQAI
|
||||
from toontown.hood import TTHoodAI
|
||||
from toontown.hood import ZoneUtil
|
||||
from toontown.racing.LeaderboardMgrAI import LeaderboardMgrAI
|
||||
from toontown.pets.PetManagerAI import PetManagerAI
|
||||
from toontown.safezone.SafeZoneManagerAI import SafeZoneManagerAI
|
||||
from toontown.suit.SuitInvasionManagerAI import SuitInvasionManagerAI
|
||||
|
@ -81,6 +82,7 @@ class ToontownAIRepository(ToontownInternalRepository):
|
|||
self.wantFishing = self.config.GetBool('want-fishing', True)
|
||||
self.wantHousing = self.config.GetBool('want-housing', True)
|
||||
self.wantPets = self.config.GetBool('want-pets', True)
|
||||
self.wantKarts = self.config.GetBool('want-karts', True)
|
||||
self.wantParties = self.config.GetBool('want-parties', True)
|
||||
self.wantEmblems = self.config.GetBool('want-emblems', True)
|
||||
self.wantCogbuildings = self.config.GetBool('want-cogbuildings', True)
|
||||
|
@ -126,6 +128,8 @@ class ToontownAIRepository(ToontownInternalRepository):
|
|||
self.buildingQueryMgr = DistributedBuildingQueryMgrAI(self)
|
||||
self.buildingQueryMgr.generateWithRequired(2)
|
||||
self.groupManager.generateWithRequired(2)
|
||||
if self.wantKarts:
|
||||
self.leaderboardMgr = LeaderboardMgrAI(self)
|
||||
if self.wantFishing:
|
||||
self.fishManager = FishManagerAI(self)
|
||||
if self.wantHousing:
|
||||
|
|
|
@ -122,6 +122,9 @@ class GSHoodAI(HoodAI.HoodAI):
|
|||
viewPad.addStartingBlock(viewingBlock)
|
||||
|
||||
def findLeaderBoards(self, dnaGroup, zoneId):
|
||||
if not self.air.wantKarts:
|
||||
return
|
||||
|
||||
leaderBoards = []
|
||||
|
||||
if isinstance(dnaGroup, DNAGroup) and ('leader_board' in dnaGroup.getName()):
|
||||
|
|
|
@ -84,12 +84,8 @@ class DistributedLeaderBoard(DistributedObject.DistributedObject):
|
|||
self.nameTextNodes[i].setText('-')
|
||||
self.timeTextNodes[i].setText('-')
|
||||
else:
|
||||
name = pLeaderList[i][1]
|
||||
time = pLeaderList[i][0]
|
||||
secs, hundredths = divmod(time, 1)
|
||||
min, sec = divmod(secs, 60)
|
||||
self.nameTextNodes[i].setText(name[:22])
|
||||
self.timeTextNodes[i].setText('%02d:%02d:%02d' % (min, sec, hundredths * 100))
|
||||
self.nameTextNodes[i].setText(pLeaderList[i][0][:22])
|
||||
self.timeTextNodes[i].setText(TTLocalizer.convertSecondsToDate(pLeaderList[i][1]))
|
||||
|
||||
def buildTitleRow(self):
|
||||
row = hidden.attachNewNode('TitleRow')
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.task import Task
|
||||
from direct.distributed.DistributedObjectAI import DistributedObjectAI
|
||||
import random
|
||||
from toontown.racing import RaceGlobals
|
||||
import random, time
|
||||
|
||||
class DistributedLeaderBoardAI(DistributedObjectAI):
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedLeaderBoardAI")
|
||||
|
@ -9,39 +10,78 @@ class DistributedLeaderBoardAI(DistributedObjectAI):
|
|||
def __init__(self, air, displays):
|
||||
DistributedObjectAI.__init__(self, air)
|
||||
self.displays = displays
|
||||
self.display = (0, 0, [])
|
||||
self.display = [0, 0, []]
|
||||
self.currentId = 0
|
||||
self.posHpr = (0, 0, 0, 0, 0, 0)
|
||||
|
||||
|
||||
def generateWithRequired(self, zoneId):
|
||||
DistributedObjectAI.generateWithRequired(self, zoneId)
|
||||
self.setup()
|
||||
|
||||
self.accept('goofyLeaderboardChange', self.__setDisplay)
|
||||
self.accept('goofyLeaderboardDisplay', self.__setDisplayRace)
|
||||
self.__updateDisplay()
|
||||
self.switchTask = taskMgr.doMethodLater(15, self.nextDisplay, 'leaderboardSwitchTask-%s' % random.random())
|
||||
|
||||
def delete(self):
|
||||
DistributedObjectAI.delete(self)
|
||||
self.ignoreAll()
|
||||
taskMgr.remove(self.switchTask)
|
||||
|
||||
def setup(self):
|
||||
self.currentId = 0
|
||||
self.switchDisplay()
|
||||
self.switchTask = taskMgr.doMethodLater(15, self.switchDisplay, 'leaderboardSwitchTask-%s' % random.random())
|
||||
|
||||
def switchDisplay(self, task=None):
|
||||
race = self.displays[self.currentId]
|
||||
|
||||
self.display = (race[0], race[1], [])
|
||||
self.currentId += 1
|
||||
|
||||
if self.currentId >= len(self.displays):
|
||||
self.currentId = 0
|
||||
|
||||
self.sendUpdate('setDisplay', [self.display[0], self.display[1], self.display[2]])
|
||||
return Task.again
|
||||
|
||||
def setPosHpr(self, x, y, z, h, p, r):
|
||||
self.posHpr = (x, y, z, h, p, r)
|
||||
|
||||
def getPosHpr(self):
|
||||
return self.posHpr
|
||||
|
||||
|
||||
def getDisplay(self):
|
||||
return self.display
|
||||
return self.display
|
||||
|
||||
def getDisplayName(self):
|
||||
return '%s, %s' % (self.display[0], self.display[1])
|
||||
|
||||
def getMaxTimeDifference(self):
|
||||
return RaceGlobals.MaxTimeDifference[self.display[1]]
|
||||
|
||||
def hasMaxTimeDifference(self):
|
||||
return self.display[1] in RaceGlobals.MaxTimeDifference
|
||||
|
||||
def nextDisplay(self, task=None):
|
||||
self.__updateDisplay()
|
||||
self.currentId += 1
|
||||
|
||||
if self.currentId >= len(self.displays):
|
||||
self.currentId = 0
|
||||
|
||||
return Task.again
|
||||
|
||||
def __setDisplayRace(self, race):
|
||||
self.currentId = race
|
||||
self.__updateDisplay()
|
||||
|
||||
def __updateDisplay(self):
|
||||
race = self.displays[self.currentId]
|
||||
|
||||
self.display = [race[0], race[1], []]
|
||||
self.__setDisplay()
|
||||
|
||||
def __setDisplay(self):
|
||||
database = self.air.leaderboardMgr.getDatabase()
|
||||
displayName = self.getDisplayName()
|
||||
|
||||
if not displayName in database:
|
||||
self.sendDisplayUpdate([])
|
||||
return
|
||||
|
||||
displayEntry = database[displayName]
|
||||
|
||||
if self.hasMaxTimeDifference():
|
||||
difference = time.time() - displayEntry[0]
|
||||
|
||||
if difference >= self.getMaxTimeDifference():
|
||||
self.air.leaderboardMgr.clearRace(displayName)
|
||||
return
|
||||
|
||||
self.sendDisplayUpdate(self.air.leaderboardMgr.trimList(displayEntry[1]))
|
||||
|
||||
def sendDisplayUpdate(self, players):
|
||||
self.display[2] = players
|
||||
self.sendUpdate('setDisplay', self.display)
|
|
@ -303,6 +303,7 @@ class DistributedRaceAI(DistributedObjectAI, FSM):
|
|||
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 = []
|
||||
|
|
61
toontown/racing/LeaderboardMgrAI.py
Normal file
61
toontown/racing/LeaderboardMgrAI.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
from otp.ai.MagicWordGlobal import *
|
||||
import RaceGlobals, operator, time
|
||||
|
||||
class LeaderboardMgrAI:
|
||||
|
||||
def __init__(self, air):
|
||||
self.air = air
|
||||
self.database = simbase.backups.load('leaderboard', (self.air.districtId,), default=({}))
|
||||
|
||||
def getDatabase(self):
|
||||
return self.database
|
||||
|
||||
def saveDatabase(self):
|
||||
simbase.backups.save('leaderboard', (self.air.districtId,), self.database)
|
||||
messenger.send('goofyLeaderboardChange')
|
||||
|
||||
def trimList(self, list):
|
||||
return list[:RaceGlobals.NumRecordsPerPeriod]
|
||||
|
||||
def clearRace(self, race):
|
||||
if race in self.database:
|
||||
del self.database[race]
|
||||
self.saveDatabase()
|
||||
|
||||
def submitRace(self, raceId, name, timestamp):
|
||||
for i in xrange(3):
|
||||
race = '%s, %s' % (raceId, i)
|
||||
|
||||
if race in self.database:
|
||||
originalRace = self.database[race][1]
|
||||
newRace = list(originalRace)
|
||||
|
||||
newRace.append((name, timestamp))
|
||||
sortedRace = self.trimList(sorted(newRace, key=operator.itemgetter(1)))
|
||||
|
||||
if originalRace != sortedRace:
|
||||
self.database[race][1] = sortedRace
|
||||
else:
|
||||
self.database[race] = (time.time(), [(name, timestamp)])
|
||||
|
||||
self.saveDatabase()
|
||||
|
||||
@magicWord(category=CATEGORY_PROGRAMMER, types=[str, int, int, str, int])
|
||||
def leaderboard(command, raceId=0, type=0, name='', time=0):
|
||||
command = command.lower()
|
||||
race = '%s, %s' % (raceId, type)
|
||||
|
||||
if command == 'clear':
|
||||
simbase.air.leaderboardMgr.clearRace(race)
|
||||
return 'Cleared race %s!' % race
|
||||
elif command == 'submit':
|
||||
simbase.air.leaderboardMgr.submitRace(raceId, name, time)
|
||||
return 'Submitted race %s for %s with %s seconds!' % (raceId, name, time)
|
||||
elif command == 'refresh':
|
||||
messenger.send('goofyLeaderboardChange')
|
||||
return 'Refreshed leaderboards!'
|
||||
elif command == 'change':
|
||||
messenger.send('goofyLeaderboardDisplay', [raceId])
|
||||
return 'Made all leaderboards show %s!' % raceId
|
||||
else:
|
||||
return 'Unknown command! Commands:\n- clear\n- submit\n- refresh\n- change'
|
|
@ -553,3 +553,8 @@ Exit_UserReq = 0
|
|||
Exit_Barrier = 1
|
||||
Exit_Slow = 2
|
||||
Exit_BarrierNoRefund = 3
|
||||
|
||||
MaxTimeDifference = {
|
||||
0: 86400,
|
||||
1: 604800
|
||||
}
|
|
@ -8473,3 +8473,4 @@ def convertSecondsToDate(seconds):
|
|||
h, m = divmod(m, 60)
|
||||
|
||||
print '%d:%02d:%02d' % (h, m, s)
|
||||
return '%d:%02d:%02d' % (h, m, s)
|
||||
|
|
Loading…
Reference in a new issue