diff --git a/src/client/creature.cpp b/src/client/creature.cpp index acd3f086..4bb814f5 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -483,14 +483,14 @@ void Creature::onDeath() callLuaField("onDeath"); } -void Creature::updateWalkAnimation(int totalPixelsWalked) +void Creature::updateWalkAnimation(int totalPixelsWalked, int stepDuration) { // update outfit animation if(m_outfit.getCategory() != ThingCategoryCreature) return; int footAnimPhases = getAnimationPhases() - 1; - int footDelay = getStepDuration(true) / 3; + int footDelay = stepDuration / 3; // Since mount is a different outfit we need to get the mount animation phases if(m_outfit.getMount() != 0) { ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory()); @@ -579,20 +579,20 @@ void Creature::nextWalkUpdate() m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { self->m_walkUpdateEvent = nullptr; self->nextWalkUpdate(); - }, getStepDuration() / 32); + }, getStepDuration(true) / Otc::TILE_PIXELS); } } void Creature::updateWalk() { - float walkTicksPerPixel = getStepDuration(true) / 32; - int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); + int stepDuration = getStepDuration(true); + int totalPixelsWalked = stepDuration ? std::min((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0; // needed for paralyze effect m_walkedPixels = std::max(m_walkedPixels, totalPixelsWalked); // update walk animation and offsets - updateWalkAnimation(totalPixelsWalked); + updateWalkAnimation(totalPixelsWalked, stepDuration); updateWalkOffset(m_walkedPixels); updateWalkingTile(); diff --git a/src/client/creature.h b/src/client/creature.h index b3fc0887..c2d689b4 100644 --- a/src/client/creature.h +++ b/src/client/creature.h @@ -135,7 +135,7 @@ public: virtual void onDeath(); protected: - virtual void updateWalkAnimation(int totalPixelsWalked); + virtual void updateWalkAnimation(int totalPixelsWalked, int stepDuration); virtual void updateWalkOffset(int totalPixelsWalked); void updateWalkingTile(); virtual void nextWalkUpdate(); diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 2d2e53b1..e354ef78 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -265,17 +265,16 @@ void LocalPlayer::updateWalkOffset(int totalPixelsWalked) void LocalPlayer::updateWalk() { - int stepDuration = getStepDuration(); - float walkTicksPerPixel = getStepDuration(true) / 32.0f; - int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); + int stepDuration = getStepDuration(true); + int totalPixelsWalked = stepDuration ? std::min((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0; // update walk animation and offsets - updateWalkAnimation(totalPixelsWalked); + updateWalkAnimation(totalPixelsWalked, stepDuration); updateWalkOffset(totalPixelsWalked); updateWalkingTile(); // terminate walk only when client and server side walk are completed - if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= stepDuration) + if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration()) terminateWalk(); }