Exemplo n.º 1
0
    def __fireCannonTask(self, task):
        launchTime = task.fireTime
        avId = task.avId
        if self.toonHead == None or not self.boss.state == 'BattleTwo':
            return Task.done
        flightResults = self.__calcFlightResults(avId, launchTime)
        if not isClient():
            print 'EXECWARNING DistributedLawbotCannon: %s' % flightResults
            printStack()
        for key in flightResults:
            exec "%s = flightResults['%s']" % (key, key)

        self.notify.debug('start position: ' + str(startPos))
        self.notify.debug('start velocity: ' + str(startVel))
        self.notify.debug('time of launch: ' + str(launchTime))
        self.notify.debug('time of impact: ' + str(timeOfImpact))
        self.notify.debug('location of impact: ' + str(trajectory.getPos(timeOfImpact)))
        head = self.toonHead
        head.stopBlink()
        head.stopLookAroundNow()
        head.reparentTo(hidden)
        juror = self.toonModel
        juror.reparentTo(render)
        juror.setPos(startPos)
        barrelHpr = self.barrel.getHpr(render)
        juror.setHpr(startHpr)
        self.jurorToon.loop('swim')
        self.jurorToon.setPosHpr(0, 0, -(self.jurorToon.getHeight() / 2.0), 0, 0, 0)
        info = {}
        info['avId'] = avId
        info['trajectory'] = trajectory
        info['launchTime'] = launchTime
        info['timeOfImpact'] = timeOfImpact
        info['hitWhat'] = hitWhat
        info['toon'] = self.toonModel
        info['hRot'] = self.cannonPosition[0]
        info['haveWhistled'] = 0
        info['maxCamPullback'] = CAMERA_PULLBACK_MIN
        if self.localToonShooting:
            camera.reparentTo(juror)
            camera.setP(45.0)
            camera.setZ(-10.0)
        self.flyColSphere = CollisionSphere(0, 0, self.av.getHeight() / 2.0, 1.0)
        self.flyColNode = CollisionNode(self.uniqueName('flySphere'))
        self.flyColNode.setCollideMask(ToontownGlobals.WallBitmask | ToontownGlobals.FloorBitmask | ToontownGlobals.PieBitmask)
        self.flyColNode.addSolid(self.flyColSphere)
        self.flyColNodePath = self.jurorToon.attachNewNode(self.flyColNode)
        self.flyColNodePath.setColor(1, 0, 0, 1)
        self.handler = CollisionHandlerEvent()
        self.handler.setInPattern(self.uniqueName('cannonHit'))
        base.cTrav.addCollider(self.flyColNodePath, self.handler)
        self.accept(self.uniqueName('cannonHit'), self.__handleCannonHit)
        shootTask = Task(self.__shootTask, self.taskName('shootTask'))
        flyTask = Task(self.__flyTask, self.taskName('flyTask'))
        shootTask.info = info
        flyTask.info = info
        seqTask = Task.sequence(shootTask, flyTask)
        taskMgr.add(seqTask, self.taskName('flyingToon') + '-' + str(avId))
        self.acceptOnce(self.uniqueName('stopFlyTask'), self.__stopFlyTask)
        return Task.done
 def _DistributedCannonGame__fireCannonTask(self, task):
     launchTime = task.fireTime
     avId = task.avId
     self.notify.debug('FIRING CANNON FOR AVATAR ' + str(avId))
     flightResults = self._DistributedCannonGame__calcFlightResults(avId, launchTime)
     if not isClient():
         print 'EXECWARNING DistributedCannonGame: %s' % flightResults
         printStack()
     
     for key in flightResults:
         exec "%s = flightResults['%s']" % (key, key)
     
     self.notify.debug('start position: ' + str(startPos))
     self.notify.debug('start velocity: ' + str(startVel))
     self.notify.debug('time of launch: ' + str(launchTime))
     self.notify.debug('time of impact: ' + str(timeOfImpact))
     self.notify.debug('location of impact: ' + str(trajectory.getPos(timeOfImpact)))
     if hitWhat == self.HIT_WATER:
         self.notify.debug('toon will land in the water')
     elif hitWhat == self.HIT_TOWER:
         self.notify.debug('toon will hit the tower')
     else:
         self.notify.debug('toon will hit the ground')
     head = self.toonHeadDict[avId]
     head.stopBlink()
     head.stopLookAroundNow()
     head.reparentTo(hidden)
     av = self.toonModelDict[avId]
     av.reparentTo(render)
     av.setPos(startPos)
     av.setHpr(startHpr)
     avatar = self.getAvatar(avId)
     avatar.loop('swim')
     avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0)
     shootTask = Task(self._DistributedCannonGame__shootTask)
     flyTask = Task(self._DistributedCannonGame__flyTask)
     seqDoneTask = Task(self._DistributedCannonGame__flySequenceDoneTask)
     info = { }
     info['avId'] = avId
     info['trajectory'] = trajectory
     info['launchTime'] = launchTime
     info['timeOfImpact'] = timeOfImpact
     info['hitWhat'] = hitWhat
     info['toon'] = self.toonModelDict[avId]
     info['hRot'] = self.cannonPositionDict[avId][0]
     info['haveWhistled'] = 0
     info['maxCamPullback'] = CAMERA_PULLBACK_MIN
     (info['timeEnterTowerXY'], info['timeExitTowerXY']) = trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render), TOWER_RADIUS)
     shootTask.info = info
     flyTask.info = info
     seqDoneTask.info = info
     seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME), seqDoneTask)
     taskMgr.add(seqTask, 'flyingToon' + str(avId))
     if avId == self.localAvId:
         if info['hitWhat'] == self.HIT_WATER:
             self.sendUpdate('setToonWillLandInWater', [
                 info['timeOfImpact']])
         
     
     return Task.done
    def __fireCannonTask(self, task):
        launchTime = task.fireTime
        avId = task.avId
        if self.toonHead == None or not self.boss.state == "BattleTwo":
            return Task.done
        startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults(avId, launchTime)

        self.notify.debug("start position: " + str(startPos))
        self.notify.debug("start velocity: " + str(startVel))
        self.notify.debug("time of launch: " + str(launchTime))
        self.notify.debug("time of impact: " + str(timeOfImpact))
        self.notify.debug("location of impact: " + str(trajectory.getPos(timeOfImpact)))
        head = self.toonHead
        head.stopBlink()
        head.stopLookAroundNow()
        head.reparentTo(hidden)
        juror = self.toonModel
        juror.reparentTo(render)
        juror.setPos(startPos)
        barrelHpr = self.barrel.getHpr(render)
        juror.setHpr(startHpr)
        self.jurorToon.loop("swim")
        self.jurorToon.setPosHpr(0, 0, -(self.jurorToon.getHeight() / 2.0), 0, 0, 0)
        info = {}
        info["avId"] = avId
        info["trajectory"] = trajectory
        info["launchTime"] = launchTime
        info["timeOfImpact"] = timeOfImpact
        info["hitWhat"] = hitWhat
        info["toon"] = self.toonModel
        info["hRot"] = self.cannonPosition[0]
        info["haveWhistled"] = 0
        info["maxCamPullback"] = CAMERA_PULLBACK_MIN
        if self.localToonShooting:
            camera.reparentTo(juror)
            camera.setP(45.0)
            camera.setZ(-10.0)
        self.flyColSphere = CollisionSphere(0, 0, self.av.getHeight() / 2.0, 1.0)
        self.flyColNode = CollisionNode(self.uniqueName("flySphere"))
        self.flyColNode.setCollideMask(
            ToontownGlobals.WallBitmask | ToontownGlobals.FloorBitmask | ToontownGlobals.PieBitmask
        )
        self.flyColNode.addSolid(self.flyColSphere)
        self.flyColNodePath = self.jurorToon.attachNewNode(self.flyColNode)
        self.flyColNodePath.setColor(1, 0, 0, 1)
        self.handler = CollisionHandlerEvent()
        self.handler.setInPattern(self.uniqueName("cannonHit"))
        base.cTrav.addCollider(self.flyColNodePath, self.handler)
        self.accept(self.uniqueName("cannonHit"), self.__handleCannonHit)
        shootTask = Task(self.__shootTask, self.taskName("shootTask"))
        flyTask = Task(self.__flyTask, self.taskName("flyTask"))
        shootTask.info = info
        flyTask.info = info
        seqTask = Task.sequence(shootTask, flyTask)
        taskMgr.add(seqTask, self.taskName("flyingToon") + "-" + str(avId))
        self.acceptOnce(self.uniqueName("stopFlyTask"), self.__stopFlyTask)
        return Task.done
    def __fireCannonTask(self, task):
        launchTime = task.fireTime
        avId = task.avId
        self.notify.debug("FIRING CANNON FOR AVATAR " + str(avId))
        startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults(avId, launchTime)

        self.notify.debug("start position: " + str(startPos))
        self.notify.debug("start velocity: " + str(startVel))
        self.notify.debug("time of launch: " + str(launchTime))
        self.notify.debug("time of impact: " + str(timeOfImpact))
        self.notify.debug("location of impact: " + str(trajectory.getPos(timeOfImpact)))
        if hitWhat == self.HIT_WATER:
            self.notify.debug("toon will land in the water")
        elif hitWhat == self.HIT_TOWER:
            self.notify.debug("toon will hit the tower")
        else:
            self.notify.debug("toon will hit the ground")
        head = self.toonHeadDict[avId]
        head.stopBlink()
        head.stopLookAroundNow()
        head.reparentTo(hidden)
        av = self.toonModelDict[avId]
        av.reparentTo(render)
        av.setPos(startPos)
        av.setHpr(startHpr)
        avatar = self.getAvatar(avId)
        avatar.loop("swim")
        avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0)
        shootTask = Task(self.__shootTask)
        flyTask = Task(self.__flyTask)
        seqDoneTask = Task(self.__flySequenceDoneTask)
        info = {}
        info["avId"] = avId
        info["trajectory"] = trajectory
        info["launchTime"] = launchTime
        info["timeOfImpact"] = timeOfImpact
        info["hitWhat"] = hitWhat
        info["toon"] = self.toonModelDict[avId]
        info["hRot"] = self.cannonPositionDict[avId][0]
        info["haveWhistled"] = 0
        info["maxCamPullback"] = CAMERA_PULLBACK_MIN
        info["timeEnterTowerXY"], info["timeExitTowerXY"] = trajectory.calcEnterAndLeaveCylinderXY(
            self.tower.getPos(render), TOWER_RADIUS
        )
        shootTask.info = info
        flyTask.info = info
        seqDoneTask.info = info
        seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME), seqDoneTask)
        taskMgr.add(seqTask, "flyingToon" + str(avId))
        if avId == self.localAvId:
            if info["hitWhat"] == self.HIT_WATER:
                self.sendUpdate("setToonWillLandInWater", [info["timeOfImpact"]])
        return Task.done
    def __fireCannonTask(self, task):
        launchTime = task.fireTime
        avId = task.avId
        self.notify.debug('FIRING CANNON FOR AVATAR ' + str(avId))
        startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults(avId, launchTime)

        self.notify.debug('start position: ' + str(startPos))
        self.notify.debug('start velocity: ' + str(startVel))
        self.notify.debug('time of launch: ' + str(launchTime))
        self.notify.debug('time of impact: ' + str(timeOfImpact))
        self.notify.debug('location of impact: ' + str(trajectory.getPos(timeOfImpact)))
        if hitWhat == self.HIT_WATER:
            self.notify.debug('toon will land in the water')
        elif hitWhat == self.HIT_TOWER:
            self.notify.debug('toon will hit the tower')
        else:
            self.notify.debug('toon will hit the ground')
        head = self.toonHeadDict[avId]
        head.stopBlink()
        head.stopLookAroundNow()
        head.reparentTo(hidden)
        av = self.toonModelDict[avId]
        av.reparentTo(render)
        av.setPos(startPos)
        av.setHpr(startHpr)
        avatar = self.getAvatar(avId)
        avatar.loop('swim')
        avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0)
        shootTask = Task(self.__shootTask)
        flyTask = Task(self.__flyTask)
        seqDoneTask = Task(self.__flySequenceDoneTask)
        info = {'avId': avId, 'trajectory': trajectory, 'launchTime': launchTime, 'timeOfImpact': timeOfImpact,
                'hitWhat': hitWhat, 'toon': self.toonModelDict[avId], 'hRot': self.cannonPositionDict[avId][0],
                'haveWhistled': 0, 'maxCamPullback': CAMERA_PULLBACK_MIN,
                'timeEnterTowerXY': trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render), TOWER_RADIUS)[0],
                'timeExitTowerXY': trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render), TOWER_RADIUS)[1]}
        shootTask.info = info
        flyTask.info = info
        seqDoneTask.info = info
        seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME), seqDoneTask)
        taskMgr.add(seqTask, 'flyingToon' + str(avId))
        if avId == self.localAvId:
            if info['hitWhat'] == self.HIT_WATER:
                self.sendUpdate('setToonWillLandInWater', [info['timeOfImpact']])
        return Task.done
    def __fireCannonTask(self, task):
        launchTime = 0.0
        toonId = task.toonId
        cannon = task.cannon
        toon = cannon.getToonInside()
        self.notify.debug(str(self.doId) + ' FIRING CANNON FOR TOON ' + str(toonId))
        if not cannon.isToonInside():
            return Task.done
        if self.isLocalToonId(toonId):
            self.inWater = 0
            flightResults = self.__calcFlightResults(cannon, toonId, launchTime)
            if not isClient():
                print 'EXECWARNING DistributedPartyCannonActivity: %s' % flightResults
                printStack()
            for key in flightResults:
                exec "%s = flightResults['%s']" % (key, key)

            self.notify.debug('start position: ' + str(startPos))
            self.notify.debug('start velocity: ' + str(startVel))
            self.notify.debug('time of launch: ' + str(launchTime))
        cannon.removeToonReadyToFire()
        shootTask = Task(self.__shootTask, self.taskNameShoot)
        shootTask.info = {'toonId': toonId,
         'cannon': cannon}
        if self.isLocalToonId(toonId):
            self.flyingToonOffsetRotation = 0
            self.flyingToonOffsetAngle = 0
            self.flyingToonOffsetX = 0
            self.flyingToonOffsetY = 0
            self.hitCloud = 0
            self.initialFlyVel = INITIAL_VELOCITY
            self.camNode = NodePath(self.uniqueName('flyingCamera'))
            self.camNode.setScale(0.5)
            self.camNode.setPos(self.localFlyingToon.getPos())
            self.camNode.setHpr(self.localFlyingToon.getHpr())
            self.camNode.reparentTo(render)
            self.lastStartVel = startVel
            place = base.cr.playGame.getPlace()
            place.fsm.request('activity')
            toon.dropShadow.hide()
            self.localFlyingDropShadow = self.shadowNode.copyTo(hidden)
            vel = startVel
            toon.lookAt(toon.getPos() + Vec3(vel[0], vel[1], vel[2]))
            toon.setP(localAvatar, -90)
            hpr = toon.getHpr()
            toon.d_setPosHpr(startPos[0], startPos[1], startPos[2], hpr[0], hpr[1], hpr[2])
            self.localFlyingToon.wrtReparentTo(render)
            info = {}
            info['toonId'] = toonId
            info['trajectory'] = trajectory
            info['launchTime'] = launchTime
            info['toon'] = self.localFlyingToon
            info['hRot'] = cannon.getRotation()
            camera.wrtReparentTo(self.localFlyingToon)
            flyTask = Task(self.__localFlyTask, self.taskNameFly)
            flyTask.info = info
            seqTask = Task.sequence(shootTask, flyTask)
            self.__startCollisionHandler()
            self.notify.debug('Disable standard local toon controls.')
            base.localAvatar.disableAvatarControls()
            frameTime = globalClock.getFrameTime()
            netLaunchTime = globalClockDelta.localToNetworkTime(launchTime + frameTime, bits=31)
            self.sendUpdate('setToonTrajectoryAi', [netLaunchTime,
             startPos[0],
             startPos[1],
             startPos[2],
             startHpr[0],
             startHpr[1],
             startHpr[2],
             startVel[0],
             startVel[1],
             startVel[2]])
        else:
            seqTask = shootTask
        taskMgr.add(seqTask, self.taskName('flyingToon') + '-' + str(toonId))
        toon.startSmooth()
        return Task.done
    def __fireCannonTask(self, task):
        launchTime = 0.0
        toonId = task.toonId
        cannon = task.cannon
        toon = cannon.getToonInside()
        self.notify.debug(str(self.doId) + " FIRING CANNON FOR TOON " + str(toonId))
        if not cannon.isToonInside():
            return Task.done
        if self.isLocalToonId(toonId):
            self.inWater = 0
            startPos, startHpr, startVel, trajectory = self.__calcFlightResults(cannon, toonId, launchTime)

            self.notify.debug("start position: " + str(startPos))
            self.notify.debug("start velocity: " + str(startVel))
            self.notify.debug("time of launch: " + str(launchTime))
        cannon.removeToonReadyToFire()
        shootTask = Task(self.__shootTask, self.taskNameShoot)
        shootTask.info = {"toonId": toonId, "cannon": cannon}
        if self.isLocalToonId(toonId):
            self.flyingToonOffsetRotation = 0
            self.flyingToonOffsetAngle = 0
            self.flyingToonOffsetX = 0
            self.flyingToonOffsetY = 0
            self.hitCloud = 0
            self.initialFlyVel = INITIAL_VELOCITY
            self.camNode = NodePath(self.uniqueName("flyingCamera"))
            self.camNode.setScale(0.5)
            self.camNode.setPos(self.localFlyingToon.getPos())
            self.camNode.setHpr(self.localFlyingToon.getHpr())
            self.camNode.reparentTo(render)
            self.lastStartVel = startVel
            place = base.cr.playGame.getPlace()
            place.fsm.request("activity")
            toon.dropShadow.hide()
            self.localFlyingDropShadow = self.shadowNode.copyTo(hidden)
            vel = startVel
            toon.lookAt(toon.getPos() + Vec3(vel[0], vel[1], vel[2]))
            toon.setP(localAvatar, -90)
            hpr = toon.getHpr()
            toon.d_setPosHpr(startPos[0], startPos[1], startPos[2], hpr[0], hpr[1], hpr[2])
            self.localFlyingToon.wrtReparentTo(render)
            info = {}
            info["toonId"] = toonId
            info["trajectory"] = trajectory
            info["launchTime"] = launchTime
            info["toon"] = self.localFlyingToon
            info["hRot"] = cannon.getRotation()
            camera.wrtReparentTo(self.localFlyingToon)
            flyTask = Task(self.__localFlyTask, self.taskNameFly)
            flyTask.info = info
            seqTask = Task.sequence(shootTask, flyTask)
            self.__startCollisionHandler()
            self.notify.debug("Disable standard local toon controls.")
            base.localAvatar.disableAvatarControls()
            frameTime = globalClock.getFrameTime()
            netLaunchTime = globalClockDelta.localToNetworkTime(launchTime + frameTime, bits=31)
            self.sendUpdate(
                "setToonTrajectoryAi",
                [
                    netLaunchTime,
                    startPos[0],
                    startPos[1],
                    startPos[2],
                    startHpr[0],
                    startHpr[1],
                    startHpr[2],
                    startVel[0],
                    startVel[1],
                    startVel[2],
                ],
            )
        else:
            seqTask = shootTask
        taskMgr.add(seqTask, self.taskName("flyingToon") + "-" + str(toonId))
        toon.startSmooth()
        return Task.done
