示例#1
0
    def handleMessage(self, msg):
        self._handleMessageSanityCheck()
        
        if isinstance(msg, bs.DieMessage):
            self.node.delete()

        elif isinstance(msg, ExplodeHitMessage):
            node = bs.getCollisionInfo("opposingNode")
            if node is not None and node.exists():
                t = self.node.position

                # new
                mag = 2000.0
                if self.blastType == 'ice': mag *= 0.7
                elif self.blastType == 'landMine': mag *= 1.5
                elif self.blastType == 'tnt': mag *= 2.6

                node.handleMessage(bs.HitMessage(pos=t,
                                                 velocity=(0,0.1,0),
                                                 magnitude=mag,
                                                 hitType=self.hitType,
                                                 hitSubType=self.hitSubType,
                                                 radius=self.radius,
                                                 sourcePlayer=self.sourcePlayer))
                if self.blastType == "ice":
                    bs.playSound(Bomb.getFactory().freezeSound, 10, position=t)
                    node.handleMessage(bs.FreezeMessage())

        else:
            bs.Actor.handleMessage(self, msg)
示例#2
0
 def _updateBoxState(self):
     claimerHold = False
     userperHold = False
     for player in self.getActivity().players:
         try:
             if player.actor.isAlive(
             ) and player.actor.node.holdNode.exists():
                 holdingBox = (player.actor.node.holdNode == self.node)
             else:
                 holdingBox = False
         except Exception:
             bs.printException("exception checking hold flag")
         if holdingBox:
             if self.claimedBy is None:
                 self.claimedBy = player
                 claimerHold = True
             else:
                 if self.claimedBy == player:
                     claimerHold = True
                 else:
                     userperHold = True
     #release claim on any other existing boxes
     for box in self.getActivity().boxes:
         if box <> self and box.claimedBy == self.claimedBy:
             box.claimedBy = None
     #Blow up this box if it belongs to someone else
     if (not claimerHold) and userperHold:
         self.handleMessage(bs.HitMessage())
    def handleMessage(self, msg):
        self._handleMessageSanityCheck()
        
        if isinstance(msg, bs.DieMessage):
            self.node.delete()

        elif isinstance(msg, ExplodeHitMessage):
            node = bs.getCollisionInfo("opposingNode")
            if node is not None and node.exists():
                t = self.node.position

                # new
                mag = 2000.0
                if self.blastType == 'ice': mag *= 0.5
                elif self.blastType == 'landMine': mag *= 2.5
                elif self.blastType == 'tnt': mag *= 2.0
                elif self.blastType == 'tbomb': mag *= 0.0
                elif self.blastType == 'weedbomb': mag *= 0.0
                elif self.blastType == 'gluebomb': mag *= 0.01

                node.handleMessage(bs.HitMessage(
                    pos=t,
                    velocity=(0,0,0),
                    magnitude=mag,
                    hitType=self.hitType,
                    hitSubType=self.hitSubType,
                    radius=self.radius,
                    sourcePlayer=self.sourcePlayer))
                if self.blastType == "ice":
                    bs.playSound(Bomb.getFactory().freezeSound, 10, position=t)
                    node.handleMessage(bs.FreezeMessage())
                node = bs.getCollisionInfo("opposingNode")
                if self.blastType == "weedbomb" and not node.getNodeType() != 'spaz':
                    bs.playSound(Bomb.getFactory().hissSound, 9, position=t)
                    def weed():
                	    node.handleMessage("knockout",10000)
                    bs.gameTimer(2000,bs.Call(weed)) #delay (forgot about the epic)
                    bs.gameTimer(5500,bs.Call(weed))
                    bs.gameTimer(8500,bs.Call(weed))
                    def hiccups():
                    	bs.emitBGDynamics(position=(node.position[0],node.position[1]-1.2,node.position[2]), velocity=(0,0.05,0), count=random.randrange(100,270), scale=1+random.random(), spread=0.71, chunkType='sweat') #reminds me of tom and jerry
                    bs.gameTimer(1000,bs.Call(hiccups))
                    bs.gameTimer(2500,bs.Call(hiccups)) #showing we are alive
                    bs.gameTimer(5000,bs.Call(hiccups))
                    bs.gameTimer(7500,bs.Call(hiccups))
                    def look():
                    	bubble = bsUtils.PopupText("o",color=(2.55,1.53,1.02), scale=0.7, randomOffset=0.2, offset=(0,-1,0), position=(node.position[0],node.position[1]-1.2,node.position[2])).autoRetain()
                    bs.gameTimer(1500,bs.Call(look))
                    bs.gameTimer(3000,bs.Call(look))
                    bs.gameTimer(8000,bs.Call(look))
                    def look():
                    	text = bsUtils.PopupText("O",color=(2.55, 1.48, 0.77), scale=0.75, randomOffset=0.2, offset=(0,-1,0), position=(node.position[0],node.position[1]-1.2,node.position[2])).autoRetain()
                    bs.gameTimer(1460,bs.Call(look))
                    bs.gameTimer(2960,bs.Call(look))
                    bs.gameTimer(5460,bs.Call(look))
                    bs.gameTimer(7960,bs.Call(look))
        else:
            bs.Actor.handleMessage(self, msg)
