Пример #1
0
    def _handleHitOwnFlag(self,team,val):

        # keep track of when each player is touching their own flag so we can award points when returned
        srcNode = bs.getCollisionInfo('sourceNode')
        try: player = srcNode.getDelegate().getPlayer()
        except Exception: player = None
        if player is not None and player.exists():
            if val: player.gameData['touchingOwnFlag'] += 1
            else: player.gameData['touchingOwnFlag'] -= 1

        # if return-time is zero, just kill it immediately.. otherwise keep track of touches and count down
        if float(self.settings['Flag Touch Return Time']) <= 0.0:
            if not team.gameData['homeFlagAtBase'] and team.gameData['flag']._heldCount == 0:
                # use a node message to kill the flag instead of just killing our team's.
                # (avoids redundantly killing new flags if multiple body parts generate callbacks in one step)
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    self._awardPlayersTouchingOwnFlag(team)
                    node.handleMessage(bs.DieMessage())
        # takes a non-zero amount of time to return
        else:
            if val:
                team.gameData['flagReturnTouches'] += 1
                if team.gameData['flagReturnTouches'] == 1:
                    team.gameData['touchReturnTimer'] = bs.Timer(100,call=bs.Call(self._touchReturnUpdate,team),repeat=True)
                    team.gameData['touchReturnTimerTicking'] = None
            else:
                team.gameData['flagReturnTouches'] -= 1
                if team.gameData['flagReturnTouches'] == 0:
                    team.gameData['touchReturnTimer'] = None
                    team.gameData['touchReturnTimerTicking'] = None
            if team.gameData['flagReturnTouches'] < 0:
                bs.printError('CTF: flagReturnTouches < 0; this shouldn\'t happen.')
    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)
Пример #3
0
    def _handlescore(self):
        """ a point has been scored """

        # our puck might stick around for a second or two
        # we dont want it to be able to score again
        if self._puck.scored: return

        region = bs.getCollisionInfo("sourceNode")
        for i in range(len(self._scoreregions)):
            if region == self._scoreregions[i].node:
                break

        scoringteam = None
        for team in self.teams:
            if team.getID() == i:
                scoringteam = team
                team.gameData['score'] += 1

                # tell all players to celebrate
                for player in team.players:
                    try:
                        player.actor.node.handleMessage('celebrate', 2000)
                    except Exception:
                        pass

                # if weve got the player from the scoring
                # team that last touched us, give them points
                if (scoringteam.getID() in self._puck.lastplayerstotouch
                        and self._puck.lastplayerstotouch[
                            scoringteam.getID()].exists()):
                    self.scoreSet.playerScored(
                        self._puck.lastplayerstotouch[scoringteam.getID()],
                        100,
                        bigMessage=True)

                # end game if we won
                if team.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()

        bs.playSound(self._foghornsound)
        bs.playSound(self._cheersound)

        self._puck.scored = True

        # kill the puck (it'll respawn itself shortly)
        bs.gameTimer(1000, self._killpuck)

        light = bs.newNode('light',
                           attrs={
                               'position': bs.getCollisionInfo('position'),
                               'heightAttenuated': False,
                               'color': (1, 0, 0)
                           })
        bs.animate(light, 'intensity', {0: 0, 500: 1, 1000: 0}, loop=True)
        bs.gameTimer(1000, light.delete)

        self.cameraFlash(duration=10)
        self._updatescoreboard()
Пример #4
0
    def _handleScore(self):
        """ a point has been scored """

        # our flag might stick around for a second or two
        # we dont want it to be able to score again
        if self._flag.scored:
            return

        # see which score region it was..
        region = bs.getCollisionInfo("sourceNode")
        for i in range(len(self.scoreRegions)):
            if region == self.scoreRegions[i].node:
                break

        for team in [self.teams[0], self._botTeam]:
            if team.getID() == i:
                team.gameData['score'] += 7

                # tell all players (or bots) to celebrate
                if i == 0:
                    for player in team.players:
                        try:
                            player.actor.node.handleMessage('celebrate', 2000)
                        except Exception:
                            pass
                else:
                    self._bots.celebrate(2000)

        # if the good guys scored, add more enemies
        if i == 0:
            if self.teams[0].gameData['score'] == 7:
                for t in self._botTypes7:
                    self._spawnBot(t)
            elif self.teams[0].gameData['score'] == 14:
                for t in self._botTypes14:
                    self._spawnBot(t)

        bs.playSound(self._scoreSound)
        if i == 0: bs.playSound(self._cheerSound)
        else: bs.playSound(self._booSound)

        #kill the flag (it'll respawn shortly)
        self._flag.scored = True

        bs.gameTimer(200, self._killFlag)

        self.updateScores()
        light = bs.newNode('light',
                           attrs={
                               'position': bs.getCollisionInfo('position'),
                               'heightAttenuated': False,
                               'color': (1, 0, 0)
                           })
        bs.animate(light, 'intensity', {0: 0, 500: 1, 1000: 0}, loop=True)
        bs.gameTimer(1000, light.delete)
        if i == 0: self.cameraFlash(duration=10)
