2019-08-03 17:36:17 +02:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Saltosion.OneWeapon.AI {
|
|
|
|
[Serializable]
|
|
|
|
public class BehaviourBranch : BehaviourNode {
|
|
|
|
public Trigger Trigger;
|
|
|
|
public BehaviourNode[] TriggeredNodes;
|
|
|
|
public BehaviourNode[] NotTriggeredNodes;
|
|
|
|
|
2019-08-04 15:44:44 +02:00
|
|
|
private String MostRecentExecution;
|
|
|
|
|
2019-08-03 17:36:17 +02:00
|
|
|
/* Returns true if any action was taken. */
|
|
|
|
public override bool Execute(Enemy subject) {
|
2019-08-04 15:44:44 +02:00
|
|
|
if (Trigger != null && Trigger.IsTriggered(subject)) {
|
2019-08-03 17:36:17 +02:00
|
|
|
foreach (BehaviourNode Node in TriggeredNodes) {
|
|
|
|
if (Node.Execute(subject)) {
|
2019-08-04 15:44:44 +02:00
|
|
|
MostRecentExecution = Node.GetExecutedName();
|
2019-08-03 17:36:17 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach (BehaviourNode Node in NotTriggeredNodes) {
|
|
|
|
if (Node.Execute(subject)) {
|
2019-08-04 15:44:44 +02:00
|
|
|
MostRecentExecution = Node.GetExecutedName();
|
2019-08-03 17:36:17 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-04 15:44:44 +02:00
|
|
|
|
|
|
|
public override string GetExecutedName() {
|
|
|
|
return MostRecentExecution;
|
|
|
|
}
|
2019-08-03 17:36:17 +02:00
|
|
|
}
|
|
|
|
}
|