Beispiel #1
0
 def __init__(self, protocol, entity, *arg, **kw):
     Vertex3.__init__(self, *arg, **kw)
     self.protocol = protocol
     self.entity = entity
     self.velocity = Vertex3()
     self.last_position = Vertex3()
     self.player_to_ball = Vertex3()
     self.distance_to_player = WeakKeyDictionary()
     self.send_position()
Beispiel #2
0
    def spawn(self, pos: None = None) -> None:
        self.spawn_call = None
        if self.team is None:
            return
        spectator = self.team.spectator
        if not spectator:
            if pos is None:
                x, y, z = self.get_spawn_location()
                x += 0.5
                y += 0.5
                z -= 2.4
            else:
                x, y, z = pos
            returned = self.on_spawn_location((x, y, z))
            if returned is not None:
                x, y, z = returned
            if self.world_object is not None:
                self.world_object.set_position(x, y, z, True)
            else:
                position = Vertex3(x, y, z)
                self.world_object = self.protocol.world.create_object(
                    world.Character, position, None, self._on_fall)
            self.world_object.dead = False
            self.tool = WEAPON_TOOL
            self.refill(True)
            create_player.x = x
            create_player.y = y
            create_player.z = z
            create_player.weapon = self.weapon
        create_player.player_id = self.player_id
        create_player.name = self.name
        create_player.team = self.team.id
        if self.filter_visibility_data and not spectator:
            self.send_contained(create_player)
        else:
            self.protocol.send_contained(create_player, save=True)
        if not spectator:
            self.on_spawn((x, y, z))

        if not self.client_info:
            self.protocol.send_contained(handshake_init)
Beispiel #3
0
 def spawn(self, pos=None):
     if self.paused:
         # won't catch spawning for the first time
         self.spawn_call = None
         self.paused_spawn = partial(self.spawn, pos)
         return
     if not self.spy or not self.team or self.team.spectator:
         return connection.spawn(self, pos)
     # spy: replicate ServerProtocol spawn but fork create_player packet
     self.spawn_call = None
     if pos is None:
         x, y, z = self.get_spawn_location()
         x += 0.5
         y += 0.5
         z -= 2.4
     else:
         x, y, z = pos
     returned = self.on_spawn_location((x, y, z))
     if returned is not None:
         x, y, z = returned
     if self.world_object is not None:
         self.world_object.set_position(x, y, z, True)
     else:
         self.world_object = self.protocol.world.create_object(
             Character, Vertex3(x, y, z), None, self._on_fall)
     self.world_object.dead = False
     self.tool = WEAPON_TOOL
     self.refill(True)
     fill_create_player(self, self.team)
     if self.filter_visibility_data:
         self.send_contained(create_player)
     else:
         self.protocol.send_contained(create_player,
                                      team=self.team,
                                      save=True)
         create_player.team = self.team.other.id
         self.protocol.send_contained(create_player,
                                      team=self.team.other,
                                      save=True)
     self.on_spawn((x, y, z))
Beispiel #4
0
 def cluster_bomb(self, grenade):  #type of bullet
     eta = grenade.fuse * (1 - CB_E)
     pos = grenade.position
     for i in range(CB_N - 1):
         X = uniform(-1 * CB_K, CB_K)
         Y = uniform(-1 * CB_K, CB_K)
         Z = uniform(-1 * CB_K, CB_K)
         speed = Vertex3(X, Y, Z)
         cluster = self.protocol.world.create_object(
             world.Grenade, 0.0, pos, None, speed,
             self.grenade_exploded)
         cluster.name = 'cluster'
         collision = cluster.get_next_collision(UPDATE_FREQUENCY)
         if collision:
             eta, x, y, z = collision
         cluster.fuse = eta
         grenade_packet.value = cluster.fuse
         grenade_packet.player_id = self.player_id
         grenade_packet.position = pos.get()
         grenade_packet.velocity = speed.get()
         self.protocol.send_contained(grenade_packet)
     self.grenade_exploded(grenade)