Exemplo n.º 8
0
    def __fireCannonTask(self, task):
        launchTime = 0.0
        toonId = task.toonId
        cannon = task.cannon
        toon = cannon.getToonInside()
        self.notify.debug(
            str(self.doId) + ' FIRING CANNON FOR TOON ' + str(toonId))
        if not cannon.isToonInside():
            return Task.done
        if self.isLocalToonId(toonId):
            self.inWater = 0
            startPos, startHpr, startVel, trajectory = self.__calcFlightResults(
                cannon, toonId, launchTime)

            self.notify.debug('start position: ' + str(startPos))
            self.notify.debug('start velocity: ' + str(startVel))
            self.notify.debug('time of launch: ' + str(launchTime))
        cannon.removeToonReadyToFire()
        shootTask = Task(self.__shootTask, self.taskNameShoot)
        shootTask.info = {'toonId': toonId, 'cannon': cannon}
        if self.isLocalToonId(toonId):
            self.flyingToonOffsetRotation = 0
            self.flyingToonOffsetAngle = 0
            self.flyingToonOffsetX = 0
            self.flyingToonOffsetY = 0
            self.hitCloud = 0
            self.initialFlyVel = INITIAL_VELOCITY
            self.camNode = NodePath(self.uniqueName('flyingCamera'))
            self.camNode.setScale(0.5)
            self.camNode.setPos(self.localFlyingToon.getPos())
            self.camNode.setHpr(self.localFlyingToon.getHpr())
            self.camNode.reparentTo(render)
            self.lastStartVel = startVel
            place = base.cr.playGame.getPlace()
            place.fsm.request('activity')
            toon.dropShadow.hide()
            self.localFlyingDropShadow = self.shadowNode.copyTo(hidden)
            vel = startVel
            toon.lookAt(toon.getPos() + Vec3(vel[0], vel[1], vel[2]))
            toon.setP(localAvatar, -90)
            hpr = toon.getHpr()
            toon.d_setPosHpr(startPos[0], startPos[1], startPos[2], hpr[0],
                             hpr[1], hpr[2])
            self.localFlyingToon.wrtReparentTo(render)
            info = {}
            info['toonId'] = toonId
            info['trajectory'] = trajectory
            info['launchTime'] = launchTime
            info['toon'] = self.localFlyingToon
            info['hRot'] = cannon.getRotation()
            camera.wrtReparentTo(self.localFlyingToon)
            flyTask = Task(self.__localFlyTask, self.taskNameFly)
            flyTask.info = info
            seqTask = Task.sequence(shootTask, flyTask)
            self.__startCollisionHandler()
            self.notify.debug('Disable standard local toon controls.')
            base.localAvatar.disableAvatarControls()
            frameTime = globalClock.getFrameTime()
            netLaunchTime = globalClockDelta.localToNetworkTime(launchTime +
                                                                frameTime,
                                                                bits=31)
            self.sendUpdate('setToonTrajectoryAi', [
                netLaunchTime, startPos[0], startPos[1], startPos[2],
                startHpr[0], startHpr[1], startHpr[2], startVel[0],
                startVel[1], startVel[2]
            ])
        else:
            seqTask = shootTask
        taskMgr.add(seqTask, self.taskName('flyingToon') + '-' + str(toonId))
        toon.startSmooth()
        return Task.done
