示例#1
0
class HangUpAttack(Attack):
    notify = directNotify.newCategory('HangUpAttack')
    attack = 'hangup'

    def __init__(self, attacksClass, suit):
        Attack.__init__(self, attacksClass, suit)
        self.phone = None
        self.receiver = None
        self.collNP = None
        self.phoneSfx = None
        self.hangupSfx = None
        self.shootIval = None
        self.cord = None
        self.receiverOutCord = None
        self.phoneOutCord = None
        return

    def loadAttack(self):
        self.phone = loader.loadModel('phase_3.5/models/props/phone.bam')
        self.phone.setHpr(0, 0, 180)
        if self.suit.type == 'B':
            self.phone.setPos(0.7, 0.15, 0)
        elif self.suit.type == 'C':
            self.phone.setPos(0.25, 0, 0)
        self.receiver = loader.loadModel('phase_3.5/models/props/receiver.bam')
        self.receiver.reparentTo(self.phone)
        self.cord = Rope()
        self.cord.ropeNode.setUseVertexColor(1)
        self.cord.ropeNode.setUseVertexThickness(1)
        self.cord.setup(3, ({'node': self.phone,
          'point': (0.8, 0, 0.2),
          'color': (0, 0, 0, 1),
          'thickness': 1000}, {'node': self.phone,
          'point': (2, 0, 0),
          'color': (0, 0, 0, 1),
          'thickness': 1000}, {'node': self.receiver,
          'point': (1.1, 0.25, 0.5),
          'color': (0, 0, 0, 1),
          'thickness': 1000}), [])
        self.cord.setH(180)
        self.phoneSfx = base.audio3d.loadSfx('phase_3.5/audio/sfx/SA_hangup.mp3')
        base.audio3d.attachSoundToObject(self.phoneSfx, self.phone)
        self.hangupSfx = base.audio3d.loadSfx('phase_3.5/audio/sfx/SA_hangup_place_down.mp3')
        base.audio3d.attachSoundToObject(self.hangupSfx, self.phone)
        collSphere = CollisionSphere(0, 0, 0, 2)
        collSphere.setTangible(0)
        collNode = CollisionNode('phone_shootout')
        collNode.addSolid(collSphere)
        collNode.setCollideMask(CIGlobals.WallBitmask)
        self.collNP = self.phone.attachNewNode(collNode)

    def doAttack(self, ts = 0):
        self.loadAttack()
        if hasattr(self.suit, 'uniqueName'):
            name = self.suit.uniqueName('doHangupAttack')
        else:
            name = 'doHangupAttack'
        if self.suit.type == 'A':
            delay2playSound = 1.0
            delayAfterSoundToPlaceDownReceiver = 0.2
            delayAfterShootToIgnoreCollisions = 1.0
            delay2PickUpReceiver = 1.0
            receiverInHandPos = Point3(-0.5, 0.5, -1)
        elif self.suit.type == 'B':
            delay2playSound = 1.5
            delayAfterSoundToPlaceDownReceiver = 0.7
            delayAfterShootToIgnoreCollisions = 1.0
            delay2PickUpReceiver = 1.5
            receiverInHandPos = Point3(-0.3, 0.5, -0.8)
        elif self.suit.type == 'C':
            delay2playSound = 1.0
            delayAfterSoundToPlaceDownReceiver = 1.15
            delayAfterShootToIgnoreCollisions = 1.0
            delay2PickUpReceiver = 1.5
            receiverInHandPos = Point3(-0.3, 0.5, -0.8)
        self.suitTrack = Parallel(name=name)
        self.suitTrack.append(ActorInterval(self.suit, 'phone'))
        self.suitTrack.append(Sequence(Wait(delay2playSound), SoundInterval(self.phoneSfx, duration=2.1), Wait(delayAfterSoundToPlaceDownReceiver), Func(self.receiver.setPos, 0, 0, 0), Func(self.receiver.setH, 0.0), Func(self.receiver.reparentTo, self.phone), Func(self.acceptOnce, 'enter' + self.collNP.node().getName(), self.handleCollision), Func(self.shootOut), Parallel(SoundInterval(self.hangupSfx), Sequence(Wait(delayAfterShootToIgnoreCollisions), Func(self.ignore, 'enter' + self.collNP.node().getName())))))
        self.suitTrack.append(Sequence(Func(self.phone.reparentTo, self.suit.find('**/joint_Lhold')), Func(self.cord.reparentTo, render), Wait(delay2PickUpReceiver), Func(self.receiver.reparentTo, self.suit.find('**/joint_Rhold')), Func(self.receiver.setPos, receiverInHandPos), Func(self.receiver.setH, 270.0)))
        self.suitTrack.setDoneEvent(self.suitTrack.getName())
        self.acceptOnce(self.suitTrack.getDoneEvent(), self.finishedAttack)
        self.suitTrack.delayDelete = DelayDelete.DelayDelete(self.suit, name)
        self.suitTrack.start(ts)

    def handleCollision(self, entry):
        if self.suit:
            self.suit.sendUpdate('toonHitByWeapon', [self.getAttackId(self.attack), base.localAvatar.doId])
            base.localAvatar.b_handleSuitAttack(self.getAttackId(self.attack), self.suit.doId)

    def shootOut(self):
        pathNode = NodePath('path')
        pathNode.reparentTo(self.suit)
        pathNode.setPos(0, 50, self.phone.getZ(self.suit))
        self.collNP.reparentTo(render)
        self.shootIval = LerpPosInterval(self.collNP, duration=1.0, pos=pathNode.getPos(render), startPos=self.phone.getPos(render))
        self.shootIval.start()
        pathNode.removeNode()
        del pathNode

    def cleanup(self):
        Attack.cleanup(self)
        if self.shootIval:
            self.shootIval.pause()
            self.shootIval = None
        if self.cord:
            self.cord.removeNode()
            self.cord = None
        if self.phone:
            self.phone.removeNode()
            self.phone = None
        if self.receiver:
            self.receiver.removeNode()
            self.receiver = None
        if self.collNP:
            self.collNP.node().clearSolids()
            self.collNP.removeNode()
            self.collNP = None
        if self.phoneSfx:
            self.phoneSfx.stop()
            self.phoneSfx = None
        return