示例#4
0
 def checkForScore(self, box):
     if box.scored: return
     player = box.claimedBy
     if player.actor.isAlive() and player.actor.node.holdNode.exists():
         if player.actor.node.holdNode == box.node:
             box.scored = True
             player.getTeam().gameData['score'] += 1
             bsUtils.animate(box.node, "modelScale", {
                 0: 1.0,
                 150: 0.5,
                 300: 0.0
             })
             bs.gameTimer(300,
                          bs.WeakCall(box.handleMessage, bs.DieMessage()))
             self._updateScoreBoard()
             for playa in player.getTeam().players:
                 try:
                     playa.actor.node.handleMessage('celebrate', 2000)
                 except Exception:
                     pass
             if player.getTeam(
             ).gameData['score'] == self.settings['Score to Win']:
                 player.getTeam().gameData['survivalSeconds'] = (
                     bs.getGameTime() - self._startGameTime) / 1000
                 self.winners.append(player.getTeam())
                 for playa in player.getTeam().players:
                     self._flashPlayer(playa, 1.0)
                     playa.actor.handleMessage(
                         bs.DieMessage(immediate=True))
             bs.playSound(self._scoreSound)
             bs.playSound(self._cheerSound)
         else:
             #print('nobody scored')
             box.handleMessage(bs.HitMessage())
     else:
         box.handleMessage(bs.HitMessage())
示例#5
0
 def _reduceHealth():
     for player in self.players:
         if hasattr(player.actor, 'node') and player.isAlive():
             actor = player.actor
             position = actor.node.position
             if position[1] < 9:
                 actor.node.handleMessage(
                     bs.HitMessage(pos=(position[0], position[1] + 1,
                                        position[2]),
                                   velocity=(0, 0, 0),
                                   magnitude=100
                                   if len(self.players) > 4 else 200,
                                   hitType='explosion',
                                   hitSubType='normal',
                                   radius=1.1,
                                   sourcePlayer=player))
                 if actor.hitPoints <= 0:
                     player.gameData['_playerNode'].node.handleMessage(
                         bs.DieMessage(immediate=False, how='impact'))
                     return
