SHADE_Y3/Assets/Scripts/Gameplay/AIBehaviour/BehaviourTree/Flow/BehaviourTreeSequence.cs

57 lines
1.9 KiB
C#
Raw Normal View History

2022-11-23 21:02:33 +08:00
/*********************************************************************
* \file BehaviourTreeSequence.cs
* \author Ryan Wang Nian Jing
* \brief Based off Kheng Ian's SC_BTSelector.cs
* Sequences function like "AND" nodes, having to process every child
* successfully to return a success. Returns a failure on the first
* child that fails
*
* \copyright Copyright (c) 2022 DigiPen Institute of Technology. Reproduction
or disclosure of this file or its contents without the prior written
consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.AIBehaviour.BehaviourTree
{
public class BehaviourTreeSequence : BehaviourTreeNode
{
public BehaviourTreeSequence(string name) : base(name) { }
public BehaviourTreeSequence(string name, List<BehaviourTreeNode> children) :
base(name, children) { }
public override BehaviourTreeNodeStatus Evaluate()
{
{
onEnter(BehaviourTreeNodeStatus.RUNNING);
for (int i = 0; i < children.Count; ++i)
{
switch (children[i].Evaluate())
{
case BehaviourTreeNodeStatus.SUCCESS:
continue;
case BehaviourTreeNodeStatus.RUNNING:
status = BehaviourTreeNodeStatus.RUNNING;
onExit(BehaviourTreeNodeStatus.RUNNING);
return status;
case BehaviourTreeNodeStatus.FAILURE:
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
}
status = BehaviourTreeNodeStatus.SUCCESS;
onExit(BehaviourTreeNodeStatus.SUCCESS);
return status;
}
}
}
}