Poodletooth-iLand/toontown/cogdominium/DistCogdoGameAI.py

106 lines
3.1 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
2015-03-06 20:46:05 -06:00
from direct.distributed.ClockDelta import *
import CogdoGameConsts
2015-03-03 16:10:12 -06:00
class DistCogdoGameAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistCogdoGameAI")
2015-03-06 20:46:05 -06:00
delayIntro = .1
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def __init__(self, air):
DistributedObjectAI.__init__(self, air)
air.cogdoGame = self
self.interiorId = 0
self.exteriorZone = 0
self.difficultyOverrides = [2147483647, -1]
self.requests = {}
self.toons = []
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def announceGenerate(self):
DistributedObjectAI.announceGenerate(self)
self.finishEvent = self.uniqueName('CogdoMazeGameDone')
self.gameOverEvent = self.uniqueName('CogdoMazeGameLose')
self.resetRequests()
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def d_startIntro(self):
self.sendUpdate('setVisible', [])
taskMgr.doMethodLater(self.delayIntro, self.__startIntro, self.taskName('CogdoStartIntro'))
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def getInterior(self):
return self.air.doId2do.get(self.interiorId)
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def resetRequests(self):
interior = self.getInterior()
toons = interior.getToons()[0]
for toon in toons:
self.requests[toon] = 0
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def __startIntro(self, task = None):
self.sendUpdate('setIntroStart', [])
if task:
return task.done
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def setAvatarReady(self):
avId = self.air.getAvatarIdFromSender()
self.requests[avId] = 1
if not avId in self.toons: self.toons.append(avId)
if self.allToonsReady():
self.handleStart()
self.sendUpdate('setGameStart', [globalClockDelta.getRealNetworkTime()])
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def allToonsReady(self):
interior = self.getInterior()
toons = interior.getToons()[0]
for toon in toons:
if self.requests.get(toon, 0) == 0:
return 0
return 1
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def handleStart(self):
2015-03-03 16:10:12 -06:00
pass
2015-03-06 20:46:05 -06:00
def setInteriorId(self, id):
self.interiorId = id
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def getInteriorId(self):
return self.interiorId
2015-03-03 16:10:12 -06:00
2015-03-06 20:46:05 -06:00
def setExteriorZone(self, zone):
self.exteriorZone = zone
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def getExteriorZone(self):
return self.exteriorZone
2015-03-03 16:10:12 -06:00
2015-03-06 20:46:05 -06:00
def setDifficultyOverrides(self, difficulty, exteriorDifficulty):
self.difficultyOverrides = [difficulty, exteriorDifficulty]
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def getDifficultyOverrides(self):
return self.difficultyOverrides
2015-03-03 16:10:12 -06:00
2015-03-06 20:46:05 -06:00
def toonWentSad(self, avId):
self.sendUpdate('setToonSad', [avId])
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def setToons(self, toons):
self.toons = toons
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def disable(self):
DistributedObjectAI.disable(self)
self.air.cogdoGame = None
del self.air.cogdoGame
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def gameDone(self, failed=False):
if not failed:
if len(self.toons) == 0:
failed = True
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
if not failed:
messenger.send(self.finishEvent, [self.toons])
else:
messenger.send(self.gameOverEvent)
2015-04-27 18:51:51 -05:00
2015-03-06 20:46:05 -06:00
def getDifficulty(self):
return CogdoGameConsts.getDifficulty(self.getSafezoneId())
2015-03-03 16:10:12 -06:00
2015-04-27 18:51:51 -05:00
def getSafezoneId(self):
2015-03-06 20:46:05 -06:00
return CogdoGameConsts.getSafezoneId(self.exteriorZone)