NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/AI/Utils/AIGroupHelper.cs

36 lines
1.3 KiB
C#

using System.Collections.Generic;
using Framework;
using Gameplay.AI;
using Gameplay.Unit;
public static class AIGroupHelper
{
public static uint GetGroupUnit(GameUnit owner)
{
var groups = owner.unitLevelData.GroupInfos;
var allFriend = GameUnitManager.instance.SearchFriends(owner);
var fitFriends = new Dictionary<GameUnit, int>();
foreach (var friend in allFriend)
{
foreach (var groupID in groups)
{
if (friend.unitLevelData != null && friend.unitLevelData.GroupInfos.Contains(groupID))
{
if (friend.unitLevelData.AIBattleInfo != null && friend.unitLevelData.AIBattleInfo.Value.targetID !=
Constants.INVALID_UINT_ID)
{
var ownerIndex = owner.transData.cellIndex;
var friendIndex = friend.transData.cellIndex;
fitFriends.Add(friend,
AIUtils.GetDistance(ownerIndex, friendIndex));
}
}
}
}
var friendNearest = AIUtils.GetNearestUnit(fitFriends);
return friendNearest == null
? Constants.INVALID_UINT_ID
: friendNearest.unitLevelData.AIBattleInfo.Value.targetID;
}
}