将下面灯塔AOI算法改造成ECS架构

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LighthouseAOI {
    // 定义光塔视野半径和光塔坐标
    private static final int SIGHT_RADIUS = 10;
    private static final int[] LIGHTHOUSE_POS = new int[]{0, 0};

    // 存储玩家位置和 ID 的映射关系
    private Map<int[], Integer> playerPositions;

    // 存储玩家 ID 和它所处的光塔 ID 的映射关系
    private Map<Integer, List<Integer>> playerLighthouseIds;

    // 存储光塔 ID 和它所能看到的玩家 ID 的映射关系
    private Map<Integer, List<Integer>> lighthousePlayerIds;

    // 存储光塔 ID 和它所能看到的其他光塔 ID 的映射关系
    private Map<Integer, List<Integer>> lighthouseLighthouseIds;

    // 构造方法，初始化各个映射关系
    public LighthouseAOI() {
        playerPositions = new HashMap<>();
        playerLighthouseIds = new HashMap<>();
        lighthousePlayerIds = new HashMap<>();
        lighthouseLighthouseIds = new HashMap<>();
    }

    // 添加玩家方法
    public void addPlayer(int playerId, int x, int y) {
        int[] playerPos = new int[]{x, y};
        playerPositions.put(playerPos, playerId);
        updatePlayerLighthouses(playerId, x, y);
    }

    // 删除玩家方法
    public void removePlayer(int playerId, int x, int y) {
        int[] playerPos = new int[]{x, y};
        playerPositions.remove(playerPos);
        removePlayerFromLighthouses(playerId);
    }

    // 更新玩家所处的光塔方法
    private void updatePlayerLighthouses(int playerId, int x, int y) {
        List<Integer> lighthousesToAddTo = new ArrayList<>();
        for (int i = 1; i <= 9; i++) {
            int[] lighthousePos = getLighthousePosition(i);
            double distance = Math.sqrt(Math.pow((lighthousePos[0] - x), 2) + Math.pow((lighthousePos[1] - y), 2));
            if (distance <= SIGHT_RADIUS) {
                lighthousesToAddTo.add(i);
                addPlayerToLighthouse(playerId, i);
                addLighthouseToLighthouses(playerId, i);
            }
        }
        playerLighthouseIds.put(playerId, lighthousesToAddTo);
    }

    // 从光塔中移除玩家方法
    private void removePlayerFromLighthouses(int playerId) {
        List<Integer> lighthousesToRemoveFrom = playerLighthouseIds.get(playerId);
        for (int lighthouseId : lighthousesToRemoveFrom) {
            removePlayerFromLighthouse(playerId, lighthouseId);
        }
        playerLighthouseIds.remove(playerId);
    }

    // 添加玩家到光塔中方法
    private void addPlayerToLighthouse(int playerId, int lighthouseId) {
        List<Integer> playersInLighthouse = lighthousePlayerIds.getOrDefault(lighthouseId, new ArrayList<>());
        if (!playersInLighthouse.contains(playerId)) {
            playersInLighthouse.add(playerId);
        }
        lighthousePlayerIds.put(lighthouseId, playersInLighthouse);
    }

    // 从光塔中移除玩家方法
    private void removePlayerFromLighthouse(int playerId, int lighthouseId) {
        List<Integer> playersInLighthouse = lighthousePlayerIds.getOrDefault(lighthouseId, new ArrayList<>());
        playersInLighthouse.remove(playerId);
        lighthousePlayerIds.put(lighthouseId, playersInLighthouse);
    }

    // 添加光塔到光塔中方法
    private void addLighthouseToLighthouses(int lighthouseId, int currentLighthouseId) {
        List<Integer> lighthousesInLighthouse = lighthouseLighthouseIds.getOrDefault(lighthouseId, new ArrayList<>());
        if (!lighthousesInLighthouse.contains(currentLighthouseId)) {
            lighthousesInLighthouse.add(currentLighthouseId);
        }
        lighthouseLighthouseIds.put(lighthouseId, lighthousesInLighthouse);
    }

    // 获取光塔坐标方法
    private int[] getLighthousePosition(int lighthouseId) {
        int x = LIGHTHOUSE_POS[0] + (lighthouseId - 1) % 3;
        int y = LIGHTHOUSE_POS[1] + (lighthouseId - 1) / 3;
        return new int[]{x, y};
    }

    // 获取玩家可见的其他玩家 ID 列表
    public List<Integer> getVisiblePlayers(int playerId) {
        List<Integer> visiblePlayers = new ArrayList<>();
        List<Integer> lighthouses = playerLighthouseIds.get(playerId);
        for (int lighthouseId : lighthouses) {
            List<Integer> playersInLighthouse = lighthousePlayerIds.getOrDefault(lighthouseId, new ArrayList<>());
            for (int playerInLighthouse : playersInLighthouse) {
                if (playerInLighthouse != playerId && !visiblePlayers.contains(playerInLighthouse)) {
                    visiblePlayers.add(playerInLighthouse);
                }
            }
        }
        return visiblePlayers;
    }

    // 获取玩家可见的其他光塔 ID 列表
    public List<Integer> getVisibleLighthouses(int playerId) {
        List<Integer> visibleLighthouses = new ArrayList<>();
        List<Integer> lighthouses = playerLighthouseIds.get(playerId);
        for (int lighthouseId : lighthouses) {
            List<Integer> lighthousesInLighthouse = lighthouseLighthouseIds.getOrDefault(lighthouseId, new ArrayList<>());
            for (int lighthouseInLighthouse : lighthousesInLighthouse) {
                if (lighthouseInLighthouse != lighthouseId && !visibleLighthouses.contains(lighthouseInLighthouse)) {
                    visibleLighthouses.add(lighthouseInLighthouse);
                }
            }
        }
        return visibleLighthouses;
    }
}