62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年06月06日 星期五 19:06:16
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Logic.AI;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using RuntimeData;
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions
|
|
{
|
|
[Category("AIAction")]
|
|
[Serializable]
|
|
public class AIParamMustGarrison : ActionTask
|
|
{
|
|
protected override string info => "必须驻守城市";
|
|
|
|
protected override void OnExecute()
|
|
{
|
|
// 直接从Blackboard获取AICalculatorData
|
|
var data = blackboard.GetVariable<AICalculatorData>("Data");
|
|
if (data?.value?.TargetParam.UnitData == null)
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var map = data.value.TargetParam.MapData;
|
|
var unit = data.value.TargetParam.UnitData;
|
|
var selfCity = new List<CityData>();
|
|
map.GetCityDataListByPlayerId(data.value.TargetParam.PlayerData.Id, selfCity);
|
|
var selfUnit = new HashSet<UnitData>();
|
|
map.GetUnitDataListByPlayerId(data.value.TargetParam.PlayerData.Id, selfUnit);
|
|
|
|
if (!map.GetGridDataByUnitId(unit.Id, out var unitGrid) ||
|
|
!map.GetCityDataByGid(unitGrid.Id, out var city) ||
|
|
!selfCity.Contains(city) || !map.CheckIfCityFullPopulation(city))
|
|
{
|
|
EndAction(false);
|
|
return;
|
|
}
|
|
|
|
var around = map.GridMap.GetAroundGridData(1, 1, unitGrid);
|
|
foreach (var grid in around)
|
|
{
|
|
if (!map.GetUnitDataByGid(grid.Id, out var attacker)) continue;
|
|
if (selfUnit.Contains(attacker)) continue;
|
|
EndAction(true);
|
|
return;
|
|
}
|
|
|
|
EndAction(false);
|
|
}
|
|
}
|
|
} |