示例#6
0
    def handleMessage(self, m):
        bs.Actor.handleMessage(self, m)
        if isinstance(m, ArrowTouchAnything):
            node = bs.getCollisionInfo("opposingNode")

            if node is not None and node.exists():
                v = self.node.velocity
                t = self.node.position
                hitDir = self.node.velocity
                m = self.node
                self.calcMagByDistance()
                node.handleMessage(bs.HitMessage(pos=t,
                                                 velocity=v,
                                                 magnitude=self.arrowMag,
                                                 velocityMagnitude=self.arrowMag,
                                                 radius=0,
                                                 srcNode=self.node,
                                                 sourcePlayer=self.sourcePlayer,
                                                 forceDirection=hitDir))

            self.node.handleMessage(bs.DieMessage())

        elif isinstance(m, bs.DieMessage):
            if self.node.exists():
                velocity = self.node.velocity
                explosion = bs.newNode("explosion",
                                       attrs={'position': self.node.position,
                                              'velocity': (velocity[0], max(-1.0, velocity[1]), velocity[2]),
                                              'radius': 1,
                                              'big': False})
                bs.playSound(sound=bs.getSound(random.choice(['impactHard', 'impactHard2', 'impactHard3'])),
                             position=self.node.position)
                self.node.delete()
                self.lightNode.delete()
                self._emit = None

        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())

        elif isinstance(m, bs.HitMessage):
            self.node.handleMessage("impulse", m.pos[0], m.pos[1], m.pos[2],
                                    m.velocity[0], m.velocity[1], m.velocity[2],
                                    1.0 * m.magnitude, 1.0 * m.velocityMagnitude, m.radius, 0,
                                    m.forceDirection[0], m.forceDirection[1], m.forceDirection[2])

        elif isinstance(m, ArrowTouchSpaz):
            node = bs.getCollisionInfo("opposingNode")
            if node is not None and node.exists():
                # node.handleMessage(bs.FreezeMessage())

                v = self.node.velocity
                t = self.node.position
                hitDir = self.node.velocity

                self.calcMagByDistance()
                hitType = 'hunter'
                if self.lifeDist > 5:
                    hitType = 'hunterGod'
                    # self.sourcePlayer.actor.setScoreText('狙击精英')
                node.handleMessage(bs.HitMessage(pos=t,
                                                 velocity=(10, 10, 10),
                                                 magnitude=self.arrowMag,
                                                 velocityMagnitude=self.arrowMag,
                                                 radius=0,
                                                 srcNode=self.node,
                                                 sourcePlayer=self.sourcePlayer,
                                                 forceDirection=hitDir,
                                                 hitType=hitType))

            self.node.handleMessage(bs.DieMessage())

        elif isinstance(m, ArrowTouchFootingMaterial):
            self.calcMagByDistance()
            bs.Blast(position=self.node.position,
                     velocity=self.node.velocity,
                     blastRadius=self.arrowBlast, blastType='normal',
                     sourcePlayer=self.sourcePlayer, hitType='hunterBlast').autoRetain()
            self.handleMessage(bs.DieMessage())
            # bs.playSound(sound=bs.getSound("blip"), position=self.node.position)
        elif isinstance(m, bs.PickedUpMessage):
            self.handleMessage(bs.DieMessage())
