70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年06月06日 星期五 19:06:16
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using Logic;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using TH1_Logic.Core;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Name("常备军训练单位")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamStandingTrainUnit : BaseActionTask
|
|
{
|
|
protected override string desc => string.Format($"常备军训练单位");
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam.CityData == null || data.value.AIActions.Count == 0)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var city = data.value.TargetParam.CityData;
|
|
var count = data.value.TargetParam.MapData.GetUnitCount(city.Id);
|
|
if (count >= Mathf.Min(5, city.Level * 0.6f))
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var targetUnitType = UnitType.None;
|
|
// 如果不能造剑士
|
|
bool canSwordsman = false;
|
|
foreach (var aiAction in data.value.AIActions)
|
|
{
|
|
if (aiAction.ActionLogic.ActionId.UnitType == UnitType.Swordsman) canSwordsman = true;
|
|
}
|
|
if (!canSwordsman) targetUnitType = UnitType.Warrior;
|
|
// 如果回合金 < 15
|
|
if (targetUnitType == UnitType.None && Main.PlayerLogic.GetPlayerStarsPerTurn(data.value.Map, data.value.Player.Id) < 15)
|
|
{
|
|
targetUnitType = UnitType.Warrior;
|
|
}
|
|
// 否则造剑士
|
|
if (targetUnitType == UnitType.None) targetUnitType = UnitType.Swordsman;
|
|
|
|
for (int i = data.value.AIActions.Count - 1; i >= 0; i--)
|
|
{
|
|
if (data.value.AIActions[i].ActionLogic.ActionId.UnitType == targetUnitType) continue;
|
|
data.value.AIActions.RemoveAt(i);
|
|
}
|
|
EndAction(data.value.AIActions.Count > 0);
|
|
}
|
|
}
|
|
} |