273 lines
9.5 KiB
C#
273 lines
9.5 KiB
C#
using cfg.LegionBattleCfg;
|
|
using Framework;
|
|
using Google.Protobuf.Collections;
|
|
using NLDPB;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.LegionBattle
|
|
{
|
|
/// <summary>
|
|
/// 军团战建筑数据
|
|
/// </summary>
|
|
public sealed class LegionBuildingData
|
|
{
|
|
/// <summary>
|
|
/// 建筑索引
|
|
/// </summary>
|
|
public int Index { get; private set; }
|
|
/// <summary>
|
|
/// 建筑坐标
|
|
/// </summary>
|
|
public Vector2Int Coordinate { get; private set; }
|
|
/// <summary>
|
|
/// 建筑内的玩家
|
|
/// </summary>
|
|
public List<uint> listActorId { get; private set; }
|
|
/// <summary>
|
|
/// 当前阵营
|
|
/// </summary>
|
|
public BattlefieldActorCamp CurCamp { get; private set; }
|
|
/// <summary>
|
|
/// 防守成功次数
|
|
/// </summary>
|
|
public int DefenceCount { get; private set; }
|
|
/// <summary>
|
|
/// 被攻占次数
|
|
/// </summary>
|
|
public int AttackedTotal { get; private set; }
|
|
/// <summary>
|
|
/// 据点配置
|
|
/// </summary>
|
|
public DataLegionBattleBuilding Cfg { get; private set; }
|
|
/// <summary>
|
|
/// 所占所有格子坐标
|
|
/// </summary>
|
|
public HashSet<int> SetAllIndex { get; private set; }
|
|
/// <summary>
|
|
/// 格子外一圈的坐标
|
|
/// </summary>
|
|
public List<Vector2Int> ListOutSide { get; private set; }
|
|
/// <summary>
|
|
/// 是否集结中
|
|
/// </summary>
|
|
public bool IsAssemble;
|
|
/// <summary>
|
|
/// 战斗id
|
|
/// </summary>
|
|
public uint FightId;
|
|
/// <summary>
|
|
/// 建筑名
|
|
/// </summary>
|
|
public string Name { get { return CommonUtils.GetLocalizeText(Cfg.NameKey); } }
|
|
|
|
public LegionBuildingData(LegionLevelData.Building building, int width, int height, Map map)
|
|
{
|
|
Index = building.position;
|
|
Coordinate = map.TGSCellIndex2BlockPosition(Index);
|
|
listActorId = new List<uint>();
|
|
SetAllIndex = new HashSet<int>();
|
|
ListOutSide = new List<Vector2Int>();
|
|
|
|
Cfg = TableManager.Instance.Tables.LegionBattleBuilding.Get(building.buildingID);
|
|
|
|
#region 处理计算建筑所占地格
|
|
Dictionary<Vector2Int, bool> dicPos = new() // 记录建筑所占地格
|
|
{
|
|
{ map.TGSCellIndex2BlockPosition(Index), false }
|
|
};
|
|
HashSet<Vector2Int> setNew = new();
|
|
List<Vector2Int> listOld = new();
|
|
|
|
#region TODO 临时处理, 建筑自身所占格子
|
|
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;
|
|
|
|
SetAllIndex.Add(map.BlockPosition2TGSCellIndex(pos));
|
|
}
|
|
#endregion
|
|
|
|
#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
|
|
#endregion
|
|
}
|
|
|
|
public void CopyData(MSG_LB_Building data)
|
|
{
|
|
Coordinate = new Vector2Int((int)data.Nz, (int)data.Nx);
|
|
|
|
listActorId.Clear();
|
|
listActorId.AddRange(data.Actors);
|
|
|
|
if (listActorId.Count <= 0)
|
|
CurCamp = BattlefieldActorCamp.BacNone;
|
|
else
|
|
CurCamp = LegionBattleManager.Instance.GetCampByActorId(listActorId[0]);
|
|
}
|
|
|
|
public void CopyData(BattlefieldActorCamp camp, int defCount, int total, RepeatedField<uint> actorIds)
|
|
{
|
|
CurCamp = camp;
|
|
DefenceCount = defCount;
|
|
AttackedTotal = total;
|
|
|
|
listActorId.Clear();
|
|
listActorId.AddRange(actorIds);
|
|
if (listActorId.Count <= 0)
|
|
CurCamp = BattlefieldActorCamp.BacNone;
|
|
else
|
|
CurCamp = LegionBattleManager.Instance.GetCampByActorId(listActorId[0]);
|
|
}
|
|
}
|
|
} |