def _broadcast(self, **kwargs) -> None: opcode: WorldOpCode = kwargs.pop('opcode') packets: List[bytes] = kwargs.pop('packets') regions: Dict[int, Region] = kwargs.pop('regions') player: Player = self.connection.player current_region: Region = regions.get(player.region.id) if current_region is None: return None current_node: OctreeNode = player.get_current_node() if not current_node: return None # we get parent of parent because some of nearest nodes can lay in the another parent node_to_notify: OctreeNode = current_node.parent_node.parent_node guids = OctreeNodeManager.get_guids(node_to_notify) guids = [guid for guid in guids if not guid == player.guid] if not guids: return None targets_to_notify: List[Player] = [ player for player in current_region.players if player.guid in guids ] if not targets_to_notify: return None for packet in packets: PlayerManager.broadcast(opcode, packet, targets_to_notify)
def broadcast(**kwargs) -> None: opcode: WorldOpCode = kwargs.pop('opcode') packets: List[bytes] = kwargs.pop('packets') regions: Dict[int, Region] = kwargs.pop('regions') for region in regions.values(): root_node: OctreeNode = region.get_octree() guids = OctreeNodeManager.get_guids(root_node) if not guids: continue targets_to_notify: List[Player] = [ player for player in region.players if player.guid in guids ] if not targets_to_notify: continue for packet in packets: PlayerManager.broadcast(opcode, packet, targets_to_notify)