Ejemplo n.º 1
0
def build_gradient_line(protocol, colors, points):
    sp = cbc.ServerPlayer()
    
    block_action = BlockAction()
    block_action.player_id = sp.player_id
    block_action.value = BUILD_BLOCK
    
    set_color = SetColor()
    set_color.player_id = sp.player_id
    
    color_range = zip(*colors)
    
    lp = len(points) - 1
    map = protocol.map
    for i in xrange(len(points)):
        if lp:
            pct = 1 - (i+0.0) / lp, (i+0.0) / lp
        else:
            pct = (1,0)
        
        color = tuple(int(round(sum(c*p for c,p in zip(crng, pct)))) for crng in color_range)
        
        map.set_point(*points[i], color = color)
        
        set_color.value = make_color(*color)
        protocol.send_contained(set_color, save = True)
        
        block_action.x, block_action.y, block_action.z = points[i]
        protocol.send_contained(block_action, save = True)
Ejemplo n.º 2
0
def build_gradient_line(protocol, colors, points):
    sp = cbc.ServerPlayer()

    block_action = BlockAction()
    block_action.player_id = sp.player_id
    block_action.value = BUILD_BLOCK

    set_color = SetColor()
    set_color.player_id = sp.player_id

    color_range = list(zip(*colors))

    lp = len(points) - 1
    map_ = protocol.map
    for i in range(len(points)):
        pct = 1 - (i + 0.0) / lp, (i + 0.0) / lp if lp else (1, 0)
        color = tuple(
            int(round(sum(c * p for c, p in zip(crng, pct))))
            for crng in color_range)

        map_.set_point(*points[i], color=color)

        set_color.value = make_color(*color)
        protocol.send_contained(set_color, save=True)

        block_action.x, block_action.y, block_action.z = points[i]
        protocol.send_contained(block_action, save=True)
Ejemplo n.º 3
0
 def cycle(self):
     if not self.blocks:
         self.loop.stop()
         if self.call_on_exhaustion:
             self.call_on_exhaustion()
         return
     blocks_left = self.blocks_per_cycle
     last_color = None
     while self.blocks and blocks_left:
         x, y, z, color = self.blocks.popleft()
         if color != last_color:
             set_color = SetColor()
             set_color.value = make_color(*color)
             set_color.player_id = 32
             self.protocol.send_contained(set_color, save=True)
             last_color = color
         if not self.protocol.map.get_solid(x, y, z):
             block_action = BlockAction()
             block_action.value = BUILD_BLOCK
             block_action.player_id = 32
             block_action.x = x
             block_action.y = y
             block_action.z = z
             self.protocol.send_contained(block_action, save=True)
             self.protocol.map.set_point(x, y, z, color)
             blocks_left -= 1
     self.protocol.update_entities()
Ejemplo n.º 4
0
 def constructSelection(self, blockList):
     map = self.map
     block_action = BlockAction()
     block_action.value = BUILD_BLOCK
     block_action.player_id = 32
     set_color = SetColor()
     set_color.player_id = 32
     set_color.value = Color(hex=0x6F6F6F).getInt()
     for block in blockList:
         exists = block[0]
         pos = block[1]
         x, y, z = pos
         color = block[2]
         block_action.x, block_action.y, block_action.z = x, y, z
         if (exists):  #Should be a block
             if (map.get_point(x, y, z)[0]):  #if there is a block
                 map.remove_point(
                     x, y,
                     z)  #Clear the block for rebuilding with color
             block_action.value = BUILD_BLOCK
             set_color.value = color.getInt()
             map.set_point(x, y, z,
                           color.getTuple())  #Set color in the map vxl
             self.broadcast_contained(set_color)  #Set color
             self.broadcast_contained(
                 block_action)  #Broadcast the build
         else:
             if (z >= 63):
                 continue
             elif (map.get_point(x, y, z)[0]):  #THERE IS A BLOCK
                 block_action.value = DESTROY_BLOCK
                 self.broadcast_contained(block_action)
                 map.remove_point(x, y, z)
     return True
Ejemplo n.º 5
0
 def grenade_exploded(self, grenade):
     if self.name is None:
         return
     if self.weapon != 1:
         return connection.grenade_exploded(self, grenade)
     position = grenade.position
     x = int(position.x)
     y = int(position.y)
     z = int(position.z)
     blocks = 19
     map = self.protocol.map
     list = []
     try_add_node(map, x, y, z, list)
     block_action = BlockAction()
     block_action.value = BUILD_BLOCK
     block_action.player_id = self.player_id
     while list:
         x, y, z = list.pop(0)
         if connection.on_block_build_attempt(self, x, y, z) == False:
             continue
         block_action.x = x
         block_action.y = y
         block_action.z = z
         self.protocol.send_contained(block_action, save=True)
         map.set_point(x, y, z, self.color)
         blocks -= 1
         if blocks == 0:
             break
         try_add_node(map, x, y, z - 1, list)
         try_add_node(map, x, y - 1, z, list)
         try_add_node(map, x, y + 1, z, list)
         try_add_node(map, x - 1, y, z, list)
         try_add_node(map, x + 1, y, z, list)
         try_add_node(map, x, y, z + 1, list)
     self.protocol.update_entities()
