diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index ef3e56b0..c7309368 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -14,7 +14,7 @@ local SpeakTypes = { channelOrange = { color = '#FE6500' }, private = { color = '#5FF7F7', private = true }, playerToNpc = { color = '#9F9DFD', private = true, npcChat = true }, - broadcast = { color = '#F55E5E', private = true }, + broadcast = { color = '#F55E5E' }, privateRed = { color = '#F55E5E', private = true } } @@ -114,29 +114,39 @@ function Console.sendCurrentMessage() if #message == 0 then return end consoleLineEdit:clearText() + -- get current channel local tab = Console.getCurrentTab() - local name = tab:getText() - if name == 'Server Log' then name = 'Default' end - local speaktypedesc = 'say' - if tab.npcChat then - speaktypedesc = 'playerToNpc' + -- when talking on server log, the message goes to default channel + local name = tab:getText() + if name == 'Server Log' then + tab = Console.getTab('Default') + name = 'Default' end + local speaktypedesc if tab.channelId then - if tab.channelId ~= 0 then + if tab.channelId == 0 then + speaktypedesc = 'say' + else speaktypedesc = 'channelYellow' end Game.talkChannel(speaktypedesc, tab.channelId, message) return else + if tab.npcChat then + speaktypedesc = 'playerToNpc' + else + speaktypedesc = 'private' + end + local speaktype = SpeakTypes[speaktypedesc] local player = Game.getLocalPlayer() + Game.talkPrivate(speaktypedesc, name, message) + message = applyMessagePrefixies(player:getName(), player:getLevel(), message) Console.addPrivateText(message, speaktype, name) - - Game.talkPrivate(speaktypedesc, name, message) end end @@ -164,8 +174,7 @@ local function onChannelList(channelList) channelsWindow.onEnter = function(self) local selectedChannelLabel = channelListPanel:getFocusedChild() if not selectedChannelLabel then return end - --Game.joinChannel(selectedChannelLabel.channelId) - --Console.addChannel(selectedChannelLabel:getText(), selectedChannelLabel .channelId) + Game.joinChannel(selectedChannelLabel.channelId) channelsWindow:destroy() end for k,v in pairs(channelList) do @@ -174,7 +183,6 @@ local function onChannelList(channelList) if channelId ~= 0 and #channelName > 0 then local label = createWidget('ChannelListLabel', channelListPanel) - print(channelId, channelName) label.channelId = channelId label:setText(channelName) end diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index b2b31b6b..20f2a2d0 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -153,7 +153,7 @@ void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldP } */ if(!m_walkFeedback && creature == m_localPlayer) { - updatePing(); + updateWalkPing(); m_walkFeedback = true; } creature->walk(newPos); @@ -168,7 +168,7 @@ void Game::processAttackCancel() void Game::processWalkCancel(Otc::Direction direction) { if(!m_walkFeedback) { - updatePing(); + updateWalkPing(); m_walkFeedback = true; } m_localPlayer->cancelWalk(direction, true); @@ -280,6 +280,14 @@ void Game::useWith(const ThingPtr& fromThing, const ThingPtr& toThing) m_protocolGame->sendUseItemEx(fromThing->getPos(), fromThing->getId(), fromStackpos, toThing->getPos(), toThing->getId(), toStackpos); } +void Game::useHotkey(int itemId, const ThingPtr& toThing) +{ + if(!m_online || !toThing || !checkBotProtection()) + return; + + m_protocolGame->sendUseItemEx(Position(0xFFFF, 0, 0), itemId, 0, toThing->getPos(), toThing->getId(), getThingStackpos(toThing)); +} + void Game::attack(const CreaturePtr& creature) { if(!m_online || !creature || !checkBotProtection()) @@ -347,7 +355,6 @@ void Game::talkChannel(const std::string& speakTypeDesc, int channelId, const st { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendTalk(speakTypeDesc, channelId, "", message); } @@ -355,15 +362,42 @@ void Game::talkPrivate(const std::string& speakTypeDesc, const std::string& rece { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendTalk(speakTypeDesc, 0, receiver, message); } -void Game::partyInvite(int creatureId) +void Game::requestChannels() { if(!m_online || !checkBotProtection()) return; + m_protocolGame->sendGetChannels(); +} + +void Game::joinChannel(int channelId) +{ + if(!m_online || !checkBotProtection()) + return; + m_protocolGame->sendJoinChannel(channelId); +} + +void Game::leaveChannel(int channelId) +{ + if(!m_online || !checkBotProtection()) + return; + m_protocolGame->sendLeaveChannel(channelId); +} + +void Game::closeNpcChannel() +{ + if(!m_online || !checkBotProtection()) + return; + m_protocolGame->sendCloseNpcChannel(); +} + +void Game::partyInvite(int creatureId) +{ + if(!m_online || !checkBotProtection()) + return; m_protocolGame->sendInviteToParty(creatureId); } @@ -371,7 +405,6 @@ void Game::partyJoin(int creatureId) { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendJoinParty(creatureId); } @@ -379,7 +412,6 @@ void Game::partyRevokeInvitation(int creatureId) { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendRevokeInvitation(creatureId); } @@ -388,7 +420,6 @@ void Game::partyPassLeadership(int creatureId) { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendPassLeadership(creatureId); } @@ -396,7 +427,6 @@ void Game::partyLeave() { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendLeaveParty(); } @@ -404,7 +434,6 @@ void Game::partyShareExperience(bool active) { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendShareExperience(active, 0); } @@ -412,31 +441,13 @@ void Game::requestOutfit() { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendGetOutfit(); } -void Game::requestChannels() -{ - if(!m_online || !checkBotProtection()) - return; - - m_protocolGame->sendGetChannels(); -} - -void Game::openChannel(int channelId) -{ - if(!m_online || !checkBotProtection()) - return; - - m_protocolGame->sendOpenChannel(channelId); -} - void Game::setOutfit(const Outfit& outfit) { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendSetOutfit(outfit); } @@ -444,7 +455,6 @@ void Game::addVip(const std::string& name) { if(!m_online || name.empty() || !checkBotProtection()) return; - m_protocolGame->sendAddVip(name); } @@ -452,7 +462,6 @@ void Game::removeVip(int playerId) { if(!m_online || !checkBotProtection()) return; - m_protocolGame->sendRemoveVip(playerId); } @@ -467,7 +476,7 @@ bool Game::checkBotProtection() return true; } -void Game::updatePing() +void Game::updateWalkPing() { m_walkPing = m_walkPingTimer.ticksElapsed(); g_lua.callGlobalField("Game", "onWalkPingUpdate", m_walkPing); diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index cb2036e2..466802cd 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -54,32 +54,49 @@ public: void processAttackCancel(); void processWalkCancel(Otc::Direction direction); + // walk related void walk(Otc::Direction direction); void turn(Otc::Direction direction); + + // item related void look(const ThingPtr& thing); void open(const ThingPtr& thing, int containerId); void use(const ThingPtr& thing); void useWith(const ThingPtr& fromThing, const ThingPtr& toThing); + void useHotkey(int itemId, const ThingPtr& toThing); + + // attack/follow related void attack(const CreaturePtr& creature); void cancelAttack(); void follow(const CreaturePtr& creature); void cancelFollow(); void rotate(const ThingPtr& thing); + + // talk related void talk(const std::string& message); void talkChannel(const std::string& speakTypeDesc, int channelId, const std::string& message); void talkPrivate(const std::string& speakTypeDesc, const std::string& receiver, const std::string& message); + void requestChannels(); + void joinChannel(int channelId); + void leaveChannel(int channelId); + void closeNpcChannel(); + + // party related void partyInvite(int creatureId); void partyJoin(int creatureId); void partyRevokeInvitation(int creatureId); void partyPassLeadership(int creatureId); void partyLeave(); void partyShareExperience(bool active); + + // outfit related void requestOutfit(); - void requestChannels(); - void openChannel(int channelId); void setOutfit(const Outfit& outfit); + + // vip related void addVip(const std::string& name); void removeVip(int playerId); + int getThingStackpos(const ThingPtr& thing); bool checkBotProtection(); @@ -99,7 +116,7 @@ public: int getWalkPing() { return m_walkPing; } private: - void updatePing(); + void updateWalkPing(); LocalPlayerPtr m_localPlayer; ProtocolGamePtr m_protocolGame; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 7349c9a7..8bb4a132 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -180,7 +180,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("isOnline", std::bind(&Game::isOnline, &g_game)); g_lua.bindClassStaticFunction("requestOutfit", std::bind(&Game::requestOutfit, &g_game)); g_lua.bindClassStaticFunction("requestChannels", std::bind(&Game::requestChannels, &g_game)); - g_lua.bindClassStaticFunction("openChannel", std::bind(&Game::openChannel, &g_game, _1)); + g_lua.bindClassStaticFunction("joinChannel", std::bind(&Game::joinChannel, &g_game, _1)); g_lua.bindClassStaticFunction("setOutfit", std::bind(&Game::setOutfit, &g_game, _1)); g_lua.bindClassStaticFunction("look", std::bind(&Game::look, &g_game, _1)); g_lua.bindClassStaticFunction("open", std::bind(&Game::open, &g_game, _1, _2));