Poodletooth-iLand/toontown/estate/DistributedTargetAI.py

86 lines
2.6 KiB
Python
Raw Normal View History

2015-03-03 22:10:12 +00:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
2015-03-23 12:56:48 +00:00
import CannonGlobals
2015-03-03 22:10:12 +00:00
class DistributedTargetAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedTargetAI")
2015-03-23 12:56:48 +00:00
def __init__(self, air):
DistributedObjectAI.__init__(self, air)
self.enabled = 0
self.highscore = 0
self.scoreDict = {}
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
self.__newGame()
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def announceGenerate(self):
DistributedObjectAI.announceGenerate(self)
taskMgr.doMethodLater(10, self.__startNewGame, self.taskName('newGame'))
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def __newGame(self):
self.power = 1
self.time = CannonGlobals.CANNON_TIMEOUT
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def getPosition(self):
return (0, 0, 40)
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def getState(self):
return self.enabled, 2**self.power, self.time
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def d_updateState(self):
self.sendUpdate("setState", self.getState())
2015-03-23 12:56:48 +00:00
def d_setReward(self, reward):
self.sendUpdate("setReward", [reward])
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
def setResult(self, avId):
if avId and self.enabled:
self.power += 1
self.time = int(CannonGlobals.CANNON_TIMEOUT / self.power)
taskMgr.remove(self.taskName('gameover'))
taskMgr.doMethodLater(self.time, self.__gameOver, self.taskName('gameover'))
self.d_updateState()
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def __gameOver(self, task):
self.enabled = 0
self.time = 0
self.d_updateState()
taskMgr.doMethodLater(10, self.__startNewGame, self.taskName('newGame'))
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
for avId in self.scoreDict:
av = self.air.doId2do.get(avId)
if av:
if av.zoneId == self.zoneId:
av.toonUp(2 ** self.power)
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
return task.done
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def __startNewGame(self, task):
self.enabled = 1
self.__newGame()
self.d_updateState()
taskMgr.doMethodLater(self.time, self.__gameOver, self.taskName('gameover'))
return task.done
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
def setBonus(self, bonus):
pass
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
def setCurPinballScore(self, avId, score, bonus):
av = self.air.doId2do.get(avId)
if not av:
return
2015-04-29 08:12:56 +00:00
2015-03-23 12:56:48 +00:00
S = score * bonus
self.scoreDict[avId] = S
if S > self.highscore:
self.highscore = S
self.d_updateHighscore(av, S)
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
def d_updateHighscore(self, av, score):
self.sendUpdate("setPinballHiScorer", [av.getName()])
self.sendUpdate("setPinballHiScore", [score])
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
def delete(self):
taskMgr.remove(self.taskName('newGame'))
taskMgr.remove(self.taskName('gameover'))