Ejemplo n.º 6
0
 def constructSelection(self, blockList):
     map = self.map
     block_action = BlockAction()
     block_action.value = BUILD_BLOCK
     block_action.player_id = 32
     set_color = SetColor()
     set_color.player_id = 32
     set_color.value = 0x707070
     for block in blockList:
         blockExists = block[0]
         x = block[1][0]
         y = block[1][1]
         z = block[1][2]
         block_action.x, block_action.y, block_action.z = x, y, z
         if (not (0 <= x <= 512 or 0 <= y <= 512 or 0 <= y <= 64)):
             continue
         color = block[2]
         if (blockExists):  #IF THERE SHOULD BE A BLOCK
             if (map.get_point(x, y, z)[0]):  #IF THERE IS A BLOCK
                 map.remove_point(x, y, z)
             #if(not map.get_point(x,y,z)[0]): #IF THERE IS NO BLOCK
             block_action.value = BUILD_BLOCK
             self.broadcast_contained(block_action)
             set_color.value = color
             map.set_point(x, y, z, colorIntToTuple(color))
             self.broadcast_contained(set_color)
         else:  #IF THERE SHOULD BE NO BLOCK
             if (z >= 63):
                 continue
             if (map.get_point(x, y, z)[0]):  #THERE IS A BLOCK
                 block_action.value = DESTROY_BLOCK
                 self.broadcast_contained(block_action)
                 map.remove_point(x, y, z)
Ejemplo n.º 7
0
def add_block(prt,
              x,
              y,
              z,
              color,
              player_id=32,
              mirror_x=False,
              mirror_y=False):
    if x >= 0 and x < 512 and y >= 0 and y < 512 and z >= 0 and z < 64:
        if mirror_x == True or mirror_y == True:
            x2 = x
            y2 = y
            if mirror_x == True:
                x2 = 511 - x
            if mirror_y == True:
                y2 = 511 - y
            add_block(prt, x2, y2, z, color, player_id, False, False)
        if not prt.map.get_solid(x, y, z):
            block_action = BlockAction()
            block_action.player_id = player_id
            block_action.value = BUILD_BLOCK
            block_action.x = x
            block_action.y = y
            block_action.z = z
            prt.send_contained(block_action)
            prt.map.set_point(x, y, z, get_color_tuple(color))
Ejemplo n.º 8
0
def clear_solid_generator(protocol,
                          x1,
                          y1,
                          z1,
                          x2,
                          y2,
                          z2,
                          god=False,
                          destroy=True):
    block_action = BlockAction()
    block_action.value = DESTROY_BLOCK
    splayer = cbc.ServerPlayer()
    block_action.player_id = splayer.player_id
    map = protocol.map
    check_protected = hasattr(protocol, 'protected')
    x1, x2 = sorted((x1, x2))
    y1, y2 = sorted((y1, y2))
    z1, z2 = sorted((z1, z2))
    clear = map.destroy_point if destroy else map.remove_point
    get_solid = map.get_solid
    for x, y, z in product(xrange(x1, x2 + 1), xrange(y1, y2 + 1),
                           xrange(z1, z2 + 1)):
        packets = 0
        if get_solid(x, y, z) and (
                god or not (check_protected and protocol.is_protected(x, y, z)
                            )  #not protected
                and not (protocol.god_blocks is not None and
                         (x, y, z) in protocol.god_blocks)):  #not a god block
            block_action.x = x
            block_action.y = y
            block_action.z = z
            protocol.send_contained(block_action, save=True)
            clear(x, y, z)
            packets = 1
        yield packets, 0
Ejemplo n.º 9
0
 def send_block(self, sender, x, y, z, value=BUILD_BLOCK):
     block_action = BlockAction()
     block_action.value = value
     block_action.player_id = 32
     block_action.x = x
     block_action.y = y
     block_action.z = z
     sender(block_action, team=self.team)
Ejemplo n.º 10
0
 def destroy_block(self, x, y, z):
     block_action = BlockAction()
     block_action.x = x
     block_action.y = y
     block_action.z = z
     block_action.player_id = 32
     block_action.value = DESTROY_BLOCK
     self.broadcast_contained(block_action, save=True)
