Exemplo n.º 1
0
 def on_block_line_recieved(self, contained):
     if not self.hp:
         return
     x1, y1, z1 = (contained.x1, contained.y1, contained.z1)
     x2, y2, z2 = (contained.x2, contained.y2, contained.z2)
     pos = self.world_object.position
     if not collision_3d(pos.x, pos.y, pos.z, x2, y2, z2,
                         MAX_BLOCK_DISTANCE):
         return
     points = world.cube_line(x1, y1, z1, x2, y2, z2)
     if not points:
         return
     if len(points) > (self.blocks + BUILD_TOLERANCE):
         return
     map = self.protocol.map
     if self.on_line_build_attempt(points) == False:
         return
     for point in points:
         x, y, z = point
         if not map.build_point(x, y, z, self.color):
             break
     self.blocks -= len(points)
     self.on_line_build(points)
     contained.player_id = self.player_id
     self.protocol.send_contained(contained, save=True)
     self.protocol.update_entities()
Exemplo n.º 2
0
 def make_line(self, x1, y1, x2, y2):
     x1 = max(0, min(511, self.x + x1))
     y1 = max(0, min(511, self.y + y1))
     x2 = max(0, min(511, self.x + x2))
     y2 = max(0, min(511, self.y + y2))
     z = self.z
     line = (x1, y1, z, x2, y2, z)
     self.blocks.update(cube_line(*line))
     self.lines.append(line)
Exemplo n.º 3
0
 def test_complex_cube_line(self):
     line = world.cube_line(10, 10, 10, 21, 19, 12)
     line_should = [(10, 10, 10), (11, 10, 10), (11, 11, 10), (12, 11, 10),
                    (12, 12, 10), (13, 12, 10), (13, 12, 11), (13, 13, 11),
                    (14, 13, 11), (14, 14, 11), (15, 14, 11), (15, 15, 11),
                    (16, 15, 11), (17, 15, 11), (17, 16, 11), (18, 16, 11),
                    (18, 17, 11), (18, 17, 12), (19, 17, 12), (19, 18, 12),
                    (20, 18, 12), (20, 19, 12), (21, 19, 12)]
     self.assertEqual(line, line_should)
Exemplo n.º 4
0
 def make_line(self, x1, y1, x2, y2):
     x1 = max(0, min(511, self.x + x1))
     y1 = max(0, min(511, self.y + y1))
     x2 = max(0, min(511, self.x + x2))
     y2 = max(0, min(511, self.y + y2))
     z = self.z
     line = (x1, y1, z, x2, y2, z)
     self.blocks.update(cube_line(*line))
     self.lines.append(line)
Exemplo n.º 5
0
    def on_block_line_recieved(self, contained):
        if not self.hp:
            return  # dead players can't build

        map_ = self.protocol.map

        x1, y1, z1 = (contained.x1, contained.y1, contained.z1)
        x2, y2, z2 = (contained.x2, contained.y2, contained.z2)
        pos = self.world_object.position
        start_pos = self.line_build_start_pos

        if (not map_.is_valid_position(x1, y1, z1)
                or not map_.is_valid_position(x2, y2, z2)):
            return  # coordinates are out of bounds

        # ensure that the player is currently within tolerance of the location
        # that the line build ended at
        if not collision_3d(pos.x, pos.y, pos.z, x2, y2, z2,
                            MAX_BLOCK_DISTANCE):
            return

        # ensure that the player was within tolerance of the location
        # that the line build started at
        if not collision_3d(start_pos.x, start_pos.y, start_pos.z, x1, y1, z1,
                            MAX_BLOCK_DISTANCE):
            return

        points = world.cube_line(x1, y1, z1, x2, y2, z2)

        if not points:
            return

        if len(points) > (self.blocks + BUILD_TOLERANCE):
            return

        if self.on_line_build_attempt(points) is False:
            return

        for point in points:
            x, y, z = point
            if not map_.build_point(x, y, z, self.color):
                break

        self.blocks -= len(points)
        self.on_line_build(points)
        contained.player_id = self.player_id
        self.protocol.send_contained(contained, save=True)
        self.protocol.update_entities()
Exemplo n.º 6
0
 def build_gate(self):
     map = self.protocol_obj.map
     set_color.value = make_color(*self.color)
     set_color.player_id = block_line.player_id = 32
     self.protocol_obj.send_contained(set_color, save=True)
     for block_line_ in self.blocks:
         start_block, end_block = block_line_
         points = world.cube_line(*(start_block + end_block))
         if not points:
             continue
         for point in points:
             x, y, z = point
             if not map.get_solid(x, y, z):
                 map.set_point(x, y, z, self.color)
         block_line.x1, block_line.y1, block_line.z1 = start_block
         block_line.x2, block_line.y2, block_line.z2 = end_block
         self.protocol_obj.send_contained(block_line, save=True)
