From 01527e389f5e07e044d074b44fbf2d2328e5ff90 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 8 Nov 2023 21:02:24 -0300 Subject: [PATCH 1/8] Update monster.cpp --- src/creatures/monsters/monster.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 97c18e6d855..3e6f7f87b33 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -601,6 +601,10 @@ void Monster::onFollowCreatureComplete(const std::shared_ptr &creature return; } + if (!hasFollowPath && creature == getAttackedCreature()) { + setAttackedCreature(nullptr); + } + auto it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); if (it == targetIDList.end()) { return; From 003e96c83eca45a45f52fd12e870f8d1596b3fed Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 8 Nov 2023 21:24:26 -0300 Subject: [PATCH 2/8] improve --- src/creatures/monsters/monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 3e6f7f87b33..e91830fc88f 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -601,7 +601,7 @@ void Monster::onFollowCreatureComplete(const std::shared_ptr &creature return; } - if (!hasFollowPath && creature == getAttackedCreature()) { + if (!hasFollowPath && creature == getAttackedCreature() && targetIDList.size() > 1) { setAttackedCreature(nullptr); } From bfadfa180e2d01c542ae5e4a950a5ff2d5634f6d Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 8 Nov 2023 21:51:23 -0300 Subject: [PATCH 3/8] improve --- src/creatures/monsters/monster.cpp | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index e91830fc88f..dd27f226f9a 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -601,24 +601,28 @@ void Monster::onFollowCreatureComplete(const std::shared_ptr &creature return; } - if (!hasFollowPath && creature == getAttackedCreature() && targetIDList.size() > 1) { - setAttackedCreature(nullptr); - } + const auto &it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); + if (it != targetIDList.end()) { + if (const auto &target = targetListMap[*it].lock()) { + targetIDList.erase(it); - auto it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); - if (it == targetIDList.end()) { - return; + if (hasFollowPath) { + targetIDList.push_front(target->getID()); + } else if (!isSummon()) { + targetIDList.push_back(target->getID()); + } else { + targetListMap.erase(target->getID()); + } + } } - if (const auto &target = targetListMap[*it].lock()) { - targetIDList.erase(it); - - if (hasFollowPath) { - targetIDList.push_front(target->getID()); - } else if (!isSummon()) { - targetIDList.push_back(target->getID()); - } else { - targetListMap.erase(target->getID()); + // Change the target if necessary + if (!hasFollowPath && !isSummon() && !targetIDList.empty() && targetIDList.front() != creature->getID()) { + const auto &it = targetListMap.find(targetIDList.front()); + if (it != targetListMap.end()) { + if (const auto &target = it->second.lock()) { + selectTarget(target); + } } } } From 997ea0643a6822d338193ff542b08a4d5543cdb5 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 8 Nov 2023 22:00:23 -0300 Subject: [PATCH 4/8] fix smell --- src/creatures/monsters/monster.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index dd27f226f9a..d29845864bd 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -618,9 +618,9 @@ void Monster::onFollowCreatureComplete(const std::shared_ptr &creature // Change the target if necessary if (!hasFollowPath && !isSummon() && !targetIDList.empty() && targetIDList.front() != creature->getID()) { - const auto &it = targetListMap.find(targetIDList.front()); - if (it != targetListMap.end()) { - if (const auto &target = it->second.lock()) { + const auto &itMap = targetListMap.find(targetIDList.front()); + if (itMap != targetListMap.end()) { + if (const auto &target = itMap->second.lock()) { selectTarget(target); } } From 2b9e0f57791d63a24aa0e28311c59615549ed203 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 8 Nov 2023 23:09:13 -0300 Subject: [PATCH 5/8] change target on logout --- src/creatures/monsters/monster.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index d29845864bd..3e00712b898 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -601,6 +601,10 @@ void Monster::onFollowCreatureComplete(const std::shared_ptr &creature return; } + if (hasFollowPath && creature->getPlayer() && creature->getPlayer()->getIP() == 0) { + hasFollowPath = false; + } + const auto &it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); if (it != targetIDList.end()) { if (const auto &target = targetListMap[*it].lock()) { From 031a87f5b4ab34fd61b242e168caf44254c2824f Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 9 Nov 2023 15:17:11 -0300 Subject: [PATCH 6/8] improve --- src/creatures/creature.cpp | 4 +++- src/creatures/monsters/monster.cpp | 4 ---- src/creatures/players/player.cpp | 8 -------- src/creatures/players/player.hpp | 9 ++++++++- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index c29fe9067ab..982a9bf92c5 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -1014,7 +1014,9 @@ void Creature::goToFollowCreature() { } } - if (listDir.empty()) { + if (followCreature->getPlayer() && followCreature->getPlayer()->isDisconnected()) { + hasFollowPath = false; + }else if (listDir.empty()) { hasFollowPath = getPathTo(getFollowCreature()->getPosition(), listDir, fpp); } diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 3e00712b898..d29845864bd 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -601,10 +601,6 @@ void Monster::onFollowCreatureComplete(const std::shared_ptr &creature return; } - if (hasFollowPath && creature->getPlayer() && creature->getPlayer()->getIP() == 0) { - hasFollowPath = false; - } - const auto &it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); if (it != targetIDList.end()) { if (const auto &target = targetListMap[*it].lock()) { diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index d26952bc54c..72002db7b4d 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -2548,14 +2548,6 @@ BlockType_t Player::blockHit(std::shared_ptr attacker, CombatType_t co return blockType; } -uint32_t Player::getIP() const { - if (client) { - return client->getIP(); - } - - return 0; -} - void Player::death(std::shared_ptr lastHitCreature) { loginPosition = town->getTemplePosition(); diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 418f8659e49..adf4b35c0ca 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -471,7 +471,14 @@ class Player final : public Creature, public Cylinder, public Bankable { client->disconnect(); } } - uint32_t getIP() const; + + uint32_t getIP() const { + return client ? client->getIP() : 0; + } + + bool isDisconnected() const { + return getIP() == 0; + } void addContainer(uint8_t cid, std::shared_ptr container); void closeContainer(uint8_t cid); From 582ad2cf5abe5905f0241ca78a28fc5e3f1dac83 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 9 Nov 2023 18:17:56 +0000 Subject: [PATCH 7/8] Code format - (Clang-format) --- src/creatures/creature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 982a9bf92c5..2ba0d7560f2 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -1016,7 +1016,7 @@ void Creature::goToFollowCreature() { if (followCreature->getPlayer() && followCreature->getPlayer()->isDisconnected()) { hasFollowPath = false; - }else if (listDir.empty()) { + } else if (listDir.empty()) { hasFollowPath = getPathTo(getFollowCreature()->getPosition(), listDir, fpp); } From 1c89bca8d509068de89a00c36121dde13f67dfdd Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 9 Nov 2023 18:25:27 -0300 Subject: [PATCH 8/8] Update creature.cpp --- src/creatures/creature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 2ba0d7560f2..e3b6d539ca4 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -1017,13 +1017,13 @@ void Creature::goToFollowCreature() { if (followCreature->getPlayer() && followCreature->getPlayer()->isDisconnected()) { hasFollowPath = false; } else if (listDir.empty()) { - hasFollowPath = getPathTo(getFollowCreature()->getPosition(), listDir, fpp); + hasFollowPath = getPathTo(followCreature->getPosition(), listDir, fpp); } startAutoWalk(listDir.data()); if (executeOnFollow) { - onFollowCreatureComplete(getFollowCreature()); + onFollowCreatureComplete(followCreature); } }