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

36 lines
1.3 KiB
C#
Raw Normal View History

2025-03-21 15:22:32 +08:00
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;
2025-03-25 13:16:08 +08:00
var allFriend = GameUnitManager.instance.SearchFriends(owner);
2025-03-21 15:22:32 +08:00
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;
}
}