From 94deb596ae86bfe453c9d88e85266caae26e3980 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 20 Jan 2012 01:42:11 +0100 Subject: Simplified and made generic the way the pickup is handled. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I also made the range be taken from the server type as for the pickup and npc talk ranges. Last but no least, I fixed the parameters sent with PGMSG_PICKUP to send the (item) position where to pickup at as described in the manaserv protocol. The pickup is still not 100% functional due certainly to two problems: 1. The client item coordinates might not be the exact same as in the server. 2. The client seems to try to pick up the item a bit too soon, probably for the reason given in 1. I'll investigate this in another patch. Reviewed-by: Thorbjørn Lindeijer, Erik Schilling. --- src/localplayer.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index efdcaa60..7ee5753f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -40,6 +40,7 @@ #include "gui/widgets/chattab.h" #include "net/chathandler.h" +#include "net/gamehandler.h" #include "net/guildhandler.h" #include "net/inventoryhandler.h" #include "net/net.h" @@ -133,20 +134,15 @@ void LocalPlayer::logic() { if (mTarget->getType() == ActorSprite::NPC) { - // NPCs are always in range - mTarget->setTargetType(TCT_IN_RANGE); + mTarget->setTargetType( + withinRange(mTarget, + Net::getGameHandler()->getNpcTalkRange()) ? + TCT_IN_RANGE : TCT_NORMAL); } else { - // Find whether target is in range - const int rangeX = abs(mTarget->getPosition().x - getPosition().x); - const int rangeY = abs(mTarget->getPosition().y - getPosition().y); - - const int attackRange = getAttackRange(); - const TargetCursorType targetType = rangeX > attackRange || - rangeY > attackRange ? - TCT_NORMAL : TCT_IN_RANGE; - mTarget->setTargetType(targetType); + mTarget->setTargetType(withinRange(mTarget, getAttackRange()) ? + TCT_IN_RANGE : TCT_NORMAL); if (!mTarget->isAlive()) stopAttack(); @@ -155,6 +151,12 @@ void LocalPlayer::logic() attack(mTarget, true); } } + else if (mPickUpTarget + && withinRange(mPickUpTarget, Net::getGameHandler()->getPickupRange())) + { + Net::getPlayerHandler()->pickUp(mPickUpTarget); + mPickUpTarget = 0; + } Being::logic(); } @@ -589,17 +591,14 @@ void LocalPlayer::pickUp(FloorItem *item) if (!item) return; - int dx = item->getTileX() - getTileX(); - int dy = item->getTileY() - getTileY(); - - if (dx * dx + dy * dy < 4) + if (withinRange(item, Net::getGameHandler()->getPickupRange())) { Net::getPlayerHandler()->pickUp(item); // We found it, so set the player direction to it // if the player does not move if (getDestination() == getPosition()) lookAt(item->getPosition()); - mPickUpTarget = NULL; + mPickUpTarget = 0; } else { @@ -694,7 +693,7 @@ void LocalPlayer::setDestination(int x, int y) Net::getPlayerHandler()->setDestination(x, y, mDirection); } - mPickUpTarget = NULL; + mPickUpTarget = 0; mKeepAttacking = false; } @@ -937,14 +936,15 @@ void LocalPlayer::setAttackRange(int range) } } -bool LocalPlayer::withinAttackRange(Being *target) +bool LocalPlayer::withinRange(Actor *target, int range) const { + if (!target || range < 0) + return false; + const Vector &targetPos = target->getPosition(); const Vector &pos = getPosition(); const int dx = abs(targetPos.x - pos.x); const int dy = abs(targetPos.y - pos.y); - const int range = getAttackRange(); - return !(dx > range || dy > range); } -- cgit v1.2.3-60-g2f50