Пример #5
0
    def _handleScore(self):
        """ a point has been scored """

        # our flag might stick around for a second or two
        # make sure it doesn't score again
        if self._flag.scored: return

        region = bs.getCollisionInfo("sourceNode")
        for i in range(len(self._scoreRegions)):
            if region == self._scoreRegions[i].node:
                break

        for team in self.teams:
            if team.getID() == i:
                team.gameData['score'] += 1

                # tell all players to celebrate
                for player in team.players:
                    try:
                        player.actor.node.handleMessage('celebrate', 2000)
                    except Exception:
                        pass

                # if someone on this team was last to touch it, give them points
                if (self._flag.lastHoldingPlayer is not None
                        and self._flag.lastHoldingPlayer.exists()
                        and team == self._flag.lastHoldingPlayer.getTeam()):
                    self.scoreSet.playerScored(self._flag.lastHoldingPlayer,
                                               50,
                                               bigMessage=True)

                # end game if we won
                if team.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()

        bs.playSound(self._scoreSound)
        bs.playSound(self._cheerSound)

        self._flag.scored = True

        # kill the flag (it'll respawn shortly)
        bs.gameTimer(1000, self._killFlag)
        bs.gameTimer(3000, self._spawnFlag)

        light = bs.newNode('light',
                           attrs={
                               'position': bs.getCollisionInfo('position'),
                               'heightAttenuated': False,
                               'color': (1, 0, 0)
                           })
        bs.animate(light, 'intensity', {0: 0, 500: 1, 1000: 0}, loop=True)
        bs.gameTimer(1000, light.delete)

        self.cameraFlash(duration=10)
        self._updateScoreBoard()
 def _handleSplat(self,m):
     node = bs.getCollisionInfo("opposingNode")
     if (node is not self.owner
             and bs.getGameTime() - self._lastStickySoundTime > 1000):
         self._lastStickySoundTime = bs.getGameTime()
         bs.playSound(self.getFactory().stickyImpactSound, 2.0,
                      position=self.node.position)
 def _handleImpact(self,m):
     node,body = bs.getCollisionInfo("opposingNode","opposingBody")
     # if we're an impact bomb and we came from this node, don't explode...
     # alternately if we're hitting another impact-bomb from the same source,
     # don't explode...
     try: nodeDelegate = node.getDelegate()
     except Exception: nodeDelegate = None
     if node is not None and node.exists():
         if (self.bombType == 'tbomb' and
             (node is self.owner
              or (isinstance(nodeDelegate, Bomb)
                  and nodeDelegate.bombType == 'tbomb'
                  and nodeDelegate.owner is self.owner))): return
         elif (self.bombType == 'weedbomb' and
             (node is self.owner
              or (isinstance(nodeDelegate, Bomb)
                  and nodeDelegate.bombType == 'weedbomb'
                  and nodeDelegate.owner is self.owner))): return
         elif (self.bombType == 'impact' and
             (node is self.owner
              or (isinstance(nodeDelegate, Bomb)
                  and nodeDelegate.bombType == 'impact'
                  and nodeDelegate.owner is self.owner))): return
         elif (self.bombType == 'gluebomb' and
             (node is self.owner
              or (isinstance(nodeDelegate, Bomb)
                  and nodeDelegate.bombType == 'gluebomb'
                  and nodeDelegate.owner is self.owner))): return
         else:
             self.handleMessage(ExplodeMessage())
    def handleMessage(self, m):
        super(self.__class__, self).handleMessage(m)

        if isinstance(m, bs.DieMessage):
            self.node.delete()
        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())
        elif isinstance(m, bs.DroppedMessage):
            bs.gameTimer(
                200, bs.WeakCall(self.handleMessage, doorStartUseMessage()))
        elif isinstance(m, doorStartUseMessage):
            self.canUse = True
        elif isinstance(m, doorHitSpazMessage):
            if not self.canUse:
                return
            if self._used:
                return
            oppoNode = bs.getCollisionInfo("opposingNode")
            if oppoNode is not None and oppoNode.exists():
                activity = self._activity()
                pos = self.getFactory().getRandomPosition(activity)
                oppoNode.handleMessage(bs.StandMessage(pos))
                bs.Blast(position=pos, blastRadius=1.0,
                         blastType='smoke').autoRetain()
                bs.playSound(bs.getSound('shieldDown'))

            self._disappear()
Пример #9
0
 def _handleResetCollide(self):
     # if we have a chosen one ignore these
     if self._getChosenOnePlayer() is not None: return
     try: player = bs.getCollisionInfo("opposingNode").getDelegate().getPlayer()
     except Exception: return
     if player is not None and player.isAlive():
         self._setChosenOnePlayer(player)
Пример #10
0
 def _onCapsulePlayerCollide(self):
     if not self.hasEnded():
         capsuleNode, playerNode = bs.getCollisionInfo('sourceNode','opposingNode')
         if capsuleNode is not None and playerNode is not None:
             capsule = capsuleNode.getDelegate()
             spaz = playerNode.getDelegate()
             player = spaz.getPlayer() if hasattr(spaz,'getPlayer') else None
             if player is not None and player.exists() and capsule is not None:
                 if player.isAlive():
                     if capsuleNode.colorTexture == self._capsuleLuckyTex:
                         player.gameData['capsules'] += 4
                         bsUtils.PopupText('BONUS!',
                                           color=(1,1,0),
                                           scale=1.5,
                                           position=(capsuleNode.position)).autoRetain()
                         bs.playSound(self._luckyCollectSound,1.0,position=capsuleNode.position)
                         bs.emitBGDynamics(position=capsuleNode.position,velocity=(0,0,0),count=int(6.4+random.random()*24),scale=1.2, spread=2.0,chunkType='spark');
                         bs.emitBGDynamics(position=capsuleNode.position,velocity=(0,0,0),count=int(4.0+random.random()*6),emitType='tendrils');
                     else:
                         player.gameData['capsules'] += 1
                         bs.playSound(self._collectSound,0.6,position=capsuleNode.position)
                     # create a flash
                     light = bs.newNode('light',
                                     attrs={'position': capsuleNode.position,
                                             'heightAttenuated':False,
                                             'radius':0.1,
                                             'color':(1,1,0)})
                     
                     # Create a short text informing about your inventory
                     self._handleCapsuleStorage(playerNode.position,player)
                     
                     bs.animate(light,'intensity',{0:0,100:0.5,200:0},loop=False)
                     bs.gameTimer(200,light.delete)
                     capsule.handleMessage(bs.DieMessage())
    def handleMessage(self, m):
        if isinstance(m, PuckTouchedMessage):
            node = bs.getCollisionInfo("opposingNode")
            # bs.screenMessage(str(node.position))
            # node.sourcePlayer
            if node.sourcePlayer.getTeam() == self.team:
                return

                # Score - isAlive to avoid multiple kills per death
            if "notKilled" not in node.sourcePlayer.gameData:
                node.sourcePlayer.gameData["notKilled"] = True
            if node.sourcePlayer.gameData["notKilled"]:
                # node.sourcePlayer.getTeam().gameData['timesKilled'] += 1
                self.team.gameData["score"] += 1
                bs.getActivity()._updateScoreBoard()
            node.sourcePlayer.gameData["notKilled"] = False

            x, y, z = node.position
            node.handleMessage("impulse", x, y, z, 0, 0, 0, 1000.0, 0, 3, 0, 0, 0, 0)  # velocity  # forceDirection
            node.frozen = True
            bs.gameTimer(1000, node.sourcePlayer.actor.shatter)
        if isinstance(m, bs.OutOfBoundsMessage):
            self.node.position = self._spawnPos
            self.movedSinceSpawn = False
            self.age = 0
        else:
            bsHockey.Puck.handleMessage(self, m)
Пример #12
0
 def handleSafeZoneEnter(self):
     self.checkEnd()
     zoneNode, playerNode = bs.getCollisionInfo("sourceNode",
                                                "opposingNode")
     try:
         player = playerNode.getDelegate().getPlayer()
     except Exception:
         return
     if player.isAlive() and player.actor.node.getDelegate().isShark:
         player.actor.handleMessage(bs.DieMessage())
         self.sharkify(player)
     elif player.isAlive() and not player.actor.node.getDelegate().isShark:
         if player.actor.node.positionCenter[
                 0] < 0 and player.actor.node.getDelegate().nextZone == 1:
             player.getTeam().gameData['score'] += 10
             self.scoreSet.playerScored(player,
                                        10,
                                        screenMessage=False,
                                        display=False)
             self.updateScore()
             player.actor.node.getDelegate().nextZone = 2
         elif player.actor.node.positionCenter[
                 0] > 0 and player.actor.node.getDelegate().nextZone == 2:
             player.getTeam().gameData['score'] += 10
             self.scoreSet.playerScored(player,
                                        10,
                                        screenMessage=False,
                                        display=False)
             self.updateScore()
             player.actor.node.getDelegate().nextZone = 1
