diff options
-rw-r--r-- | src/being.cpp | 4 | ||||
-rw-r--r-- | src/net/tmwa/beinghandler.cpp | 53 |
2 files changed, 42 insertions, 15 deletions
diff --git a/src/being.cpp b/src/being.cpp index 86bebea2..fc2f2f2d 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -770,10 +770,6 @@ void Being::logic() ActorSprite::logic(); - int frameCount = getFrameCount(); - if (frameCount < 10) - frameCount = 10; - // Remove it after 3 secs. TODO: Just play the dead animation before removing if (!isAlive() && Net::getGameHandler()->removeDeadBeings() && get_elapsed_time(mActionTime) > 3000) diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index ddb15428..40c1107b 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -39,9 +39,13 @@ #include "resources/emotedb.h" #include <iostream> +#include <cmath> namespace TmwAthena { +// Number of pixels where we decide that the position doesn't need to be reset. +static const float POS_DEST_DIFF_TOLERANCE = 48.0f; + BeingHandler::BeingHandler(bool enableSync): mSync(enableSync) { @@ -215,10 +219,17 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) dstBeing->setAction(Being::STAND); Vector pos(srcX * tileWidth + tileWidth / 2, srcY * tileHeight + tileHeight / 2); - dstBeing->setPosition(pos); - // We turn the destination back to a pixel one. + dstX = dstX * tileWidth + tileWidth / 2; dstY = dstY * tileHeight + tileHeight / 2; + // Don't set the position as the movement algorithm can guess + // it and it would break the animation played, when we're + // close enough. + if (std::abs((float)dstX - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs((float)dstY - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + // We turn the destination back to a pixel one. dstBeing->setDestination(dstX, dstY); } else @@ -249,6 +260,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_BEING_MOVE2: + { /* * A simplified movement packet, used by the * later versions of eAthena for both mobs and @@ -269,11 +281,21 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) msg.readCoordinatePair(srcX, srcY, dstX, dstY); msg.readInt32(); // Server tick - dstBeing->setAction(Being::STAND); - dstBeing->setPosition(Vector(srcX * tileWidth + tileWidth / 2, - srcY * tileHeight + tileHeight / 2)); - dstBeing->setDestination(dstX * tileWidth + tileWidth / 2, - dstY * tileHeight + tileHeight / 2); + //dstBeing->setAction(Being::STAND); <-- Not needed anymore. + + Vector pos(srcX * tileWidth + tileWidth / 2, + srcY * tileHeight + tileHeight / 2); + Vector dest(dstX * tileWidth + tileWidth / 2, + dstY * tileHeight + tileHeight / 2); + // Don't set the position as the movement algorithm can guess + // it and it would break the animation played, when we're + // close enough. + if (std::abs((float)dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs((float)dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + dstBeing->setDestination(dest.x, dest.y); + } break; case SMSG_BEING_REMOVE: @@ -581,10 +603,19 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) { Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); - dstBeing->setPosition(Vector(srcX * tileWidth + tileWidth / 2, - srcY * tileHeight + tileHeight / 2)); - dstBeing->setDestination(dstX * tileWidth + tileWidth / 2, - dstY * tileHeight + tileHeight / 2); + Vector pos(srcX * tileWidth + tileWidth / 2, + srcY * tileHeight + tileHeight / 2); + Vector dest(dstX * tileWidth + tileWidth / 2, + dstY * tileHeight + tileHeight / 2); + + // Don't set the position as the movement algorithm can guess + // it and it would break the animation played, when we're + // close enough. + if (std::abs((float)dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs((float)dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + dstBeing->setDestination(dest.x, dest.y); } else { |