73 lines
2.2 KiB
C#
73 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("周围敌军数量")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamAroundOtherUnitCount : BaseActionTask
|
|
{
|
|
public bool GreaterThan = true;
|
|
public float Count = 0;
|
|
private static List<GridData> _aroundBuf;
|
|
|
|
|
|
protected override string desc
|
|
{
|
|
get
|
|
{
|
|
if (GreaterThan) return string.Format($"周围敌军大于等于 {Count}");
|
|
return string.Format($"周围敌军小于等于 {Count}");
|
|
}
|
|
}
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam.UnitData == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var selfUnit = data.value.TargetParam.UnitData;
|
|
var selfGrid = selfUnit.Grid(data.value.TargetParam.MapData);
|
|
var selfPlayer = selfUnit.Player(data.value.TargetParam.MapData);
|
|
if (selfGrid != null && selfPlayer != null)
|
|
{
|
|
var count = 0;
|
|
_aroundBuf ??= new List<GridData>();
|
|
_aroundBuf.Clear();
|
|
data.value.TargetParam.MapData.GridMap.GetAroundGridData(1, 1, selfGrid, _aroundBuf);
|
|
foreach (var around in _aroundBuf)
|
|
{
|
|
around.VisibleUnit(data.value.TargetParam.MapData,selfPlayer,out var unit);
|
|
if (unit == null || unit == selfUnit) continue;
|
|
if (data.value.TargetParam.MapData.IsLeagueUnitByUnit(unit.Id, selfUnit.Id)) continue;
|
|
count++;
|
|
}
|
|
if (GreaterThan) EndAction(count >= Count);
|
|
else EndAction(count <= Count);
|
|
return;
|
|
}
|
|
|
|
EndAction(false);
|
|
}
|
|
}
|
|
} |