[Dialogue Window / Saylinks] Missing Changes (#1574)

* Implement auto saylink injection

* Cover Lua say since it takes a different code path

* [Dialogue] Dialogue Window Middleware (#1526)

* Dialogue window quest dialogue work

* Add rest of DialogueWindow hooks

* Remove spacing
This commit is contained in:
Chris Miles
2021-10-01 22:09:21 -05:00
committed by GitHub
parent 0762ffa3dc
commit 3883adcefc
7 changed files with 107 additions and 13 deletions
+49 -4
View File
@@ -4,6 +4,10 @@ void DialogueWindow::Render(Client *c, std::string markdown)
{
std::string output = markdown;
if (!c->ClientDataLoaded()) {
return;
}
// this is the NPC that the client is interacting with if there is dialogue going on
Mob *target;
if (c->GetTarget()) {
@@ -81,6 +85,21 @@ void DialogueWindow::Render(Client *c, std::string markdown)
}
}
if (animation.empty() && RuleB(Chat, DialogueWindowAnimatesNPCsIfNoneSet)) {
std::vector<int> greet_animations = {
29, // wave
48, // nodyes
64, // point
67, // salute
69, // tapfoot
70, // bowto
};
int random_animation = rand() % (greet_animations.size() - 1) + 0;
target->DoAnim(greet_animations[random_animation]);
}
// window expire time
std::string expire_time = get_between(output, "=", "=");
uint32 window_expire_seconds = 0;
@@ -234,7 +253,7 @@ void DialogueWindow::Render(Client *c, std::string markdown)
button_one_name = button_one.c_str();
}
}
LogDiaWind("Client [{}] Rendering button_two option.", c->GetCleanName());
auto two_first_split = split_string(output, "button_two:");
@@ -266,6 +285,33 @@ void DialogueWindow::Render(Client *c, std::string markdown)
std::vector<std::string> responses;
std::vector<std::string> bracket_responses;
if (markdown.find('[') != std::string::npos && markdown.find(']') != std::string::npos) {
// record any saylinks that may be in saylink form
std::string strip_saylinks = output;
std::map<std::string, std::string> replacements = {};
while (strip_saylinks.find('[') != std::string::npos && strip_saylinks.find(']') != std::string::npos) {
std::string bracket_message = get_between(strip_saylinks, "[", "]");
// strip saylinks and normalize to [regular message]
size_t link_open = bracket_message.find('\x12');
size_t link_close = bracket_message.find_last_of('\x12');
if (link_open != link_close && (bracket_message.length() - link_open) > EQ::constants::SAY_LINK_BODY_SIZE) {
replacements.insert(
std::pair<std::string, std::string>(
bracket_message,
bracket_message.substr(EQ::constants::SAY_LINK_BODY_SIZE + 1)
)
);
}
find_replace(strip_saylinks, fmt::format("[{}]", bracket_message), "");
}
// write replacement strips
for (auto &replacement: replacements) {
find_replace(output, replacement.first, replacement.second.substr(0, replacement.second.size() - 1));
}
// copy
std::string content = output;
@@ -412,8 +458,8 @@ void DialogueWindow::Render(Client *c, std::string markdown)
color_tag
);
std::string html_tag;
for (const auto& color : html_colors) {
std::string html_tag;
for (const auto &color : html_colors) {
if (color_tag.find(color.first) != std::string::npos) {
// build html tag
html_tag = fmt::format("<c \"{}\">", color.second);
@@ -426,7 +472,6 @@ void DialogueWindow::Render(Client *c, std::string markdown)
}
}
// build the final output string
std::string final_output;
final_output = fmt::format("{}{}{} <br><br> {}", quote_string, output, quote_string, click_response);