13 file::Conversation::Node errorNode() {
14 file::Conversation::Node node;
16 node.message() =
"<ERROR: Current node is invalid>";
27 nodes = &conv.
nodes();
37 if (!
finished())
return nodes->at(current);
44 current = nodes->at(current).next();
51 current = nodes->at(current).nextOnPass();
58 current = nodes->at(current).nextOnReject();
65 for (
const auto& pair : nodes->at(current).choices()) {
66 if (pair.first == choice) {
67 current = pair.second;
75 void Conversation::followNodes() {
77 const auto isBlocking = [
this](
unsigned int i) {
78 switch (nodes->at(i).getType()) {
79 case E::CheckInteracted:
80 case E::CheckSaveFlag:
90 while (!
finished() && !isBlocking(current)) {
91 switch (nodes->at(current).getType()) {
92 case E::CheckInteracted:
94 alreadyTalked ? nodes->at(current).nextOnPass() : nodes->at(current).nextOnReject();
99 current = nodes->at(current).next();
102 case E::CheckSaveFlag:
104 nodes->at(current).nextOnPass() :
105 nodes->at(current).nextOnReject();
109 const auto cb = [
this](bl::ecs::Entity e) {
110 if (e != entity)
return true;
115 bl::script::Script script(nodes->at(current).script(),
116 script::ConversationContext(systems, entity, cb));
117 if (nodes->at(current).runConcurrently()) {
118 script.runBackground(&systems.
engine().scriptManager());
121 script.run(&systems.
engine().scriptManager());
123 current = nodes->at(current).next();
127 BL_LOG_ERROR <<
"Unhandled nonblocking node type " << nodes->at(current).getType()
129 current = nodes->size();
Core classes and functionality for both the editor and game.
void notifyNext()
Continues to the next node on player input.
bool finished() const
Returns whether or not the conversation is finished.
void notifyCheckFailed()
Jumps to the node for a check pass (ie take item/money fail etc)
void notifyCheckPassed()
Jumps to the node for a check pass (ie take item/money success etc)
void notifyChoiceMade(const std::string &choice)
Jumps to the node for the given choice if the current node is a Prompt.
const file::Conversation::Node & currentNode() const
Returns the current node.
Conversation(system::Systems &systems)
Creates an empty conversation wrapper.
void setConversation(const file::Conversation &conversation, bl::ecs::Entity entity, bool talked)
Sets the wrapper to point to the given underlying. The underlying must remain in scope during the lif...
Stores a conversation that an NPC or trainer can have with the player.
const std::vector< Node > & nodes() const
Returns the list of nodes in the conversation.
Building block of conversations. A conversation is a tree of nodes and each node is an action that ha...
Type
Represents the different effects that nodes can have.
@ Prompt
This will output a message then prompt the player for a choice.
@ Talk
This just outputs a message.
static void warn(const std::string &script)
In debug mode logs a warning if the given script is detected to be legacy.
bool flagSet(const std::string &flag) const
Checks if the given conversation flag has been set.
void setFlag(const std::string &flag)
Sets the conversation flag.
Owns all primary systems and a reference to the engine.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Interaction & interaction()
Returns the interaction system.