Fix talk command crash

This commit is contained in:
Yunfan Li
2024-02-12 12:38:10 +08:00
parent de31d88fba
commit 187989ddd1

View File

@@ -61,8 +61,8 @@ bool GossipHelloAction::Execute(Event event)
else else
{ {
menuToSelect = atoi(text.c_str()); menuToSelect = atoi(text.c_str());
if (menuToSelect > 0) // if (menuToSelect > 0)
menuToSelect--; // menuToSelect--;
ProcessGossip(menuToSelect); ProcessGossip(menuToSelect);
} }
@@ -104,11 +104,11 @@ void GossipHelloAction::TellGossipMenus()
TellGossipText(textId); TellGossipText(textId);
} }
for (uint32 i = 0; i < menu.GetMenuItemCount(); i++) GossipMenuItemContainer const &items = menu.GetMenuItems();
{ for (auto iter = items.begin(); iter != items.end(); iter++) {
GossipMenuItem const* item = menu.GetItem(i); GossipMenuItem const* item = &(iter->second);
std::ostringstream out; std::ostringstream out;
out << "[" << (i+1) << "] " << item->Message; out << "[" << iter->first << "] " << item->Message;
botAI->TellMasterNoFacing(out.str()); botAI->TellMasterNoFacing(out.str());
} }
} }
@@ -117,7 +117,7 @@ void GossipHelloAction::TellGossipMenus()
bool GossipHelloAction::ProcessGossip(int32 menuToSelect) bool GossipHelloAction::ProcessGossip(int32 menuToSelect)
{ {
GossipMenu& menu = bot->PlayerTalkClass->GetGossipMenu(); GossipMenu& menu = bot->PlayerTalkClass->GetGossipMenu();
if (menuToSelect != -1 && menuToSelect >= menu.GetMenuItemCount()) if (menuToSelect != -1 && !menu.GetItem(menuToSelect))
{ {
botAI->TellError("Unknown gossip option"); botAI->TellError("Unknown gossip option");
return false; return false;