65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年10月21日 星期二 17:10:56
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using RuntimeData;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Name("目标格子周围有敌军")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamIsTargetGridHasAttacker : BaseActionTask
|
|
{
|
|
private static List<GridData> _aroundBuf;
|
|
protected override string desc => "目标格子周围有敌军";
|
|
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.AIActions == 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;
|
|
if (!selfUnit.Player(map, out var selfPlayer)) continue;
|
|
var targetGrid = data.value.AIActions[i].Param.GridData;
|
|
_aroundBuf ??= new List<GridData>();
|
|
_aroundBuf.Clear();
|
|
map.GridMap.GetAroundGridData(1, 1, targetGrid, _aroundBuf);
|
|
var hasAttacker = false;
|
|
foreach (var around in _aroundBuf)
|
|
{
|
|
if (around == targetGrid) continue;
|
|
around.VisibleUnit(map,selfPlayer,out var unit);
|
|
if (selfUnit == null || unit == null) continue;
|
|
if (map.IsLeagueUnitByUnit(unit.Id, selfUnit.Id)) continue;
|
|
hasAttacker = true;
|
|
}
|
|
|
|
if (hasAttacker) continue;
|
|
data.value.AIActions.RemoveAt(i);
|
|
}
|
|
|
|
EndAction(data.value.AIActions.Count > 0);
|
|
}
|
|
}
|
|
} |