diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 70ec478a..0b949fc7 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -104,6 +104,8 @@ void Game::processTextMessage(int type, const std::string& message) void Game::walk(Otc::Direction direction) { + if(!m_online) + return; // TODO: check if we can walk. @@ -157,3 +159,22 @@ void Game::turn(Otc::Direction direction) break; } } + +// Game.talkChannel(1, 0, "lalala") +// TODO: MAKE SURE IT WAS AN USER EVENT AND NOT DIRECTLY FROM SCRIPT. + +void Game::talkChannel(int channelType, int channelId, const std::string& message) +{ + if(!m_online) + return; + + m_protocolGame->sendTalk(channelType, channelId, "", message); +} + +void Game::talkPrivate(int channelType, const std::string& receiver, const std::string& message) +{ + if(!m_online) + return; + + m_protocolGame->sendTalk(channelType, 0, receiver, message); +} diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index 5e1f6c95..be49cd2f 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -48,6 +48,8 @@ public: void walk(Otc::Direction direction); void turn(Otc::Direction direction); + void talkChannel(int channelType, int channelId, const std::string& message); + void talkPrivate(int channelType, const std::string& receiver, const std::string& message); bool isOnline() { return m_online; } diff --git a/src/otclient/net/protocolgame.h b/src/otclient/net/protocolgame.h index ba6fa130..3d9567e6 100644 --- a/src/otclient/net/protocolgame.h +++ b/src/otclient/net/protocolgame.h @@ -54,7 +54,7 @@ public: void sendTurnEast(); void sendTurnSouth(); void sendTurnWest(); - void sendTalk(int channelType, const std::string& message, int channelId = 1, const std::string& receiver = ""); + void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message); void sendAddVip(const std::string& name); void sendRemoveVip(int id); diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index 14fa9c81..a74c4616 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -158,12 +158,9 @@ void ProtocolGame::sendTurnWest() send(oMsg); } -void ProtocolGame::sendTalk(int channelType, const std::string& message, int channelId, const std::string& receiver) +void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message) { - // Game.getProtocolGame():sendTalk(1, "lalala", 0, "ignore") - // TODO: MAKE SURE IT WAS AN USER EVENT AND NOT DIRECTLY FROM SCRIPT. - - if(message.length() > 255 && message.length() <= 0) + if(message.length() > 255 || message.length() <= 0) return; OutputMessage oMsg; diff --git a/src/otclient/otclientluafunctions.cpp b/src/otclient/otclientluafunctions.cpp index e3a4242d..47b7c7fd 100644 --- a/src/otclient/otclientluafunctions.cpp +++ b/src/otclient/otclientluafunctions.cpp @@ -49,7 +49,6 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("cancelLogin", &ProtocolLogin::cancelLogin); g_lua.registerClass(); - g_lua.bindClassMemberFunction("sendTalk", &ProtocolGame::sendTalk); g_lua.registerClass(); g_lua.registerClass(); @@ -64,7 +63,8 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("logout", std::bind(&Game::logout, &g_game, _1)); g_lua.bindClassStaticFunction("cancelLogin", std::bind(&Game::cancelLogin, &g_game)); g_lua.bindClassStaticFunction("isOnline", std::bind(&Game::isOnline, &g_game)); - g_lua.bindClassStaticFunction("getProtocolGame", std::bind(&Game::getProtocolGame, &g_game)); + g_lua.bindClassStaticFunction("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3)); + g_lua.bindClassStaticFunction("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3)); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create);