Beispiel #5
0
 def multiple_bombs(self, grenade):  #type of bullet
     eta = grenade.fuse * (1 - CB_E)
     pos = grenade.position
     vel = grenade.velocity
     vel = vel.get()
     for i in range(MB_N - 1):
         X = vel[0] * uniform(1, 1 + MB_K)
         Y = vel[1] * uniform(1, 1 + MB_K)
         Z = vel[2] * uniform(1, 1 + MB_K)
         speed = Vertex3(X, Y, Z)
         multiple = self.protocol.world.create_object(
             world.Grenade, 0.0, pos, None, speed,
             self.grenade_exploded)
         multiple.name = 'multiple'
         collision = multiple.get_next_collision(UPDATE_FREQUENCY)
         if collision:
             eta, x, y, z = collision
         multiple.fuse = eta * 1.1
         grenade_packet.value = multiple.fuse
         grenade_packet.player_id = self.player_id
         grenade_packet.position = pos.get()
         grenade_packet.velocity = speed.get()
         self.protocol.send_contained(grenade_packet)
     self.grenade_exploded(grenade)
        def _on_fire(self):
            if self.team is not None and self.world_object is not None:
                bullets = self.weapon_object.generate_bullet_direction(
                    self.world_object.orientation)
                params = weapon_trajectory_param[self.weapon_object.id]
                weapon_range = params['range']

                pts = []
                for bullet in bullets:

                    dummy_character = world.Character(
                        self.world_object.world, self.world_object.position,
                        bullet)

                    loc = dummy_character.cast_ray(weapon_range * 2.0)
                    if loc:
                        x, y, z = loc
                        if (Vertex3(x, y, z) - self.world_object.position
                            ).length_sqr() > weapon_range * weapon_range:
                            # out of range
                            continue
                        pts.append((x, y, z))
                self.protocol.paint_block_by_team_splat(
                    self, pts, self.team, params['drop_size'])
