File tree Expand file tree Collapse file tree
BrainAI/AI/UtilityAI/Intents Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+
3+ namespace BrainAI . AI . UtilityAI
4+ {
5+ public class QueueIntent < T > : IIntent < T >
6+ {
7+ private readonly Queue < IIntent < T > > intents ;
8+ private IIntent < T > currentIntent ;
9+
10+ public QueueIntent ( params IIntent < T > [ ] intents )
11+ {
12+ this . intents = new Queue < IIntent < T > > ( intents ) ;
13+ }
14+
15+ public void Enter ( T context )
16+ {
17+ currentIntent ? . Enter ( context ) ;
18+ }
19+
20+ public bool Execute ( T context )
21+ {
22+ if ( currentIntent == null )
23+ {
24+ if ( intents . Count == 0 )
25+ {
26+ return true ;
27+ }
28+ currentIntent = intents . Dequeue ( ) ;
29+ currentIntent . Enter ( context ) ;
30+ }
31+
32+ var deleted = currentIntent . Execute ( context ) ;
33+ if ( deleted )
34+ {
35+ currentIntent . Exit ( context ) ;
36+ currentIntent = null ;
37+ }
38+
39+ return false ;
40+ }
41+
42+ public void Exit ( T context )
43+ {
44+ currentIntent ? . Exit ( context ) ;
45+ }
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments