58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Level;
|
|
namespace Gameplay.Area.Around
|
|
{
|
|
public static class AroundHelper
|
|
{
|
|
|
|
private static List<int> _cacheWorkList = new List<int>();
|
|
private static List<int> _cacheNextWorkList = new List<int>();
|
|
private static List<int> _cacheVisitList = new List<int>();
|
|
private static List<TGS.Cell> _cacheCellList = new List<TGS.Cell>();
|
|
|
|
public static void GetAround(int centerIndex, int stepCount, List<int> result)
|
|
{
|
|
var workStep = 0;
|
|
_cacheWorkList.Clear();
|
|
_cacheVisitList.Clear();
|
|
_cacheCellList.Clear();
|
|
|
|
_cacheWorkList.Add(centerIndex);
|
|
_cacheVisitList.Add(centerIndex);
|
|
var mapTgs = LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem;
|
|
|
|
while (true)
|
|
{
|
|
_cacheNextWorkList.Clear();
|
|
for (var i = 0; i < _cacheWorkList.Count; ++i)
|
|
{
|
|
var index = _cacheWorkList[i];
|
|
mapTgs.CellGetNeighbours(index, _cacheCellList);
|
|
for (int j = 0; j < _cacheCellList.Count; j++)
|
|
{
|
|
var cell = _cacheCellList[j];
|
|
if (_cacheVisitList.Contains(cell.index))
|
|
{
|
|
continue;
|
|
}
|
|
result.Add(cell.index);
|
|
_cacheNextWorkList.Add(cell.index);
|
|
_cacheVisitList.Add(cell.index);
|
|
}
|
|
}
|
|
|
|
workStep++;
|
|
if (workStep >= stepCount)
|
|
{
|
|
break;
|
|
}
|
|
|
|
_cacheWorkList.Clear();
|
|
_cacheWorkList.AddRange(_cacheNextWorkList);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|