diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/gui.cpp | 4 | ||||
-rw-r--r-- | src/localplayer.cpp | 29 | ||||
-rw-r--r-- | src/localplayer.h | 2 |
3 files changed, 27 insertions, 8 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 491a4009..3d8d8a98 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -310,10 +310,6 @@ Gui::mousePress(int mx, int my, int button) // Pick up some item else if ((item = find_floor_item_by_cor(tilex, tiley))) { - int dx = tilex - player_node->x; - int dy = tiley - player_node->y; - - if ((dx * dx + dy * dy) < 4) player_node->pickUp(item); } // Just walk around 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); } diff --git a/src/localplayer.h b/src/localplayer.h index 56814e05..fe87fbab 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -49,6 +49,7 @@ class LocalPlayer : public Player void setNetwork(Network *network) { mNetwork = network; } virtual void logic(); + virtual void nextStep(); virtual Type getType() const; @@ -140,6 +141,7 @@ class LocalPlayer : public Player protected: Network *mNetwork; Being *mTarget; + FloorItem *mPickUpTarget; bool mTrading; }; |