Poodletooth-iLand/toontown/estate/DistributedCannonAI.py

122 lines
4.3 KiB
Python
Raw Normal View History

2015-07-23 10:53:54 -05:00
from toontown.toonbase import ToontownGlobals
2015-03-23 07:56:48 -05:00
from direct.distributed.ClockDelta import *
2015-07-23 10:53:54 -05:00
from direct.fsm import ClassicFSM
from direct.fsm import State
from direct.task import Task
2015-03-23 07:56:48 -05:00
from toontown.minigame import CannonGameGlobals
2015-07-23 10:53:54 -05:00
from direct.distributed import DistributedObjectAI
from toontown.minigame import Trajectory
2015-03-23 07:56:48 -05:00
import CannonGlobals
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
class DistributedCannonAI(DistributedObjectAI.DistributedObjectAI):
notify = directNotify.newCategory('DistributedCannonAI')
def __init__(self, air, estateId, targetId, x, y, z, h, p, r):
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
self.posHpr = [x,
y,
z,
h,
p,
r]
2015-03-23 07:56:48 -05:00
self.avId = 0
self.estateId = estateId
2015-07-23 10:53:54 -05:00
self.timeoutTask = None
2015-03-23 07:56:48 -05:00
self.targetId = targetId
2015-07-23 10:53:54 -05:00
self.cannonBumperPos = list(ToontownGlobals.PinballCannonBumperInitialPos)
return
2015-04-29 03:12:56 -05:00
2015-07-23 10:53:54 -05:00
def delete(self):
self.ignoreAll()
self.__stopTimeout()
DistributedObjectAI.DistributedObjectAI.delete(self)
2015-03-03 16:10:12 -06:00
def requestEnter(self):
2015-03-23 07:56:48 -05:00
avId = self.air.getAvatarIdFromSender()
2015-07-23 10:53:54 -05:00
if self.avId == 0:
2015-03-23 07:56:48 -05:00
self.avId = avId
2015-07-23 10:53:54 -05:00
self.__stopTimeout()
self.setMovie(CannonGlobals.CANNON_MOVIE_LOAD, self.avId)
2015-03-23 07:56:48 -05:00
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.__handleUnexpectedExit, extraArgs=[avId])
2015-07-23 10:53:54 -05:00
self.acceptOnce('bootAvFromEstate-' + str(avId), self.__handleBootMessage, extraArgs=[avId])
self.__startTimeout(CannonGlobals.CANNON_TIMEOUT)
2015-03-23 07:56:48 -05:00
else:
self.air.writeServerEvent('suspicious', avId, 'DistributedCannonAI.requestEnter cannon already occupied')
self.notify.warning('requestEnter() - cannon already occupied')
2015-07-23 10:53:54 -05:00
self.sendUpdateToAvatarId(avId, 'requestExit', [])
2015-03-23 07:56:48 -05:00
2015-07-23 10:53:54 -05:00
def setMovie(self, mode, avId):
2015-03-23 07:56:48 -05:00
self.avId = avId
2015-07-23 10:53:54 -05:00
self.sendUpdate('setMovie', [mode, avId])
2015-03-23 07:56:48 -05:00
2015-07-23 10:53:54 -05:00
def getCannonBumperPos(self):
self.notify.debug('---------getCannonBumperPos %s' % self.cannonBumperPos)
return self.cannonBumperPos
2015-03-23 07:56:48 -05:00
2015-07-23 10:53:54 -05:00
def requestBumperMove(self, x, y, z):
self.cannonBumperPos = [x, y, z]
self.sendUpdate('setCannonBumperPos', [x, y, z])
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
def getPosHpr(self):
return self.posHpr
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
def getEstateId(self):
return self.estateId
def getTargetId(self):
return self.targetId
2015-03-03 16:10:12 -06:00
2015-03-23 07:56:48 -05:00
def setCannonPosition(self, zRot, angle):
2015-07-23 10:53:54 -05:00
avId = self.air.getAvatarIdFromSender()
self.notify.debug('setCannonPosition: ' + str(avId) + ': zRot=' + str(zRot) + ', angle=' + str(angle))
self.sendUpdate('updateCannonPosition', [avId, zRot, angle])
2015-03-03 16:10:12 -06:00
2015-03-23 07:56:48 -05:00
def setCannonLit(self, zRot, angle):
avId = self.air.getAvatarIdFromSender()
2015-07-23 10:53:54 -05:00
self.__stopTimeout()
self.notify.debug('setCannonLit: ' + str(avId) + ': zRot=' + str(zRot) + ', angle=' + str(angle))
fireTime = CannonGameGlobals.FUSE_TIME
self.sendUpdate('setCannonWillFire', [avId,
fireTime,
zRot,
angle,
globalClockDelta.getRealNetworkTime()])
def setLanded(self):
self.ignore(self.air.getAvatarExitEvent(self.avId))
self.setMovie(CannonGlobals.CANNON_MOVIE_LANDED, 0)
self.avId = 0
def setActive(self, active):
if active < 0 or active > 1:
self.air.writeServerEvent('suspicious', active, 'DistributedCannon.setActive value should be 0-1 range')
2015-03-23 07:56:48 -05:00
return
2015-07-23 10:53:54 -05:00
self.active = active
self.sendUpdate('setActiveState', [active])
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
def __startTimeout(self, timeLimit):
self.__stopTimeout()
self.timeoutTask = taskMgr.doMethodLater(timeLimit, self.__handleTimeout, self.taskName('timeout'))
2015-04-29 03:12:56 -05:00
2015-07-23 10:53:54 -05:00
def __stopTimeout(self):
if self.timeoutTask != None:
taskMgr.remove(self.timeoutTask)
self.timeoutTask = None
return
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
def __handleTimeout(self, task):
self.notify.debug('Timeout expired!')
self.__doExit()
return Task.done
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
def __handleUnexpectedExit(self, avId):
self.notify.warning('avatar:' + str(avId) + ' has exited unexpectedly')
self.__doExit()
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
def __handleBootMessage(self, avId):
self.notify.warning('avatar:' + str(avId) + ' got booted ')
self.__doExit()
2015-03-03 16:10:12 -06:00
2015-07-23 10:53:54 -05:00
def __doExit(self):
self.setMovie(CannonGlobals.CANNON_MOVIE_FORCE_EXIT, self.avId)