59 lines
1.7 KiB
C#
59 lines
1.7 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 AIParamChooseMaxAttacker : BaseActionTask
|
|
{
|
|
public bool IsMax;
|
|
|
|
|
|
protected override string desc
|
|
{
|
|
get
|
|
{
|
|
if (IsMax) return string.Format($"选取攻击力最高的目标单位");
|
|
return string.Format($"选取攻击力最低的目标单位");
|
|
}
|
|
}
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
AIActionBase action = null;
|
|
for (int i = data.value.AIActions.Count - 1; i >= 0; i--)
|
|
{
|
|
var map = data.value.AIActions[i].Param.MapData;
|
|
var targetUnit = data.value.AIActions[i].Param.TargetUnitData;
|
|
if (action != null && targetUnit.GetAllAttackValue(map) >= action.Param.TargetUnitData.GetAllAttackValue(map)) continue;
|
|
action = data.value.AIActions[i];
|
|
}
|
|
|
|
data.value.AIActions.Clear();
|
|
if (action != null) data.value.AIActions.Add(action);
|
|
EndAction(data.value.AIActions.Count > 0);
|
|
}
|
|
}
|
|
} |