54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年06月06日 星期五 19:06:16
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Category("AIAction")]
|
|
public class AIParamHealth : ActionTask
|
|
{
|
|
public bool GreaterThan = true;
|
|
public float Ratio = 0.6f;
|
|
|
|
|
|
protected override string info
|
|
{
|
|
get
|
|
{
|
|
if (GreaterThan) return string.Format($"血量大于等于 {(int)(Ratio * 100)}");
|
|
return string.Format($"血量小于等于 {(int)(Ratio * 100)}");
|
|
}
|
|
}
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam.UnitData == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var unit = data.value.TargetParam.UnitData;
|
|
if (!Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(unit.UnitType, unit.GiantType, out var info))
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
if (GreaterThan && unit.Health >= info.MaxHealth * Ratio) EndAction(true);
|
|
else if (!GreaterThan && unit.Health <= info.MaxHealth * Ratio) EndAction(true);
|
|
else EndAction(false);
|
|
}
|
|
}
|
|
} |