Пример #13
0
    def _handleFlagPlayerCollide(self):
        flagNode, playerNode = bs.getCollisionInfo("sourceNode",
                                                   "opposingNode")
        try:
            player = playerNode.getDelegate().getPlayer()
            flag = flagNode.getDelegate()
        except Exception:
            return  # player may have left and his body hit the flag

        if flag.getTeam() is not player.getTeam():
            flag.setTeam(player.getTeam())
            flag.light.color = player.getTeam().color
            flag.node.color = player.getTeam().color
            self.scoreSet.playerScored(player, 10, screenMessage=False)
            bs.playSound(self._swipSound)
            self._flashFlag(flag)
            self._updateScores()

            # respawn any players on this team that were in limbo due to the
            # lack of a flag for their team
            for p in self.players:
                if (p.getTeam() is flag.getTeam() and p.actor is not None
                        and not p.isAlive()
                        and p.gameData['respawnTimer'] is None):
                    self.spawnPlayer(p)
Пример #14
0
    def handleMessage(self, m):
        self._handleMessageSanityCheck()

        if isinstance(m, PowerupAcceptMessage):
            factory = self.getFactory()
            if self.powerupType == 'health':
                bs.playSound(factory.healthPowerupSound,
                             3,
                             position=self.node.position)
            bs.playSound(factory.powerupSound, 3, position=self.node.position)
            self._powersGiven = True
            self.handleMessage(bs.DieMessage())

        elif isinstance(m, _TouchedMessage):
            if not self._powersGiven and not self.picked:
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    node.handleMessage(
                        PowerupMessage(self.powerupType, sourceNode=self.node))

        elif isinstance(m, bs.DieMessage):
            if self.node.exists():
                if (m.immediate):
                    self.node.delete()
                else:
                    curve = bs.animate(self.node, "modelScale", {0: 1, 100: 0})
                    if some.show_powerup_name: curve1 = bs.animate(self._powText, "scale", {
                        0: 0.01,
                        100: 0
                    })
                    if hasattr(self, 'nodeLight'):
                        curve2 = bs.animate(self.nodeLight, "radius", {
                            0: 0.5,
                            100: 0
                        })
                    bs.gameTimer(100, self.node.delete)

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

        elif isinstance(m, bs.PickedUpMessage):
            self.picked = True

        elif isinstance(m, bs.DroppedMessage):
            self.picked = False

        elif isinstance(m, bs.HitMessage):
            # dont die on punches (thats annoying)
            msg = m
            if some.interactive_powerups:
	            self.node.handleMessage("impulse", msg.pos[0], msg.pos[1],
	                                    msg.pos[2], msg.velocity[0],
	                                    msg.velocity[1], msg.velocity[2],
	                                    msg.magnitude, msg.velocityMagnitude,
	                                    msg.radius, 0, msg.velocity[0],
	                                    msg.velocity[1], msg.velocity[2])
            if m.hitType != 'punch':
                self.handleMessage(bs.DieMessage())
        else:
            bs.Actor.handleMessage(self, m)
Пример #15
0
	def handleMessage(self, m):
		if isinstance(m, PuckTouchedMessage):
			node = bs.getCollisionInfo("opposingNode")
			#bs.screenMessage(str(node.position))
			#node.sourcePlayer
			if node.sourcePlayer.getTeam() == self.team:
				return


			#Score - isAlive to avoid multiple kills per death
			if 'notKilled' not in node.sourcePlayer.gameData:
				node.sourcePlayer.gameData['notKilled'] = True
			if node.sourcePlayer.gameData['notKilled']:
				#node.sourcePlayer.getTeam().gameData['timesKilled'] += 1
				self.team.gameData['score'] += 1
				bs.getActivity()._updateScoreBoard()
			node.sourcePlayer.gameData['notKilled'] = False

			x, y, z = node.position
			node.handleMessage("impulse", x, y, z,
							0, 0, 0, #velocity
							1000.0, 0, 3, 0,
							0, 0, 0) # forceDirection
			node.frozen = True
			bs.gameTimer(1000, node.sourcePlayer.actor.shatter)
		if isinstance(m, bs.OutOfBoundsMessage):
			self.node.position = self._spawnPos
			self.movedSinceSpawn = False
			self.age = 0
		else:
			bsHockey.Puck.handleMessage(self, m)
 def _onEggPlayerCollide(self):
     if not self.hasEnded():
         eggNode, playerNode = bs.getCollisionInfo(
             'sourceNode', 'opposingNode')
         if eggNode is not None and playerNode is not None:
             egg = eggNode.getDelegate()
             spaz = playerNode.getDelegate()
             player = (spaz.getPlayer()
                       if hasattr(spaz, 'getPlayer') else None)
             if player is not None and player.exists() and egg is not None:
                 player.getTeam().gameData['score'] += 1
                 # displays a +1 (and adds to individual player score in
                 # teams mode)
                 self.scoreSet.playerScored(player, 1, screenMessage=False)
                 if self._maxEggs < 5:
                     self._maxEggs += 1.0
                 elif self._maxEggs < 10:
                     self._maxEggs += 0.5
                 elif self._maxEggs < 30:
                     self._maxEggs += 0.3
                 self._updateScoreBoard()
                 bs.playSound(self._collectSound, 0.5,
                              position=egg.node.position)
                 # create a flash
                 light = bs.newNode('light',
                                    attrs={'position': eggNode.position,
                                           'heightAttenuated': False,
                                           'radius': 0.1,
                                           'color': (1, 1, 0)})
                 bs.animate(light, 'intensity', {
                            0: 0, 100: 1.0, 200: 0}, loop=False)
                 bs.gameTimer(200, light.delete)
                 egg.handleMessage(bs.DieMessage())
