Botcraft 1.21.4
Loading...
Searching...
No Matches
BaseTasks.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace Botcraft
9{
10 /// @brief Just call client.Yield(). Can be used to Idle the behaviour.
11 /// @param client The client performing the action
12 /// @return Always return Success
13 Status Yield(BehaviourClient& client);
14
15
16 /// @brief Ask this client to disconnect from the server by setting should_be_closed to true.
17 /// @param client The client performing the action
18 /// @return Always return Success
19 Status Disconnect(BehaviourClient& client);
20
21
22 /// @brief Send a message in the game chat
23 /// @param client The client performing the action
24 /// @param msg The message to send
25 /// @return Always return Success
26 Status Say(BehaviourClient& client, const std::string& msg);
27
28 /// @brief Same thing as Say, but reads its parameters from the blackboard
29 /// @param client The client performing the action
30 /// @return Always return Success
31 Status SayBlackboard(BehaviourClient& client);
32
33
34 /// @brief Interact (right click) with the block at the given location. If too far, will try to pathfind toward it.
35 /// @param client The client performing the action
36 /// @param pos The position of the block
37 /// @param face Face on which we want to clik on
38 /// @param animation Whether or not we should send an animation to the server (vanilla client does)
39 /// @return Failure if couldn't interact (because the client couldn't get close enough for example). Success otherwise.
40 Status InteractWithBlock(BehaviourClient& client, const Position& pos, const PlayerDiggingFace face = PlayerDiggingFace::Up, const bool animation = true);
41
42 /// @brief Same thing as InteractWithBlock, but reads its parameters from the blackboard
43 /// @param client The client performing the action
44 /// @return Failure if couldn't interact (because the client couldn't get close enough for example). Success otherwise.
45 Status InteractWithBlockBlackboard(BehaviourClient& client);
46
47
48 /// @brief Check in the blackboard if the bool at key is true
49 /// @param client The client performing the action
50 /// @param key The key to get the bool from
51 /// @return Success if true, failure if false or not found
52 Status CheckBlackboardBoolData(BehaviourClient& client, const std::string& key);
53
54 /// @brief Same thing as CheckBlackboardBoolData, but reads its parameters from the blackboard
55 /// @param client The client performing the action
56 /// @return Success if true, failure if false or not found
57 Status CheckBlackboardBoolDataBlackboard(BehaviourClient& client);
58
59
60 namespace Internal
61 {
62 template<typename T>
63 Status SetBlackboardDataImpl(BehaviourClient& client, const std::string& key, const T& data)
64 {
65 client.GetBlackboard().Set(key, data);
66 return Status::Success;
67 }
68 }
69
70 /// @brief Set a value in the blackboard
71 /// @tparam T Any type
72 /// @param client The client performing the action
73 /// @param key The key in the blackboard
74 /// @param data The data to store
75 /// @return Always return success
76 template<typename T>
77 Status SetBlackboardData(BehaviourClient& client, const std::string& key, const T& data)
78 {
79 constexpr std::array variable_names = {
80 "SetBlackboardData.key",
81 "SetBlackboardData.data"
82 };
83
84 Blackboard& blackboard = client.GetBlackboard();
85
86 blackboard.Set<std::string>(variable_names[0], key);
87 blackboard.Set<T>(variable_names[1], data);
88
89 return Internal::SetBlackboardDataImpl<T>(client, key, data);
90 }
91
92 /// @brief Same thing as SetBlackboardData, but reads its parameters from the blackboard
93 /// @tparam T Any type
94 /// @param client The client performing the action
95 /// @return Always return success
96 template<typename T>
98 {
99 constexpr std::array variable_names = {
100 "SetBlackboardData.key",
101 "SetBlackboardData.data"
102 };
103
104 Blackboard& blackboard = client.GetBlackboard();
105
106 // Mandatory
107 const std::string& key = blackboard.Get<std::string>(variable_names[0]);
108 const T& data = blackboard.Get<T>(variable_names[1]);
109
110 return Internal::SetBlackboardDataImpl<T>(client, key, data);
111 }
112
113
114 /// @brief Remove a value from the blackboard if exist
115 /// @param client The client performing the action
116 /// @param key The key to clear
117 /// @return Always return Success
118 Status RemoveBlackboardData(BehaviourClient& client, const std::string& key);
119
120 /// @brief Same thing as RemoveBlackboardData, but reads its parameters from the blackboard
121 /// @param client The client performing the action
122 /// @return Always return Success
123 Status RemoveBlackboardDataBlackboard(BehaviourClient& client);
124
125
126 /// @brief Return success if player food is below a threshold
127 /// @param client The client performing the action
128 /// @param threshold Threshold under which the player is considered to be hungry
129 /// @return Success if player.GetFood() < threshold, Failure otherwise
130 Status IsHungry(BehaviourClient& client, const int threshold = 20);
131
132 /// @brief Same thing as IsHungry, but reads its parameters from the blackboard
133 /// @param client The client performing the action
134 /// @return Success if player.GetFood() < threshold, Failure otherwise
135 Status IsHungryBlackboard(BehaviourClient& client);
136
137
138 /// @brief Copy a blackboard data
139 /// @param client The client performing the action
140 /// @param src Source blackboard key
141 /// @param dst Destination blackboard key
142 /// @return Always return Success
143 Status CopyBlackboardData(BehaviourClient& client, const std::string& src, const std::string& dst);
144
145 /// @brief Same thing as CopyBlackboardData, but reads its parameters from the blackboard
146 /// @param client The client performing the action
147 /// @return Always return Success
148 Status CopyBlackboardDataBlackboard(BehaviourClient& client);
149
150
151 /// @brief Return Success if it's night time (sleep is possible)
152 /// @param client The client performing the action
153 /// @return Success if it's time to sleep, Failure otherwise
154 Status IsNightTime(BehaviourClient& client);
155
156
157 /// @brief Return success if player is alive
158 /// @param client The client performing the action
159 /// @return Success if player.GetHealth() > 0, Failure otherwise
160 Status IsAlive(BehaviourClient& client);
161} // namespace Botcraft
A ManagersClient extended with a blackboard that can store any kind of data and a virtual Yield funct...
A map wrapper to store arbitrary data.
void Set(const std::string &key, const T &value)
Set map entry at key to value.
const T & Get(const std::string &key)
Get the map value at key, casting it to T.
Status SetBlackboardDataImpl(BehaviourClient &client, const std::string &key, const T &data)
Definition BaseTasks.hpp:63
Status IsHungryBlackboard(BehaviourClient &client)
Same thing as IsHungry, but reads its parameters from the blackboard.
Status SetBlackboardData(BehaviourClient &client, const std::string &key, const T &data)
Set a value in the blackboard.
Definition BaseTasks.hpp:77
Status RemoveBlackboardDataBlackboard(BehaviourClient &client)
Same thing as RemoveBlackboardData, but reads its parameters from the blackboard.
Status SayBlackboard(BehaviourClient &client)
Same thing as Say, but reads its parameters from the blackboard.
Definition BaseTasks.cpp:45
Status CopyBlackboardData(BehaviourClient &client, const std::string &src, const std::string &dst)
Copy a blackboard data.
Status IsHungry(BehaviourClient &client, const int threshold=20)
Return success if player food is below a threshold.
Status Disconnect(BehaviourClient &client)
Ask this client to disconnect from the server by setting should_be_closed to true.
Definition BaseTasks.cpp:19
Status CopyBlackboardDataBlackboard(BehaviourClient &client)
Same thing as CopyBlackboardData, but reads its parameters from the blackboard.
Status Yield(BehaviourClient &client)
Just call client.Yield().
Definition BaseTasks.cpp:11
Status Say(BehaviourClient &client, const std::string &msg)
Send a message in the game chat.
Definition BaseTasks.cpp:32
Status CheckBlackboardBoolDataBlackboard(BehaviourClient &client)
Same thing as CheckBlackboardBoolData, but reads its parameters from the blackboard.
Vector3< int > Position
Definition Vector3.hpp:282
Status InteractWithBlock(BehaviourClient &client, const Position &pos, const PlayerDiggingFace face=PlayerDiggingFace::Up, const bool animation=true)
Interact (right click) with the block at the given location.
Direction PlayerDiggingFace
Definition Enums.hpp:211
Status IsNightTime(BehaviourClient &client)
Return Success if it's night time (sleep is possible)
Status InteractWithBlockBlackboard(BehaviourClient &client)
Same thing as InteractWithBlock, but reads its parameters from the blackboard.
Status CheckBlackboardBoolData(BehaviourClient &client, const std::string &key)
Check in the blackboard if the bool at key is true.
Status RemoveBlackboardData(BehaviourClient &client, const std::string &key)
Remove a value from the blackboard if exist.
Status IsAlive(BehaviourClient &client)
Return success if player is alive.
Status SetBlackboardDataBlackboard(BehaviourClient &client)
Same thing as SetBlackboardData, but reads its parameters from the blackboard.
Definition BaseTasks.hpp:97