using cfg.LegionBattleCfg; using Framework; using Gameplay.Level; using NLDPB; using System.Collections.Generic; using UnityEngine; namespace Gameplay.LegionBattle { /// /// 军团战建筑数据 /// public sealed class LegionBuildingData { /// /// 建筑索引 /// public int Index { get; private set; } /// /// 建筑坐标 /// public Vector2Int Coordinate { get; private set; } /// /// 建筑内的玩家 /// public List listActorId { get; private set; } /// /// 当前阵营 /// public BattlefieldActorCamp CurCamp { get; private set; } /// /// 防守成功次数 /// public int DefenceCount { get; private set; } /// /// 被攻占次数 /// public int AttackedTotal { get; private set; } /// /// 名字key /// public string NameKey { get; private set; } /// /// 据点配置 /// public DataLegionBattleBuilding Cfg { get; private set; } /// /// 所占所有格子坐标 /// public List ListAllIndex { get; private set; } public LegionBuildingData(LegionLevelData.Building building, int width, int height, Map map) { Index = building.position; listActorId = new List(); ListAllIndex = new List(); NameKey = building.buildingNameKey; Cfg = TableManager.Instance.Tables.LegionBattleBuilding.Get(building.buildingID); #region 临时处理计算建筑所占地格 Dictionary dicPos = new() // TODO 临时处理,记录建筑所占地格 { { map.TGSCellIndex2BlockPosition(building.position), false } }; HashSet setNew = new(); List listOld = new(); int range = 1; while (range < Cfg.BuildingRange) { foreach (var kv in dicPos) { if (kv.Value) continue; if (kv.Key.x < 0 || kv.Key.x >= width || kv.Key.y < 0 || kv.Key.y > height) continue; if (1 == (kv.Key.x & 1)) // 中心在奇数行 { Vector2Int newPos = new(kv.Key.x, kv.Key.y - 1); // 左 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x - 1, kv.Key.y); // 左下 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x - 1, kv.Key.y + 1); // 右下 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x, kv.Key.y + 1); // 右 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x + 1, kv.Key.y + 1); // 右上 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x + 1, kv.Key.y); // 左上 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); } else // 中心在偶数行 { Vector2Int newPos = new(kv.Key.x, kv.Key.y - 1); // 左 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x - 1, kv.Key.y - 1); // 左下 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x - 1, kv.Key.y); // 右下 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x, kv.Key.y + 1); // 右 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x + 1, kv.Key.y); // 右上 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); newPos = new(kv.Key.x + 1, kv.Key.y - 1); // 左上 if (!dicPos.ContainsKey(newPos)) setNew.Add(newPos); } listOld.Add(kv.Key); } foreach (Vector2Int pos in listOld) { dicPos[pos] = true; } foreach (Vector2Int pos in setNew) { dicPos[pos] = false; } listOld.Clear(); setNew.Clear(); ++range; } foreach (Vector2Int pos in dicPos.Keys) { if (pos.x < 0 || pos.x >= width || pos.y < 0 || pos.y > height) continue; ListAllIndex.Add(map.BlockPosition2TGSCellIndex(pos)); } #endregion #region 临时处理建筑地板颜色 foreach (int index in ListAllIndex) { map.SetBlockColor(index, true, Color.white); } #endregion } public void CopyData(MSG_LB_Building data) { Coordinate = new Vector2Int((int)data.Nz, (int)data.Nx); listActorId.Clear(); for (int i = 0; i < data.Actors.Count; ++i) { listActorId.Add(data.Actors[i]); } if (data.Actors.Count <= 0) CurCamp = BattlefieldActorCamp.BacNone; else CurCamp = LegionBattleManager.Instance.GetCampByActorId(data.Actors[0]); } public void CopyData(BattlefieldActorCamp camp, int defCount, int total) { CurCamp = camp; DefenceCount = defCount; AttackedTotal = total; } } }