Traveller/scripts/behaviorTree/ai/AiPatrolNode.cs

72 lines
2.1 KiB
C#
Raw Normal View History

2024-04-28 13:55:19 +00:00
using ColdMint.scripts.behaviorTree.framework;
using ColdMint.scripts.character;
namespace ColdMint.scripts.behaviorTree.ai;
/// <summary>
/// <para>AI巡逻节点</para>
/// </summary>
public class AiPatrolNode : SelectorNode
2024-04-28 13:55:19 +00:00
{
public AiCharacter? Character { get; set; }
2024-04-28 13:55:19 +00:00
protected override IBehaviorTreeNode? SelectNode(bool isPhysicsProcess, double delta, IBehaviorTreeNode[] children)
2024-04-28 13:55:19 +00:00
{
if (Character == null)
{
return null;
}
2024-04-28 13:55:19 +00:00
if (Character.NodesInTheAttackRange.Length > 1)
{
if (Character.CurrentItem == null)
{
//No weapon
//没有武器
var weaponTemplates = Character.GetCanPickedWeapon();
if (weaponTemplates.Length > 0)
2024-04-28 13:55:19 +00:00
{
var aiPickNode = GetChild<AiPickNode>(null);
if (aiPickNode != null)
2024-04-28 13:55:19 +00:00
{
return aiPickNode;
2024-04-28 13:55:19 +00:00
}
}
//No weapon, and no weapon to pick up, then try to escape
//没有武器,且没有武器可捡,那么尝试逃跑
var aiRotorNode = GetChild<AiRotorNode>(null);
2024-04-28 13:55:19 +00:00
if (aiRotorNode != null)
{
return aiRotorNode;
}
return children[0];
}
//There are enemies around
//周围有敌人
if (Character.AttackObstacleDetection != null && Character.AttackObstacleDetection.GetCollider() == null)
2024-04-28 13:55:19 +00:00
{
var aiAttackNode = GetChild<AiAttackNode>(null);
2024-04-28 13:55:19 +00:00
if (aiAttackNode != null)
{
return aiAttackNode;
}
}
}
if (Character.WallDetection?.GetCollider() != null)
2024-04-28 13:55:19 +00:00
{
//Encounter a wall
//遇到墙壁
var aiRotorNode = GetChild<AiRotorNode>(null);
2024-04-28 13:55:19 +00:00
if (aiRotorNode != null)
{
return aiRotorNode;
}
}
return children[0];
}
}