Exemplo n.º 9
0
    def __fireCannonTask(self, task):
        launchTime = task.fireTime
        avId = task.avId
        self.notify.debug('FIRING CANNON FOR AVATAR ' + str(avId))
        flightResults = self.__calcFlightResults(avId, launchTime)
        if not isClient():
            print 'EXECWARNING DistributedCannonGame: %s' % flightResults
            printStack()
        for key in flightResults:
            exec "%s = flightResults['%s']" % (key, key)

        self.notify.debug('start position: ' + str(startPos))
        self.notify.debug('start velocity: ' + str(startVel))
        self.notify.debug('time of launch: ' + str(launchTime))
        self.notify.debug('time of impact: ' + str(timeOfImpact))
        self.notify.debug('location of impact: ' +
                          str(trajectory.getPos(timeOfImpact)))
        if hitWhat == self.HIT_WATER:
            self.notify.debug('toon will land in the water')
        elif hitWhat == self.HIT_TOWER:
            self.notify.debug('toon will hit the tower')
        else:
            self.notify.debug('toon will hit the ground')
        head = self.toonHeadDict[avId]
        head.stopBlink()
        head.stopLookAroundNow()
        head.reparentTo(hidden)
        av = self.toonModelDict[avId]
        av.reparentTo(render)
        av.setPos(startPos)
        av.setHpr(startHpr)
        avatar = self.getAvatar(avId)
        avatar.loop('swim')
        avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0)
        shootTask = Task(self.__shootTask)
        flyTask = Task(self.__flyTask)
        seqDoneTask = Task(self.__flySequenceDoneTask)
        info = {}
        info['avId'] = avId
        info['trajectory'] = trajectory
        info['launchTime'] = launchTime
        info['timeOfImpact'] = timeOfImpact
        info['hitWhat'] = hitWhat
        info['toon'] = self.toonModelDict[avId]
        info['hRot'] = self.cannonPositionDict[avId][0]
        info['haveWhistled'] = 0
        info['maxCamPullback'] = CAMERA_PULLBACK_MIN
        info['timeEnterTowerXY'], info[
            'timeExitTowerXY'] = trajectory.calcEnterAndLeaveCylinderXY(
                self.tower.getPos(render), TOWER_RADIUS)
        shootTask.info = info
        flyTask.info = info
        seqDoneTask.info = info
        seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME),
                                seqDoneTask)
        taskMgr.add(seqTask, 'flyingToon' + str(avId))
        if avId == self.localAvId:
            if info['hitWhat'] == self.HIT_WATER:
                self.sendUpdate('setToonWillLandInWater',
                                [info['timeOfImpact']])
        return Task.done
    def __fireCannonTask(self, task):
        launchTime = task.fireTime
        avId = task.avId
        if self.toonHead == None or not self.boss.state == 'BattleTwo':
            return Task.done
        startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults(
            avId, launchTime)

        self.notify.debug('start position: ' + str(startPos))
        self.notify.debug('start velocity: ' + str(startVel))
        self.notify.debug('time of launch: ' + str(launchTime))
        self.notify.debug('time of impact: ' + str(timeOfImpact))
        self.notify.debug('location of impact: ' +
                          str(trajectory.getPos(timeOfImpact)))
        head = self.toonHead
        head.stopBlink()
        head.stopLookAroundNow()
        head.reparentTo(hidden)
        juror = self.toonModel
        juror.reparentTo(render)
        juror.setPos(startPos)
        barrelHpr = self.barrel.getHpr(render)
        juror.setHpr(startHpr)
        self.jurorToon.loop('swim')
        self.jurorToon.setPosHpr(0, 0, -(self.jurorToon.getHeight() / 2.0), 0,
                                 0, 0)
        info = {}
        info['avId'] = avId
        info['trajectory'] = trajectory
        info['launchTime'] = launchTime
        info['timeOfImpact'] = timeOfImpact
        info['hitWhat'] = hitWhat
        info['toon'] = self.toonModel
        info['hRot'] = self.cannonPosition[0]
        info['haveWhistled'] = 0
        info['maxCamPullback'] = CAMERA_PULLBACK_MIN
        if self.localToonShooting:
            camera.reparentTo(juror)
            camera.setP(45.0)
            camera.setZ(-10.0)
        self.flyColSphere = CollisionSphere(0, 0,
                                            self.av.getHeight() / 2.0, 1.0)
        self.flyColNode = CollisionNode(self.uniqueName('flySphere'))
        self.flyColNode.setCollideMask(ToontownGlobals.WallBitmask
                                       | ToontownGlobals.FloorBitmask
                                       | ToontownGlobals.PieBitmask)
        self.flyColNode.addSolid(self.flyColSphere)
        self.flyColNodePath = self.jurorToon.attachNewNode(self.flyColNode)
        self.flyColNodePath.setColor(1, 0, 0, 1)
        self.handler = CollisionHandlerEvent()
        self.handler.setInPattern(self.uniqueName('cannonHit'))
        base.cTrav.addCollider(self.flyColNodePath, self.handler)
        self.accept(self.uniqueName('cannonHit'), self.__handleCannonHit)
        shootTask = Task(self.__shootTask, self.taskName('shootTask'))
        flyTask = Task(self.__flyTask, self.taskName('flyTask'))
        shootTask.info = info
        flyTask.info = info
        seqTask = Task.sequence(shootTask, flyTask)
        taskMgr.add(seqTask, self.taskName('flyingToon') + '-' + str(avId))
        self.acceptOnce(self.uniqueName('stopFlyTask'), self.__stopFlyTask)
        return Task.done
