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
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))
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
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()
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()
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
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)
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)
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))
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
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)
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
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)
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
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))
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
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