Exemplo n.º 7
0
 def build_gate(self):
     map = self.protocol_obj.map
     set_color.value = make_color(*self.color)
     set_color.player_id = block_line.player_id = 32
     self.protocol_obj.send_contained(set_color, save = True)
     for block_line_ in self.blocks:
         start_block, end_block = block_line_
         points = world.cube_line(*(start_block + end_block))
         if not points:
             continue
         for point in points:
             x, y, z = point
             if not map.get_solid(x, y, z):
                 map.set_point(x, y, z, self.color)
         block_line.x1, block_line.y1, block_line.z1 = start_block
         block_line.x2, block_line.y2, block_line.z2 = end_block
         self.protocol_obj.send_contained(block_line, save = True)
Exemplo n.º 8
0
 def destroy_gate(self):
     map = self.protocol_obj.map
     block_action.player_id = 32
     block_action.value = DESTROY_BLOCK
     for block in self.support_blocks:  # optimize wire traffic
         if map.get_solid(*block):
             map.remove_point(*block)
             block_action.x, block_action.y, block_action.z = block
             self.protocol_obj.send_contained(block_action, save=True)
     for block_line_ in self.blocks:  # avoid desyncs
         start_block, end_block = block_line_
         points = world.cube_line(*(start_block + end_block))
         if not points:
             continue
         for point in points:
             x, y, z = point
             if map.get_solid(x, y, z):
                 map.remove_point(x, y, z)
Exemplo n.º 9
0
 def destroy_gate(self):
     map = self.protocol_obj.map
     block_action.player_id = 32
     block_action.value = DESTROY_BLOCK
     for block in self.support_blocks: # optimize wire traffic
         if map.get_solid(*block):
             map.remove_point(*block)
             block_action.x, block_action.y, block_action.z = block
             self.protocol_obj.send_contained(block_action, save = True)
     for block_line_ in self.blocks: # avoid desyncs
         start_block, end_block = block_line_
         points = world.cube_line(*(start_block + end_block))
         if not points:
             continue
         for point in points:
             x, y, z = point
             if map.get_solid(x, y, z):
                 map.remove_point(x, y, z)
Exemplo n.º 10
0
def plane_operation(player, x, y, z, size, value):
    theta = player.world_object.orientation
    th_cos, th_sin = int(round(theta.x)), int(round(theta.y))
    if abs(th_cos) == abs(th_sin):
        return
    x, y, z = int(x), int(y), int(z)
    x1, z1, x2, z2 = size
    y1, y2 = 0, 0
    u1 = y1 * th_cos - x1 * th_sin + x
    v1 = y1 * th_sin + x1 * th_cos + y
    w1 = z1 + z
    u2 = y2 * th_cos - x2 * th_sin + x
    v2 = y2 * th_sin + x2 * th_cos + y
    w2 = z2 + z
    u1, u2 = max(0, min(u1, u2)), min(511, max(u1, u2, 0) + 1)
    v1, v2 = max(0, min(v1, v2)), min(511, max(v1, v2, 0) + 1)
    w1, w2 = max(0, min(w1, w2) + 1), min(63, max(w1, w2) + 1)
    protocol = player.protocol
    if value == DESTROY_BLOCK:
        block_action.value = value
        block_action.player_id = player.player_id
        for i, j, k in prism(u1, v1, w1, u2, v2, w2):
            if protocol.map.destroy_point(i, j, k):
                block_action.x = i
                block_action.y = j
                block_action.z = k
                protocol.send_contained(block_action, save=True)
    elif value == BUILD_BLOCK:
        block_line.player_id = player.player_id
        for i1, j1, k1, i2, j2, k2 in prism_lines(u1, v1, w1, u2, v2, w2):
            line = cube_line(i1, j1, k1, i2, j2, k2)
            for i, j, k in line:
                protocol.map.set_point(i, j, k, player.color)
            block_line.x1 = i1
            block_line.y1 = j1
            block_line.z1 = k1
            block_line.x2 = i2
            block_line.y2 = j2
            block_line.z2 = k2
            protocol.send_contained(block_line, save=True)