Ejemplo n.º 11
0
def send_block(protocol, x, y, z, value=BUILD_BLOCK):
    block_action_packet = BlockAction()
    block_action_packet.value = value
    block_action_packet.player_id = 32
    block_action_packet.x = x
    block_action_packet.y = y
    block_action_packet.z = z
    protocol.send_contained(block_action_packet, save=True)
Ejemplo n.º 12
0
 def build_block(self, x, y, z):
     block_action = BlockAction()
     block_action.x = x
     block_action.y = y
     block_action.z = z
     block_action.player_id = 32
     block_action.value = BUILD_BLOCK
     self.broadcast_contained(block_action, save=True)
Ejemplo n.º 13
0
 def destroy_gate(self):
     map_ = self.protocol_obj.map
     block_action = BlockAction()
     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)
Ejemplo n.º 14
0
def destroyBlock(self, x, y, z):
    block_action = BlockAction()
    block_action.x = x
    block_action.y = y
    block_action.z = z
    block_action.player_id = 32
    block_action.value = DESTROY_BLOCK
    self.protocol.send_contained(block_action, save=True)
    self.protocol.map.destroy_point(x, y, z)
Ejemplo n.º 15
0
def placeC4(connection, *args):
    if(connection.c4Count<=0):
        connection.send_chat("You have no c4 charges")
        return
    hit = connection.world_object.cast_ray(512)
    if(hit)
        connection.c4Count -= 1
        map = connection.protocol.map
        block_action = BlockAction()
        block_action.value = BUILD_BLOCK
        block_action.player_id = 32
        set_color = SetColor()
        set_color.player_id = 32
        set_color.value = c4Color
        if(not map.get_point(*hit)[0]):
            block_action.x, block_action.y, block_action.z = hit
            connection.protocol.broadcast_contained(block_action)
        connection.protocol.broadcast_contained(set_color)
        connection.protocol.c4BlockPositions.append( (hit) )
    connection.send_chat("Your next block placed will be a C4")
Ejemplo n.º 16
0
def rebuild_block(player, x, y, z, color):
    set_color = SetColor()
    set_color.value = make_color(*color)
    set_color.player_id = 32
    block_action = BlockAction()
    block_action.player_id = 32
    block_action.x = x
    block_action.y = y
    block_action.z = z
    block_action.value = DESTROY_BLOCK
    player.send_contained(block_action)
    block_action.value = BUILD_BLOCK
    player.send_contained(set_color)
    player.send_contained(block_action)
Ejemplo n.º 17
0
def clear_solid_generator(protocol, x1, y1, z1, x2, y2, z2, god = False, destroy = True):
    block_action = BlockAction()
    block_action.value = DESTROY_BLOCK
    splayer = cbc.ServerPlayer()
    block_action.player_id = splayer.player_id
    map = protocol.map
    check_protected = hasattr(protocol, 'protected')
    x1, x2 = sorted((x1 , x2))
    y1, y2 = sorted((y1 , y2))
    z1, z2 = sorted((z1 , z2))
    clear = map.destroy_point if destroy else map.remove_point
    get_solid = map.get_solid
    for x, y, z in product( xrange(x1, x2+1)
                          , xrange(y1, y2+1)
                          , xrange(z1, z2+1)):
        packets = 0
        if get_solid(x, y, z) and (god or 
                    not (check_protected and protocol.is_protected(x, y, z)) #not protected
                and not (protocol.god_blocks is not None and (x, y, z) in protocol.god_blocks)): #not a god block
            block_action.x = x
            block_action.y = y
            block_action.z = z
            protocol.send_contained(block_action, save = True)
            clear(x, y, z)
            packets = 1
        yield packets, 0
Ejemplo n.º 18
0
 def build_block(self, x, y, z, looped=False):
     if ((x < 0 or x > 511 or y < 0 or y > 511 or z < 1 or z > 61) is
             False):
         self.protocol.map.set_point(x, y, z, self.color)
         block_action = BlockAction()
         block_action.x = x
         block_action.y = y
         block_action.z = z
         block_action.value = BUILD_BLOCK
         block_action.player_id = self.player_id
         self.protocol.send_contained(block_action, save=True)
Ejemplo n.º 19
0
 def singleBlock(self, protocol, x, y, z, color):
     if not protocol.map.get_solid(x, y, z):
         z += 1
     if protocol.map.get_color(x, y, z) == color:
         return
     block_action = BlockAction()
     block_action.x = x
     block_action.y = y
     block_action.z = z
     block_action.player_id = 32
     protocol.map.set_point(x, y, z, color)
     block_action.value = DESTROY_BLOCK
     protocol.broadcast_contained(block_action, save=True)
     block_action.value = BUILD_BLOCK
     protocol.broadcast_contained(block_action, save=True)