class HangUpAttack(Attack):
    notify = directNotify.newCategory('HangUpAttack')
    attack = 'hangup'

    def __init__(self, attacksClass, suit):
        Attack.__init__(self, attacksClass, suit)
        self.phone = None
        self.receiver = None
        self.collNP = None
        self.phoneSfx = None
        self.hangupSfx = None
        self.shootIval = None
        self.cord = None
        self.receiverOutCord = None
        self.phoneOutCord = None
        return

    def loadAttack(self):
        self.phone = loader.loadModel('phase_3.5/models/props/phone.bam')
        self.phone.setHpr(0, 0, 180)
        if self.suit.type == 'B':
            self.phone.setPos(0.7, 0.15, 0)
        else:
            if self.suit.type == 'C':
                self.phone.setPos(0.25, 0, 0)
        self.receiver = loader.loadModel('phase_3.5/models/props/receiver.bam')
        self.receiver.reparentTo(self.phone)
        self.cord = Rope()
        self.cord.ropeNode.setUseVertexColor(1)
        self.cord.ropeNode.setUseVertexThickness(1)
        self.cord.setup(3, ({'node': self.phone, 'point': (0.8, 0, 0.2), 'color': (0, 0, 0, 1), 'thickness': 1000}, {'node': self.phone, 'point': (2, 0, 0), 'color': (0, 0, 0, 1), 'thickness': 1000}, {'node': self.receiver, 'point': (1.1, 0.25, 0.5), 'color': (0, 0, 0, 1), 'thickness': 1000}), [])
        self.cord.setH(180)
        self.phoneSfx = base.audio3d.loadSfx('phase_3.5/audio/sfx/SA_hangup.ogg')
        base.audio3d.attachSoundToObject(self.phoneSfx, self.phone)
        self.hangupSfx = base.audio3d.loadSfx('phase_3.5/audio/sfx/SA_hangup_place_down.ogg')
        base.audio3d.attachSoundToObject(self.hangupSfx, self.phone)
        collSphere = CollisionSphere(0, 0, 0, 2)
        collSphere.setTangible(0)
        collNode = CollisionNode('phone_shootout')
        collNode.addSolid(collSphere)
        collNode.setCollideMask(CIGlobals.WallBitmask)
        self.collNP = self.phone.attachNewNode(collNode)

    def doAttack(self, ts=0):
        self.loadAttack()
        if hasattr(self.suit, 'uniqueName'):
            name = self.suit.uniqueName('doHangupAttack')
        else:
            name = 'doHangupAttack'
        if self.suit.type == 'A':
            delay2playSound = 1.0
            delayAfterSoundToPlaceDownReceiver = 0.2
            delayAfterShootToIgnoreCollisions = 1.0
            delay2PickUpReceiver = 1.0
            receiverInHandPos = Point3(-0.5, 0.5, -1)
        else:
            if self.suit.type == 'B':
                delay2playSound = 1.5
                delayAfterSoundToPlaceDownReceiver = 0.7
                delayAfterShootToIgnoreCollisions = 1.0
                delay2PickUpReceiver = 1.5
                receiverInHandPos = Point3(-0.3, 0.5, -0.8)
            else:
                if self.suit.type == 'C':
                    delay2playSound = 1.0
                    delayAfterSoundToPlaceDownReceiver = 1.15
                    delayAfterShootToIgnoreCollisions = 1.0
                    delay2PickUpReceiver = 1.5
                    receiverInHandPos = Point3(-0.3, 0.5, -0.8)
        self.suitTrack = Parallel(name=name)
        self.suitTrack.append(ActorInterval(self.suit, 'phone'))
        self.suitTrack.append(Sequence(Wait(delay2playSound), SoundInterval(self.phoneSfx, duration=2.1), Wait(delayAfterSoundToPlaceDownReceiver), Func(self.receiver.setPos, 0, 0, 0), Func(self.receiver.setH, 0.0), Func(self.receiver.reparentTo, self.phone), Func(self.acceptOnce, 'enter' + self.collNP.node().getName(), self.handleCollision), Func(self.shootOut), Parallel(SoundInterval(self.hangupSfx), Sequence(Wait(delayAfterShootToIgnoreCollisions), Func(self.ignore, 'enter' + self.collNP.node().getName())))))
        self.suitTrack.append(Sequence(Func(self.phone.reparentTo, self.suit.find('**/joint_Lhold')), Func(self.cord.reparentTo, render), Wait(delay2PickUpReceiver), Func(self.receiver.reparentTo, self.suit.find('**/joint_Rhold')), Func(self.receiver.setPos, receiverInHandPos), Func(self.receiver.setH, 270.0)))
        self.suitTrack.setDoneEvent(self.suitTrack.getName())
        self.acceptOnce(self.suitTrack.getDoneEvent(), self.finishedAttack)
        self.suitTrack.delayDelete = DelayDelete.DelayDelete(self.suit, name)
        self.suitTrack.start(ts)

    def handleCollision(self, entry):
        if self.suit:
            self.suit.sendUpdate('toonHitByWeapon', [self.getAttackId(self.attack), base.localAvatar.doId])
            base.localAvatar.b_handleSuitAttack(self.getAttackId(self.attack), self.suit.doId)

    def shootOut(self):
        pathNode = NodePath('path')
        pathNode.reparentTo(self.suit)
        pathNode.setPos(0, 50, self.phone.getZ(self.suit))
        self.collNP.reparentTo(render)
        self.shootIval = LerpPosInterval(self.collNP, duration=1.0, pos=pathNode.getPos(render), startPos=self.phone.getPos(render))
        self.shootIval.start()
        pathNode.removeNode()
        del pathNode

    def cleanup(self):
        Attack.cleanup(self)
        if self.shootIval:
            self.shootIval.pause()
            self.shootIval = None
        if self.cord:
            self.cord.removeNode()
            self.cord = None
        if self.phone:
            self.phone.removeNode()
            self.phone = None
        if self.receiver:
            self.receiver.removeNode()
            self.receiver = None
        if self.collNP:
            self.collNP.node().clearSolids()
            self.collNP.removeNode()
            self.collNP = None
        if self.phoneSfx:
            self.phoneSfx.stop()
            self.phoneSfx = None
        return
