Poodletooth-iLand/toontown/estate/DistributedCannonAI.py

103 lines
3.2 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
from direct.distributed.ClockDelta import *
from toontown.minigame import CannonGameGlobals
from toontown.toonbase import ToontownGlobals
import CannonGlobals
2015-03-03 22:10:12 +00:00
class DistributedCannonAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedCannonAI")
2015-03-23 12:56:48 +00:00
def __init__(self, air):
DistributedObjectAI.__init__(self, air)
self.estateId = 0
self.targetId = 0
self.posHpr = (0, 0, 0, 0, 0, 0)
self.bumperPos = ToontownGlobals.PinballCannonBumperInitialPos
self.active = 0
self.avId = 0
def setEstateId(self, estateId):
self.estateId = estateId
def getEstateId(self):
return self.estateId
def setTargetId(self, targetId):
self.targetId = targetId
def getTargetId(self):
return self.targetId
def setPosHpr(self, x, y, z, h, p, r):
self.posHpr = (x, y, z, h, p, r)
def getPosHpr(self):
return self.posHpr
def setActive(self, active):
self.active = active
self.sendUpdate("setActiveState", [active])
2015-03-03 22:10:12 +00:00
def requestEnter(self):
2015-03-23 12:56:48 +00:00
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
if not av:
return
if not self.avId:
self.avId = avId
self.d_setMovie(CannonGlobals.CANNON_MOVIE_LOAD)
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.__handleUnexpectedExit, extraArgs=[avId])
else:
self.air.writeServerEvent('suspicious', avId, 'DistributedCannonAI.requestEnter cannon already occupied')
self.notify.warning('requestEnter() - cannon already occupied')
def setMovie(self, mode, avId, extraInfo):
self.avId = avId
self.sendUpdate('setMovie', [mode, avId, extraInfo])
def __handleUnexpectedExit(self, avId):
self.notify.warning('avatar:' + str(avId) + ' has exited unexpectedly')
self.__doExit()
def __doExit(self, movie=CannonGlobals.CANNON_MOVIE_FORCE_EXIT):
self.ignore(self.air.getAvatarExitEvent(self.avId))
self.d_setMovie(movie)
self.avId = 0
2015-03-03 22:10:12 +00:00
def requestExit(self):
pass
2015-03-23 12:56:48 +00:00
def d_setMovie(self, movie):
self.sendUpdate("setMovie", [movie, self.avId])
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
def setCannonPosition(self, zRot, angle):
self.sendUpdate("updateCannonPosition", [self.avId, zRot, angle])
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
def setCannonLit(self, zRot, angle):
avId = self.air.getAvatarIdFromSender()
if avId != self.avId:
return
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
fireTime = CannonGameGlobals.FUSE_TIME
self.sendUpdate('setCannonWillFire', [avId, fireTime, zRot, angle, globalClockDelta.getRealNetworkTime()])
2015-03-03 22:10:12 +00:00
def setFired(self):
pass
def setLanded(self):
2015-03-23 12:56:48 +00:00
self.__doExit(CannonGlobals.CANNON_MOVIE_CLEAR)
self.sendUpdate('setCannonExit', [self.avId])
2015-03-03 22:10:12 +00:00
def setCannonExit(self, todo0):
pass
2015-03-23 12:56:48 +00:00
def requestBumperMove(self, x, y, z):
self.bumperPos = (x, y, z)
self.sendUpdate('setCannonBumperPos', self.getCannonBumperPos())
2015-03-03 22:10:12 +00:00
2015-03-23 12:56:48 +00:00
def getCannonBumperPos(self):
return self.bumperPos