90 lines
2.9 KiB
C#
90 lines
2.9 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年06月06日 星期五 19:06:16
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Logic;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using RuntimeData;
|
|
using TH1_Logic.Core;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Name("空城紧急造兵")]
|
|
[Category("AI节点")]
|
|
[Serializable]
|
|
public class AIParamDefendTrainUnit : 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 map = data.value.TargetParam.MapData;
|
|
var city = data.value.TargetParam.CityData;
|
|
if (!map.GetGridDataByCityId(city.Id, out var cityGrid) || map.GetUnitDataByGid(cityGrid.Id, out var unit))
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
bool needTrain = false;
|
|
var selfUnit = new HashSet<UnitData>();
|
|
map.GetUnitDataListByPlayerId(data.value.TargetParam.PlayerData.Id, selfUnit);
|
|
var around = map.GridMap.GetAroundGridData(1, 1, cityGrid);
|
|
foreach (var grid in around)
|
|
{
|
|
if (!map.GetUnitDataByGid(grid.Id, out var attacker)) continue;
|
|
if (selfUnit.Contains(attacker)) continue;
|
|
needTrain = true;
|
|
break;
|
|
}
|
|
|
|
if (!needTrain)
|
|
{
|
|
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.GetPlayerCoinPerTurn(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);
|
|
}
|
|
}
|
|
} |