示例#3
0
class DistributedDeliveryTruck(DistributedNode):
    notify = directNotify.newCategory('DistributedDeliveryTruck')
    barrelscale = 0.15
    barrelpoints = [(1.05, 2.68, 0.84), (0, 2.68, 0.84), (-1.05, 2.68, 0.84),
                    (1.05, 3.68, 0.84), (0, 3.68, 0.84), (-1.05, 3.68, 0.84),
                    (1.05, 4.68, 0.84), (0, 4.68, 0.84), (-1.05, 4.68, 0.84),
                    (1.05, 5.68, 0.84), (0, 5.68, 0.84), (-1.05, 5.68, 0.84),
                    (1.05, 6.68, 0.84), (0, 6.68, 0.84), (-1.05, 6.68, 0.84),
                    (1.05, 7.68, 0.84), (0, 7.68, 0.84), (-1.05, 7.68, 0.84)]

    def __init__(self, cr):
        DistributedNode.__init__(self, cr)
        self.kart = None
        self.rope = None
        self.pod = None
        self.barrels = []
        self.numBarrels = 0
        self.triggerNP = None
        self.mg = None
        return

    def setNumBarrels(self, num):
        self.numBarrels = num
        self.__generateBarrels()

    def getNumBarrels(self):
        return self.numBarrels

    def __removeAllBarrels(self):
        for barrel in self.barrels:
            barrel.removeNode()

        self.barrels = []

    def __generateBarrels(self):
        self.__removeAllBarrels()
        for i in xrange(self.numBarrels):
            point = self.barrelpoints[i]
            barrel = loader.loadModel('phase_4/models/cogHQ/gagTank.bam')
            barrel.setScale(self.barrelscale)
            barrel.setPos(point)
            barrel.setH(180)
            barrel.reparentTo(self)
            self.barrels.append(barrel)

    def __handleTruckTrigger(self, entry):
        if not base.localAvatar.hasBarrel:
            self.sendUpdate('requestBarrel')

    def announceGenerate(self):
        DistributedNode.announceGenerate(self)
        self.kart = loader.loadModel('phase_6/models/karting/Kart3_Final.bam')
        self.kart.find('**/decals').removeNode()
        self.kart.reparentTo(self)
        self.pod = loader.loadModel('phase_4/models/minigames/pods_truck.egg')
        self.pod.reparentTo(self)
        self.pod.setScale(0.2)
        self.pod.setY(8.5)
        self.pod.setH(180)
        self.pod.find('**/metal_ramp').setBin('ground', 18)
        self.pod.find('**/metal_ramp_coll').setCollideMask(
            CIGlobals.FloorBitmask)
        self.rope = Rope()
        self.rope.ropeNode.setUseVertexColor(1)
        self.rope.setup(3, ({
            'node': self.kart,
            'point': (0, 1.5, 0.7),
            'color': (0, 0, 0, 1),
            'thickness': 1000
        }, {
            'node': self.kart,
            'point': (0, 1.5, 0.7),
            'color': (0, 0, 0, 1),
            'thickness': 1000
        }, {
            'node': self.pod,
            'point': (0, 31, 5),
            'color': (0, 0, 0, 1),
            'thickness': 1000
        }), [])
        self.rope.setH(180)
        self.rope.reparentTo(self)
        sphere = CollisionSphere(0, 0, 0, 2)
        sphere.setTangible(0)
        node = CollisionNode(self.uniqueName('truck_trigger'))
        node.addSolid(sphere)
        node.setCollideMask(CIGlobals.WallBitmask)
        self.triggerNP = self.attachNewNode(node)
        self.triggerNP.setPos(0, 8.0, 2.0)
        self.setScale(2.0)
        self.accept('enter' + self.triggerNP.node().getName(),
                    self.__handleTruckTrigger)

    def disable(self):
        self.ignore('enter' + self.triggerNP.node().getName())
        self.__removeAllBarrels()
        self.barrels = None
        self.numBarrels = None
        if self.rope:
            self.rope.removeNode()
            self.rope = None
        if self.pod:
            self.pod.removeNode()
            self.pod = None
        if self.kart:
            self.kart.removeNode()
            self.kart = None
        self.mg = None
        DistributedNode.disable(self)
        return