Ejemplo n.º 20
0
        def quickbuild_generator(self, origin, structure, default_color):
            map = self.protocol.map
            protocol = self.protocol

            splayer = cbc.ServerPlayer()

            block_action = BlockAction()
            block_action.value = BUILD_BLOCK
            block_action.player_id = splayer.player_id

            set_color = SetColor()
            set_color.value = make_color(*default_color)
            set_color.player_id = splayer.player_id
            pcolor = default_color

            protocol.send_contained(set_color, save=True)

            if not isinstance(structure, dict):
                structure = dict(structure)

            for xyz, color in structure.iteritems():
                x, y, z = [a + b for a, b in zip(xyz, origin)]
                if (x < 0 or x >= 512 or y < 0 or y >= 512 or z < 0
                        or z >= 62):
                    continue
                if map.get_solid(x, y, z):
                    continue
                color = color or default_color
                if color != pcolor:
                    set_color.value = make_color(*color)
                    protocol.send_contained(set_color, save=True)
                    pcolor = color
                    yield 1, 0
                self.on_block_build(x, y, z)
                block_action.x, block_action.y, block_action.z = x, y, z
                protocol.send_contained(block_action, save=True)
                map.set_point(x, y, z, pcolor)
                yield 1, 0
Ejemplo n.º 21
0
def paint_block(protocol, player, x, y, z, color):
    if x < 0 or y < 0 or z < 0 or x >= 512 or y >= 512 or z >= 62:
        return False
    if protocol.map.get_color(x, y, z) == color:
        return False
    protocol.map.set_point(x, y, z, color)
    block_action = BlockAction()
    block_action.x = x
    block_action.y = y
    block_action.z = z
    block_action.player_id = player.player_id
    block_action.value = DESTROY_BLOCK
    protocol.send_contained(block_action, save=True)
    block_action.value = BUILD_BLOCK
    protocol.send_contained(block_action, save=True)
    return True
Ejemplo n.º 22
0
def setBlockColor(self, x, y, z, color):
    set_color = SetColor()
    set_color.value = make_color(*color)
    set_color.player_id = 32
    self.protocol.send_contained(set_color, save=True)

    block_action = BlockAction()
    block_action.x = x
    block_action.y = y
    block_action.z = z
    block_action.player_id = 32
    block_action.value = DESTROY_BLOCK
    self.protocol.send_contained(block_action, save=True)
    block_action.value = BUILD_BLOCK
    self.protocol.send_contained(block_action, save=True)
    self.protocol.map.set_point(x, y, z, color)
Ejemplo n.º 23
0
 def quickbuild_generator(self, origin, structure, default_color):
     map = self.protocol.map
     protocol = self.protocol
     
     splayer = cbc.ServerPlayer()
     
     block_action = BlockAction()
     block_action.value = BUILD_BLOCK
     block_action.player_id = splayer.player_id
     
     set_color = SetColor()
     set_color.value = make_color(*default_color)
     set_color.player_id = splayer.player_id
     pcolor = default_color
     
     protocol.send_contained(set_color, save = True)
     
     if not isinstance(structure, dict):
         structure = dict(structure)
     
     for xyz, color in structure.iteritems():
         x, y, z = [a+b for a,b in zip(xyz, origin)]
         if (x < 0 or x >= 512 or y < 0 or y >= 512 or z < 0 or z >= 62):
             continue
         if map.get_solid(x, y, z):
             continue
         color = color or default_color
         if color != pcolor:
             set_color.value = make_color(*color)
             protocol.send_contained(set_color, save = True)
             pcolor = color
             yield 1, 0
         self.on_block_build(x, y, z)
         block_action.x, block_action.y, block_action.z = x, y, z
         protocol.send_contained(block_action, save = True)
         map.set_point(x, y, z, pcolor)
         yield 1, 0
Ejemplo n.º 24
0
def destroy_block(connection, x, y, z):
    if connection.protocol.map.get_solid(x, y, z):
        block_action = BlockAction()
        block_action.player_id = connection.player_id
        block_action.x = x
        block_action.y = y
        block_action.z = z
        block_action.value = DESTROY_BLOCK
        if z == 62:
            connection.protocol.map.remove_point(x, y, z)
        else:
            connection.protocol.map.destroy_point(x, y, z)
        connection.protocol.broadcast_contained(block_action, save=True)
