diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index 81a46d9c..a3300474 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -30,8 +30,9 @@ function TextMessage.create() end -- hooked events -function Game.onTextMessage(type, message) +function TextMessage.onTextMessage(type, message) local messageType = messageTypes[type - messageTypes.first] + print(messageType.color) if messageType.showOnConsole then -- TODO @@ -46,9 +47,9 @@ function Game.onTextMessage(type, message) end label:setVisible(true) - label:setForegroundColor(messageType.color) label:setText(message) label:setStyle(messageType.windowLocation) + label:setForegroundColor(messageType.color) time = #message * 75 removeEvent(hideEvent) @@ -60,4 +61,5 @@ end connect(Game, { onLogin = TextMessage.create, - onLogout = TextMessage.destroy }) \ No newline at end of file + onLogout = TextMessage.destroy, + onTextMessage = TextMessage.onTextMessage }) diff --git a/src/otclient/const.h b/src/otclient/const.h index 32273cb8..e8cb60b8 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -349,6 +349,14 @@ namespace Otc SpeakMonsterYell = 0x0E //Yell orange }; + enum CreaturesIdRange { + PlayerStartId = 0x10000000, + PlayerEndId = 0x40000000, + MonsterStartId = 0x40000000, + MonsterEndId = 0x80000000, + NpcStartId = 0x80000000, + NpcEndId = 0xffffffff + }; } #endif diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index c9286a40..73c8f9d1 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -22,6 +22,8 @@ #include "game.h" #include "localplayer.h" +#include "map.h" +#include "tile.h" #include #include @@ -154,6 +156,17 @@ void Game::turn(Otc::Direction direction) } } +void Game::look(const Position& position) +{ + const TilePtr& tile = g_map.getTile(position); + if(tile) { + int stackpos = tile->getLookStackpos(); + ThingPtr thing = tile->getThing(stackpos); + if(thing) + m_protocolGame->sendLookAt(position, thing->getId(), stackpos); + } +} + void Game::talkChannel(int channelType, int channelId, const std::string& message) { if(!m_online) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index a17d9ff2..3c14d5d1 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -48,6 +48,7 @@ public: void walk(Otc::Direction direction); void turn(Otc::Direction direction); + void look(const Position& position); void talkChannel(int channelType, int channelId, const std::string& message); void talkPrivate(int channelType, const std::string& receiver, const std::string& message); void openOutfitWindow(); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 31590375..69ace4b1 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -181,6 +181,14 @@ ItemPtr Tile::getGround() return nullptr; } +int Tile::getLookStackpos() +{ + // TODO: this needs to be improved + // check if thing has look property. + // check other floors + return m_things.size() - 1; +} + bool Tile::isWalkable() { if(!getGround()) @@ -257,11 +265,6 @@ bool Tile::canCopyName() // TODO: /* -//Ranges for ID Creatures -#define PLAYER_ID_RANGE 0x10000000 -#define MONSTER_ID_RANGE 0x40000000 -#define NPC_ID_RANGE 0x80000000 - Get menu options diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index ecf54446..890f10c7 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -46,6 +46,7 @@ public: int getDrawElevation() { return m_drawElevation; } std::vector getCreatures(); ItemPtr getGround(); + int getLookStackpos(); bool isWalkable(); bool isFullGround(); bool isFullyOpaque(); diff --git a/src/otclient/net/protocolgame.h b/src/otclient/net/protocolgame.h index ab44ff79..366c9cd1 100644 --- a/src/otclient/net/protocolgame.h +++ b/src/otclient/net/protocolgame.h @@ -55,6 +55,7 @@ public: void sendTurnSouth(); void sendTurnWest(); void sendUseItem(const Position& position, int itemId, int stackpos, int index); + void sendLookAt(const Position& position, int thingId, int stackpos); void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message); void sendGetOutfit(); void sendSetOutfit(const Outfit& outfit); diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index dd0a2901..d58f58d1 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -1062,7 +1062,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) uint16 thingId = msg.getU16(); if(thingId == 0x0061 || thingId == 0x0062) { // add new creature - CreaturePtr creature = CreaturePtr(new Creature); + CreaturePtr creature; if(thingId == 0x0062) { //creature is known uint32 id = msg.getU32(); @@ -1070,19 +1070,29 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) CreaturePtr knownCreature = g_map.getCreatureById(id); if(knownCreature) creature = knownCreature; + else + logFatal("Server says creature is known, but its not on creatures list."); } else if(thingId == 0x0061) { //creature is not known uint32 removeId = msg.getU32(); uint32 id = msg.getU32(); std::string name = msg.getString(); - if(name.length() > 0) // every creature name must have a capital letter + if(name.length() > 0) // every creature name must start with a capital letter name[0] = toupper(name[0]); g_map.removeCreatureById(removeId); - if(m_localPlayer->getId() == id) + if(id == m_localPlayer->getId()) creature = m_localPlayer->asCreature(); + else if(id >= Otc::PlayerStartId && id < Otc::PlayerEndId) + creature = PlayerPtr(new Player)->asCreature(); + else if(id >= Otc::MonsterStartId && id < Otc::MonsterEndId) + creature = CreaturePtr(new Creature); + else if(id >= Otc::NpcStartId && id < Otc::NpcEndId) + creature = CreaturePtr(new Creature); + else + logFatal("creature id is invalid"); creature->setId(id); creature->setName(name); diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index ebd4b914..143d5220 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -168,6 +168,16 @@ void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpo send(oMsg); } +void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpos) +{ + OutputMessage oMsg; + oMsg.addU8(Otc::ClientLook); + addPosition(oMsg, position); + oMsg.addU16(thingId); + oMsg.addU8(stackpos); + send(oMsg); +} + void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message) { if(message.length() > 255 || message.length() <= 0) diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index aa3c47e5..4869a149 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -21,6 +21,7 @@ */ #include "uimap.h" +#include #include #include #include @@ -95,6 +96,8 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) animatedText->setColor(12); animatedText->setText("8"); g_map.addThing(animatedText, g_map.getCentralPosition()); + + g_game.look(tilePos); } }