81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年10月21日 星期二 17:10:56
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Name("目标格子周围有英雄且血量判断")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamIsTargetGridHasHeroAndHealth : BaseActionTask
|
|
{
|
|
public bool GreaterThan = true;
|
|
public float Ratio = 0.5f;
|
|
|
|
protected override string desc
|
|
{
|
|
get
|
|
{
|
|
if (GreaterThan) return string.Format($"目标格子周围有英雄且血量大于等于 {(int)(Ratio * 100)}");
|
|
return string.Format($"目标格子周围有英雄且血量小于等于 {(int)(Ratio * 100)}");
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var selfUnit = data.value.TargetParam.UnitData;
|
|
var selfPlayer = selfUnit.Player(data.value.TargetParam.MapData);
|
|
for (int i = data.value.AIActions.Count - 1; i >= 0; i--)
|
|
{
|
|
var targetGrid = data.value.AIActions[i].Param.GridData;
|
|
if (targetGrid == null)
|
|
{
|
|
data.value.AIActions.RemoveAt(i);
|
|
continue;
|
|
}
|
|
var map = data.value.AIActions[i].Param.MapData;
|
|
var arounds = map.GridMap.GetAroundGridData(1, 1, targetGrid);
|
|
var match = false;
|
|
foreach (var around in arounds)
|
|
{
|
|
var unit = around.Unit(map);
|
|
var unitPlayer = unit?.Player(map);
|
|
if (unit != null && selfUnit != unit)
|
|
{
|
|
if (unit.UnitFullType.UnitType == UnitType.Giant)
|
|
{
|
|
if (GreaterThan && unit.GetHealthRatio() >= Ratio) match = true;
|
|
if (!GreaterThan && unit.GetHealthRatio() <= Ratio) match = true;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
if (match) continue;
|
|
data.value.AIActions.RemoveAt(i);
|
|
}
|
|
|
|
EndAction(data.value.AIActions.Count > 0);
|
|
}
|
|
}
|
|
} |