Пример #17
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)
Пример #18
0
    def handleMessage(self, m):
        self._handleMessageSanityCheck()

        if isinstance(m, PowerupAcceptMessage):
            factory = self.getFactory()
            if self.powerupType == 'health':
                bs.playSound(factory.healthPowerupSound,
                             3,
                             position=self.node.position)
            bs.playSound(factory.powerupSound, 3, position=self.node.position)
            self._powersGiven = True
            self.handleMessage(bs.DieMessage())

        elif isinstance(m, _TouchedMessage):
            if not self._powersGiven:
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    # We won't tell the spaz about the bunny.  It'll just happen.
                    if self.powerupType == 'bunny':
                        p = node.getDelegate().getPlayer()
                        if not 'bunnies' in p.gameData:
                            p.gameData['bunnies'] = BuddyBunny.BunnyBotSet(p)
                        p.gameData['bunnies'].doBunny()
                        self._powersGiven = True
                        self.handleMessage(bs.DieMessage())
                    # a Spaz doesn't know what to do with a snoball powerup. All the snowball functionality
                    # is handled through SnoBallz.py to minimize modifications to the original game files
                    elif self.powerupType == 'snoball':
                        spaz = node.getDelegate()
                        SnoBallz.snoBall().getFactory().giveBallz(spaz)
                        self._powersGiven = True
                        self.handleMessage(bs.DieMessage())
                    elif self.powerupType == 'randomDoor':
                        spaz = node.getDelegate()
                        random_door.randomDoor().getFactory().giveRD(spaz)
                        self._powersGiven = True
                        self.handleMessage(bs.DieMessage())
                    else:
                        node.handleMessage(
                            PowerupMessage(self.powerupType,
                                           sourceNode=self.node))

        elif isinstance(m, bs.DieMessage):
            if self.node.exists():
                if (m.immediate):
                    self.node.delete()
                else:
                    curve = bs.animate(self.node, "modelScale", {0: 1, 100: 0})
                    bs.gameTimer(100, self.node.delete)

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

        elif isinstance(m, bs.HitMessage):
            # dont die on punches (thats annoying)
            if m.hitType != 'punch':
                self.handleMessage(bs.DieMessage())
        else:
            bs.Actor.handleMessage(self, m)
Пример #19
0
    def _handlePuckPlayerCollide(self):
        try:
            puckNode,playerNode = bs.getCollisionInfo('sourceNode','opposingNode')
            puck = puckNode.getDelegate()
            player = playerNode.getDelegate().getPlayer()
        except Exception: player = puck = None

        if player is not None and player.exists() and puck is not None: puck.lastPlayersToTouch[player.getTeam().getID()] = player
Пример #20
0
    def _handleBallPlayerCollide(self):
        try:
            ballNode,playerNode = bs.getCollisionInfo('sourceNode','opposingNode')
            ball = ballNode.getDelegate()
            player = playerNode.getDelegate().getPlayer()
        except Exception: player = ball = None

        if player is not None and player.exists() and ball is not None: ball.lastPlayersToTouch[player.getTeam().getID()] = player
