69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年06月06日 星期五 19:06:16
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using RuntimeData;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Name("目标附近存在不满血的拥有Skill的友方单位")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamAroundTargetSkillUnit : BaseActionTask
|
|
{
|
|
public SkillType TargetSkill;
|
|
private static List<GridData> _aroundBuf;
|
|
|
|
|
|
protected override string desc => $"目标点附近存在不满血的拥有 {TargetSkill} 的友方单位";
|
|
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam.UnitData == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
for (int i = data.value.AIActions.Count - 1; i >= 0; i--)
|
|
{
|
|
var map = data.value.AIActions[i].Param.MapData;
|
|
var selfUnit = data.value.AIActions[i].Param.UnitData;
|
|
var targetGrid = data.value.AIActions[i].Param.GridData;
|
|
_aroundBuf ??= new List<GridData>();
|
|
_aroundBuf.Clear();
|
|
map.GridMap.GetAroundGridData(1, 1, targetGrid, _aroundBuf);
|
|
var hasTarget = false;
|
|
foreach (var around in _aroundBuf)
|
|
{
|
|
if (around == targetGrid) continue;
|
|
around.RealUnit(map, out var unit);
|
|
if (selfUnit == null || unit == null) continue;
|
|
if (!map.IsLeagueUnitByUnit(unit.Id, selfUnit.Id)) continue;
|
|
if (!unit.GetSkill(TargetSkill, out _)) continue;
|
|
if (unit.GetHealthRatio() >= 1) continue;
|
|
hasTarget = true;
|
|
}
|
|
|
|
if (hasTarget) continue;
|
|
data.value.AIActions.RemoveAt(i);
|
|
}
|
|
|
|
EndAction(data.value.AIActions.Count > 0);
|
|
}
|
|
}
|
|
} |