class DistributedDeliveryTruck(DistributedNode):
    notify = directNotify.newCategory('DistributedDeliveryTruck')
    barrelscale = 0.15
    barrelpoints = [(1.05, 2.68, 0.84),
     (0, 2.68, 0.84),
     (-1.05, 2.68, 0.84),
     (1.05, 3.68, 0.84),
     (0, 3.68, 0.84),
     (-1.05, 3.68, 0.84),
     (1.05, 4.68, 0.84),
     (0, 4.68, 0.84),
     (-1.05, 4.68, 0.84),
     (1.05, 5.68, 0.84),
     (0, 5.68, 0.84),
     (-1.05, 5.68, 0.84),
     (1.05, 6.68, 0.84),
     (0, 6.68, 0.84),
     (-1.05, 6.68, 0.84),
     (1.05, 7.68, 0.84),
     (0, 7.68, 0.84),
     (-1.05, 7.68, 0.84)]

    def __init__(self, cr):
        DistributedNode.__init__(self, cr)
        self.kart = None
        self.rope = None
        self.pod = None
        self.barrels = []
        self.numBarrels = 0
        self.triggerNP = None
        self.mg = None
        return

    def setNumBarrels(self, num):
        self.numBarrels = num
        self.__generateBarrels()

    def getNumBarrels(self):
        return self.numBarrels

    def __removeAllBarrels(self):
        for barrel in self.barrels:
            barrel.removeNode()

        self.barrels = []

    def __generateBarrels(self):
        self.__removeAllBarrels()
        for i in xrange(self.numBarrels):
            point = self.barrelpoints[i]
            barrel = loader.loadModel('phase_4/models/cogHQ/gagTank.bam')
            barrel.setScale(self.barrelscale)
            barrel.setPos(point)
            barrel.setH(180)
            barrel.reparentTo(self)
            self.barrels.append(barrel)

    def __handleTruckTrigger(self, entry):
        if not base.localAvatar.hasBarrel:
            self.sendUpdate('requestBarrel')

    def announceGenerate(self):
        DistributedNode.announceGenerate(self)
        self.kart = loader.loadModel('phase_6/models/karting/Kart3_Final.bam')
        self.kart.find('**/decals').removeNode()
        self.kart.reparentTo(self)
        self.pod = loader.loadModel('phase_4/models/minigames/pods_truck.egg')
        self.pod.reparentTo(self)
        self.pod.setScale(0.2)
        self.pod.setY(8.5)
        self.pod.setH(180)
        self.rope = Rope()
        self.rope.ropeNode.setUseVertexColor(1)
        self.rope.setup(3, ({'node': self.kart,
          'point': (0, 1.5, 0.7),
          'color': (0, 0, 0, 1),
          'thickness': 1000}, {'node': self.kart,
          'point': (0, 1.5, 0.7),
          'color': (0, 0, 0, 1),
          'thickness': 1000}, {'node': self.pod,
          'point': (0, 31, 5),
          'color': (0, 0, 0, 1),
          'thickness': 1000}), [])
        self.rope.setH(180)
        self.rope.reparentTo(self)
        sphere = CollisionSphere(0, 0, 0, 2)
        sphere.setTangible(0)
        node = CollisionNode(self.uniqueName('truck_trigger'))
        node.addSolid(sphere)
        node.setCollideMask(CIGlobals.WallBitmask)
        self.triggerNP = self.attachNewNode(node)
        self.triggerNP.setPos(0, 8.0, 2.0)
        self.setScale(2.0)
        self.accept('enter' + self.triggerNP.node().getName(), self.__handleTruckTrigger)

    def disable(self):
        self.ignore('enter' + self.triggerNP.node().getName())
        self.__removeAllBarrels()
        self.barrels = None
        self.numBarrels = None
        if self.rope:
            self.rope.removeNode()
            self.rope = None
        if self.pod:
            self.pod.removeNode()
            self.pod = None
        if self.kart:
            self.kart.removeNode()
            self.kart = None
        self.mg = None
        DistributedNode.disable(self)
        return