Ejemplo n.º 25
0
def build_block(connection, x, y, z, color):
    set_color = SetColor()
    set_color.value = make_color(*color)
    set_color.player_id = 32
    connection.protocol.broadcast_contained(set_color)
    block_action = BlockAction()
    block_action.player_id = 32
    block_action.x = x
    block_action.y = y
    block_action.z = z
    block_action.value = BUILD_BLOCK
    connection.protocol.map.set_point(x, y, z, color)
    connection.protocol.broadcast_contained(block_action, save=True)
Ejemplo n.º 26
0
 def place_estrogen_block(self, x, y, z):
     block_action = BlockAction()
     block_action.player_id = 31
     set_color = SetColor()
     set_color.value = 0xFF66FF
     set_color.player_id = block_action.player_id
     self.send_contained(set_color, save=True)
     self.map.set_point(x, y, z, (255, 102, 255))
     block_action.value = BUILD_BLOCK
     set_color.value = 0xFF66FF
     block_action.x = x
     block_action.y = y
     block_action.z = z
     self.send_contained(block_action, save=True)
Ejemplo n.º 27
0
 def santa_drop_block(self, x, y, z):
    """Places a gift from Santa"""
    block_action = BlockAction()
    block_action.player_id = 32
    set_color = SetColor()
    set_color.value = 0xFF0000
    set_color.player_id = block_action.player_id
    self.send_contained(set_color, save = True)
    self.map.set_point(x, y, z, (255,0,0))
    block_action.value = BUILD_BLOCK
    set_color.value = 0xFF0000
    block_action.x = x
    block_action.y = y
    block_action.z = z
    self.send_contained(block_action, save = True)
Ejemplo n.º 28
0
		def place_estrogen_block(self, x, y, z):
			block_action = BlockAction()
			block_action.player_id = 31
			set_color = SetColor()
			set_color.value = 0xFF66FF
			set_color.player_id = block_action.player_id
			self.send_contained(set_color, save = True)
			self.map.set_point(x, y, z, (255, 102, 255))
			block_action.value = BUILD_BLOCK
			set_color.value = 0xFF66FF
			block_action.x = x
			block_action.y = y
			block_action.z = z
			self.send_contained(block_action, save = True)
Ejemplo n.º 29
0
def set(connection, *args):
    pos1 = connection.selectPos1
    pos2 = connection.selectPos2
    if pos1 is None or pos2 is None:
        connection.send_chat('You are missing a position, try /sel to see your positions')
        return
    block_action = BlockAction()
    block_action.value = DESTROY_BLOCK
    block_action.player_id = 32
    set_color = SetColor()
    set_color.value = connection.selectColor if connection.selectColor is not None else 0x707070
    set_color.player_id = 32
    map = connection.protocol.map
    n = 0
    for x in range(*(pos1[0], pos2[0] + 1) if pos1[0] < pos2[0] else (pos2[0], pos1[0] + 1)):
        block_action.x = x
        for y in range(*(pos1[1], pos2[1] + 1) if pos1[1] < pos2[1] else (pos2[1], pos1[1] + 1)):
            block_action.y = y
            for z in range(*(pos1[2], pos2[2] + 1) if pos1[2] < pos2[2] else (pos2[2], pos1[2] + 1)):
                block_action.z = z
                if 'air' in args:
                    if map.get_point(x, y, z):
                        connection.protocol.broadcast_contained(block_action)
                        map.remove_point(x, y, z)
                        n += 1
                        continue
                else:
                    if not map.get_point(x, y, z):
                        connection.protocol.broadcast_contained(block_action)
                    if map.get_point(x, y, z):
                        block_action.value = BUILD_BLOCK
                        connection.protocol.broadcast_contained(block_action)
                    connection.protocol.broadcast_contained(set_color)
                    ctuple = (set_color.value >> 16 & 255, set_color.value >> 8 & 255, set_color.value & 255)
                    map.set_point(x, y, z, ctuple)
                n += 1

    connection.send_chat('set %s blocks' % n)
Ejemplo n.º 30
0
 def clear_box_solid_generator(self, x1, y1, z1, x2, y2, z2):
     block_action = BlockAction()
     block_action.value = DESTROY_BLOCK
     block_action.player_id = self.player_id
     protocol = self.protocol
     check_protected = hasattr(protocol, 'protected')
     for x in xrange(min(x1, x2), max(x1, x2) + 1):
         block_action.x = x
         for y in xrange(min(y1, y2), max(y1, y2) + 1):
             block_action.y = y
             for z in xrange(min(z1, z2), max(z1, z2) + 1):
                 if not self.god and check_protected and protocol.is_protected(
                         x, y, z):
                     continue
                 if not self.god and protocol.god_blocks is not None and (
                         x, y, z) in protocol.god_blocks:
                     continue
                 block_action.z = z
                 protocol.send_contained(block_action, save=True)
                 protocol.map.destroy_point(x, y, z)
                 yield 1, (x - min(x1, x2) + 0.0) / (abs(x1 - x2) + 1)