Beispiel #7
0
        def update(self):
            if not self.hp:
                return
            obj = self.world_object
            pos = obj.position
            ori = obj.orientation
            nav = self.protocol.navigation
            vel = obj.velocity
            obj.set_position(*self.get_location())

            if self.aim_at:
                aim_at_pos = None
                if type(self.aim_at) is not Territory:
                    if self.aim_at.hp:
                        aim_at_pos = self.aim_at.world_object.position
                else:
                    aim_at_pos = Vertex3()
                    aim_at_pos.set(*self.aim_at.get())
                if aim_at_pos is not None:
                    self.aim.set_vector(aim_at_pos)
                    self.aim -= pos
                    distance_to_aim = self.aim.normalize(
                    )  # don't move this line
                    # look at the target if it's within sight
                    if obj.can_see(*aim_at_pos.get()):
                        self.target_orientation.set_vector(self.aim)
                    if distance_to_aim <= MELEE_DISTANCE:
                        self.input.discard('sprint')
                        current_time = seconds()
                        if current_time - self.last_spade >= 0.25:
                            self.input.add('primary_fire')
                            if not self.spade_loop.running:
                                self.last_spade = current_time
                                self.spade_loop.start(0.25)
                        else:
                            self.spade_loop.stop()
                    else:
                        vel.x, vel.y = vel.x * 1.02, vel.y * 1.02
                        self.spade_loop.stop()
                    # creeper behavior
                    # if distance_to_aim < 16.0 and self.grenade_call is None:
                    # self.grenade_call = callLater(3.0, self.throw_grenade, 0.0)

            if self.steps and not self.next_step:
                self.next_step = self.steps.pop()
            if self.next_step:
                self.input.add('up')
                self.input.add('sprint')
                x, y = self.next_step
                to_next_step = self.to_next_step
                to_next_step.set(x - pos.x, y - pos.y, 0.0)

                # strafe if the target is in front of us
                dot = ori.dot(to_next_step)
                if dot > 0.7071 and dot < 0.98:
                    p_dot = ori.perp_dot(to_next_step)
                    self.input.add('left' if p_dot < 0.0 else 'right')
                else:
                    self.target_orientation.set_vector(to_next_step)
                    to_next_step = self.target_orientation
                dist_to_next_step = to_next_step.normalize()
                if dist_to_next_step < 0.065:
                    self.next_step = None

            # check whether we're failing to go anywhere
            self.last_pos -= pos
            self.last_pos.z = 0.0
            distance_moved = self.last_pos.length_sqr()
            self.last_pos.set_vector(pos)
            if distance_moved < 0.0066:
                self.input.discard('sprint')
                self.ticks_stumped += 1
                if self.ticks_stumped == TICKS_STUMPED_BEFORE_RETRYING:
                    self.path = None
                if self.ticks_stumped == TICKS_STUMPED_BEFORE_WIGGLING:
                    self.ticks_wiggling_remaining = 60
                if self.ticks_stumped == TICKS_STUMPED_BEFORE_KILL:
                    self.kill()
            else:
                self.ticks_stumped = 0

            if self.ticks_wiggling_remaining > 0:
                # alternate strafing left and right, it might get us out
                self.ticks_wiggling_remaining -= 1
                left = sin(self.ticks_wiggling_remaining * 0.1) < 0.0
                self.input.discard('right' if left else 'left')
                self.input.add('left' if left else 'right')

            # project position and check for obstacles
            #~ ori_z, ori.z = ori.z, 0.0
            #~ ret = player.world_object.cast_ray(PROXIMITY_RAY_LENGTH)
            #~ ori.z = ori_z
            #~ if ret:
            #~ x, y, z = ret
            x, y, z = int(pos.x + ori.x), int(pos.y + ori.y), pos.z + 2
            x_i, y_i = int(pos.x), int(pos.y)
            diagonal = sgn(x - x_i) and sgn(y - y_i)
            walled = (nav.is_wall(x, y, z) if not diagonal else
                      nav.is_wall(x, y_i, z) and nav.is_wall(x_i, y, z))
            self.ticks_obstructed = self.ticks_obstructed + 1 if walled else 0

            if (self.ticks_obstructed >= TICKS_BEFORE_JUMPING and
                (nav.is_jumpable(x, y, z) if not diagonal else
                 nav.is_jumpable(x, y_i, z) or nav.is_jumpable(x_i, y, z))):
                self.input.discard('sprint')
                self.input.add('jump')
                self.jumpable = x, y, z - 4
            # jump correction
            if self.jumpable is not None and fabs(
                    self.jumpable[2] - pos.z) < 0.41 and sqrt(
                        (self.jumpable[0] - pos.x)**2 +
                        (self.jumpable[1] - pos.y)**2) <= 0.7071:
                self.world_object.set_position(pos.x, pos.y, self.jumpable[2])
                self.jumpable = None

            # orientate towards target
            diff = ori - self.target_orientation
            diff.z = 0.0
            diff = diff.length_sqr()
            if diff > 0.001:
                p_dot = ori.perp_dot(self.target_orientation)
                if p_dot > 0.0:
                    ori.rotate(self._turn_vector)
                else:
                    ori.unrotate(self._turn_vector)
                new_p_dot = ori.perp_dot(self.target_orientation)
                if new_p_dot * p_dot < 0.0:
                    ori.set_vector(self.target_orientation)
            else:
                ori.set_vector(self.target_orientation)

            if self.grenade_call:
                self.input.add('primary_fire')

            obj.set_orientation(*ori.get())
            self.flush_input()
Beispiel #8
0
 def _set_turn_speed(self, value):
     self._turn_speed = value
     self._turn_vector = Vertex3(cos(value), sin(value), 0.0)
Beispiel #9
0
 def __init__(self, entity_id, protocol, *arg, **kw):
     Vertex3.__init__(self, *arg, **kw)
     self.id = entity_id
     self.protocol = protocol