Exemplo n.º 11
0
    def __fireCannonTask(self, task):
        """
        Decides how to fire a cannon.
        If the local toon is firing then set up flight control
        Other clients just fire the cannon and get the toon position from broadcast.
        Always returns Task.done
        """
        launchTime = 0.0
        toonId = task.toonId
        cannon = task.cannon
        toon = cannon.getToonInside()

        self.notify.debug(
            str(self.doId) + " FIRING CANNON FOR TOON " + str(toonId))

        # Make sure if a toon is still inside
        # The a client may have crashed at this point
        if not cannon.isToonInside():
            return Task.done

        # Compute the flight results if the local toon is firing out of the cannon.
        if self.isLocalToonId(toonId):
            self.inWater = 0

            # calculate the trajectory
            flightResults = self.__calcFlightResults(cannon, toonId,
                                                     launchTime)
            # pull all the results (startPos, startHpr, startVel, trajectory) into the local namespace
            for key in flightResults:
                exec("%s = flightResults['%s']" % (key, key))

            #self.notify.debug("start position: " + str(startPos))
            #self.notify.debug("start velocity: " + str(startVel))
            #self.notify.debug("time of launch: " + str(launchTime))

        cannon.removeToonReadyToFire()

        # Create the shoot task
        shootTask = Task(self.__shootTask, self.taskNameShoot)
        shootTask.info = {'toonId': toonId, 'cannon': cannon}

        if self.isLocalToonId(toonId):
            self.flyingToonOffsetRotation = 0
            self.flyingToonOffsetAngle = 0
            self.flyingToonOffsetX = 0
            self.flyingToonOffsetY = 0

            self.hitCloud = 0
            self.initialFlyVel = INITIAL_VELOCITY
            self.camNode = NodePath(self.uniqueName("flyingCamera"))
            self.camNode.setScale(.5)
            self.camNode.setPos(self.localFlyingToon.getPos())
            self.camNode.setHpr(self.localFlyingToon.getHpr())
            self.camNode.reparentTo(render)
            startVel = cannon.getToonFireVel()
            self.lastStartVel = startVel

            place = base.cr.playGame.getPlace()
            place.fsm.request("activity")

            toon.dropShadow.hide()
            self.localFlyingDropShadow = self.shadowNode.copyTo(hidden)

            # stock the tasks up with the info they need
            # store the info in a shared dictionary
            self.localFlyingToon.wrtReparentTo(render)
            info = {}
            info['toonId'] = toonId
            info['trajectory'] = self.trajectory
            info['launchTime'] = launchTime
            info['toon'] = self.localFlyingToon
            info['hRot'] = cannon.getRotation()

            camera.wrtReparentTo(self.localFlyingToon)

            flyTask = Task(self.__localFlyTask, self.taskNameFly)
            flyTask.info = info

            seqTask = Task.sequence(shootTask, flyTask)

            self.__startCollisionHandler()

            self.notify.debug("Disable standard local toon controls.")
            base.localAvatar.disableAvatarControls()
            base.localAvatar.startPosHprBroadcast()

        else:
            seqTask = shootTask

        taskMgr.add(seqTask, self.taskName('flyingToon') + "-" + str(toonId))

        toon.startSmooth()

        return Task.done
