1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Brains.Framework.Designer;
namespace Brains.Framework.Behaviors
{
/// <summary>
/// This Behavior is a Composite behavior which will randomly select a sub behavior to run.
/// </summary>
[BehaviorAttribute("Random")]
public class RandomBehavior : CompositeBehavior, ICompositeBehavior
{
public RandomBehavior()
{
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
public override void OnSuccess()
{
CurrentSubBehavior = 0;
base.OnSuccess();
}
public override void OnFailure()
{
SubBehaviors[CurrentSubBehavior].State = BehaviorState.Idle;
CurrentSubBehavior = 0;
base.OnFailure();
}
public override void OnSubBehaviorFailure()
{
OnFailure();
base.OnSubBehaviorFailure();
}
public override void OnSubBehaviorSuccess()
{
SubBehaviors[CurrentSubBehavior].State = BehaviorState.Idle;
if (CurrentSubBehavior == Count - 1) //Is it the final behavior?
OnSuccess();
else //Move onto the next item in the sequence.
CurrentSubBehavior++;
base.OnSubBehaviorSuccess();
}
}
} |