Пример #21
0
    def handleMessage(self, m):
        if isinstance(m, bs.HitMessage):
            if not self.node.exists():
                return
            if not m.sourcePlayer is None:
                #it seems as though spazBots are actually players, but with invalid names... Do a try for invalid name?
                try:
                    playa = m.sourcePlayer.getName(
                        True, False)  # Long name, no icons
                    if not playa is None:
                        #Player had a name.  Hit by a person. No damage unless player is also zombie (zero lives).
                        if m.sourcePlayer.gameData['lives'] < 1:
                            super(self.__class__, self).handleMessage(m)
                except:
                    super(self.__class__, self).handleMessage(m)
            else:
                super(self.__class__, self).handleMessage(m)
        elif isinstance(m, bs.FreezeMessage):
            pass  #Can't be frozen.  Would allow self-freeze, but can't prevent others from freezing.
        elif isinstance(
                m, bsSpaz._PickupMessage
        ):  #Complete copy from bsSpaz except for added section to prevent picking players
            opposingNode, opposingBody = bs.getCollisionInfo(
                'opposingNode', 'opposingBody')
            if opposingNode is None or not opposingNode.exists(): return True

            # dont allow picking up of invincible dudes
            try:
                if opposingNode.invincible == True: return True
            except Exception:
                pass
            ####ADDED SECTION - Don't allow picking up of non-Zombie dudes
            try:
                playa = opposingNode.sourcePlayer.getName(
                    True, False)  # Long name, no icons
                if not playa is None:
                    #Player had a name.  Prevent pickup unless player is also zombie (zero lives).
                    if opposingNode.sourcePlayer.gameData['lives'] > 0:
                        return True
            except Exception:
                pass
            #####
            # if we're grabbing the pelvis of a non-shattered spaz, we wanna grab the torso instead
            if opposingNode.getNodeType(
            ) == 'spaz' and not opposingNode.shattered and opposingBody == 4:
                opposingBody = 1

            # special case - if we're holding a flag, dont replace it
            # ( hmm - should make this customizable or more low level )
            held = self.node.holdNode
            if held is not None and held.exists() and held.getNodeType(
            ) == 'flag':
                return True

            self.node.holdBody = opposingBody  # needs to be set before holdNode
            self.node.holdNode = opposingNode
        else:
            super(self.__class__, self).handleMessage(m)
Пример #22
0
    def _handleScore(self):
        if self._flag.scored: return
        region = bs.getCollisionInfo("sourceNode")
        for i in range(len(self._scoreRegions)):
            if region == self._scoreRegions[i].node:
                break

        for team in self.teams:
            if team.getID() == i:
                team.gameData['score'] += 1

                for player in team.players:
                    try:
                        player.actor.node.handleMessage('celebrate', 2000)
                    except Exception:
                        pass

                if (self._flag.lastHoldingPlayer is not None
                        and self._flag.lastHoldingPlayer.exists()
                        and team == self._flag.lastHoldingPlayer.getTeam()):
                    self.scoreSet.playerScored(self._flag.lastHoldingPlayer,
                                               50,
                                               bigMessage=True)

                if team.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()

        bs.playSound(self._scoreSound)
        bs.playSound(self._cheerSound)
        self._flag.scored = True
        bs.gameTimer(1000, self._killFlag)
        bs.gameTimer(3000, self._spawnFlag)

        light = bs.newNode('light',
                           attrs={
                               'position': bs.getCollisionInfo('position'),
                               'heightAttenuated': False,
                               'color': (1, 0, 0)
                           })

        bs.animate(light, 'intensity', {0: 0, 500: 1, 1000: 0}, loop=True)
        bs.gameTimer(1000, light.delete)
        self.cameraFlash(duration=10)
        self._updateScoreBoard()
    def _handlePuckPlayerCollide(self):
        try:
            puckNode, playerNode = bs.getCollisionInfo("sourceNode", "opposingNode")
            puck = puckNode.getDelegate()
            player = playerNode.getDelegate().getPlayer()
        except Exception:
            player = puck = None

        if player is not None and player.exists() and puck is not None:
            puck.lastPlayersToTouch[player.getTeam().getID()] = player
Пример #24
0
 def handleMessage(self, m):
     if isinstance(m, _PunchHitMessage):
         node = bs.getCollisionInfo("opposingNode")
         try:
             node.handleMessage(bs.FreezeMessage())
         except Exception:
             print('Cant freeze')
         bs.playSound(bs.getSound('freeze'))
         super(self.__class__, self).handleMessage(m)
     else:
         super(self.__class__, self).handleMessage(m)
