using cfg.CampCfg;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.Common;
using PhxhSDK;
using System.Collections;
using System.Collections.Generic;
using TGS;
using UnityEngine;
namespace Gameplay.Camp
{
public sealed partial class Camp
{
///
/// 营地单位集合
///
private HashSet setUnit;
private void InitUnit()
{
setUnit = new HashSet();
}
private void ExitUnit()
{
foreach (CampUnitBase unit in setUnit)
{
unit.Dispose();
}
setUnit.Clear();
}
///
/// 检查能否放置
///
///
public bool CheckPlace(int cellIndex, params Vector2[] offsets)
{
if (!TryGetCellByIndex(cellIndex, out Cell centerCell))
return false;
foreach (Vector2 offset in offsets)
{
Vector2Int cellPos = new(centerCell.row + (int)offset.x, centerCell.column + (int)offset.y); // 计算格子位置
if (!dicCellByRowCol.TryGetValue(cellPos, out Cell cell))
return false;
if (!TryGetCellStateByIndex(cell.index, out E_CampCellState cellState))
return false;
if (E_CampCellState.Empty != cellState)
return false;
}
return true;
}
///
/// 放置营地物件
///
///
///
public void PlaceCampItem(BuildingCampUnit unit)
{
#region 设置营地地板状态
if (!dicCellByIndex.TryGetValue(unit.CellIndex, out Cell centerCell))
return;
foreach (Vector2 offset in unit.Cfg.ListPosOffset)
{
Vector2Int gridPos = new(centerCell.row + (int)offset.x, centerCell.column + (int)offset.y); // 计算格子位置
if (!dicCellByRowCol.TryGetValue(gridPos, out Cell cell))
continue;
if (dicCellStateByIndex.ContainsKey(cell.index))
dicCellStateByIndex[cell.index] = E_CampCellState.Occupancy;
}
#endregion
Vector3 pos = GridSystem.CellGetPosition(centerCell.index);
unit.SetPos(new Vector3(pos.x, 0f, pos.z)); // 设置建筑物位置
setUnit.Add(unit);
}
}
}