File size: 1,581 Bytes
ac55997
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
using Photon.Deterministic;
using System;

namespace Quantum
{
	[Serializable]
	public unsafe partial class WaitLeaf : BTLeaf
	{
		// How many time shall be waited
		// This is measured in seconds
		public FP Duration;

		// Indexer for us to store the End Time value on the BTAgent itself
		public BTDataIndex EndTimeIndex;

		public override void Init(Frame frame, AIBlackboardComponent* blackboard, BTAgent* agent)
		{
			base.Init(frame, blackboard, agent);

			// We allocate space for the End Time on the Agent so we can change it in runtime
			agent->AddFPData(frame, 0);
		}

		public override void OnEnter(BTParams btParams)
		{
			base.OnEnter(btParams);

			FP currentTime;
			FP endTime;

			// Get the current time
			currentTime = btParams.Frame.BotSDKGameTime;
			// Add the Duration value so we know when the Leaf will stop running
			endTime = currentTime + Duration;

			// Store the final value on the Agent data
			btParams.Agent->SetFPData(btParams.Frame, endTime, EndTimeIndex.Index);
		}

		protected override BTStatus OnUpdate(BTParams btParams)
		{
			FP currentTime;
			FP endTime;

			currentTime = btParams.Frame.BotSDKGameTime;
			endTime = btParams.Agent->GetFPData(btParams.Frame, EndTimeIndex.Index);

			// If waiting time isn't over yet, then we need more frames executing this Leaf
			// So we say that we're still Running
			if (currentTime < endTime)
			{
				return BTStatus.Running;
			}

			// If the waiting time is over, then we succeeded on waiting that amount of time
			// Then we return Success
			return BTStatus.Success;
		}
	}
}