示例#7
0
    def handleMessage(self,m):
        super(self.__class__, self).handleMessage(m)
        if isinstance(m, otherHitMessage):
            if self._exploded: return #Don't bother with calcs if we've done blowed up or busted.
            if self.shouldBust:
                myVel = self.node.velocity
                #Get the velocity at the instant of impact.  We'll check it after 20ms (after bounce). If it has changed a lot, bust.
                bs.gameTimer(10, bs.WeakCall(self.calcBust,myVel))
            else:
                return
        if isinstance(m,bs.DieMessage):
            self.node.delete()
            bs.gameTimer(100, self.nodeLight.delete)
        elif isinstance(m,bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())
        elif isinstance(m,bs.HitMessage):
            self.node.handleMessage("impulse",m.pos[0],m.pos[1],m.pos[2],
                                    m.velocity[0],m.velocity[1],m.velocity[2],
                                    1.0*m.magnitude,1.0*m.velocityMagnitude,m.radius,0,
                                    m.forceDirection[0],m.forceDirection[1],m.forceDirection[2])
        elif isinstance(m, bs.ImpactDamageMessage):
            print [dir(m), m.intensity]
        elif isinstance(m,snoMessage):
            #We should get a snoMessage any time a snowball hits a spaz.
            #We'll either explode (if we're exploding) or calculate like a punch.
            #We have to do this the hard way because the ImpactMessage won't do it for us (no source)
            #Below is modified pretty much from bsSpaz handling of a _punchHitMessage
            #print bsVector.Vector(*self.node.velocity).length()
            if self._exploded: return #Don't do anything if we've already done our damage, or if we've busted already
            if self.shouldExplode:
                """
                Blows up the ball if it has not yet done so.
                """
                if self._exploded: return
                self._exploded = True
                activity = self.getActivity()
                if activity is not None and self.node.exists():
                    blast = bsBomb.Blast(position=self.node.position,velocity=self.node.velocity,
                                  blastRadius=0.7,blastType='impact',sourcePlayer=self.sourcePlayer,hitType='snoBall',hitSubType='explode').autoRetain()
                    
                # we blew up so we need to go away
                bs.gameTimer(1,bs.WeakCall(self.handleMessage,bs.DieMessage()))
            else:
                v = self.node.velocity
                #Only try to damage if the ball is moving at some reasonable rate of speed
                if bs.Vector(*v).length() > 5.0:
                    node = bs.getCollisionInfo("opposingNode")

                    # only allow one hit per node per ball
                    if node is not None and node.exists() and not node in self._hitNodes:

                        t = self.node.position #was punchPosition
                        hitDir = self.node.velocity 

                        self._hitNodes.add(node)
                        node.handleMessage(bs.HitMessage(pos=t,
                                                         velocity=v,
                                                         magnitude=bsVector.Vector(*v).length()*0.1,
                                                         velocityMagnitude=bsVector.Vector(*v).length()*0.1,
                                                         radius=0,
                                                         srcNode=self.node,
                                                         sourcePlayer=self.sourcePlayer,
                                                         forceDirection = hitDir,
                                                         hitType='snoBall',
                                                         hitSubType='default'))

                if self.shouldBust:
                    #Since we hit someone, let's bust:
                    #Add a very short timer to allow one ball to hit more than one spaz if almost simultaneous.
                    bs.gameTimer(50, bs.WeakCall(self.doBust))
        else:
            bs.Actor.handleMessage(self,m)
示例#8
0
    def handleMessage(self, m):
        super(self.__class__, self).handleMessage(m)
        if isinstance(m, TouchedToAnything):
            node = bs.getCollisionInfo('opposingNode')
            if node is not None and node.exists():
                v = self.node.velocity
                t = self.node.position
                hitDir = self.node.velocity
                m = self.node
                node.handleMessage(
                    bs.HitMessage(
                        pos=t,
                        velocity=v,
                        magnitude=bsVector.Vector(*v).length() * 40,
                        velocityMagnitude=bsVector.Vector(*v).length() * 40,
                        radius=0,
                        srcNode=self.node,
                        sourcePlayer=self.sourcePlayer,
                        forceDirection=hitDir))

            self.node.handleMessage(bs.DieMessage())

        elif isinstance(m, bs.DieMessage):
            if self.node.exists():
                velocity = self.node.velocity
                explosion = bs.newNode('explosion',
                                       attrs={
                                           'position':
                                           self.node.position,
                                           'velocity':
                                           (velocity[0],
                                            max(-1.0,
                                                velocity[1]), velocity[2]),
                                           'radius':
                                           1,
                                           'big':
                                           False
                                       })

                bs.playSound(sound=bs.getSound(
                    random.choice(['impactHard', 'impactHard2',
                                   'impactHard3'])),
                             position=self.node.position)

                self.node.delete()
                self.lightNode.delete()
                self._emit = None

        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())

        elif isinstance(m, bs.HitMessage):
            self.node.handleMessage('impulse', m.pos[0], m.pos[1], m.pos[2],
                                    m.velocity[0], m.velocity[1],
                                    m.velocity[2], 1.0 * m.magnitude,
                                    1.0 * m.velocityMagnitude, m.radius, 0,
                                    m.forceDirection[0], m.forceDirection[1],
                                    m.forceDirection[2])

        elif isinstance(m, TouchedToSpaz):
            node = bs.getCollisionInfo('opposingNode')
            try:
                if node is not None and node.exists() and node != self.owner \
                        and node.getDelegate().getPlayer().getTeam() != self.owner.getTeam():
                    node.handleMessage(bs.FreezeMessage())
                    v = self.node.velocity
                    t = self.node.position
                    hitDir = self.node.velocity

                    node.handleMessage(
                        bs.HitMessage(pos=t,
                                      velocity=(10, 10, 10),
                                      magnitude=50,
                                      velocityMagnitude=50,
                                      radius=0,
                                      srcNode=self.node,
                                      sourcePlayer=self.sourcePlayer,
                                      forceDirection=hitDir))

                self.node.handleMessage(bs.DieMessage())
            except:
                pass

        elif isinstance(m, TouchedToFootingMaterial):
            bs.playSound(sound=bs.getSound('blip'),
                         position=self.node.position)
