using System.Collections.Generic; using Gameplay.Area; using Gameplay.Character; using Gameplay.Unit; using Gameplay.Unit.Data; namespace Gameplay.PlayerSkill.Logic { /// /// 散列移动, /// 以目标点为中心,找到合适的位置,让所有己方单位移动到这些位置 /// public class PlayerSkillLogic11 : BasePlayerSkillLogic { protected override void _OnInit() { base._OnInit(); var searchedList = new List(); var allSelfUnits = GameUnitManager.instance.infightUnits.GetListByTroop(ETroopsId.Self); var allFilterUnits = new List(); for (int i = 0; i < allSelfUnits.Count; i++) { var unit = allSelfUnits[i]; if (unit.gameunitType != EGameUnitType.Character && unit.gameunitType != EGameUnitType.Vehicle) { // 只对角色和载具生效 continue; } if (!unit.commonData.canControl) { // 不能控制的单位不移动 continue; } if (unit.transData.cellIndex == owner.selectedCellIndex) { // 自己不需要移动 searchedList.Add(owner.selectedCellIndex); continue; } allFilterUnits.Add(unit); } // 寻找符合的位置 var availableCellIndexs = new List(); var workList = new List(); var searchUnitIndex = 0; var searchDistance = 1; var aroundCellIndex = AreaManager.instance.GetCellIndexsAround(owner.selectedCellIndex, searchDistance); workList.AddRange(aroundCellIndex); while (availableCellIndexs.Count < allFilterUnits.Count) { var unit = allFilterUnits[searchUnitIndex]; while (workList.Count > 0) { var cellIndex = workList[0]; workList.RemoveAt(0); if (searchedList.Contains(cellIndex)) { continue; } searchedList.Add(cellIndex); // 判断地面是否可通行 var canPass = PathFinder.CanPass(cellIndex, unit); if (!canPass) { continue; } availableCellIndexs.Add(cellIndex); unit.MoveTo(cellIndex, true); searchUnitIndex++; break; } if (workList.Count == 0) { searchDistance++; if (searchDistance >= 5) { // 超出范围 break; } aroundCellIndex = AreaManager.instance.GetCellIndexsAround(owner.selectedCellIndex, searchDistance); workList.AddRange(aroundCellIndex); } } isFinished = true; } } }