Exemplo n.º 11
0
def plane_operation(player, x, y, z, size, value):
    theta = player.world_object.orientation
    th_cos, th_sin = int(round(theta.x)), int(round(theta.y))
    if abs(th_cos) == abs(th_sin):
        return
    x, y, z = int(x), int(y), int(z)
    x1, z1, x2, z2 = size
    y1, y2 = 0, 0
    u1 = y1 * th_cos - x1 * th_sin + x
    v1 = y1 * th_sin + x1 * th_cos + y
    w1 = z1 + z
    u2 = y2 * th_cos - x2 * th_sin + x
    v2 = y2 * th_sin + x2 * th_cos + y
    w2 = z2 + z
    u1, u2 = max(0, min(u1, u2)), min(511, max(u1, u2, 0) + 1)
    v1, v2 = max(0, min(v1, v2)), min(511, max(v1, v2, 0) + 1)
    w1, w2 = max(0, min(w1, w2) + 1), min(63, max(w1, w2) + 1)
    protocol = player.protocol
    if value == DESTROY_BLOCK:
        block_action.value = value
        block_action.player_id = player.player_id
        for i, j, k in prism(u1, v1, w1, u2, v2, w2):
            if protocol.map.destroy_point(i, j, k):
                block_action.x = i
                block_action.y = j
                block_action.z = k
                protocol.send_contained(block_action, save = True)
    elif value == BUILD_BLOCK:
        block_line.player_id = player.player_id
        for i1, j1, k1, i2, j2, k2 in prism_lines(u1, v1, w1, u2, v2, w2):
            line = cube_line(i1, j1, k1, i2, j2, k2)
            for i, j, k in line:
                protocol.map.set_point(i, j, k, player.color)
            block_line.x1 = i1
            block_line.y1 = j1
            block_line.z1 = k1
            block_line.x2 = i2
            block_line.y2 = j2
            block_line.z2 = k2
            protocol.send_contained(block_line, save = True)
        def on_animation_update(self, jump, crouch, sneak, sprint):

            if (
                ((time.monotonic() - self.lastteleport) >=
                 self.protocol.cooldown) or self.invisible
            ) and sneak == True and not self.team.other.flag.player is self and self.world_object.cast_ray(
                    self.protocol.length) is not None:
                for unfallablekeys in self.makeunfallable.keys():
                    if self.makeunfallable[unfallablekeys].active():
                        self.makeunfallable[unfallablekeys].cancel()
                self.makeunfallable = {}
                if self.world_object.velocity.z >= 0.58 and not self.god:
                    self.kill(self, FALL_KILL)
                headpoints = world.cube_line(
                    *(self.world_object.cast_ray(self.protocol.length)) +
                    (self.world_object.position.get()))
                nice = False
                for headblocks in headpoints:
                    x1, y1, z1 = headblocks
                    if self.protocol.map.get_solid(
                            x1, y1, z1) == 0 and self.protocol.map.get_solid(
                                x1, y1,
                                z1 + 1) == 0 and self.protocol.map.get_solid(
                                    x1, y1, z1 + 2) == 0:
                        nice = True
                        set_pos(self, (x1, y1, z1 + 1),
                                (self.world_object.position.get()))
                        break
                    elif self.protocol.map.get_solid(
                            x1, y1,
                            z1 - 1) == 0 and self.protocol.map.get_solid(
                                x1, y1,
                                z1) == 0 and self.protocol.map.get_solid(
                                    x1, y1, z1 + 1) == 0:
                        nice = True
                        set_pos(self, (x1, y1, z1),
                                (self.world_object.position.get()))
                        break
                    elif self.protocol.map.get_solid(
                            x1, y1,
                            z1 - 2) == 0 and self.protocol.map.get_solid(
                                x1, y1,
                                z1 - 1) == 0 and self.protocol.map.get_solid(
                                    x1, y1, z1) == 0:
                        nice = True
                        set_pos(self, (x1, y1, z1 - 1),
                                (self.world_object.position.get()))
                        break
                    elif (z1 <= 1) * (self.world_object.position.z < 4):
                        nice = True
                        set_pos(self, (x1, y1, z1 - 2),
                                (self.world_object.position.get()))
                        break
                if nice == False:  #emergency case
                    x1, y1, z1 = self.world_object.cast_ray(
                        self.protocol.length)
                    x1, y1, z1 = int(x1), int(y1), int(z1)
                    for pos in self.protocol.pos_table:
                        if self.is_location_free(x1 + pos[0], y1 + pos[1],
                                                 z1 + pos[2]):
                            set_pos(self,
                                    (x1 + pos[0], y1 + pos[1], z1 + pos[2]),
                                    (self.world_object.position.get()))
                            break
                self.lastteleport = time.monotonic()
            return connection.on_animation_update(self, jump, crouch, sneak,
                                                  sprint)
Exemplo n.º 13
0
 def test_giant_cube_line(self):
     world.cube_line(1, 1, 1, 100, 100, 100)
     world.cube_line(100, 100, 100, 1, 1, 1)
     world.cube_line(1, 1, 1, 1, 100, 100)
     world.cube_line(1, 1, 1, 1, 5000, 100)
Exemplo n.º 14
0
 def test_simple_cube_line(self):
     line = world.cube_line(1, 1, 1, 10, 1, 1)
     line_should = [(x, 1, 1) for x in range(1, 11)]
     self.assertEqual(line, line_should)