Пример #25
0
    def _handleReachedEnd(self):
        n = bs.getCollisionInfo("opposingNode")
        spaz = n.getDelegate()

        if not spaz.isAlive():
            return  # ignore bodies flying in..

        self._flawless = False
        p = spaz.node.position
        bs.playSound(self._badGuyScoreSound, position=p)
        light = bs.newNode('light',
                           attrs={
                               'position': p,
                               'radius': 0.5,
                               'color': (1, 0, 0)
                           })
        bs.animate(light, 'intensity', {0: 0, 100: 1, 500: 0}, loop=False)
        bs.gameTimer(1000, light.delete)
        spaz.handleMessage(bs.DieMessage(immediate=True, how='goal'))

        if self._lives > 0:
            self._lives -= 1
            if self._lives == 0:
                self._bots.stopMoving()
                self.continueOrEndGame()

            self._livesText.node.text = str(self._lives)
            t = 0

            def _safeSetAttr(node, attr, value):
                if node.exists():
                    setattr(node, attr, value)

            for i in range(4):
                bs.gameTimer(
                    t,
                    bs.Call(_safeSetAttr, self._livesText.node, 'color',
                            (1, 0, 0, 1.0)))
                bs.gameTimer(
                    t, bs.Call(_safeSetAttr, self._livesBG.node, 'opacity',
                               0.5))
                t += 125
                bs.gameTimer(
                    t,
                    bs.Call(_safeSetAttr, self._livesText.node, 'color',
                            (1.0, 1.0, 0.0, 1.0)))
                bs.gameTimer(
                    t, bs.Call(_safeSetAttr, self._livesBG.node, 'opacity',
                               1.0))
                t += 125
            bs.gameTimer(
                t,
                bs.Call(_safeSetAttr, self._livesText.node, 'color',
                        (0.8, 0.8, 0.8, 1.0)))
Пример #26
0
    def _handlePlayerFlagRegionCollide(self,colliding):
        flagNode,playerNode = bs.getCollisionInfo("sourceNode","opposingNode")
        try: player = playerNode.getDelegate().getPlayer()
        except Exception: return

        # different parts of us can collide so a single value isn't enough
        # also don't count it if we're dead (flying heads shouldnt be able to win the game :-)
        if colliding and player.isAlive(): player.gameData['atFlag'] += 1
        else: player.gameData['atFlag'] = max(0,player.gameData['atFlag'] - 1)

        self._updateFlagState()
Пример #27
0
    def _handleBaseCollide(self,team):

        cval = bs.getCollisionInfo('opposingNode')
        try: player = cval.getDelegate().getPlayer()
        except Exception: return
        if player is None or not player.exists(): return
        
        # if its another team's player, they scored
        playerTeam = player.getTeam()
        if playerTeam is not team:

            # (prevent multiple simultaneous scores)
            if bs.getGameTime() != self._lastScoreTime:
                self._lastScoreTime = bs.getGameTime()

                self.scoreSet.playerScored(player,50,bigMessage=True)

                bs.playSound(self._scoreSound)
                self._flashBase(team)

                # move all players on the scoring team back to their start
                # and add flashes of light so its noticable
                for p in playerTeam.players:
                    if p.isAlive():
                        pos = p.actor.node.position
                        light = bs.newNode('light',
                                           attrs={'position':pos,
                                                  'color':playerTeam.color,
                                                  'heightAttenuated':False,
                                                  'radius':0.4})
                        bs.gameTimer(500,light.delete)
                        bs.animate(light,'intensity',{0:0,100:1.0,500:0})

                        newPos = self.getMap().getStartPosition(playerTeam.getID())
                        light = bs.newNode('light',
                                           attrs={'position':newPos,
                                                  'color':playerTeam.color,
                                                  'radius':0.4,
                                                  'heightAttenuated':False})
                        bs.gameTimer(500,light.delete)
                        bs.animate(light,'intensity',{0:0,100:1.0,500:0})
                        p.actor.handleMessage(bs.StandMessage(newPos,random.uniform(0,360)))

                # have teammates celebrate
                for player in playerTeam.players:
                    try: player.actor.node.handleMessage('celebrate',2000)
                    except Exception: pass

                playerTeam.gameData['score'] += 1
                self._updateScoreBoard()
                if playerTeam.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()
Пример #28
0
    def _handleFlagEnteredBase(self, team):
        flag = bs.getCollisionInfo("opposingNode").getDelegate()

        if flag.getTeam() is team:
            team.gameData['homeFlagAtBase'] = True

            # if the enemy flag is already here, score!
            if team.gameData['enemyFlagAtBase']:
                self._score(team)
        else:
            team.gameData['enemyFlagAtBase'] = True
            if team.gameData['homeFlagAtBase']:
                # award points to whoever was carrying the enemy flag
                try:
                    player = flag._lastPlayerToHold
                except Exception:
                    player = None
                if player is not None and player.exists(
                ) and player.getTeam() is team:
                    self.scoreSet.playerScored(player, 50, bigMessage=True)

                # update score and reset flags
                self._score(team)

            # if the home-team flag isn't here, print a message to that effect
            else:
                if not hasattr(self, '_lastHomeFlagNoticePrintTime'):
                    self._lastHomeFlagNoticePrintTime = 0
                t = bs.getRealTime()
                if t - self._lastHomeFlagNoticePrintTime > 5000:
                    self._lastHomeFlagNoticePrintTime = t
                    p = team.gameData['basePos']
                    tNode = bs.newNode(
                        'text',
                        attrs={
                            'text':
                            bs.Lstr(resource='ownFlagAtYourBaseWarning'),
                            'inWorld': True,
                            'scale': 0.013,
                            'color': (1, 1, 0, 1),
                            'hAlign': 'center',
                            'position': (p[0], p[1] + 3.2, p[2])
                        })
                    bs.gameTimer(5100, tNode.delete)
                    bs.animate(tNode, 'scale', {
                        0: 0,
                        200: 0.013,
                        4800: 0.013,
                        5000: 0
                    })
