Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
    def on_weapon_input_recieved(self, contained: loaders.WeaponInput) -> None:
        if not self.hp:
            return
        primary = contained.primary
        secondary = contained.secondary
        if self.world_object.primary_fire != primary:
            # player has pressed or released 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)

        if self.world_object.secondary_fire != secondary:
            # player has pressed or released secondary fire
            self.on_secondary_fire_set(secondary)

            if secondary and self.tool == BLOCK_TOOL:
                # hook into here to save the start location of the line build.
                # This is needed so we can check if the player was actually at
                # the starting location of the line build when it was started.
                # this is inspired by 1AmYF's fbpatch2.py script
                position = self.world_object.position
                self.line_build_start_pos = position.copy()
                self.on_line_build_start()

        # remember the current state of the mouse buttons
        self.world_object.primary_fire = primary
        self.world_object.secondary_fire = secondary
        if self.filter_weapon_input:
            return
        contained.player_id = self.player_id
        self.protocol.send_contained(contained, sender=self)
Exemplo n.º 3
0
 def on_weapon_input_recieved(self, contained: loaders.WeaponInput) -> None:
     if not self.hp:
         return
     primary = contained.primary
     secondary = contained.secondary
     if self.world_object.primary_fire != primary:
         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)
     if self.world_object.secondary_fire != secondary:
         self.on_secondary_fire_set(secondary)
     self.world_object.primary_fire = primary
     self.world_object.secondary_fire = secondary
     if self.filter_weapon_input:
         return
     contained.player_id = self.player_id
     self.protocol.send_contained(contained, sender=self)
Exemplo n.º 4
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
Exemplo n.º 5
0
from random import choice
from twisted.internet import reactor
from pyspades.contained import KillAction, InputData, SetColor, WeaponInput
from pyspades.player import create_player, set_tool
from pyspades.constants import (GRENADE_KILL, FALL_KILL, NETWORK_FPS)
from pyspades.common import (prettify_timespan, make_color)
from piqueserver.commands import command, CommandError, get_player, join_arguments

# aparently, we need to send packets in this file. For now, I give in.
kill_action = KillAction()
input_data = InputData()
set_color = SetColor()
weapon_input = WeaponInput()


def get_ban_arguments(connection, arg):
    duration = None
    if len(arg):
        try:
            duration = int(arg[0])
            arg = arg[1:]
        except (IndexError, ValueError):
            pass
    if duration is None:
        if len(arg) > 0 and arg[0] == "perma":
            arg = arg[1:]
        else:
            duration = connection.protocol.default_ban_time
    reason = join_arguments(arg)
    return duration, reason