695 lines
24 KiB
C#
695 lines
24 KiB
C#
using cfg.AreaCfg;
|
|
using Framework;
|
|
using Gameplay.Level;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Gameplay.Area.Around;
|
|
using Gameplay.Area.AttackArea;
|
|
using Gameplay.Area.Ready;
|
|
using Gameplay.Common;
|
|
using Gameplay.Skill;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.Area
|
|
{
|
|
using Skill;
|
|
|
|
public class AreaManager
|
|
{
|
|
|
|
public static bool ENABLE_LOG = false;
|
|
|
|
private static AreaManager _instance;
|
|
public static AreaManager instance
|
|
{
|
|
get
|
|
{
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public static void CreateInstance()
|
|
{
|
|
if (_instance != null)
|
|
{
|
|
DebugUtil.LogError("请勿重复创建AreaManager");
|
|
return;
|
|
}
|
|
_instance = new AreaManager();
|
|
}
|
|
|
|
private readonly Dictionary<int, List<Vector2Int>> _areaDict;
|
|
// public readonly SkillAreaSelector skillAreaSelector;
|
|
public readonly SkillAreaSelector2 skillAreaSelector2;
|
|
public readonly PlayerSkillAreaSelector playerSkillAreaSelector;
|
|
|
|
private readonly Dictionary<int, List<GameUnit>> _cellIndex2Units;
|
|
|
|
private Map _map;
|
|
|
|
public readonly AttackAreaView attackArea;
|
|
|
|
public readonly ReadyAreaManager readyAreaManager;
|
|
|
|
public readonly AttackAreaManager attackAreaManager;
|
|
|
|
public readonly MoveAreaView moveAreaView;
|
|
|
|
// public SkillAreaSelecter skillAreaSelecter => _skillAreaSelecter;
|
|
|
|
private Dictionary<int, AroundCellData> _aroundCellDatas = new Dictionary<int, AroundCellData>();
|
|
|
|
public bool isInSkillPreview
|
|
{
|
|
get
|
|
{
|
|
return skillAreaSelector2.isInPreview || playerSkillAreaSelector.isInPreview;
|
|
}
|
|
}
|
|
|
|
public ParentGroup parentGroup = new ParentGroup();
|
|
|
|
private AreaManager()
|
|
{
|
|
_areaDict = new Dictionary<int, List<Vector2Int>>();
|
|
// skillAreaSelector = new SkillAreaSelector();
|
|
skillAreaSelector2 = new SkillAreaSelector2();
|
|
playerSkillAreaSelector = new PlayerSkillAreaSelector();
|
|
_cellIndex2Units = new Dictionary<int, List<GameUnit>>();
|
|
attackArea = new AttackAreaView();
|
|
|
|
_map = LevelManager.Instance.CurrentLevel.Map;
|
|
|
|
readyAreaManager = new ReadyAreaManager(_map);
|
|
attackAreaManager = new AttackAreaManager();
|
|
|
|
moveAreaView = new MoveAreaView();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
_InitMathV3();
|
|
parentGroup.Init();
|
|
moveAreaView.Init();
|
|
// skillAreaSelector.Init();
|
|
attackArea.Init();
|
|
readyAreaManager.Init();
|
|
attackAreaManager.Init();
|
|
_RegistEvents();
|
|
}
|
|
|
|
private void _InitMathV3()
|
|
{
|
|
var cellList = LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem.cells;
|
|
for (int i = 0; i < cellList.Count; i++)
|
|
{
|
|
var cell = cellList[i];
|
|
var mathPos = AroundHelper.GetMathPosV3(cell.index);
|
|
cell.mathPointV3 = mathPos;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// skillAreaSelector.Dispose();
|
|
readyAreaManager.Dispose();
|
|
attackAreaManager.Dispose();
|
|
moveAreaView.Dispose();
|
|
playerSkillAreaSelector.Dispose();
|
|
parentGroup.Dispose();
|
|
_aroundCellDatas.Clear();
|
|
_UnRegistEvents();
|
|
_instance = null;
|
|
}
|
|
|
|
private void _RegistEvents()
|
|
{
|
|
// EventManager.Instance.Register(EventManager.EventName.UI_START_USE_SKILL, (Action<GameUnit>)_OnPreUseSkill);
|
|
// EventManager.Instance.Register(EventManager.EventName.UI_END_USE_SKILL, (Action<bool>)_OnEndUseSkill);
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_READY, (Action<GameUnit>)_OnUnitReady);
|
|
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_REMOVE, (Action<GameUnit>)_OnUnitRemove);
|
|
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, (Action<GameUnit>)_OnUnitCellChange);
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.LevelUnitSelect, (Action<GameUnit>)_OnSelectCharacter);
|
|
EventManager.Instance.Register(EventManager.EventName.LevelUnitUnSelect, (Action<GameUnit>)_OnUnSelectCharacter);
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UP_VEHICLE, (Action<GameUnit>)_OnUpVehicle);
|
|
EventManager.Instance.Register(EventManager.EventName.INFIGHT_DOWN_VEHICLE, (Action<EDDownVehicle>)_OnDownVehicle);
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.INFIGHT_SKILL_END_PAUSE, _OnSkillPauseEnd);
|
|
}
|
|
|
|
private void _UnRegistEvents()
|
|
{
|
|
// EventManager.Instance.Unregister(EventManager.EventName.UI_START_USE_SKILL, (Action<GameUnit>)_OnPreUseSkill);
|
|
// EventManager.Instance.Unregister(EventManager.EventName.UI_END_USE_SKILL, (Action<bool>)_OnEndUseSkill);
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_READY, (Action<GameUnit>)_OnUnitReady);
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_REMOVE, (Action<GameUnit>)_OnUnitRemove);
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, (Action<GameUnit>)_OnUnitCellChange);
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.LevelUnitSelect, (Action<GameUnit>)_OnSelectCharacter);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LevelUnitUnSelect, (Action<GameUnit>)_OnUnSelectCharacter);
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UP_VEHICLE, (Action<GameUnit>)_OnUpVehicle);
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_DOWN_VEHICLE, (Action<EDDownVehicle>)_OnDownVehicle);
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_SKILL_END_PAUSE, _OnSkillPauseEnd);
|
|
}
|
|
|
|
private void _OnUpVehicle(GameUnit unit)
|
|
{
|
|
var cellIndex = unit.transData.cellIndex;
|
|
|
|
// 设置地图通行状态
|
|
// _map.GetRuntimeBlockProperty(cellIndex, out var oldData);
|
|
// var blockData = _map.GetBlockData(cellIndex);
|
|
// oldData.crossLevel = blockData.GetTerrainTypeProperty().crossLevel;
|
|
// _map.SetRuntimeBlockProperty(cellIndex, oldData);
|
|
|
|
// 移除角色
|
|
var unitList = _cellIndex2Units[cellIndex];
|
|
unitList.Remove(unit);
|
|
_Log($"Unit: {unit.GetID()} Up Vehicle at:{cellIndex}");
|
|
}
|
|
|
|
private void _OnDownVehicle(EDDownVehicle ed)
|
|
{
|
|
var unit = ed.unit;
|
|
var bornCellIndex = unit.transData.cellIndex;
|
|
_Log($"Unit: {unit.GetID()} Down Vehicle at:{bornCellIndex}");
|
|
|
|
var getUnits = GetUnitsByCellIndex(bornCellIndex);
|
|
if (getUnits.Contains(unit))
|
|
{
|
|
// 重复添加
|
|
return;
|
|
}
|
|
|
|
_AddUnitToCellIndex(bornCellIndex, unit);
|
|
}
|
|
|
|
private void _OnSelectCharacter(GameUnit c)
|
|
{
|
|
if (!LevelManager.Instance.CurrentLevel.IsInBattle())
|
|
{
|
|
return;
|
|
}
|
|
|
|
attackArea.SetOwner(c);
|
|
moveAreaView.Show(c);
|
|
}
|
|
|
|
private void _OnUnSelectCharacter(GameUnit c)
|
|
{
|
|
if (!LevelManager.Instance.CurrentLevel.IsInBattle())
|
|
{
|
|
return;
|
|
}
|
|
|
|
attackArea.HideArea();
|
|
moveAreaView.Hide();
|
|
}
|
|
|
|
private void _OnUnitReady(GameUnit unit)
|
|
{
|
|
var bornCellIndex = unit.transData.cellIndex;
|
|
_Log($"Unit: {unit.GetID()} Ready at: {bornCellIndex}");
|
|
|
|
var getUnits = GetUnitsByCellIndex(bornCellIndex);
|
|
if (getUnits.Contains(unit))
|
|
{
|
|
// 重复添加
|
|
return;
|
|
}
|
|
|
|
_AddUnitToCellIndex(bornCellIndex, unit);
|
|
}
|
|
|
|
private void _AddUnitToCellIndex(int cellIndex,
|
|
GameUnit unit)
|
|
{
|
|
// 设置地图通行状态
|
|
// >0 才进行设置
|
|
// if (unit.commonData.standLevel > 0)
|
|
// {
|
|
// _map.GetRuntimeBlockProperty(cellIndex, out var setData);
|
|
// setData.crossLevel = unit.commonData.standLevel;
|
|
// _map.SetRuntimeBlockProperty(cellIndex, setData);
|
|
// }
|
|
|
|
|
|
if (_cellIndex2Units.TryGetValue(cellIndex, out var unitList))
|
|
{
|
|
unitList.Add(unit);
|
|
}
|
|
else
|
|
{
|
|
unitList = new List<GameUnit>();
|
|
unitList.Add(unit);
|
|
_cellIndex2Units.Add(cellIndex, unitList);
|
|
}
|
|
if (CodeDefine.ENABLE_FIGHT_NORMAL_ATTACK_LOG)
|
|
{
|
|
_Log($"add unit:{unit.GetID()} to cellIndex:{cellIndex}");
|
|
}
|
|
}
|
|
|
|
private void _OnUnitRemove(GameUnit unit)
|
|
{
|
|
var cellIndex = unit.transData.cellIndex;
|
|
if (CodeDefine.ENABLE_FIGHT_NORMAL_ATTACK_LOG)
|
|
_Log($"Unit: {unit.GetID()} Remove at: {cellIndex}");
|
|
|
|
// 这里必须能去到,所以不用tryget, 如果报错 需要排查上游
|
|
// if (unit.commonData.standLevel > 0)
|
|
// {
|
|
// // 设置地图通行状态
|
|
// _map.GetRuntimeBlockProperty(cellIndex, out var oldData);
|
|
// var blockData = _map.GetBlockData(cellIndex);
|
|
// oldData.crossLevel = blockData.GetTerrainTypeProperty().crossLevel;
|
|
// _map.SetRuntimeBlockProperty(cellIndex, oldData);
|
|
// }
|
|
|
|
if (_cellIndex2Units.TryGetValue(cellIndex, out var unitList))
|
|
{
|
|
unitList.Remove(unit);
|
|
}
|
|
|
|
}
|
|
|
|
private void _OnUnitCellChange(GameUnit unit)
|
|
{
|
|
var lastCellIndex = unit.transData.lastCellIndex;
|
|
var newCellIndex = unit.transData.cellIndex;
|
|
|
|
if (lastCellIndex != -1)
|
|
{
|
|
// 移除旧的
|
|
if (_cellIndex2Units.TryGetValue(lastCellIndex, out var unitList))
|
|
{
|
|
unitList.Remove(unit);
|
|
}
|
|
}
|
|
// 添加新的
|
|
_AddUnitToCellIndex(newCellIndex, unit);
|
|
if (CodeDefine.ENABLE_FIGHT_NORMAL_ATTACK_LOG)
|
|
_Log($"Unit CellIndexChange:{unit.GetID()} from:{lastCellIndex} to {newCellIndex}");
|
|
}
|
|
|
|
private static void _Log(string str)
|
|
{
|
|
if (!ENABLE_LOG) return;
|
|
DebugUtil.Log("[AreaManager] {0}", str);
|
|
}
|
|
|
|
|
|
public DataArea GetConfigById(int areaId)
|
|
{
|
|
return TableManager.Instance.Tables.AreaConfig.Get(areaId);
|
|
}
|
|
|
|
private List<int> _emptyList = new List<int>();
|
|
public List<int> GetCellIndexsAround(int centerCellIndex,
|
|
int distance, bool containsCenter = true)
|
|
{
|
|
var key = AroundCellData.GetKey(centerCellIndex, distance, containsCenter);
|
|
if (_aroundCellDatas.TryGetValue(key, out var data))
|
|
{
|
|
return data.aroundCellIndexs;
|
|
}
|
|
|
|
var list = _GetCellIndexAround(centerCellIndex, distance, containsCenter);
|
|
var aroundData = new AroundCellData(centerCellIndex, distance, containsCenter);
|
|
aroundData.aroundCellIndexs = list;
|
|
_aroundCellDatas.Add(key, aroundData);
|
|
return list;
|
|
}
|
|
|
|
private List<int> _GetCellIndexAround(int centerCellIndex,
|
|
int distance, bool containsCenter = true)
|
|
{
|
|
if (distance <= 0)
|
|
{
|
|
if (containsCenter)
|
|
{
|
|
return new List<int>()
|
|
{
|
|
centerCellIndex
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return _emptyList;
|
|
}
|
|
}
|
|
var list = new List<int>();
|
|
if (containsCenter)
|
|
{
|
|
list.Insert(0, centerCellIndex);
|
|
}
|
|
AroundHelper.GetAround(centerCellIndex, distance, list);
|
|
return list;
|
|
}
|
|
|
|
public bool IsCellEmpty(int cellIndex)
|
|
{
|
|
var unitList = GetUnitsByCellIndex(cellIndex);
|
|
return unitList.Count == 0;
|
|
}
|
|
|
|
public int GetDistance(int cellIndex1,
|
|
int cellIndex2)
|
|
{
|
|
// 实测TGS的方法性能更好 0.66 vs 0.8
|
|
// var mathPoint1 = AroundHelper.GetMathPosV3FromTable(cellIndex1);
|
|
// var mathPoint2 = AroundHelper.GetMathPosV3FromTable(cellIndex2);
|
|
// var offsetX = Mathf.Abs(mathPoint1.x - mathPoint2.x);
|
|
// var offsetY = Mathf.Abs(mathPoint1.y - mathPoint2.y);
|
|
// var offsetZ = Mathf.Abs(mathPoint1.z - mathPoint2.z);
|
|
// return Mathf.Max(offsetX, Mathf.Max(offsetY, offsetZ));
|
|
return _map.TerrainGridSystem.CellGetHexagonDistance(cellIndex1, cellIndex2);
|
|
}
|
|
|
|
public Vector3 GetWorldPosByIndex(int cellIndex)
|
|
{
|
|
var getPos = _map.TerrainGridSystem.CellGetPosition(cellIndex);
|
|
return getPos;
|
|
}
|
|
|
|
public int GetCellIndexByPos(Vector3 pos)
|
|
{
|
|
if (_map.WorldPosition2TGSCellIndex(pos, out var result))
|
|
{
|
|
return result;
|
|
}
|
|
DebugUtil.LogError("无法获取到CellIndex:" + pos);
|
|
return -1;
|
|
}
|
|
|
|
public bool CheckIsNeighbour(int fromIndex,
|
|
int checkIndex)
|
|
{
|
|
var aroundList = _map.TerrainGridSystem.CellGetNeighbours(fromIndex);
|
|
for (var i = 0; i < aroundList.Count; i++)
|
|
{
|
|
var around = aroundList[i];
|
|
if (around.index == checkIndex)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public List<int> GetCellIndexs(int centerCellIndex,
|
|
int areaId)
|
|
{
|
|
var list = new List<int>();
|
|
GetCellIndexs(centerCellIndex, areaId, list);
|
|
return list;
|
|
}
|
|
|
|
public void GetCellIndexs(int centerCellIndex,
|
|
int areaId,
|
|
List<int> list)
|
|
{
|
|
var map = LevelManager.Instance.CurrentLevel.Map;
|
|
var posVec = map.TGSCellIndex2BlockPosition(centerCellIndex);
|
|
var offsetList = _GetOffsetList(areaId);
|
|
for (var i = 0; i < offsetList.Count; ++i)
|
|
{
|
|
var offset = offsetList[i];
|
|
var calcPos = posVec + offset;
|
|
if (posVec.x % 2 == 1 && calcPos.x % 2 == 0)
|
|
{
|
|
calcPos.y += 1;
|
|
}
|
|
var cellIndex = map.BlockPosition2TGSCellIndex(calcPos);
|
|
if (cellIndex == -1)
|
|
{
|
|
continue;
|
|
}
|
|
var getSuccess = map.GetRuntimeBlockProperty(cellIndex, out var blockData);
|
|
if (!getSuccess)
|
|
{
|
|
continue;
|
|
}
|
|
if (blockData.selectable == false)
|
|
{
|
|
continue;
|
|
}
|
|
list.Add(cellIndex);
|
|
}
|
|
}
|
|
|
|
private List<Vector2Int> _GetOffsetList(int areaId)
|
|
{
|
|
if (_areaDict.TryGetValue(areaId, out var offsetList))
|
|
{
|
|
return offsetList;
|
|
}
|
|
else
|
|
{
|
|
// 不存在,现场进行加载
|
|
var areaData = GetConfigById(areaId);
|
|
if (areaData == null)
|
|
{
|
|
DebugUtil.LogError("AreaId:{0}不存在", areaId);
|
|
return null;
|
|
}
|
|
offsetList = new List<Vector2Int>();
|
|
var intList = areaData.Points;
|
|
for (int i = 0; i < intList.Count; i += 2)
|
|
{
|
|
offsetList.Add(new Vector2Int(intList[i], intList[i + 1]));
|
|
}
|
|
_areaDict.Add(areaId, offsetList);
|
|
return offsetList;
|
|
}
|
|
}
|
|
|
|
// private void _OnPreUseSkill(GameUnit unit)
|
|
// {
|
|
// var skillUnit = SkillManager.instance.GetUnitSkillManager(unit);
|
|
// if (skillUnit == null)
|
|
// {
|
|
// DebugUtil.LogError("Unit:{0} 未挂载UnitSkillManager", unit.GetID());
|
|
// return;
|
|
// }
|
|
// if (skillUnit.positiveSkill == null)
|
|
// {
|
|
// DebugUtil.LogError("Unit:{0} 未挂载PositiveSkill", unit.GetID());
|
|
// return;
|
|
// }
|
|
//
|
|
// _attackArea.ForceHide();
|
|
// skillAreaSelector.ShowArea(skillUnit.positiveSkill);
|
|
// }
|
|
|
|
// private void _OnEndUseSkill(bool isCancel)
|
|
// {
|
|
// if (DebugUtil.LogEnable)
|
|
// DebugUtil.Log("UI事件: 结束技能预选: 是否cancel:{0}", isCancel);
|
|
// var isUse = skillAreaSelector.EndShow(!isCancel);
|
|
//
|
|
// if (isUse)
|
|
// {
|
|
// // 使用技能的话 要等技能结束才显示攻击范围
|
|
// }
|
|
// else
|
|
// {
|
|
// _attackArea.CancelForce();
|
|
// }
|
|
// }
|
|
|
|
private void _OnSkillPauseEnd()
|
|
{
|
|
if (attackArea == null)
|
|
{
|
|
DebugUtil.LogError("AttackArea为空");
|
|
return;
|
|
}
|
|
attackArea.CancelForce();
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
// skillAreaSelector.LogicUpdate(dt);
|
|
attackArea.LogicUpdate(dt);
|
|
readyAreaManager.LogicUpdate(dt);
|
|
attackAreaManager.LogicUpdate(dt);
|
|
moveAreaView.LogicUpdate();
|
|
}
|
|
|
|
public int SearchNearCanClaimCellIndexWithAttack(GameUnit searchUnit, int maxDistance = 2)
|
|
{
|
|
if (searchUnit.controlData.targetEnemy == null)
|
|
{
|
|
return SearchNearCanClaimCellIndex(searchUnit, maxDistance);
|
|
}
|
|
var cellIndex = searchUnit.transData.cellIndex;
|
|
if (!CheckContainsMoveUnit(cellIndex))
|
|
{
|
|
return cellIndex;
|
|
}
|
|
var enemy = searchUnit.controlData.targetEnemy;
|
|
var enemyCellIndex = enemy.transData.cellIndex;
|
|
for (int i = 1; i <= maxDistance; i++)
|
|
{
|
|
var minSteps = i - 1;
|
|
var maxSteps = i;
|
|
var list = _map.TerrainGridSystem.CellGetNeighboursWithinRange(cellIndex, minSteps, maxSteps,
|
|
canCrossCheckType: TGS.CanCrossCheckType.IgnoreCanCrossCheckOnAllCells);
|
|
for (int j = 0; j < list.Count; j++)
|
|
{
|
|
// 先判断是否可到达
|
|
var checkIndex = list[j];
|
|
if (!CheckMapCellAvailable(checkIndex))
|
|
{
|
|
continue;
|
|
}
|
|
if (!PathFinder.CanBasePass(cellIndex, searchUnit))
|
|
{
|
|
continue;
|
|
}
|
|
if (!CheckContainsMoveUnit(checkIndex))
|
|
{
|
|
// 在判断该位置是否可攻击
|
|
var searchArea = attackAreaManager.GetAttackArea(checkIndex, searchUnit.fightData.attackDistance);
|
|
if (searchArea.canAttackCells.Contains(enemyCellIndex))
|
|
{
|
|
if (maxSteps > 1)
|
|
{
|
|
// 大于1之后需要额外判断一下是否有路径
|
|
var path = PathFinder.FindPath(_map, checkIndex, searchUnit);
|
|
if (path.Count > 0)
|
|
{
|
|
return checkIndex;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return checkIndex;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DebugUtil.LogG("没有找到可用的位置,返回中心位置");
|
|
// 没有找到,返回原来的
|
|
return cellIndex;
|
|
}
|
|
|
|
public int SearchNearCanClaimCellIndex(GameUnit searchUnit, int maxDistance = 2)
|
|
{
|
|
var cellIndex = searchUnit.transData.cellIndex;
|
|
if (!CheckContainsMoveUnit(cellIndex))
|
|
{
|
|
return cellIndex;
|
|
}
|
|
for (int i = 1; i <= maxDistance; i++)
|
|
{
|
|
var minSteps = i - 1;
|
|
var maxSteps = i;
|
|
var list = _map.TerrainGridSystem.CellGetNeighboursWithinRange(cellIndex, minSteps, maxSteps,
|
|
canCrossCheckType: TGS.CanCrossCheckType.IgnoreCanCrossCheckOnAllCells);
|
|
for (int j = 0; j < list.Count; j++)
|
|
{
|
|
var checkIndex = list[j];
|
|
if (!CheckMapCellAvailable(checkIndex))
|
|
{
|
|
continue;
|
|
}
|
|
if (!PathFinder.CanBasePass(cellIndex, searchUnit))
|
|
{
|
|
continue;
|
|
}
|
|
if (CheckContainsMoveUnit(checkIndex))
|
|
{
|
|
continue;
|
|
}
|
|
if (maxSteps > 1)
|
|
{
|
|
// 大于1之后需要额外判断一下是否有路径
|
|
var path = PathFinder.FindPath(_map, checkIndex, searchUnit);
|
|
if (path.Count > 0)
|
|
{
|
|
return cellIndex;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return checkIndex;
|
|
}
|
|
}
|
|
}
|
|
DebugUtil.LogG("没有找到可用的位置,返回中心位置");
|
|
// 没有找到,返回原来的
|
|
return cellIndex;
|
|
}
|
|
|
|
public bool CheckContainsMoveUnit(int cellIndex)
|
|
{
|
|
var allUnits = GameUnitManager.instance.infightUnits.unitList;
|
|
for (int i = 0; i < allUnits.Count; i++)
|
|
{
|
|
var unit = allUnits[i];
|
|
if (unit.statusData.isOnVehicle) continue;
|
|
if (unit.commonData.canClaimStandCellIndex && unit.transData.cellIndex == cellIndex)
|
|
{
|
|
return true;
|
|
}
|
|
if (unit.commonData.canClaimTargetCellIndex && unit.controlData.targetCellIndex == cellIndex)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public List<GameUnit> GetUnitsByCellIndex(int cellIndex)
|
|
{
|
|
if (_cellIndex2Units.TryGetValue(cellIndex, out var result))
|
|
{
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
var newList = new List<GameUnit>();
|
|
_cellIndex2Units.Add(cellIndex, newList);
|
|
return newList;
|
|
}
|
|
}
|
|
|
|
public bool CheckCellCanCross(int targetCellIndex, int crossLevel)
|
|
{
|
|
_map.GetRuntimeBlockProperty(targetCellIndex, out var blockData);
|
|
return blockData.crossLevel >= crossLevel;
|
|
}
|
|
|
|
public bool CheckMapCellAvailable(int cellIndex)
|
|
{
|
|
var mapCellData = LevelManager.Instance.CurrentLevel.Map.GetBlockData(cellIndex);
|
|
if (mapCellData == null)
|
|
{
|
|
return false;
|
|
}
|
|
var propData = mapCellData.GetTerrainTypeProperty();
|
|
if (propData == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (!propData.selectable)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|