示例#9
0
    def handleMessage(self, msg):
        self._handleMessageSanityCheck()

        if isinstance(msg, bs.DieMessage):
            self.node.delete()

        elif isinstance(msg, DirtBombOutMessage):
            node = bs.getCollisionInfo("opposingNode")
            if node is not None and node.exists(): 
                if node in getattr(self, 'dirt_nodes', []): self.dirt_nodes.remove(node)
                node.handleMessage(DirtBombOutMessage())

        elif isinstance(msg, ExplodeHitMessage):
            node = bs.getCollisionInfo("opposingNode")
            if node is not None and node.exists():
                t = self.node.position

                # new
                mag = 2000.0
                if self.blastType == 'ice': mag *= 0.5
                elif self.blastType == 'landMine': mag *= 2.5
                elif self.blastType == 'firework': mag *= 0.2
                elif self.blastType == 'tp': mag *= 0.65
                elif self.blastType == 'qq': mag *= 0.65
                elif self.blastType == 'killLaKill': mag *= 1.75
                elif self.blastType == 'tnt': mag *= 2.0
                elif self.blastType == 'poison': mag *= 0.4
                elif self.blastType == 'boss': mag *= 5.0

                
                if self.blastType not in ['dirt']:
                    node.handleMessage(bs.HitMessage(
                        pos=t,
                        velocity=(0,0,0),
                        magnitude=mag,
                        hitType=self.hitType,
                        hitSubType=self.hitSubType,
                        radius=self.radius,
                        sourcePlayer=self.sourcePlayer, 
                        kickBack = 0))
                if self.blastType == "ice":
                    bs.playSound(Bomb.getFactory().freezeSound, 10, position=t)
                    node.handleMessage(bs.FreezeMessage())
                elif self.blastType == "firework":
                    node.handleMessage(FireworkBombHitMessage())
                elif self.blastType == "poison":
                    node.handleMessage(PoisonBombHitMessage())
                elif self.blastType == "qq":
                    node.handleMessage("knockout", 110.0)
                elif self.blastType == "tp":
                    node.handleMessage(TeleportBombHitMessage())
                    node.handleMessage("knockout", 45.0)
                elif self.blastType == "boss":
                    node.handleMessage("knockout", 100.0)
                elif self.blastType == "dirt" and node.getNodeType() == "spaz":
                    bs.playSound(Bomb.getFactory().splatterSound, 10, position=t)
                    node.handleMessage(bs.SlowMoveMessage())
                    if not hasattr(self, 'dirt_nodes'): self.dirt_nodes=[node]
                    elif node not in self.dirt_nodes: self.dirt_nodes.append(node)
        else:
            bs.Actor.handleMessage(self, msg)