using Gameplay.Area.Around; using NLDPB; using System.Collections.Generic; using TGS; using UnityEngine; namespace Gameplay.LegionBattle { /// /// 军团战格子数据 /// public sealed class LegionBattleHexesData { /// /// A阵营地板 /// private GameObject goACell; /// /// B阵营地板 /// private GameObject goBCell; /// /// 索引 /// public int Index { get; private set; } /// /// 坐标 /// public Vector2Int Coordinate { get; private set; } /// /// 所属阵营 /// public BattlefieldActorCamp Camp { get; private set; } /// /// 周围格子 /// public List ListAroundCell { get; private set; } /// /// 周围边界索引 /// public List ListAroundSideIndex { get; private set; } public LegionBattleHexesData(Cell cell, Vector2Int coordinate, GameObject aCell, GameObject bCell) { Index = cell.index; Coordinate = coordinate; Camp = BattlefieldActorCamp.BacNone; goACell = aCell; goBCell = bCell; ListAroundCell = new(LegionBattle.MAX_SIDE); ListAroundSideIndex = new(LegionBattle.MAX_SIDE); GetAroundCell(); GetBoardSideMath(cell, ListAroundSideIndex); } /// /// 设置阵营 /// public void SetCamp(BattlefieldActorCamp camp) { Camp = camp; if (BattlefieldActorCamp.CampA == Camp) { goACell.SetActive(true); goBCell.SetActive(false); } else if (BattlefieldActorCamp.CampB == Camp) { goACell.SetActive(false); goBCell.SetActive(true); } else { goACell.SetActive(false); goBCell.SetActive(false); } } /// /// 更新边界 /// public void UpdateSide() { for (int i = 0; i < ListAroundSideIndex.Count; ++i) { LegionBattleManager.Instance.CurBattle.UpdateSideShow(Camp, ListAroundCell[i], ListAroundSideIndex[i]); } } /// /// 获取周围地板 /// private void GetAroundCell() { if (1 == (Coordinate.x & 1)) // 中心在奇数行 { Vector2Int newPos = new(Coordinate.x - 1, Coordinate.y + 1); // 右下 ListAroundCell.Add(newPos); newPos = new(Coordinate.x - 1, Coordinate.y); // 左下 ListAroundCell.Add(newPos); newPos = new(Coordinate.x, Coordinate.y + 1); // 右 ListAroundCell.Add(newPos); newPos = new(Coordinate.x, Coordinate.y - 1); // 左 ListAroundCell.Add(newPos); newPos = new(Coordinate.x + 1, Coordinate.y + 1); // 右上 ListAroundCell.Add(newPos); newPos = new(Coordinate.x + 1, Coordinate.y); // 左上 ListAroundCell.Add(newPos); } else // 中心在偶数行 { Vector2Int newPos = new(Coordinate.x - 1, Coordinate.y); // 右下 ListAroundCell.Add(newPos); newPos = new(Coordinate.x - 1, Coordinate.y - 1); // 左下 ListAroundCell.Add(newPos); newPos = new(Coordinate.x, Coordinate.y + 1); // 右 ListAroundCell.Add(newPos); newPos = new(Coordinate.x, Coordinate.y - 1); // 左 ListAroundCell.Add(newPos); newPos = new(Coordinate.x + 1, Coordinate.y); // 右上 ListAroundCell.Add(newPos); newPos = new(Coordinate.x + 1, Coordinate.y - 1); // 左上 ListAroundCell.Add(newPos); } } private int GetBoardIndexBySide(int centerCellIndex, int side) { return centerCellIndex * 10 + side; } private void GetBoardSideMath(Cell centerCell, List boardSideCellIndexList) { Vector3Int centerPos = centerCell.mathPointV3; int minX = centerPos.x - 1; int maxX = centerPos.x + 1; int minY = centerPos.y - 1; int maxY = centerPos.y + 1; int minZ = centerPos.z - 1; int maxZ = centerPos.z + 1; int cacheBoardIndex = 0; for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { if (x == centerPos.x && y == centerPos.y) continue; int z = -x - y; if (z < minZ || z > maxZ) continue; cacheBoardIndex++; Vector3Int pos = new(x, y, z); int calcIndex = AroundHelper.GetCellIndexV3(pos); int centerCellIndex = centerCell.index; if (calcIndex < 0) { // 说明是边界 int sideIndex = GetBoardIndexBySide(centerCellIndex, cacheBoardIndex); boardSideCellIndexList.Add(sideIndex); } else { Cell cell = LegionBattleManager.Instance.CurBattle.Map.TerrainGridSystem.cells[calcIndex]; if (!cell.isInArea) { int sideIndex = GetBoardIndexBySide(centerCellIndex, cacheBoardIndex); boardSideCellIndexList.Add(sideIndex); } } } } } } }