Beispiel #10
0
def dropNuke(x, y, accuracy, connectionTeam, connection=None):
    mapData = connection.protocol.map
    z = mapData.get_z(x, y)
    centerPosition = [x, y, z]

    block_action = loaders.BlockAction()
    block_action.value = DESTROY_BLOCK
    block_action.player_id = 32

    radius = radiusConfig.get()
    upHeight = upHeightConfig.get()
    downHeight = downHeightConfig.get()
    for x in range(-1 * radius, radius):
        block_action.x = centerPosition[0] + x
        for y in range(-1 * radius, radius):
            block_action.y = centerPosition[1] + y
            for z in range(-1 * downHeight, upHeight):
                block_action.z = centerPosition[2] + z
                if (block_action.z >= 63): continue
                if (sqrt((block_action.x - centerPosition[0])**2 +
                         (block_action.y - centerPosition[1])**2) <= radius):
                    if (mapData.get_color(block_action.x, block_action.y,
                                          block_action.z) is not None):
                        connection.protocol.broadcast_contained(block_action)
                        mapData.remove_point(block_action.x, block_action.y,
                                             block_action.z)

    def killPlayers(players):
        for player in players:
            ploc = player.get_location()
            if (sqrt((ploc[0] - centerPosition[0])**2 +
                     (ploc[1] - centerPosition[1])**2) <= radius
                    and (centerPosition[2] - upHeight + 4) <= (ploc[2]) <=
                (centerPosition[2] + downHeight + 2)):

                #player.kill(kill_type=GRENADE_KILL)

                killGrenade = connection.protocol.world.create_object(
                    Grenade, 0.0, Vertex3(-5, -5, -5), None, Vertex3(0, 0, 2),
                    None)
                killGrenade.name = "NoStreak"
                player.kill(kill_type=GRENADE_KILL,
                            by=connection,
                            grenade=killGrenade)

                connection.personalSuccessNukeTime = time()
                if (connectionTeam.id == 0):
                    connection.protocol.team1SuccessNukeTime = time()
                else:
                    connection.protocol.team2SuccessNukeTime = time()

    killPlayers(connectionTeam.other.get_players())
    #killPlayers((connection.protocol.team_1 if connectionTeam.id==1 else connection.protocol.team_2).get_players())
    if (nukeTKConfig.get()):
        killPlayers(connection.team.get_players())
    grenadeAmount = grenadeAmountConfig.get()
    for i in range(0, grenadeAmount):
        randomDistance = (maximumRadiusConfig.get() -
                          radius) / (1 + exp(-flatnessConfig.get() *
                                             (i - shiftnessConfig.get())))
        fuse = (propogationTimeConfig.get()) / (grenadeAmount - radius) * i
        randomDegrees = random() * 360
        grenadeX = centerPosition[0] + (randomDistance * cos(randomDegrees))
        grenadeY = centerPosition[1] + (randomDistance * sin(randomDegrees))
        grenade = connection.protocol.world.create_object(
            Grenade, fuse,
            Vertex3(
                grenadeX, grenadeY,
                min(
                    62,
                    mapData.get_z(grenadeX, grenadeY) + ceil(
                        (random() - 0.25) * 1.5))), None, Vertex3(0, 0, 2),
            connection.nuke_grenade_exploded)

        grenade.team = connectionTeam
        grenade.name = "nadeNoStreak" + ("NukeTeamID" + str(connectionTeam.id))
    if (connectionTeam.id == 0):
        connection.protocol.team1NukeTime = time()
    else:
        connection.protocol.team2NukeTime = time()
Beispiel #11
0
 def nadesplode(self, hit_player):
     self.protocol.world.create_object(Grenade, 0.0, hit_player.world_object.position, None, Vertex3(), self.nadepl_exploded)
     grenade_packet.value = 0.1
     grenade_packet.player_id = self.player_id
     grenade_packet.position = (hit_player.world_object.position.x, hit_player.world_object.position.y, hit_player.world_object.position.z)
     grenade_packet.velocity = (0.0, 0.0, 0.0)
     self.protocol.send_contained(grenade_packet)