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)
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.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.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 invisible(connection, player = None): protocol = connection.protocol if player is not None: player = get_player(protocol, player) elif connection in protocol.players: player = connection else: raise ValueError() player.invisible = not player.invisible player.filter_visibility_data = player.invisible player.god = player.invisible player.god_build = False player.killing = not player.invisible if player.invisible: player.send_chat("You're now invisible") protocol.irc_say('* %s became invisible' % player.name) kill_action = KillAction() kill_action.kill_type = choice([GRENADE_KILL, FALL_KILL]) kill_action.player_id = kill_action.killer_id = player.player_id reactor.callLater(1.0 / NETWORK_FPS, protocol.send_contained, kill_action, sender = player) else: player.send_chat("You return to visibility") protocol.irc_say('* %s became visible' % player.name) x, y, z = player.world_object.position.get() create_player.player_id = player.player_id create_player.name = player.name create_player.x = x create_player.y = y create_player.z = z create_player.weapon = player.weapon create_player.team = player.team.id world_object = player.world_object input_data.player_id = player.player_id input_data.up = world_object.up input_data.down = world_object.down input_data.left = world_object.left input_data.right = world_object.right input_data.jump = world_object.jump input_data.crouch = world_object.crouch input_data.sneak = world_object.sneak input_data.sprint = world_object.sprint set_tool.player_id = player.player_id set_tool.value = player.tool set_color.player_id = player.player_id set_color.value = make_color(*player.color) weapon_input.primary = world_object.primary_fire weapon_input.secondary = world_object.secondary_fire protocol.send_contained(create_player, sender = player, save = True) protocol.send_contained(set_tool, sender = player) protocol.send_contained(set_color, sender = player, save = True) protocol.send_contained(input_data, sender = player) protocol.send_contained(weapon_input, sender = player) if connection is not player and connection in protocol.players: if player.invisible: return '%s is now invisible' % player.name else: return '%s is now visible' % player.name
def build_filled_generator(protocol, x1, y1, z1, x2, y2, z2, color, god = False, god_build = False): # create a player instance, freed when the generator is done # other scripts that also use ServerPlayer won't get the same id! # this won't be necessary in 1.0 splayer = cbc.ServerPlayer() line = BlockLine() line.player_id = splayer.player_id set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = splayer.player_id protocol.send_contained(set_color, save = True) packets = 1 check_protected = hasattr(protocol, 'protected') if god_build and protocol.god_blocks is None: protocol.god_blocks = set() map = protocol.map ranges = [xrange(min(x1 , x2) , max(x1 , x2)+1) , xrange(min(y1 , y2) , max(y1 , y2)+1) , xrange(min(z1 , z2) , max(z1 , z2)+1)] order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1] # set the first block position prod = ordered_product(ranges, order) line.x1, line.y1, line.z1 = prod.next() line.x2 = line.x1 line.y2 = line.y1 line.z2 = line.z1 map.set_point(line.x1, line.y1, line.z1, color) for x, y, z in prod: packets = 0 if not god and check_protected and protocol.is_protected(x, y, z): continue if god_build: protocol.god_blocks.add((x, y, z)) changed = (line.x1 != x or line.x2 != x) + (line.y1 != y or line.y2 != y) + (line.z1 != z or line.z2 != z) dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z) if changed > 1 or dist >= MAX_LINE_BLOCKS: protocol.send_contained(line, save = True) packets += 2 line.x1 = x line.y1 = y line.z1 = z line.x2 = x line.y2 = y line.z2 = z map.set_point(x, y, z, color) yield packets, 0 protocol.send_contained(line, save = True) yield 1, 0
def random_color(self): (h, l, s) = self.team.hls l = randint(self.team.light_range[0], self.team.light_range[1]) color = byte_hls_to_rgb((h, l, s)) self.color = color set_color.player_id = self.player_id set_color.value = make_color(*color) self.send_contained(set_color) self.protocol.send_contained(set_color, save=True)
def rebuild_block(player, x, y, z, color): set_color.value = make_color(*color) set_color.player_id = 32 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 build_block(connection, x, y, z, color): set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = 32 connection.protocol.send_contained(set_color) 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.send_contained(block_action, save=True)
def on_block_build_attempt(self, x, y, z): # make sure block is built with the team color if self.team is not None: brightness = random.randint(180, 255) self.color = (self.team.color[0] * brightness >> 8, self.team.color[1] * brightness >> 8, self.team.color[2] * brightness >> 8) set_color.player_id = self.player_id set_color.value = make_color(*self.color) self.protocol.send_contained(set_color, sender=None, save=True) return connection.on_block_build_attempt(self, x, y, z)
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
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
def build_block(connection, x, y, z, color): if is_invalid_coord(x, y, z): return set_color = loaders.SetColor() set_color.value = make_color(*color) set_color.player_id = 32 connection.protocol.broadcast_contained(set_color) block_action = loaders.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 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 my_invisible(connection): protocol = connection.protocol player = connection player.invisible = not player.invisible player.filter_visibility_data = player.invisible if not player.invisible and player.world_object is not None: x, y, z = player.world_object.position.get() create_player.player_id = player.player_id create_player.name = player.name create_player.x = x create_player.y = y create_player.z = z create_player.weapon = player.weapon create_player.team = player.team.id world_object = player.world_object input_data.player_id = player.player_id input_data.up = world_object.up input_data.down = world_object.down input_data.left = world_object.left input_data.right = world_object.right input_data.jump = world_object.jump input_data.crouch = world_object.crouch input_data.sneak = world_object.sneak input_data.sprint = world_object.sprint set_tool.player_id = player.player_id set_tool.value = player.tool set_color.player_id = player.player_id set_color.value = make_color(*player.color) weapon_input.primary = world_object.primary_fire weapon_input.secondary = world_object.secondary_fire protocol.send_contained(create_player, sender = player, save = True) protocol.send_contained(set_tool, sender = player) protocol.send_contained(set_color, sender = player, save = True) protocol.send_contained(input_data, sender = player) protocol.send_contained(weapon_input, sender = player) player.send_chat("Now visible.")
def my_invisible(connection): protocol = connection.protocol player = connection player.invisible = not player.invisible player.filter_visibility_data = player.invisible if not player.invisible and player.world_object is not None: x, y, z = player.world_object.position.get() create_player.player_id = player.player_id create_player.name = player.name create_player.x = x create_player.y = y create_player.z = z create_player.weapon = player.weapon create_player.team = player.team.id world_object = player.world_object input_data.player_id = player.player_id input_data.up = world_object.up input_data.down = world_object.down input_data.left = world_object.left input_data.right = world_object.right input_data.jump = world_object.jump input_data.crouch = world_object.crouch input_data.sneak = world_object.sneak input_data.sprint = world_object.sprint set_tool.player_id = player.player_id set_tool.value = player.tool set_color.player_id = player.player_id set_color.value = make_color(*player.color) weapon_input.primary = world_object.primary_fire weapon_input.secondary = world_object.secondary_fire protocol.send_contained(create_player, sender = player, save = True) protocol.send_contained(set_tool, sender = player) protocol.send_contained(set_color, sender = player, save = True) protocol.send_contained(input_data, sender = player) protocol.send_contained(weapon_input, sender = player) player.send_chat("Ora visibile")
def paint_block_by_team(self, player, points, team): updated_points = set() for x, y, z in points: if x < 0 or y < 0 or z < 0 or x >= 512 or y >= 512 or z >= 63: continue # empty? if not self.map.get_solid(x, y, z) or not self.map.is_surface( x, y, z): continue # already owned? if not self.territory_map.own(x, y, z, team.id + 1): pass # return False updated_points.add((x, y, z)) color = self.map.get_color(x, y, z) color = blend_color(color, team.color, random.randint(160, 200)) self.map.set_point(x, y, z, color) for x, y, z in updated_points: color = self.map.get_color(x, y, z) player.color = color set_color.player_id = player.player_id set_color.value = make_color(*color) self.send_contained(set_color, sender=None, save=True) block_action.x = x block_action.y = y block_action.z = z block_action.player_id = player.player_id block_action.value = DESTROY_BLOCK self.send_contained(block_action, save=True) block_action.value = BUILD_BLOCK self.send_contained(block_action, save=True) if (x, y) not in self.check_destroy_spans: self.check_destroy_spans.add((x, y)) self.check_destroy_spans_list.append((x, y))
def cast_rocket(self, pos, ori, start_boom=True): if pos.z <= -1: self.send_chat_error("Too high. Go down to launch a rocket") return False obj = Rocket() obj.pos = pos obj.ori = ori obj.player = self self.protocol.rockets.append(obj) set_color = SetColor() set_color.value = make_color(*ROCKET_COLOR.get()) set_color.player_id = 32 self.protocol.broadcast_contained(set_color) if start_boom: grenade_packet = GrenadePacket() grenade_packet.value = 0 grenade_packet.player_id = self.player_id grenade_packet.position = self.world_object.position.get() grenade_packet.velocity = (0, 0, 0) self.protocol.broadcast_contained(grenade_packet) return True
def __init__(self, protocol, team, x, y): self.protocol = protocol self.team = team self.x = x self.y = y if self.random_colors: self.color = choice(self.random_colors) elif self.team_color: self.color = make_color(*team.color) self.blocks = set() base_lines, base_points = self.lines, self.points self.lines, self.points = [], [] for line in base_lines: self.make_line(*line) for point in base_points: self.make_block(*point) # find markers we're colliding with has_timer = self.duration is not None collisions = [] current_time = seconds() worst_time = current_time + self.duration if has_timer else None for marker in protocol.markers: intersect = marker.blocks & self.blocks if intersect: self.blocks -= intersect collisions.append(marker) if has_timer and marker.expire_call: worst_time = min(worst_time, marker.expire_call.getTime()) # forward expiration time so that colliding markers vanish all at once if has_timer: delay = worst_time - current_time self.expire_call = callLater(delay, self.expire) self.build() team.marker_count[self.__class__] += 1 protocol.markers.append(self) if self.background_class: self.background = self.background_class(protocol, team, x, y)
def _set_paused(self, value): if self._paused == value: return is_spectator = self.team and self.team.spectator if value and is_spectator: # spectators are unaffected return self._paused = value self.filter_weapon_input = value self.filter_animation_data = value self.freeze_animation = value send_others = partial(self.protocol.send_contained, sender = self, save = True) world_object = self.world_object if value: # start sticky position loop self.pause_loop = LoopingCall(reposition, self) self.pause_loop.start(0.08) self.paused_spawn = None self.paused_orientation = None if world_object is None: return # stop walking and shooting world_object.set_walk(False, False, False, False) weapon_input.player_id = self.player_id weapon_input.primary = False weapon_input.secondary = False send_others(weapon_input) else: # end repositioning if self.pause_loop and self.pause_loop.running: self.pause_loop.stop() self.pause_loop = None if self.paused_spawn: # game got paused while player was waiting to spawn self.paused_spawn() self.paused_spawn = None return if world_object is None: return if self.paused_orientation: # assume stored orientation world_object.set_orientation(*self.paused_orientation) set_tool.player_id = self.player_id set_tool.value = self.tool set_color.player_id = self.player_id set_color.value = make_color(*self.color) weapon_input.player_id = self.player_id weapon_input.primary = world_object.primary_fire weapon_input.secondary = world_object.secondary_fire send_others(set_tool) send_others(set_color) send_others(weapon_input) input_data.player_id = self.player_id input_data.up = world_object.up input_data.down = world_object.down input_data.left = world_object.left input_data.right = world_object.right input_data.jump = world_object.jump input_data.crouch = world_object.crouch input_data.sneak = world_object.sneak input_data.sprint = world_object.sprint send_others(input_data)
def _send_connection_data(self): saved_loaders = self.saved_loaders = [] if self.player_id is None: for player in self.protocol.players.values(): if player.name is None: continue existing_player.name = player.name existing_player.player_id = player.player_id existing_player.tool = player.tool or 0 existing_player.weapon = player.weapon existing_player.kills = player.kills existing_player.team = player.team.id existing_player.color = make_color(*player.color) saved_loaders.append(existing_player.generate()) self.player_id = self.protocol.player_ids.pop() self.protocol.update_master() # send initial data blue = self.protocol.blue_team green = self.protocol.green_team state_data.player_id = self.player_id state_data.fog_color = self.protocol.fog_color state_data.team1_color = blue.color state_data.team1_name = blue.name state_data.team2_color = green.color state_data.team2_name = green.name game_mode = self.protocol.game_mode if game_mode == CTF_MODE: blue_base = blue.base blue_flag = blue.flag green_base = green.base green_flag = green.flag ctf_data.cap_limit = self.protocol.max_score ctf_data.team1_score = blue.score ctf_data.team2_score = green.score ctf_data.team1_base_x = blue_base.x ctf_data.team1_base_y = blue_base.y ctf_data.team1_base_z = blue_base.z ctf_data.team2_base_x = green_base.x ctf_data.team2_base_y = green_base.y ctf_data.team2_base_z = green_base.z if green_flag.player is None: ctf_data.team1_has_intel = 0 ctf_data.team2_flag_x = green_flag.x ctf_data.team2_flag_y = green_flag.y ctf_data.team2_flag_z = green_flag.z else: ctf_data.team1_has_intel = 1 ctf_data.team2_carrier = green_flag.player.player_id if blue_flag.player is None: ctf_data.team2_has_intel = 0 ctf_data.team1_flag_x = blue_flag.x ctf_data.team1_flag_y = blue_flag.y ctf_data.team1_flag_z = blue_flag.z else: ctf_data.team2_has_intel = 1 ctf_data.team1_carrier = blue_flag.player.player_id state_data.state = ctf_data elif game_mode == TC_MODE: state_data.state = tc_data generated_data = state_data.generate() saved_loaders.append(generated_data)
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
class NumberMarker(BaseMarker): duration = Enemy.duration background_class = Enemy color = make_color(255, 255, 255) always_there = True
class BuildBackground(BaseMarker): color = make_color(255, 255, 255) s = """
class BackupBackground(BaseMarker): color = make_color(0, 0, 0) s = """
def send_color(protocol, color): set_color_packet = SetColor() set_color_packet.value = make_color(*color) set_color_packet.player_id = 32 protocol.send_contained(set_color_packet, save=True)
def send_fog(player, color): fog_color.color = make_color(*color) player.send_contained(fog_color)
def set_fog_color(self, color): self.fog_color = color fog_color.color = make_color(*color) self.send_contained(fog_color, save=True, rule=send_fog_rule)
def send_fog(self, sender = None): sender = sender or self.protocol color = self.get_color() fog_color.color = make_color(*color) sender.send_contained(fog_color, save = True)
def send_fog(player, color): fog_color = loaders.FogColor() fog_color.color = make_color(*color) player.send_contained(fog_color)
def updateColor(self, protocol, color): set_color.value = make_color(*color) set_color.player_id = 32 protocol.send_contained(set_color, save = True) return color
class EnemyBackground(BaseMarker): color = make_color(0, 0, 0) s = """
def set_fog_effects_on_color(self, color): self._fog_effects_on_color = color if self._fog_effects: fog_color.color = make_color(*color) self.send_contained(fog_color, save=True)
class Intel(BaseMarker): name = 'Intel' color = make_color(255, 255, 255) s = """
def updateColor(self, protocol, color): set_color.value = make_color(*color) set_color.player_id = 32 protocol.send_contained(set_color, save=True) return color
class TunnelBackground(BaseMarker): color = make_color(255, 255, 255) s = """
def build_filled_generator(protocol, x1, y1, z1, x2, y2, z2, color, god=False, god_build=False): # create a player instance, freed when the generator is done # other scripts that also use ServerPlayer won't get the same id! # this won't be necessary in 1.0 splayer = cbc.ServerPlayer() line = BlockLine() line.player_id = splayer.player_id set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = splayer.player_id protocol.send_contained(set_color, save=True) packets = 1 check_protected = hasattr(protocol, 'protected') if god_build and protocol.god_blocks is None: protocol.god_blocks = set() map = protocol.map ranges = [ xrange(min(x1, x2), max(x1, x2) + 1), xrange(min(y1, y2), max(y1, y2) + 1), xrange(min(z1, z2), max(z1, z2) + 1) ] order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1] # set the first block position prod = ordered_product(ranges, order) line.x1, line.y1, line.z1 = prod.next() line.x2 = line.x1 line.y2 = line.y1 line.z2 = line.z1 map.set_point(line.x1, line.y1, line.z1, color) for x, y, z in prod: packets = 0 if not god and check_protected and protocol.is_protected(x, y, z): continue if god_build: protocol.god_blocks.add((x, y, z)) changed = (line.x1 != x or line.x2 != x) + ( line.y1 != y or line.y2 != y) + (line.z1 != z or line.z2 != z) dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z) if changed > 1 or dist >= MAX_LINE_BLOCKS: protocol.send_contained(line, save=True) packets += 2 line.x1 = x line.y1 = y line.z1 = z line.x2 = x line.y2 = y line.z2 = z map.set_point(x, y, z, color) yield packets, 0 protocol.send_contained(line, save=True) yield 1, 0
def invisible(connection, player): """ Turn invisible /invisible [player] """ protocol = connection.protocol # TODO: move this logic to a more suitable place player.invisible = not player.invisible player.filter_visibility_data = player.invisible player.god = player.invisible player.god_build = False player.killing = not player.invisible if player.invisible: player.send_chat("You're now invisible") protocol.irc_say('* %s became invisible' % player.name) kill_action = KillAction() kill_action.kill_type = choice([GRENADE_KILL, FALL_KILL]) kill_action.player_id = kill_action.killer_id = player.player_id reactor.callLater(1.0 / NETWORK_FPS, protocol.broadcast_contained, kill_action, sender=player) else: player.send_chat("You return to visibility") protocol.irc_say('* %s became visible' % player.name) x, y, z = player.world_object.position.get() create_player = CreatePlayer() create_player.player_id = player.player_id create_player.name = player.name create_player.x = x create_player.y = y create_player.z = z create_player.weapon = player.weapon create_player.team = player.team.id world_object = player.world_object input_data = InputData() input_data.player_id = player.player_id input_data.up = world_object.up input_data.down = world_object.down input_data.left = world_object.left input_data.right = world_object.right input_data.jump = world_object.jump input_data.crouch = world_object.crouch input_data.sneak = world_object.sneak input_data.sprint = world_object.sprint set_tool = SetTool() set_tool.player_id = player.player_id set_tool.value = player.tool set_color = SetColor() set_color.player_id = player.player_id set_color.value = make_color(*player.color) weapon_input = WeaponInput() weapon_input.primary = world_object.primary_fire weapon_input.secondary = world_object.secondary_fire protocol.broadcast_contained(create_player, sender=player, save=True) protocol.broadcast_contained(set_tool, sender=player) protocol.broadcast_contained(set_color, sender=player, save=True) protocol.broadcast_contained(input_data, sender=player) protocol.broadcast_contained(weapon_input, sender=player) if connection is not player and connection in protocol.players.values(): if player.invisible: return '%s is now invisible' % player.name else: return '%s is now visible' % player.name
def send_fog(self, sender=None): sender = sender or self.protocol color = self.get_color() fog_color.color = make_color(*color) sender.send_contained(fog_color, save=True)
def set_fog_color(self, color): self.fog_color = color fog_color = loaders.FogColor() fog_color.color = make_color(*color) self.send_contained(fog_color, save=True)