92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年06月06日 星期五 19:06:16
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Category("AIAction")]
|
|
[Serializable]
|
|
public class AIForeachCreate : ActionTask
|
|
{
|
|
public Strategy Strategy;
|
|
public bool IsCity;
|
|
public bool IsUnit;
|
|
public bool IsLegion;
|
|
public string ExtraName;
|
|
|
|
|
|
protected override string info
|
|
{
|
|
get
|
|
{
|
|
if (IsCity) return string.Format($"创建 {Strategy} 策略的城市迭代 \n 标记为 {GetName()}");
|
|
if (IsUnit) return string.Format($"创建 {Strategy} 策略的自由人迭代 \n 标记为 {GetName()}");
|
|
if (IsLegion) return string.Format($"创建 {Strategy} 策略的军团迭代 \n 标记为 {GetName()}");
|
|
return "迭代器";
|
|
}
|
|
}
|
|
|
|
private string GetName()
|
|
{
|
|
if (IsCity) return $"City{Strategy}{ExtraName}Foreach";
|
|
if (IsUnit) return $"FreeUnit{Strategy}{ExtraName}Foreach";
|
|
if (IsLegion) return $"Legion{Strategy}{ExtraName}Foreach";
|
|
|
|
return "";
|
|
}
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value == null || string.IsNullOrEmpty(GetName()) || data.value.Marks.Contains(GetName()))
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
data.value.ForeachCity.Clear();
|
|
data.value.ForeachLegion.Clear();
|
|
data.value.ForeachUnit.Clear();
|
|
if (IsCity)
|
|
{
|
|
foreach (var kv in data.value.CityStrategy)
|
|
{
|
|
if (Strategy != Strategy.Common && kv.Value != Strategy) continue;
|
|
data.value.ForeachCity.Add(kv.Key);
|
|
}
|
|
}
|
|
|
|
if (IsUnit)
|
|
{
|
|
foreach (var kv in data.value.FreeUnitStrategy)
|
|
{
|
|
if (Strategy != Strategy.Common && kv.Value != Strategy) continue;
|
|
data.value.ForeachUnit.Add(kv.Key);
|
|
}
|
|
}
|
|
|
|
if (IsLegion)
|
|
{
|
|
foreach (var kv in data.value.LegionStrategy)
|
|
{
|
|
if (Strategy != Strategy.Common && kv.Value != Strategy) continue;
|
|
data.value.ForeachLegion.Add(kv.Key);
|
|
}
|
|
}
|
|
|
|
data.value.Marks.Add(GetName());
|
|
EndAction(data.value.ForeachUnit.Count != 0 || data.value.ForeachCity.Count != 0 || data.value.ForeachLegion.Count != 0);
|
|
}
|
|
}
|
|
} |