summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2006-02-05 04:18:35 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2006-02-05 04:18:35 +0000
commit3c8a29048703a6f830061c8bd0965adde4adb706 (patch)
treed860fdb3cd2924c343f34ca988ec01776284c0b3 /src/localplayer.cpp
parentcfc9ed654330452405cf4a107ec55e3bfa6137b0 (diff)
downloadmana-client-3c8a29048703a6f830061c8bd0965adde4adb706.tar.gz
mana-client-3c8a29048703a6f830061c8bd0965adde4adb706.tar.bz2
mana-client-3c8a29048703a6f830061c8bd0965adde4adb706.tar.xz
mana-client-3c8a29048703a6f830061c8bd0965adde4adb706.zip
Made the player walk to items prior to picking them up.
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index d76ebc30..1b3178e1 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -40,7 +40,7 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
Player(id, job, map),
mInventory(new Inventory()),
mEquipment(new Equipment()),
- mTarget(NULL),
+ mTarget(NULL), mPickUpTarget(NULL),
mTrading(false)
{
}
@@ -72,6 +72,14 @@ void LocalPlayer::logic()
Being::logic();
}
+void LocalPlayer::nextStep()
+{
+ if (mPath.empty() && mPickUpTarget) {
+ pickUp(mPickUpTarget);
+ }
+ Player::nextStep();
+}
+
Being::Type LocalPlayer::getType() const
{
return LOCALPLAYER;
@@ -138,9 +146,19 @@ void LocalPlayer::dropItem(Item *item, int quantity)
void LocalPlayer::pickUp(FloorItem *item)
{
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_ITEM_PICKUP);
- outMsg.writeInt32(item->getId());
+ int dx = item->getX() - x;
+ int dy = item->getY() - y;
+
+ if (dx * dx + dy * dy < 4) {
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_ITEM_PICKUP);
+ outMsg.writeInt32(item->getId());
+ mPickUpTarget = NULL;
+ } else {
+ setDestination(item->getX(), item->getY());
+ mPickUpTarget = item;
+ stopAttack();
+ }
}
void LocalPlayer::walk(Being::Direction dir)
@@ -228,6 +246,9 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y)
set_coordinates(temp, x, y, direction);
outMsg.writeInt16(0x0085);
outMsg.writeString(temp, 3);
+
+ mPickUpTarget = NULL;
+
Being::setDestination(x, y);
}