From 8005fc32e41ad0e1e0d7161fc2c43ea00e9be137 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 8 Nov 2024 18:49:25 -0300 Subject: [PATCH 1/2] fix: walk double step --- src/client/creature.cpp | 4 --- src/client/creature.h | 4 --- src/client/game.cpp | 59 +++++++++++++++-------------------------- src/client/game.h | 2 +- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/src/client/creature.cpp b/src/client/creature.cpp index c6bc9ae44..b69cf2490 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -392,9 +392,6 @@ void Creature::walk(const Position& oldPos, const Position& newPos) m_walkTimer.restart(); m_walkedPixels = 0; - if (++m_walkSteps == 0) - m_walkSteps = 1; - // no direction need to be changed when the walk ends m_walkTurnDirection = Otc::InvalidDirection; @@ -701,7 +698,6 @@ void Creature::terminateWalk() const auto self = static_self_cast(); m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] { - self->m_walkSteps = 0; self->m_walkAnimationPhase = 0; self->m_walkFinishAnimEvent = nullptr; }, g_game.getServerBeat()); diff --git a/src/client/creature.h b/src/client/creature.h index 195be8a16..e806eb303 100644 --- a/src/client/creature.h +++ b/src/client/creature.h @@ -94,8 +94,6 @@ class Creature : public Thing void hideStaticSquare() { m_showStaticSquare = false; } // walk related - int getWalkSteps() const { return m_walkSteps; } - void setWalkSteps(uint8_t step) { m_walkSteps = step; } void turn(Otc::Direction direction); void jump(int height, int duration); void allowAppearWalk() { m_allowAppearWalk = true; } @@ -294,8 +292,6 @@ class Creature : public Thing uint8_t m_disableWalkAnimation{ 0 }; - uint8_t m_walkSteps{ 0 }; - // Mount Shader uint8_t m_mountShaderId{ 0 }; diff --git a/src/client/game.cpp b/src/client/game.cpp index 07e41fe38..ce86500c4 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -630,19 +630,9 @@ void Game::safeLogout() m_protocolGame->sendLogout(); } -bool Game::walk(const Otc::Direction direction, bool force) +bool Game::walk(const Otc::Direction direction) { - static ScheduledEventPtr nextWalkSchedule = nullptr; - - if (direction == Otc::InvalidDirection) { - if (nextWalkSchedule) { - nextWalkSchedule->cancel(); - nextWalkSchedule = nullptr; - } - return false; - } - - if (!canPerformGameAction()) + if (!canPerformGameAction() || direction == Otc::InvalidDirection) return false; // must cancel auto walking, and wait next try @@ -652,39 +642,32 @@ bool Game::walk(const Otc::Direction direction, bool force) return false; } - if (!force) { - if (nextWalkSchedule) - return false; + static ScheduledEventPtr nextWalkSchedule = nullptr; + static uint16_t steps = 0; + static Timer timer; - if (m_localPlayer->getWalkSteps() > 0) { - uint16_t delay = 0; - if (m_localPlayer->getWalkSteps() == 1) { - if (m_localPlayer->isWalking()) - return false; - - delay = m_walkFirstStepDelay; - } else if (direction != m_localPlayer->getDirection()) - delay = m_walkTurnDelay; - - if (delay > 0) { - nextWalkSchedule = g_dispatcher.scheduleEvent([this, direction] { - if (m_localPlayer) { - m_localPlayer->setWalkSteps(1); - walk(direction, true); - } - - nextWalkSchedule = nullptr; - }, delay); - return false; - } - } - } + if (nextWalkSchedule) nextWalkSchedule->cancel(); + nextWalkSchedule = g_dispatcher.scheduleEvent([this] { + nextWalkSchedule = nullptr; + steps = 0; + }, 150); // check we can walk and add new walk event if false if (!m_localPlayer->canWalk(direction)) { return false; } + if (steps == 1) { + if (timer.ticksElapsed() <= m_walkFirstStepDelay) + return false; + } else if (direction != m_localPlayer->getDirection()) { + if (timer.ticksElapsed() <= m_walkTurnDelay) + return false; + } + + ++steps; + timer.restart(); + const auto& toPos = m_localPlayer->getPosition().translatedToDirection(direction); // only do prewalks to walkable tiles (like grounds and not walls) diff --git a/src/client/game.h b/src/client/game.h index 53fe2b620..500bbe0f8 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -541,7 +541,7 @@ class Game void safeLogout(); // walk related - bool walk(const Otc::Direction direction, bool force = false); + bool walk(const Otc::Direction direction); void autoWalk(const std::vector& dirs, const Position& startPos); void forceWalk(const Otc::Direction direction); void turn(const Otc::Direction direction); From c3aace1ccea0a80fb93f94513abeea147d03a407 Mon Sep 17 00:00:00 2001 From: kokekanon <114332266+kokekanon@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:18:54 -0300 Subject: [PATCH 2/2] fix: trade between players in canary 13.40 (#965) --- src/client/protocolcodes.h | 1 + src/client/protocolgame.h | 1 + src/client/protocolgameparse.cpp | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/src/client/protocolcodes.h b/src/client/protocolcodes.h index 957a07ffc..46e0c0e88 100644 --- a/src/client/protocolcodes.h +++ b/src/client/protocolcodes.h @@ -117,6 +117,7 @@ namespace Proto GameServerMissleEffect = 133, // Anthem on 13.x GameServerItemClasses = 134, GameServerTrappers = 135, + GameServerCloseForgeWindow = 137, GameServerCreatureData = 139, GameServerCreatureHealth = 140, GameServerCreatureLight = 141, diff --git a/src/client/protocolgame.h b/src/client/protocolgame.h index 3549e9bc2..2444df226 100644 --- a/src/client/protocolgame.h +++ b/src/client/protocolgame.h @@ -231,6 +231,7 @@ class ProtocolGame : public Protocol void parseCreatureMark(const InputMessagePtr& msg); void parseTrappers(const InputMessagePtr& msg); void addCreatureIcon(const InputMessagePtr& msg); + void parseCloseForgeWindow(const InputMessagePtr& msg); void parseCreatureData(const InputMessagePtr& msg); void parseCreatureHealth(const InputMessagePtr& msg); void parseCreatureLight(const InputMessagePtr& msg); diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index 27ebb7c5d..caf257752 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -267,6 +267,9 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerTrappers: parseTrappers(msg); break; + case Proto::GameServerCloseForgeWindow: + parseCloseForgeWindow(msg); + break; case Proto::GameServerCreatureData: parseCreatureData(msg); break; @@ -1844,6 +1847,11 @@ void ProtocolGame::addCreatureIcon(const InputMessagePtr& msg) // TODO: implement creature icons usage } +void ProtocolGame::parseCloseForgeWindow(const InputMessagePtr& /*msg*/) +{ + g_lua.callGlobalField("g_game", "onCloseForgeCloseWindows"); +} + void ProtocolGame::parseCreatureData(const InputMessagePtr& msg) { const uint32_t creatureId = msg->getU32();