oldschool-toontown/toontown/racing/DistributedRacePadAI.py

119 lines
4.2 KiB
Python
Raw Normal View History

2019-11-08 22:55:55 -06:00
from direct.directnotify import DirectNotifyGlobal
2019-12-05 21:42:29 -06:00
from direct.distributed.ClockDelta import globalClockDelta
from direct.fsm.FSM import FSM
2019-11-08 22:55:55 -06:00
2020-01-02 16:36:49 -06:00
from toontown.racing import RaceGlobals
2019-12-05 21:42:29 -06:00
from toontown.racing.DistributedKartPadAI import DistributedKartPadAI
2020-01-02 16:36:49 -06:00
from toontown.racing.KartShopGlobals import KartGlobals
2020-01-02 19:05:45 -06:00
from toontown.racing.RaceManagerAI import CircuitRaceHolidayMgr
2019-12-05 21:42:29 -06:00
class DistributedRacePadAI(DistributedKartPadAI, FSM):
2019-11-08 22:55:55 -06:00
notify = DirectNotifyGlobal.directNotify.newCategory('DistributedRacePadAI')
defaultTransitions = {'Off': ['WaitEmpty'],
'WaitEmpty': ['WaitCountdown', 'Off'],
'WaitCountdown': ['WaitEmpty',
'WaitBoarding',
'Off',
'AllAboard'],
'WaitBoarding': ['AllAboard', 'WaitEmpty', 'Off'],
'AllAboard': ['Off', 'WaitEmpty', 'WaitCountdown']}
2019-12-05 21:42:29 -06:00
def __init__(self, air):
DistributedKartPadAI.__init__(self, air)
FSM.__init__(self, 'DistributedRacePadAI')
2020-01-01 18:55:54 -06:00
self.genre = 'urban'
2019-12-05 21:42:29 -06:00
self.state = 'Off'
self.trackInfo = [0, 0]
2020-01-01 18:55:54 -06:00
self.laps = 3
2020-01-02 16:36:49 -06:00
self.avIds = []
2019-12-05 21:42:29 -06:00
2020-01-02 19:05:45 -06:00
def delete(self):
taskMgr.remove(self.uniqueName('changeTrack'))
taskMgr.remove(self.uniqueName('countdownTask'))
DistributedKartPadAI.delete(self)
def request(self, state):
FSM.request(self, state)
self.b_setState(state)
2019-12-05 21:42:29 -06:00
def setState(self, state):
self.state = state
def d_setState(self, state):
self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
def b_setState(self, state):
self.setState(state)
self.d_setState(state)
def getState(self):
return self.state, globalClockDelta.getRealNetworkTime()
2020-01-01 18:55:54 -06:00
def setTrackInfo(self, trackInfo):
2020-01-02 19:05:45 -06:00
self.trackInfo = trackInfo
def d_setTrackInfo(self, trackInfo):
self.sendUpdate('setTrackInfo', [trackInfo])
def b_setTrackInfo(self, trackInfo):
self.setTrackInfo(trackInfo)
self.d_setTrackInfo(trackInfo)
2020-01-01 18:55:54 -06:00
2019-12-05 21:42:29 -06:00
def getTrackInfo(self):
return self.trackInfo
2020-01-02 19:05:45 -06:00
def enterWaitEmpty(self):
taskMgr.doMethodLater(RaceGlobals.TrackSignDuration, self.changeTrack, self.uniqueName('changeTrack'))
def exitWaitEmpty(self):
taskMgr.remove(self.uniqueName('changeTrack'))
def enterWaitCountdown(self):
taskMgr.doMethodLater(KartGlobals.COUNTDOWN_TIME, self.considerAllAboard, self.uniqueName('countdownTask'))
def exitWaitCountdown(self):
taskMgr.remove(self.uniqueName('countdownTask'))
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
2020-01-02 16:36:49 -06:00
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
elif self.state == 'Off':
return KartGlobals.ERROR_CODE.eTrackClosed
elif self.state in ('AllAboard', 'WaitBoarding'):
return KartGlobals.ERROR_CODE.eBoardOver
elif startingBlock.avId != 0:
return KartGlobals.ERROR_CODE.eOcuppied
elif 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 removeAvBlock(self, avId, startingBlock):
if avId == startingBlock.avId and avId in self.avIds:
self.avIds.remove(avId)
def kartMovieDone(self):
if len(self.avIds) == 0 and not self.state == 'WaitEmpty':
self.request('WaitEmpty')
if self.state == 'WaitBoarding':
self.considerAllAboard(0)