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