Poodletooth-iLand/toontown/cogdominium/DistCogdoCraneGameAI.py

62 lines
2.3 KiB
Python
Raw Normal View History

2015-03-06 20:46:05 -06:00
from direct.directnotify.DirectNotifyGlobal import directNotify
2015-03-03 16:10:12 -06:00
from toontown.cogdominium.DistCogdoLevelGameAI import DistCogdoLevelGameAI
2015-03-06 20:46:05 -06:00
from toontown.cogdominium.DistCogdoCraneAI import DistCogdoCraneAI
from toontown.cogdominium import CogdoCraneGameConsts as GameConsts
from toontown.cogdominium.CogdoCraneGameBase import CogdoCraneGameBase
2015-03-03 16:10:12 -06:00
2015-03-06 20:46:05 -06:00
class DistCogdoCraneGameAI(DistCogdoLevelGameAI, CogdoCraneGameBase):
notify = directNotify.newCategory('DistCogdoCraneGameAI')
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def __init__(self, air, interior):
DistCogdoLevelGameAI.__init__(self, air, interior)
self._cranes = [
None] * self.MaxPlayers
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def enterLoaded(self):
DistCogdoLevelGameAI.enterLoaded(self)
for i in xrange(self.MaxPlayers):
crane = DistCogdoCraneAI(self.air, self, i)
crane.generateWithRequired(self.zoneId)
self._cranes[i] = crane
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def exitLoaded(self):
for i in xrange(self.MaxPlayers):
if self._cranes[i]:
self._cranes[i].requestDelete()
self._cranes[i] = None
continue
DistCogdoLevelGameAI.exitLoaded(self)
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def enterGame(self):
DistCogdoLevelGameAI.enterGame(self)
for i in xrange(self.getNumPlayers()):
self._cranes[i].request('Controlled', self.getToonIds()[i])
self._scheduleGameDone()
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def _scheduleGameDone(self):
timeLeft = GameConsts.Settings.GameDuration.get() - globalClock.getRealTime() - self.getStartTime()
if timeLeft > 0:
self._gameDoneEvent = taskMgr.doMethodLater(timeLeft, self._gameDoneDL, self.uniqueName('boardroomGameDone'))
else:
self._gameDoneDL()
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def exitGame(self):
taskMgr.remove(self._gameDoneEvent)
self._gameDoneEvent = None
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def _gameDoneDL(self, task = None):
self._handleGameFinished()
return task.done
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def enterFinish(self):
DistCogdoLevelGameAI.enterFinish(self)
self._finishDoneEvent = taskMgr.doMethodLater(10.0, self._finishDoneDL, self.uniqueName('boardroomFinishDone'))
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def exitFinish(self):
taskMgr.remove(self._finishDoneEvent)
self._finishDoneEvent = None
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def _finishDoneDL(self, task):
self.announceGameDone()
2015-04-27 18:51:51 -05:00
return task.done