Пример #29
0
    def _handleScore(self):
        """ a point has been scored """

        # our puck might stick around for a second or two
        # we dont want it to be able to score again
        if self._puck.scored: return

        region = bs.getCollisionInfo("sourceNode")
        for i in range(len(self._scoreRegions)):
            if region == self._scoreRegions[i].node:
                break

        scoringTeam = None
        for team in self.teams:
            if team.getID() == i:
                scoringTeam = team
                team.gameData['score'] += 1

                # tell all players to celebrate
                for player in team.players:
                    try:
                        player.actor.node.handleMessage('celebrate', 1000)
                    except Exception:
                        pass

                # if weve got the player from the scoring team that last touched us, give them points
                if scoringTeam.getID(
                ) in self._puck.lastPlayersToTouch and self._puck.lastPlayersToTouch[
                        scoringTeam.getID()].exists():
                    self.scoreSet.playerScored(
                        self._puck.lastPlayersToTouch[scoringTeam.getID()],
                        100,
                        bigMessage=True)

                # end game if we won
                if team.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()

                bs.shakeCamera(intensity=0.0)
        bs.playSound(self._glSound)
        bs.playSound(self._cheerSound)

        self._puck.scored = True

        # kill the puck (it'll respawn itself shortly)
        bs.gameTimer(500, self._killPuck)

        self._updateScoreBoard()
Пример #30
0
 def _handleImpact(self, m):
     node, body = bs.getCollisionInfo("opposingNode", "opposingBody")
     if node is None: return
     try:
         player = node.getDelegate().getPlayer()
     except Exception:
         player = None
     if self.getActivity().settings["Orbs Explode Other Orbs"]:
         if isinstance(node.getDelegate(),
                       WWBomb) and node.getNodeType() == 'prop' and (
                           node.getDelegate().sourcePlayer.getTeam()
                           is not self.sourcePlayer.getTeam()):
             self.handleMessage(ExplodeMessage())
     if (player is not None) and (player.getTeam()
                                  is not self.sourcePlayer.getTeam()):
         self.handleMessage(ExplodeMessage())
Пример #31
0
    def _handleForceBomb(self, m):
        node = bs.getCollisionInfo("opposingNode")
        if self.node.exists():
            if node is not self.owner and bs.getSharedObject(
                    'playerMaterial') in node.materials:
                self.node.sticky = True

                def on():
                    try:
                        self.node.extraAcceleration = (0, 160, 0)
                        if self.aim is not None:
                            self.aim.off()
                    except:
                        pass

                bs.gameTimer(2, on)
Пример #32
0
    def handleMessage(self, msg):
        self._handleMessageSanityCheck()

        if isinstance(msg, PowerupAcceptMessage):
            factory = self.getFactory()
            if self.powerupType == 'health':
                bs.playSound(factory.healthPowerupSound,
                             3,
                             position=self.node.position)
            bs.playSound(factory.powerupSound, 3, position=self.node.position)
            self._powersGiven = True
            self.handleMessage(bs.DieMessage())

        elif isinstance(msg, _TouchedMessage):
            if not self._powersGiven:
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    node.handleMessage(
                        PowerupMessage(self.powerupType, sourceNode=self.node))

        elif isinstance(msg, bs.DieMessage):
            if self.node.exists():
                if (msg.immediate): self.node.delete()
                else:
                    curve = bs.animate(self.node, "modelScale", {0: 1, 100: 0})
                    bs.gameTimer(100, self.node.delete)

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

        elif isinstance(msg, bs.HitMessage):
            if msg.hitType == 'punch':
                if self.powerupType == 'curse':
                    bs.Blast(position=self.node.position,
                             velocity=(0, 0, 0),
                             blastRadius=1,
                             blastType="normal",
                             sourcePlayer=None,
                             hitType='explosion',
                             hitSubType='normal').autoRetain()
                    self.handleMessage(bs.DieMessage())
            else:
                self.handleMessage(bs.DieMessage())
        else:
            bs.Actor.handleMessage(self, msg)