def flush_input(self):
     input = self.input
     world_object = self.world_object
     z_vel = world_object.velocity.z
     if "jump" in input and not (z_vel >= 0.0 and z_vel < 0.017):
         input.discard("jump")
     input_changed = not (("up" in input) == world_object.up and
                          ("down" in input) == world_object.down and
                          ("left" in input) == world_object.left and
                          ("right" in input) == world_object.right and
                          ("jump" in input) == world_object.jump and
                          ("crouch" in input) == world_object.crouch and
                          ("sneak" in input) == world_object.sneak and
                          ("sprint" in input) == world_object.sprint)
     if input_changed:
         if not self.freeze_animation:
             world_object.set_walk(
                 "up" in input,
                 "down" in input,
                 "left" in input,
                 "right" in input,
             )
             world_object.set_animation(
                 "jump" in input,
                 "crouch" in input,
                 "sneak" in input,
                 "sprint" in input,
             )
         if not self.filter_visibility_data and not self.filter_animation_data:
             input_data = InputData()
             input_data.player_id = self.player_id
             input_data.up = world_object.up
             input_data.down = world_object.down
             input_data.left = world_object.left
             input_data.right = world_object.right
             input_data.jump = world_object.jump
             input_data.crouch = world_object.crouch
             input_data.sneak = world_object.sneak
             input_data.sprint = world_object.sprint
             self.protocol.send_contained(input_data)
     primary = "primary_fire" in input
     secondary = "secondary_fire" in input
     shoot_changed = not (primary == world_object.primary_fire
                          and secondary == world_object.secondary_fire)
     if shoot_changed:
         if primary != world_object.primary_fire:
             if self.tool == WEAPON_TOOL:
                 self.weapon_object.set_shoot(primary)
             if self.tool == WEAPON_TOOL or self.tool == SPADE_TOOL:
                 self.on_shoot_set(primary)
         world_object.primary_fire = primary
         world_object.secondary_fire = secondary
         if not self.filter_visibility_data:
             weapon_input = WeaponInput()
             weapon_input.player_id = self.player_id
             weapon_input.primary = primary
             weapon_input.secondary = secondary
             self.protocol.send_contained(weapon_input)
     input.clear()
Example #2
0
def invisible(connection, player):
    """
    Turn invisible
    /invisible [player]
    """
    protocol = connection.protocol
    # TODO: move this logic to a more suitable place
    player.invisible = not player.invisible
    player.filter_visibility_data = player.invisible
    player.god = player.invisible
    player.god_build = False
    player.killing = not player.invisible
    if player.invisible:
        player.send_chat("You're now invisible")
        protocol.irc_say('* %s became invisible' % player.name)
        kill_action = KillAction()
        kill_action.kill_type = choice([GRENADE_KILL, FALL_KILL])
        kill_action.player_id = kill_action.killer_id = player.player_id
        reactor.callLater(1.0 / NETWORK_FPS, protocol.broadcast_contained,
                          kill_action, sender=player)
    else:
        player.send_chat("You return to visibility")
        protocol.irc_say('* %s became visible' % player.name)
        x, y, z = player.world_object.position.get()
        create_player = CreatePlayer()
        create_player.player_id = player.player_id
        create_player.name = player.name
        create_player.x = x
        create_player.y = y
        create_player.z = z
        create_player.weapon = player.weapon
        create_player.team = player.team.id
        world_object = player.world_object
        input_data = InputData()
        input_data.player_id = player.player_id
        input_data.up = world_object.up
        input_data.down = world_object.down
        input_data.left = world_object.left
        input_data.right = world_object.right
        input_data.jump = world_object.jump
        input_data.crouch = world_object.crouch
        input_data.sneak = world_object.sneak
        input_data.sprint = world_object.sprint
        set_tool = SetTool()
        set_tool.player_id = player.player_id
        set_tool.value = player.tool
        set_color = SetColor()
        set_color.player_id = player.player_id
        set_color.value = make_color(*player.color)
        weapon_input = WeaponInput()
        weapon_input.primary = world_object.primary_fire
        weapon_input.secondary = world_object.secondary_fire
        protocol.broadcast_contained(create_player, sender=player, save=True)
        protocol.broadcast_contained(set_tool, sender=player)
        protocol.broadcast_contained(set_color, sender=player, save=True)
        protocol.broadcast_contained(input_data, sender=player)
        protocol.broadcast_contained(weapon_input, sender=player)
    if connection is not player and connection in protocol.players.values():
        if player.invisible:
            return '%s is now invisible' % player.name
        else:
            return '%s is now visible' % player.name