Ejemplo n.º 31
0
def remove_block(prt, x, y, z, mirror_x=False, mirror_y=False):
    if x >= 0 and x < 512 and y >= 0 and y < 512 and z >= 0 and z < 64:
        if mirror_x == True or mirror_y == True:
            x2 = x
            y2 = y
            if mirror_x == True:
                x2 = 511 - x
            if mirror_y == True:
                y2 = 511 - y
            remove_block(prt, x2, y2, z, False, False)
        if prt.map.get_solid(x, y, z):
            block_action = BlockAction()
            block_action.player_id = 32
            block_action.value = DESTROY_BLOCK
            block_action.x = x
            block_action.y = y
            block_action.z = z
            prt.map.remove_point(x, y, z)
            prt.send_contained(block_action)
            return True
    return False
Ejemplo n.º 32
0
 def clear_box_solid_generator(self, x1, y1, z1, x2, y2, z2):
     block_action = BlockAction()
     block_action.value = DESTROY_BLOCK
     block_action.player_id = self.player_id
     protocol = self.protocol
     check_protected = hasattr(protocol, 'protected')
     for x in xrange(min(x1 , x2) , max(x1 , x2)+1):
         block_action.x = x
         for y in xrange(min(y1 , y2) , max(y1 , y2)+1):
             block_action.y = y
             for z in xrange(min(z1 , z2) , max(z1 , z2)+1):
                 if not self.god and check_protected and protocol.is_protected(x, y, z):
                     continue
                 if not self.god and protocol.god_blocks is not None and (x, y, z) in protocol.god_blocks:
                     continue
                 block_action.z = z
                 protocol.send_contained(block_action, save = True)
                 protocol.map.destroy_point(x, y, z)
                 yield 1, (x - min(x1, x2) + 0.0) / (abs(x1 - x2)+1)
Ejemplo n.º 33
0
def add_block(prt, x, y, z, color, player_id = 32, mirror_x = False, mirror_y = False):
    if x >= 0 and x < 512 and y >= 0 and y < 512 and z >= 0 and z < 64:
        if mirror_x == True or mirror_y == True:
            x2 = x
            y2 = y
            if mirror_x == True:
                x2 = 511 - x
            if mirror_y == True:
                y2 = 511 - y
            add_block(prt, x2, y2, z, color, player_id, False, False)
        if not prt.map.get_solid(x, y, z):
            block_action = BlockAction()
            block_action.player_id = player_id
            block_action.value = BUILD_BLOCK
            block_action.x = x
            block_action.y = y
            block_action.z = z
            prt.send_contained(block_action)
            prt.map.set_point(x, y, z, get_color_tuple(color))
Ejemplo n.º 34
0
def clear_solid_generator(protocol, x1, y1, z1, x2, y2, z2, god=False, destroy=True):
    block_action = BlockAction()
    block_action.value = DESTROY_BLOCK
    splayer = cbc.ServerPlayer()
    block_action.player_id = splayer.player_id
    map_ = protocol.map
    check_protected = hasattr(protocol, 'protected')
    x1, x2 = sorted((x1, x2))
    y1, y2 = sorted((y1, y2))
    z1, z2 = sorted((z1, z2))
    clear_ = map_.destroy_point if destroy else map_.remove_point
    get_solid = map_.get_solid
    for x, y, z in product(range(x1, x2+1), range(y1, y2+1), range(z1, z2+1)):
        solid = get_solid(x, y, z)
        protected = (check_protected and protocol.is_protected(x, y, z))
        is_god_block = (protocol.god_blocks is not None and (x, y, z) in protocol.god_blocks)
        if not solid or (not god and (protected or is_god_block)):
            continue
        block_action.x = x
        block_action.y = y
        block_action.z = z
        protocol.send_contained(block_action, save=True)
        clear_(x, y, z)
        yield 1, 0
Ejemplo n.º 35
0
def remove_block(prt, x, y, z, mirror_x = False, mirror_y = False):
    if x >= 0 and x < 512 and y >= 0 and y < 512 and z >= 0 and z < 64:
        if mirror_x == True or mirror_y == True:
            x2 = x
            y2 = y
            if mirror_x == True:
                x2 = 511 - x
            if mirror_y == True:
                y2 = 511 - y
            remove_block(prt, x2, y2, z, False, False)
        if prt.map.get_solid(x, y, z):
            block_action = BlockAction()
            block_action.player_id = 32
            block_action.value = DESTROY_BLOCK
            block_action.x = x
            block_action.y = y
            block_action.z = z
            prt.map.remove_point(x, y, z)
            prt.send_contained(block_action)
            return True
    return False
