Exemplo n.º 1
0
    def announceGenerate(self):
        DistributedTNT.announceGenerate(self)
        self.stopSmooth()
        self.startPosHprBroadcast()

        pos = base.localAvatar.getPos(render)
        # Make sure to start the TNT out in front of our capsule to prevent weird physics
        extrude = base.localAvatar.getQuat(render).xform(
            Vec3(0, 1.0 + 0.3925,
                 base.localAvatar.getHeight() / 2.0))
        self.setPos(pos + extrude)

        push = ((pos + (0, 0, base.localAvatar.getHeight() / 2.0)) -
                camera.getPos(render)).length()
        self.lookAt(render, PhysicsUtils.getHitPosFromCamera(push=push))
        self.d_clearSmoothing()
        self.d_broadcastPosHpr()

        power = 50.0
        bp = base.localAvatar.backpack
        if bp:
            gag = bp.getGagByID(GagGlobals.gagIdByName[GagGlobals.TNT])
            if gag and gag.powerBar:
                power = gag.powerBar.getPower()
        self.toss(power)
Exemplo n.º 2
0
    def start(self):
        Gag.start(self)

        self.hitSfx.play()

        gag = self.gag
        if self.isLocal():
            vm = self.getViewModel()
            fpsCam = self.getFPSCam()
            fpsCam.setVMAnimTrack(
                Sequence(ActorInterval(vm, "sg_shoot_begin"),
                         ActorInterval(vm, "sg_shoot_end"),
                         Func(vm.loop, "sg_idle")))
            gag = self.getVMGag()

        nozzle = gag.find("**/joint_nozzle")

        if self.isLocal() and base.localAvatar.battleControls:
            if base.localAvatar.isFirstPerson():
                self.getFPSCam().resetViewPunch()
                self.getFPSCam().addViewPunch(
                    Vec3(random.uniform(-0.6, 0.6),
                         random.uniform(-0.25, -0.5), 0.0))
                startPos = camera.getPos(render)
            else:
                startPos = nozzle.getPos(render)
            hitPos = PhysicsUtils.getHitPosFromCamera()
        else:
            startPos = nozzle.getPos(render)
            quat = Quat()
            quat.setHpr(
                self.avatar.getHpr(render) + (0, self.avatar.lookPitch, 0))
            hitPos = quat.xform(Vec3.forward() * 10000)
            hit = PhysicsUtils.rayTestClosestNotMe(
                self.avatar, startPos, hitPos,
                CIGlobals.WorldGroup | CIGlobals.LocalAvGroup)
            if hit is not None:
                hitPos = hit.getHitPos()

        pellet = WaterPellet(self.isLocal())
        pellet.addToWorld(nozzle.getPos(render),
                          lookAt=hitPos,
                          velo=Vec3.forward() * self.pelletSpeed)

        if self.isLocal():
            base.localAvatar.sendUpdate('usedGag', [self.id])
    def release(self):
        Gag.release(self)
        base.audio3d.attachSoundToObject(self.woosh, self.gag)
        base.playSfx(self.woosh, node=self.gag)

        if self.isLocal() and base.localAvatar.battleControls:
            if base.localAvatar.isFirstPerson():
                # Add a small kick to the camera to give more feedback
                self.getFPSCam().addViewPunch(
                    Vec3(random.uniform(.5, 1), random.uniform(-.5, -1), 0))

                startPos = camera.getPos(render) + camera.getQuat(
                    render).xform(Vec3.right())
                push = 0.0
            else:
                startPos = self.handJoint.getPos(render)
                push = (startPos - camera.getPos(render)).length()
            hitPos = PhysicsUtils.getHitPosFromCamera()
        else:
            startPos = self.handJoint.getPos(render)
            quat = Quat()
            quat.setHpr(
                self.avatar.getHpr(render) + (0, self.avatar.lookPitch, 0))
            hitPos = quat.xform(Vec3.forward() * self.power)
            hit = PhysicsUtils.rayTestClosestNotMe(
                self.avatar, startPos, hitPos,
                CIGlobals.WorldGroup | CIGlobals.LocalAvGroup)
            if hit is not None:
                hitPos = hit.getHitPos()

        throwDir = (hitPos - startPos).normalized()
        endPos = startPos + (throwDir * self.power) - (0, 0, 90)

        entity = self.gag

        if not entity:
            entity = self.build()

        gagRoot = render.attachNewNode('gagRoot')
        gagRoot.setPos(startPos)

        entity.reparentTo(render)
        entity.setPos(0, 0, 0)
        entity.headsUp(throwDir)
        rot = entity.getHpr(render)
        entity.reparentTo(gagRoot)
        entity.setHpr(rot[0], -90, 0)
        self.gag = None

        if not self.handJoint:
            self.handJoint = self.avatar.find('**/def_joint_right_hold')

        track = FlightProjectileInterval(gagRoot,
                                         startPos=startPos,
                                         endPos=endPos,
                                         gravityMult=1.07,
                                         duration=2.5)
        event = self.avatar.uniqueName('throwIvalDone') + '-' + str(
            hash(entity))
        track.setDoneEvent(event)
        base.acceptOnce(event, self.__handlePieIvalDone, [entity])
        track.start()

        if self.isLocal():
            collider = self.buildCollisions(entity)
            self.entities.append([gagRoot, track, collider])
            base.localAvatar.sendUpdate('usedGag', [self.id])
        else:
            self.entities.append([gagRoot, track, NodePath()])
        self.reset()