75 lines
2.4 KiB
C#
75 lines
2.4 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("筛选血量小于等于阈值的最低血量目标单位(EirinCommon专用)")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamChooseMinHealthSelfGiant : BaseActionTask
|
|
{
|
|
public float Ratio = 60f;
|
|
public bool IsCondi;
|
|
public float AttackCondi = 60f;
|
|
public float DefendCondi = 60f;
|
|
public float DevelopmentCondi = 60f;
|
|
public float CommonCondi = 60f;
|
|
|
|
|
|
protected override string desc
|
|
{
|
|
get
|
|
{
|
|
var ratio = IsCondi ? "Condi" : Ratio.ToString();
|
|
return string.Format($"选小于等于 {ratio}% 血量的最低血量目标单位");
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var condi = Ratio / 100f;
|
|
if (IsCondi)
|
|
{
|
|
if (data.value.TargetStrategy == Strategy.Attack) condi = AttackCondi / 100f;
|
|
if (data.value.TargetStrategy == Strategy.Development) condi = DefendCondi / 100f;
|
|
if (data.value.TargetStrategy == Strategy.Defend) condi = DevelopmentCondi / 100f;
|
|
if (data.value.TargetStrategy == Strategy.Common) condi = CommonCondi / 100f;
|
|
}
|
|
|
|
AIActionBase action = null;
|
|
for (int i = data.value.AIActions.Count - 1; i >= 0; i--)
|
|
{
|
|
var targetUnit = data.value.AIActions[i].Param.TargetUnitData;
|
|
if (targetUnit == null) continue;
|
|
if (targetUnit.GetHealthRatio() > condi) continue;
|
|
if (action != null && targetUnit.Health >= action.Param.TargetUnitData.Health) continue;
|
|
action = data.value.AIActions[i];
|
|
}
|
|
|
|
data.value.AIActions.Clear();
|
|
if (action != null) data.value.AIActions.Add(action);
|
|
EndAction(data.value.AIActions.Count > 0);
|
|
}
|
|
}
|
|
} |