NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/LegionBattle/Data/LegionBuildingData.cs

273 lines
9.5 KiB
C#
Raw Normal View History

2025-02-19 19:32:35 +08:00
using cfg.LegionBattleCfg;
using Framework;
2025-02-25 13:23:42 +08:00
using Google.Protobuf.Collections;
2025-02-08 16:47:10 +08:00
using NLDPB;
using System.Collections.Generic;
using UnityEngine;
namespace Gameplay.LegionBattle
{
/// <summary>
/// 军团战建筑数据
/// </summary>
2025-02-19 17:50:08 +08:00
public sealed class LegionBuildingData
2025-02-08 16:47:10 +08:00
{
/// <summary>
/// 建筑索引
/// </summary>
public int Index { get; private set; }
2025-02-08 16:47:10 +08:00
/// <summary>
/// 建筑坐标
/// </summary>
public Vector2Int Coordinate { get; private set; }
/// <summary>
/// 建筑内的玩家
/// </summary>
2025-02-21 14:43:27 +08:00
public List<uint> listActorId { get; private set; }
2025-02-08 18:50:07 +08:00
/// <summary>
/// 当前阵营
/// </summary>
public BattlefieldActorCamp CurCamp { get; private set; }
/// <summary>
/// 防守成功次数
/// </summary>
public int DefenceCount { get; private set; }
/// <summary>
/// 被攻占次数
/// </summary>
public int AttackedTotal { get; private set; }
2025-02-19 19:32:35 +08:00
/// <summary>
/// 据点配置
/// </summary>
public DataLegionBattleBuilding Cfg { get; private set; }
2025-02-20 16:18:38 +08:00
/// <summary>
/// 所占所有格子坐标
/// </summary>
2025-02-25 13:23:42 +08:00
public HashSet<int> SetAllIndex { get; private set; }
2025-02-24 19:46:57 +08:00
/// <summary>
/// 格子外一圈的坐标
2025-02-25 13:23:42 +08:00
/// </summary>
public List<Vector2Int> ListOutSide { get; private set; }
2025-03-18 18:52:45 +08:00
/// <summary>
2025-03-20 14:52:49 +08:00
/// 是否集结中
/// </summary>
2025-03-24 16:02:01 +08:00
public bool IsAssemble;
/// <summary>
/// 战斗id
/// </summary>
public uint FightId;
2025-03-20 14:52:49 +08:00
/// <summary>
2025-03-18 18:52:45 +08:00
/// 建筑名
/// </summary>
public string Name { get { return CommonUtils.GetLocalizeText(Cfg.NameKey); } }
2025-02-08 16:47:10 +08:00
2025-02-20 16:18:38 +08:00
public LegionBuildingData(LegionLevelData.Building building, int width, int height, Map map)
2025-02-08 16:47:10 +08:00
{
Index = building.position;
2025-03-04 14:29:51 +08:00
Coordinate = map.TGSCellIndex2BlockPosition(Index);
2025-02-21 14:43:27 +08:00
listActorId = new List<uint>();
2025-02-25 13:23:42 +08:00
SetAllIndex = new HashSet<int>();
2025-02-24 19:46:57 +08:00
ListOutSide = new List<Vector2Int>();
2025-02-20 16:18:38 +08:00
Cfg = TableManager.Instance.Tables.LegionBattleBuilding.Get(building.buildingID);
#region 处理计算建筑所占地格
Dictionary<Vector2Int, bool> dicPos = new() // 记录建筑所占地格
2025-02-20 16:18:38 +08:00
{
{ map.TGSCellIndex2BlockPosition(Index), false }
2025-02-20 16:18:38 +08:00
};
HashSet<Vector2Int> setNew = new();
List<Vector2Int> listOld = new();
#region TODO 临时处理, 建筑自身所占格子
2025-02-20 16:18:38 +08:00
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);
2025-02-20 14:47:44 +08:00
2025-02-20 16:18:38 +08:00
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;
2025-02-25 13:23:42 +08:00
SetAllIndex.Add(map.BlockPosition2TGSCellIndex(pos));
2025-02-20 16:18:38 +08:00
}
#endregion
2025-02-24 19:46:57 +08:00
#region 记录外一圈
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);
}
}
foreach (Vector2Int pos in setNew)
{
ListOutSide.Add(pos);
}
#endregion
2025-02-20 16:18:38 +08:00
#endregion
2025-02-08 16:47:10 +08:00
}
2025-02-19 17:50:08 +08:00
public void CopyData(MSG_LB_Building data)
2025-02-08 16:47:10 +08:00
{
2025-02-19 17:50:08 +08:00
Coordinate = new Vector2Int((int)data.Nz, (int)data.Nx);
2025-02-08 16:47:10 +08:00
listActorId.Clear();
2025-02-25 13:23:42 +08:00
listActorId.AddRange(data.Actors);
2025-02-21 14:43:27 +08:00
2025-02-24 19:46:57 +08:00
if (listActorId.Count <= 0)
2025-02-21 14:43:27 +08:00
CurCamp = BattlefieldActorCamp.BacNone;
else
2025-02-24 19:46:57 +08:00
CurCamp = LegionBattleManager.Instance.GetCampByActorId(listActorId[0]);
2025-02-08 18:50:07 +08:00
}
2025-02-25 13:23:42 +08:00
public void CopyData(BattlefieldActorCamp camp, int defCount, int total, RepeatedField<uint> actorIds)
2025-02-08 18:50:07 +08:00
{
CurCamp = camp;
DefenceCount = defCount;
AttackedTotal = total;
2025-02-25 13:23:42 +08:00
listActorId.Clear();
listActorId.AddRange(actorIds);
if (listActorId.Count <= 0)
CurCamp = BattlefieldActorCamp.BacNone;
else
CurCamp = LegionBattleManager.Instance.GetCampByActorId(listActorId[0]);
2025-02-08 16:47:10 +08:00
}
}
2025-02-08 18:50:07 +08:00
}