Exemplo n.º 12
0
    def __fireCannonTask(self, task):
        launchTime = task.fireTime
        avId = task.avId
        self.notify.debug('FIRING CANNON FOR AVATAR ' + str(avId))
        startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults(
            avId, launchTime)

        self.notify.debug('start position: ' + str(startPos))
        self.notify.debug('start velocity: ' + str(startVel))
        self.notify.debug('time of launch: ' + str(launchTime))
        self.notify.debug('time of impact: ' + str(timeOfImpact))
        self.notify.debug('location of impact: ' +
                          str(trajectory.getPos(timeOfImpact)))
        if hitWhat == self.HIT_WATER:
            self.notify.debug('toon will land in the water')
        elif hitWhat == self.HIT_TOWER:
            self.notify.debug('toon will hit the tower')
        else:
            self.notify.debug('toon will hit the ground')
        head = self.toonHeadDict[avId]
        head.stopBlink()
        head.stopLookAroundNow()
        head.reparentTo(hidden)
        av = self.toonModelDict[avId]
        av.reparentTo(render)
        av.setPos(startPos)
        av.setHpr(startHpr)
        avatar = self.getAvatar(avId)
        avatar.loop('swim')
        avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0)
        shootTask = Task(self.__shootTask)
        flyTask = Task(self.__flyTask)
        seqDoneTask = Task(self.__flySequenceDoneTask)
        info = {
            'avId':
            avId,
            'trajectory':
            trajectory,
            'launchTime':
            launchTime,
            'timeOfImpact':
            timeOfImpact,
            'hitWhat':
            hitWhat,
            'toon':
            self.toonModelDict[avId],
            'hRot':
            self.cannonPositionDict[avId][0],
            'haveWhistled':
            0,
            'maxCamPullback':
            CAMERA_PULLBACK_MIN,
            'timeEnterTowerXY':
            trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render),
                                                   TOWER_RADIUS)[0],
            'timeExitTowerXY':
            trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render),
                                                   TOWER_RADIUS)[1]
        }
        shootTask.info = info
        flyTask.info = info
        seqDoneTask.info = info
        seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME),
                                seqDoneTask)
        taskMgr.add(seqTask, 'flyingToon' + str(avId))
        if avId == self.localAvId:
            if info['hitWhat'] == self.HIT_WATER:
                self.sendUpdate('setToonWillLandInWater',
                                [info['timeOfImpact']])
        return Task.done