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()
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()
def sculpt_ray(player): if player.tool != SPADE_TOOL: return location = player.world_object.cast_ray(SCULPT_RAY_LENGTH) if location: px, py, pz = player.get_location() x, y, z = location map = player.protocol.map #if not player.sculpt_primary and player.sculpt_secondary: if collision_3d(px, py, pz, x, y, z, MAX_DIG_DISTANCE / 2): # sculpting too close print "CLOSE" return if player.on_block_destroy(x, y, z, DESTROY_BLOCK) == False: return if z > 62 or not destroy_block(player.protocol, x, y, z): return if map.get_solid(x, y, z): # sculpt allows destroying base blocks, but the API doesn't # like this. work around it and force destruction map.remove_point(x, y, z) map.check_node(x, y, z, True) player.on_block_removed(x, y, z)
def sculpt_ray(player): if player.tool != BLOCK_TOOL: return location = player.world_object.cast_ray(SCULPT_RAY_LENGTH) if location: px, py, pz = player.get_location() x, y, z = location map = player.protocol.map if player.sculpt_primary and not player.sculpt_secondary: # build if collision_3d(px, py, pz, x, y, z, MAX_BLOCK_DISTANCE - 1): # sculpting too close return black = (0, 0, 0) adjacent = set() for uvw in axes(x, y, z): if map.get_solid(*uvw) == False: u, v, w = uvw map.set_point(u, v, w, black) adjacent.add(uvw) location = player.world_object.cast_ray(SCULPT_RAY_LENGTH) for uvw in adjacent: map.remove_point(*uvw) if location and location in adjacent: if player.on_block_build_attempt(*location) != False: build_block(player.protocol, player, *location) player.on_block_build(*location) elif not player.sculpt_primary and player.sculpt_secondary: # remove if collision_3d(px, py, pz, x, y, z, MAX_DIG_DISTANCE / 2): # sculpting too close return if player.on_block_destroy(x, y, z, DESTROY_BLOCK) == False: return if z > 62 or not destroy_block(player.protocol, x, y, z): return if map.get_solid(x, y, z): # sculpt allows destroying base blocks, but the API doesn't # like this. work around it and force destruction map.remove_point(x, y, z) map.check_node(x, y, z, True) player.on_block_removed(x, y, z)
def on_block_destroy(self, x, y, z, mode): if self.protocol.minefield_debug: message = MINEFIELD_DBG_MESSAGE.format(x = x, y = y, z = z, m = self.protocol.minefieldAt(x, y, z) or 'None') self.send_chat(message) return False if mode == DESTROY_BLOCK or mode == SPADE_DESTROY: pos = self.world_object.position #xx, yy, zz = x + 0.5, y + 0.5, z + 0.5 if collision_3d(x, y, z, pos.x, pos.y, pos.z, 10): self.protocol.check_mine(self, x, y, z) return connection.on_block_destroy(self, x, y, z, mode)
def update(self, player): if not player.world_object: return location1 = [coord + 0.5 for coord in self._button.location] location2 = player.world_object.position.get() if collision_3d(*location1, *location2, self._radius): if player not in self.affected_players: self.affected_players.add(player) self._fire_if_active() else: if player in self.affected_players: self.affected_players.remove(player) self._fire_if_active()
def wield_spade(self): for player in self.protocol.players.values(): if player.hp <= 0: continue position1 = self.world_object.position position2 = player.world_object.position if not vector_collision(position1, position2, MELEE_DISTANCE): continue valid_hit = self.world_object.validate_hit( player.world_object, MELEE, HIT_TOLERANCE) if not valid_hit: continue if player.team is not self.team: speed = self.world_object.velocity.length() hit_amount = 20 * speed + 15 type = MELEE_KILL returned = self.on_hit(hit_amount, player, type, None) if returned == False: continue elif returned is not None: hit_amount = returned player.hit(hit_amount, self, type) return loc = self.world_object.cast_ray(6) # 6 = MAX_DIG_DISTANCE if loc: map = self.protocol.map x, y, z = loc if z >= 62: return if not map.get_solid(x, y, z): return pos = position1 if not collision_3d(pos.x, pos.y, pos.z, x, y, z, 6): return value = DESTROY_BLOCK if self.on_block_destroy(x, y, z, value) == False: return if map.destroy_point(x, y, z): self.on_block_removed(x, y, z) block_action.x = x block_action.y = y block_action.z = z block_action.value = value block_action.player_id = self.player_id self.protocol.send_contained(block_action, save=True) self.protocol.update_entities()
def on_block_action_recieved(self, contained): world_object = self.world_object if not self.hp: return value = contained.value if value == BUILD_BLOCK: interval = TOOL_INTERVAL[BLOCK_TOOL] elif self.tool == WEAPON_TOOL: if self.weapon_object.is_empty(): return interval = WEAPON_INTERVAL[self.weapon] else: interval = TOOL_INTERVAL[self.tool] current_time = reactor.seconds() last_time = self.last_block self.last_block = current_time if (self.rapid_hack_detect and last_time is not None and current_time - last_time < interval): self.rapids.add(current_time) if self.rapids.check(): start, end = self.rapids.get() if end - start < MAX_RAPID_SPEED: print('RAPID HACK:', self.rapids.window) self.on_hack_attempt('Rapid hack detected') return map = self.protocol.map x = contained.x y = contained.y z = contained.z if z >= 62: return if value == BUILD_BLOCK: self.blocks -= 1 pos = world_object.position if self.blocks < -BUILD_TOLERANCE: return elif not collision_3d(pos.x, pos.y, pos.z, x, y, z, MAX_BLOCK_DISTANCE): return elif self.on_block_build_attempt(x, y, z) == False: return elif not map.build_point(x, y, z, self.color): return self.on_block_build(x, y, z) else: if not map.get_solid(x, y, z): return pos = world_object.position if self.tool == SPADE_TOOL and not collision_3d( pos.x, pos.y, pos.z, x, y, z, MAX_DIG_DISTANCE): return if self.on_block_destroy(x, y, z, value) == False: return elif value == DESTROY_BLOCK: count = map.destroy_point(x, y, z) if count: self.total_blocks_removed += count self.blocks = min(50, self.blocks + 1) self.on_block_removed(x, y, z) elif value == SPADE_DESTROY: for xyz in ((x, y, z), (x, y, z + 1), (x, y, z - 1)): count = map.destroy_point(*xyz) if count: self.total_blocks_removed += count self.on_block_removed(*xyz) self.last_block_destroy = reactor.seconds() block_action.x = x block_action.y = y block_action.z = z block_action.value = contained.value block_action.player_id = self.player_id self.protocol.send_contained(block_action, save=True) self.protocol.update_entities()
def think(self): obj = self.world_object pos = obj.position found = () # find nearby foes if self.acquire_targets: for player in self.team.other.get_players(): if vector_collision(pos, player.world_object.position, 108.0): if not self.aim_at: if obj.can_see(*player.world_object.position.get()): self.aim_at = player else: if point_distance2(self, player) < point_distance2(self, self.aim_at): if obj.can_see(*player.world_object.position.get()) and self.aim_at is not player: self.aim_at = player if self.aim_at: self.acquire_targets = False dist = point_distance2(self, self.aim_at ) if self.target_orientation.z < -0.25: cont = block_line cont.player_id = self.player_id cont.x1 = (pos.x) cont.y1 = (pos.y) cont.z1 = (pos.z) cont.x2 = (pos.x) cont.y2 = (pos.y) cont.z2 = (pos.z+2) self.input.add("secondary_fire") if random.random() > 0.95 or self.aim_at is None: if self.team.other.flag.player is not self: self.acquire_targets = True if self.aim_at and not obj.can_see(*self.aim_at.world_object.position.get()) and not self.terminator: self.aim_at = None # replicate player functionality if self.protocol.game_mode == CTF_MODE: other_flag = self.team.other.flag our_flag = self.team.flag if self.aim_at is None and our_flag.player and other_flag.player is not self: self.aim_at = our_flag.player if self.aim_at is None and other_flag.player is self: self.aim.set_vector( self.team.base ) self.aim -= pos distance_to_aim = self.aim.normalize() # don't move this line self.target_orientation.set_vector(self.aim ) self.input.add("up") elif other_flag.player is not self: self.aim.set_vector( other_flag ) self.aim -= pos distance_to_aim = self.aim.normalize() # don't move this line self.target_orientation.set_vector(self.aim ) self.input.add("up") if vector_collision(pos, self.team.base): if other_flag.player is self: self.capture_flag() self.check_refill() if not other_flag.player and vector_collision(pos, other_flag): self.take_flag() if self.hp < 30 and self.hp > 0 and self.terminator: if self.suicide_call is None: self.set_tool( GRENADE_TOOL ) self.suicide_call = callLater(.2, self.suicide_grenade, 1.0) if random.random() >=0.15: self.input.add("secondary_fire") if random.random() >=0.92 or self.target_orientation.z < -0.25: self.input.add("jump") if random.random() >=0.995: self.on_block_destroy( pos.x, pos.y, pos.z, DESTROY_BLOCK ) player = self location = player.world_object.cast_ray( 3 ) if location: px, py, pz = player.get_location() x, y, z = location map = player.protocol.map if not collision_3d(px, py, pz, x, y, z, 3): return self.input.add("primary_fire") if player.on_block_destroy(x, y, z, DESTROY_BLOCK) == False: return if z > 62 or not destroy_block(player.protocol, x, y, z): return if map.get_solid(x, y, z): map.remove_point(x, y, z) map.check_node(x, y, z, True) player.on_block_removed(x, y, z)
def player_in_action_range(self, player): pos = player.world_object.position x, y, z = self.entry_location return collision_3d(pos.x, pos.y, pos.z, x, y, z, distance = 2)
def player_in_action_range(self, player): pos = player.world_object.position x, y, z = self.entry_location return collision_3d(pos.x, pos.y, pos.z, x, y, z, distance=2)