Ejemplo n.º 36
0
 def create_rollback_generator(self, cur, new, start_x, start_y, end_x,
                               end_y, ignore_indestructable):
     surface = {}
     block_action = BlockAction()
     block_action.player_id = 31
     set_color = SetColor()
     set_color.value = make_color(*NON_SURFACE_COLOR)
     set_color.player_id = 31
     self.send_contained(set_color, save=True)
     old = cur.copy()
     check_protected = hasattr(protocol, 'protected')
     for x in xrange(start_x, end_x):
         block_action.x = x
         for y in xrange(start_y, end_y):
             block_action.y = y
             if check_protected and self.is_protected(x, y, 0):
                 continue
             for z in xrange(63):
                 action = None
                 cur_solid = cur.get_solid(x, y, z)
                 new_solid = new.get_solid(x, y, z)
                 if cur_solid and not new_solid:
                     if (not ignore_indestructable
                             and self.is_indestructable(x, y, z)):
                         continue
                     else:
                         action = DESTROY_BLOCK
                         cur.remove_point(x, y, z)
                 elif new_solid:
                     new_is_surface = new.is_surface(x, y, z)
                     if new_is_surface:
                         new_color = new.get_color(x, y, z)
                     if not cur_solid and new_is_surface:
                         surface[(x, y, z)] = new_color
                     elif not cur_solid and not new_is_surface:
                         action = BUILD_BLOCK
                         cur.set_point(x, y, z, NON_SURFACE_COLOR)
                     elif cur_solid and new_is_surface:
                         old_is_surface = old.is_surface(x, y, z)
                         if old_is_surface:
                             old_color = old.get_color(x, y, z)
                         if not old_is_surface or old_color != new_color:
                             surface[(x, y, z)] = new_color
                             action = DESTROY_BLOCK
                             cur.remove_point(x, y, z)
                 if action is not None:
                     block_action.z = z
                     block_action.value = action
                     self.send_contained(block_action, save=True)
                     yield 1
         yield 0
     last_color = None
     block_action.value = BUILD_BLOCK
     for pos, color in sorted(surface.iteritems(),
                              key=operator.itemgetter(1)):
         x, y, z = pos
         packets_sent = 0
         if color != last_color:
             set_color.value = make_color(*color)
             self.send_contained(set_color, save=True)
             packets_sent += 1
             last_color = color
         cur.set_point(x, y, z, color)
         block_action.x = x
         block_action.y = y
         block_action.z = z
         self.send_contained(block_action, save=True)
         packets_sent += 1
         yield packets_sent
