diff --git a/TODO b/TODO index 19518818..2f8814f7 100644 --- a/TODO +++ b/TODO @@ -86,3 +86,6 @@ [baxnie] edit texts [baxnie] ignore list [baxnie] viplist marks +[baxnie] fix walk jump when cancel creature following +[baxnie] fix creature outfit when invisible or with item appearance + diff --git a/modules/game/thing.lua b/modules/game/thing.lua index c4e26026..32854d95 100644 --- a/modules/game/thing.lua +++ b/modules/game/thing.lua @@ -30,22 +30,24 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) end if creatureThing then - menu:addSeparator() if creatureThing:asLocalPlayer() then menu:addOption('Set Outfit', function() Game.openOutfitWindow() end) else - if Game.getAttackingCreature() ~= creatureThing then - menu:addOption('Attack', function() Game.attack(creatureThing) end) - else - menu:addOption('Stop Attack', function() Game.cancelAttack() end) - end - - if Game.getFollowingCreature() ~= creatureThing then - menu:addOption('Follow', function() Game.follow(creatureThing) end) - else - menu:addOption('Stop Follow', function() Game.cancelFollow() end) + local localPlayer = Game.getLocalPlayer() + if localPlayer then + if localPlayer:getAttackingCreature() ~= creatureThing then + menu:addOption('Attack', function() Game.attack(creatureThing) end) + else + menu:addOption('Stop Attack', function() Game.cancelAttack() end) + end + + if localPlayer:getFollowingCreature() ~= creatureThing then + menu:addOption('Follow', function() Game.follow(creatureThing) end) + else + menu:addOption('Stop Follow', function() Game.cancelFollow() end) + end end if creatureThing:asPlayer() then diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 4e652a55..794c603f 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -116,18 +116,19 @@ void Game::processInventoryChange(int slot, const ItemPtr& item) void Game::processAttackCancel() { - if(m_attackingCreature) { - m_attackingCreature->hideStaticSquare(); - m_attackingCreature = nullptr; - } + if(m_localPlayer->isAttacking()) + m_localPlayer->setAttackingCreature(nullptr); } void Game::walk(Otc::Direction direction) { - if(!isOnline() || isDead() || !checkBotProtection() || !m_localPlayer->canWalk(direction)) + if(m_localPlayer->isFollowing()) { + cancelFollow(); return; + } - cancelFollow(); + if(!isOnline() || isDead() || !checkBotProtection() || !m_localPlayer->canWalk(direction)) + return; m_localPlayer->clientWalk(direction); @@ -205,22 +206,17 @@ void Game::attack(const CreaturePtr& creature) if(!m_online || !creature || !checkBotProtection()) return; - if(m_attackingCreature) - m_attackingCreature->hideStaticSquare(); - - creature->showStaticSquare(Fw::red); - m_attackingCreature = creature; + if(m_localPlayer->isFollowing()) + cancelFollow(); + m_localPlayer->setAttackingCreature(creature); m_protocolGame->sendAttack(creature->getId()); } void Game::cancelAttack() { - if(m_attackingCreature) { - m_protocolGame->sendAttack(0); - m_attackingCreature->hideStaticSquare(); - m_attackingCreature = nullptr; - } + m_localPlayer->setAttackingCreature(nullptr); + m_protocolGame->sendAttack(0); } void Game::follow(const CreaturePtr& creature) @@ -228,22 +224,17 @@ void Game::follow(const CreaturePtr& creature) if(!m_online || !creature || !checkBotProtection()) return; - if(m_followingCreature) - m_followingCreature->hideStaticSquare(); - - creature->showStaticSquare(Fw::green); - m_followingCreature = creature; + if(m_localPlayer->isAttacking()) + cancelAttack(); + m_localPlayer->setFollowingCreature(creature); m_protocolGame->sendFollow(creature->getId()); } void Game::cancelFollow() { - if(m_followingCreature) { - m_protocolGame->sendFollow(0); - m_followingCreature->hideStaticSquare(); - m_followingCreature = nullptr; - } + m_localPlayer->setFollowingCreature(nullptr); + m_protocolGame->sendFollow(0); } void Game::rotate(const ThingPtr& thing) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index dcda5f77..1753d097 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -70,9 +70,6 @@ public: bool checkBotProtection(); - CreaturePtr getAttackingCreature() { return m_attackingCreature; } - CreaturePtr getFollowingCreature() { return m_followingCreature; } - bool isOnline() { return m_online; } bool isDead() { return m_dead; } @@ -89,7 +86,7 @@ private: bool m_dead; int m_serverBeat; - CreaturePtr m_attackingCreature, m_followingCreature; + }; extern Game g_game; diff --git a/src/otclient/core/localplayer.cpp b/src/otclient/core/localplayer.cpp index b1eb5a4b..e58312fd 100644 --- a/src/otclient/core/localplayer.cpp +++ b/src/otclient/core/localplayer.cpp @@ -107,3 +107,29 @@ bool LocalPlayer::canWalk(Otc::Direction direction) return true; } + +void LocalPlayer::setAttackingCreature(const CreaturePtr& creature) +{ + if(m_attackingCreature) { + m_attackingCreature->hideStaticSquare(); + m_attackingCreature = nullptr; + } + + if(creature) { + creature->showStaticSquare(Fw::red); + m_attackingCreature = creature; + } +} + +void LocalPlayer::setFollowingCreature(const CreaturePtr& creature) +{ + if(m_followingCreature) { + m_followingCreature->hideStaticSquare(); + m_followingCreature = nullptr; + } + + if(creature) { + creature->showStaticSquare(Fw::green); + m_followingCreature = creature; + } +} diff --git a/src/otclient/core/localplayer.h b/src/otclient/core/localplayer.h index 543dd96c..321aa6e5 100644 --- a/src/otclient/core/localplayer.h +++ b/src/otclient/core/localplayer.h @@ -30,32 +30,37 @@ class LocalPlayer : public Player public: LocalPlayer(); - void setDrawSpeed(uint16 drawSpeed) { m_drawSpeed = drawSpeed; } - uint16 getDrawSpeed() { return m_drawSpeed; } - void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); } - bool getCanReportBugs() { return m_canReportBugs; } - void setSkill(Otc::Skill skill, Otc::SkillType skillType, int value) { m_skills[skill][skillType] = value; } - int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; } - void setStatistic(Otc::Statistic statistic, double value) { m_statistics[statistic] = value; } + void setAttackingCreature(const CreaturePtr& creature); + void setFollowingCreature(const CreaturePtr& creature); + void setIcons(int icons) { m_icons = icons; } + + bool getCanReportBugs() { return m_canReportBugs; } + int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; } double getStatistic(Otc::Statistic statistic) { return m_statistics[statistic]; } + CreaturePtr getAttackingCreature() { return m_attackingCreature; } + CreaturePtr getFollowingCreature() { return m_followingCreature; } + Otc::Direction getNextWalkDirection() { return m_nextWalkDirection; } + int getIcons() { return m_icons; } + + bool isAttacking() { return m_attackingCreature != nullptr; } + bool isFollowing() { return m_followingCreature != nullptr; } void clientWalk(Otc::Direction direction); void walk(const Position& position, bool inverse); void cancelWalk(Otc::Direction direction, bool force = false); bool canWalk(Otc::Direction direction); - Otc::Direction getNextWalkDirection() { return m_nextWalkDirection; } LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast(shared_from_this()); } private: - uint16 m_drawSpeed; bool m_canReportBugs; bool m_clientWalking; Otc::Direction m_nextWalkDirection; - + CreaturePtr m_attackingCreature, m_followingCreature; + int m_icons; int m_skills[Otc::LastSkill][Otc::LastSkillType]; double m_statistics[Otc::LastStatistic]; }; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 84a2cfa7..f3554b6b 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -84,7 +84,11 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("setEmblemTexture", &Creature::setEmblemTexture); g_lua.registerClass(); + g_lua.registerClass(); + g_lua.bindClassMemberFunction("getAttackingCreature", &LocalPlayer::getAttackingCreature); + g_lua.bindClassMemberFunction("getFollowingCreature", &LocalPlayer::getFollowingCreature); + g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); @@ -106,11 +110,10 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("inviteToParty", std::bind(&Game::inviteToParty, &g_game, _1)); g_lua.bindClassStaticFunction("addVip", std::bind(&Game::addVip, &g_game, _1)); g_lua.bindClassStaticFunction("removeVip", std::bind(&Game::removeVip, &g_game, _1)); - g_lua.bindClassStaticFunction("getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game)); - g_lua.bindClassStaticFunction("getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game)); g_lua.bindClassStaticFunction("talk", std::bind(&Game::talk, &g_game, _1)); 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.bindClassStaticFunction("getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game)); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIItemPtr(new UIItem); } ); diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 972bceb5..6ee87420 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -265,13 +265,12 @@ void ProtocolGame::parseMessage(InputMessage& msg) void ProtocolGame::parsePlayerLogin(InputMessage& msg) { int playerId = msg.getU32(); - int playerDrawSpeed = msg.getU16(); + int serverBeat = msg.getU16(); int playerCanReportBugs = msg.getU8(); m_localPlayer = LocalPlayerPtr(new LocalPlayer); m_localPlayer->setId(playerId); - g_game.setServerBeat(playerDrawSpeed); - m_localPlayer->setDrawSpeed(playerDrawSpeed); + g_game.setServerBeat(serverBeat); m_localPlayer->setCanReportBugs(playerCanReportBugs); } @@ -536,7 +535,6 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg) EffectPtr effect = EffectPtr(new Effect()); effect->setId(effectId); - effect->setPos(pos); g_map.addThing(effect, pos); } @@ -548,7 +546,6 @@ void ProtocolGame::parseAnimatedText(InputMessage& msg) std::string text = msg.getString(); AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); - animatedText->setPos(position); animatedText->setColor(color); animatedText->setText(text); @@ -731,7 +728,8 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg) void ProtocolGame::parsePlayerIcons(InputMessage& msg) { - msg.getU16(); // icons + uint16 icons = msg.getU16(); + m_localPlayer->setIcons(icons); } void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg) diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 39f3c6c8..85576963 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -26,9 +26,8 @@ #include #include #include -#include +#include #include -#include UIMap::UIMap() { @@ -63,6 +62,9 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) // Get tile position Point relativeStretchMousePos = mousePos - m_mapRect.topLeft(); + LocalPlayerPtr localPlayer = g_game.getLocalPlayer(); + if(localPlayer) + relativeStretchMousePos += localPlayer->getWalkOffset(); Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS); PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height()); @@ -91,6 +93,11 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) if(button == Fw::MouseLeftButton) { g_game.look(tile->getTopLookThing()); + EffectPtr effect = EffectPtr(new Effect); + static int id = 0; + effect->setId(id++); + dump << id; + g_map.addThing(effect, tilePos); } else if(button == Fw::MouseRightButton) {