Ejemplo n.º 37
0
def stack(connection, *args):
    pos1 = connection.selectPos1
    pos2 = connection.selectPos2
    
    try:
        offset = [(0,0,-1),(0,0,1),(0,-1,0),(1,0,0),(0,1,0),(-1,0,0)][['up', 'down', 'north', 'east', 'south', 'west'].index(args[0])]
    except ValueError:
        return
    if(None in (pos1,pos2)):
        return
    try:
        amount = int(args[1])
    except Exception as E:
        amount = 1
    map = connection.protocol.map
    xh = abs(pos1[0]-pos2[0])+1 #IN XYZ ORDER
    yh = abs(pos1[1]-pos2[1])+1
    zh = abs(pos1[2]-pos2[2])+1
    allBlocks = [None]*(xh*yh*zh)
    allPositions = [None]*len(allBlocks)
    i = 0
    for x in range(*(pos1[0], pos2[0] + 1) if pos1[0] < pos2[0] else (pos2[0], pos1[0] + 1)):
        for y in range(*(pos1[1], pos2[1] + 1) if pos1[1] < pos2[1] else (pos2[1], pos1[1] + 1)):
            for z in range(*(pos1[2], pos2[2] + 1) if pos1[2] < pos2[2] else (pos2[2], pos1[2] + 1)):
                allBlocks[i] = map.get_point(x, y, z)
                allPositions = (x,y,z)
                i += 1
    
    operations = []
    for run in range(0, amount):
        operations.append([])
        operations[run-1].append("NEW")
        block_action = BlockAction()
        block_action.value = DESTROY_BLOCK
        block_action.player_id = 32
        set_color = SetColor()
        set_color.value = connection.selectColor if connection.selectColor is not None else 0x707070
        set_color.player_id = 32
        i = 0
        for x in range(*(pos1[0], pos2[0] + 1) if pos1[0] < pos2[0] else (pos2[0], pos1[0] + 1)):
            block_action.x = x + (offset[0]*xh*(run+1))
            for y in range(*(pos1[1], pos2[1] + 1) if pos1[1] < pos2[1] else (pos2[1], pos1[1] + 1)):
                block_action.y = y + (offset[1]*yh*(run+1))
                for z in range(*(pos1[2], pos2[2] + 1) if pos1[2] < pos2[2] else (pos2[2], pos1[2] + 1)):
                    block_action.value = DESTROY_BLOCK
                    block_action.z = z + (offset[2]*zh*(run+1))
                    if(not allBlocks[i][0]):
                        if map.get_point(block_action.x, block_action.y, block_action.z):
                            connection.protocol.broadcast_contained(block_action)
                            map.remove_point(block_action.x, block_action.y, block_action.z)
                        i += 1
                        operations[run-1].append("blank")
                        continue
                    else:
                        if(not map.get_point(block_action.x, block_action.y, block_action.z)):
                            block = allBlocks[i]
                            blockColor = block[1]
                            icolor = blockColor[0]*(256**2) + blockColor[1]*256 + blockColor[2]
                            set_color.value = icolor
                            connection.protocol.broadcast_contained(set_color)
                        else:
                            block_action.value = BUILD_BLOCK
                            connection.protocol.broadcast_contained(block_action)
                            block = allBlocks[i]
                            blockColor = block[1]
                            icolor = blockColor[0]*(256**2) + blockColor[1]*256 + blockColor[2]
                            icolor = blockColor[0]*(256**2) + blockColor[1]*256 + blockColor[2]
                            set_color.value = icolor
                            connection.protocol.broadcast_contained(set_color)
                            
                            ctuple = (set_color.value >> 16 & 255, set_color.value >> 8 & 255, set_color.value & 255)
                            map.set_point(block_action.x, block_action.y, block_action.z, ctuple)
                        i += 1
                        operations[run-1].append("block")
                        continue
Ejemplo n.º 38
0
 def create_rollback_generator(self, cur, new, start_x, start_y,
     end_x, end_y, ignore_indestructable):
     surface = {}
     block_action = BlockAction()
     block_action.player_id = 31
     set_color = SetColor()
     set_color.value = make_color(*NON_SURFACE_COLOR)
     set_color.player_id = 31
     self.send_contained(set_color, save = True)
     old = cur.copy()
     check_protected = hasattr(protocol, 'protected')
     x_count = abs(start_x - end_x)
     for x in xrange(start_x, end_x):
         block_action.x = x
         for y in xrange(start_y, end_y):
             block_action.y = y
             if check_protected and self.is_protected(x, y, 0):
                 continue
             for z in xrange(63):
                 action = None
                 cur_solid = cur.get_solid(x, y, z)
                 new_solid = new.get_solid(x, y, z)
                 if cur_solid and not new_solid:
                     if (not ignore_indestructable and
                         self.is_indestructable(x, y, z)):
                         continue
                     else:
                         action = DESTROY_BLOCK
                         cur.remove_point(x, y, z)
                 elif new_solid:
                     new_is_surface = new.is_surface(x, y, z)
                     if new_is_surface:
                         new_color = new.get_color(x, y, z)
                     if not cur_solid and new_is_surface:
                         surface[(x, y, z)] = new_color
                     elif not cur_solid and not new_is_surface:
                         action = BUILD_BLOCK
                         cur.set_point(x, y, z, NON_SURFACE_COLOR)
                     elif cur_solid and new_is_surface:
                         old_is_surface = old.is_surface(x, y, z)
                         if old_is_surface:
                             old_color = old.get_color(x, y, z)
                         if not old_is_surface or old_color != new_color:
                             surface[(x, y, z)] = new_color
                             action = DESTROY_BLOCK
                             cur.remove_point(x, y, z)
                 if action is not None:
                     block_action.z = z
                     block_action.value = action
                     self.send_contained(block_action, save = True)
                 yield action is not None, ((x-start_x+0.0) / x_count)
     last_color = None
     block_action.value = BUILD_BLOCK
     i = 0.0
     for pos, color in sorted(surface.iteritems()):
         x, y, z = pos
         packets_sent = 0
         if color != last_color:
             set_color.value = make_color(*color)
             self.send_contained(set_color, save = True)
             packets_sent += 1
             last_color = color
         cur.set_point(x, y, z, color)
         block_action.x = x
         block_action.y = y
         block_action.z = z
         self.send_contained(block_action, save = True)
         packets_sent += 1
         i += 1
         yield packets_sent, -(i / len(surface))