| Attached Files | report [^] (1,348 bytes) 2010-06-30 22:08 [Show Content] [Hide Content]Latest Commit:
$ git log --pretty=oneline | head -n1
f1cab9c5ab1d36586ae1e0d1dae3f3d1483522b5 Make whisper responses from tmwAthena show up in correct tabs
Steps to Reproduce:
Connect two characters to the server.
Have one character drop an item and wait by it.
Have the second character stand a few tiles away and right-click the "Pick Up" action.
Before the second character has gotten to the item, have the first character pick it up.
Backtrace:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb6a166d0 (LWP 17982)]
0x00000000 in ?? ()
#0 0x00000000 in ?? ()
#1 0x0819e9f7 in LocalPlayer::pickUp (this=0x84381a0, item=0x8ce9540)
at localplayer.cpp:689
#2 0x081a3d99 in LocalPlayer::nextTile (this=0x84381a0, dir=0 '\0')
at localplayer.cpp:596
#3 0x081a435c in LocalPlayer::nextTile (this=0x84381a0) at localplayer.h:142
#4 0x0816fc8e in Being::logic (this=0x84381a0) at being.cpp:796
#5 0x081a40c5 in LocalPlayer::logic (this=0x84381a0) at localplayer.cpp:221
#6 0x0816c9d1 in ActorSpriteManager::logic (this=0x857b8e8)
at actorspritemanager.cpp:205
#7 0x08197005 in Game::logic (this=0x8451b50) at game.cpp:334
#8 0x081820ac in Client::exec (this=0xbfecb0f8) at client.cpp:515
#9 0x081a6b4b in main (argc=-1947891371, argv=0xbfecb294) at main.cpp:241
0001-Ironed-out-the-pickUp-handling.-Please-test.patch [^] (2,263 bytes) 2010-07-06 23:19 [Show Content] [Hide Content]From 3e2c241110c2dc0baaa7ec581f6779da4c85fac4 Mon Sep 17 00:00:00 2001
From: Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>
Date: Wed, 7 Jul 2010 01:18:24 +0200
Subject: [PATCH] Ironed out the pickUp handling. Please test!!
(Should) Resolve: Mana-Mantis #160
---
src/localplayer.cpp | 3 +++
src/net/manaserv/playerhandler.cpp | 13 ++++++++-----
src/net/tmwa/playerhandler.cpp | 7 +++++--
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 9606286..92623c0 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -686,6 +686,9 @@ void LocalPlayer::setInvItem(int index, int id, int amount)
void LocalPlayer::pickUp(FloorItem *item)
{
+ if (!item)
+ return;
+
int dx = item->getTileX() - (int) getPosition().x / 32;
int dy = item->getTileY() - (int) getPosition().y / 32;
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 60fa5b2..c2803ce 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -329,11 +329,14 @@ void PlayerHandler::increaseSkill(int skillId)
void PlayerHandler::pickUp(FloorItem *floorItem)
{
- int id = floorItem->getId();
- MessageOut msg(PGMSG_PICKUP);
- msg.writeInt16(id >> 16);
- msg.writeInt16(id & 0xFFFF);
- gameServerConnection->send(msg);
+ if (floorItem)
+ {
+ int id = floorItem->getId();
+ MessageOut msg(PGMSG_PICKUP);
+ msg.writeInt16(id >> 16);
+ msg.writeInt16(id & 0xFFFF);
+ gameServerConnection->send(msg);
+ }
}
void PlayerHandler::setDirection(char direction)
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index 26c7e92..735da08 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -582,8 +582,11 @@ void PlayerHandler::increaseSkill(int skillId)
void PlayerHandler::pickUp(FloorItem *floorItem)
{
- MessageOut outMsg(CMSG_ITEM_PICKUP);
- outMsg.writeInt32(floorItem->getId());
+ if (floorItem)
+ {
+ MessageOut outMsg(CMSG_ITEM_PICKUP);
+ outMsg.writeInt32(floorItem->getId());
+ }
}
void PlayerHandler::setDirection(char direction)
--
1.7.1
report2 [^] (1,369 bytes) 2010-07-07 05:27 [Show Content] [Hide Content]Latest Commit:
$ git log --pretty=oneline | head -n1
781cd3fdea06cf9da8548b00a5e7157fcec29a86 Ironed out the pickUp handling. Please test!!
Steps to Reproduce:
Connect two characters to the server.
Have one character drop an item and wait by it.
Have the second character stand a few tiles away and right-click the "Pick Up" action.
Before the second character has gotten to the item, have the first character pick it up.
Backtrace:
[Switching to Thread 0xb6a256d0 (LWP 12606)]
0x0819e9fc in LocalPlayer::pickUp (this=0x83c1988, item=0x85ed3e8)
at localplayer.cpp:692
692 int dx = item->getTileX() - (int) getPosition().x / 32;
#0 0x0819e9fc in LocalPlayer::pickUp (this=0x83c1988, item=0x85ed3e8)
at localplayer.cpp:692
#1 0x081a3da9 in LocalPlayer::nextTile (this=0x83c1988, dir=0 '\0')
at localplayer.cpp:596
#2 0x081a436c in LocalPlayer::nextTile (this=0x83c1988) at localplayer.h:142
#3 0x0816fc8e in Being::logic (this=0x83c1988) at being.cpp:796
#4 0x081a40d5 in LocalPlayer::logic (this=0x83c1988) at localplayer.cpp:221
#5 0x0816c9d1 in ActorSpriteManager::logic (this=0x85e9258)
at actorspritemanager.cpp:205
#6 0x08197005 in Game::logic (this=0x843e6d8) at game.cpp:334
#7 0x081820ac in Client::exec (this=0xbfeac288) at client.cpp:515
#8 0x081a6b5b in main (argc=-1947891371, argv=0xbfeac424) at main.cpp:241
0001-Fix-crash-in-picking-up-an-item-that-no-longer-exist.patch [^] (9,502 bytes) 2010-07-07 10:30 [Show Content] [Hide Content]From 7fbc89f495e359e78013a3f6ec628ba1054eeba7 Mon Sep 17 00:00:00 2001
From: remoitnane <remoit(DOT)nane(AT)gmail(DOT)com>
Date: Wed, 7 Jul 2010 03:23:28 -0700
Subject: [PATCH] Fix crash in picking up an item that no longer exists
Adds ActorSpriteListener to manage ActorSprite destruction as
recommended by Jaxad0127. This likewise includes the changes made by
Bertram.
Mantis Issue: 160
---
mana.cbp | 1 +
mana.files | 1 +
src/CMakeLists.txt | 1 +
src/Makefile.am | 1 +
src/actorsprite.cpp | 16 +++++++++++++
src/actorsprite.h | 16 +++++++++++++
src/actorspritelistener.h | 42 ++++++++++++++++++++++++++++++++++++
src/localplayer.cpp | 11 +++++++++
src/localplayer.h | 8 ++++++-
src/net/manaserv/playerhandler.cpp | 13 ++++++----
src/net/tmwa/playerhandler.cpp | 7 ++++-
11 files changed, 109 insertions(+), 8 deletions(-)
create mode 100644 src/actorspritelistener.h
diff --git a/mana.cbp b/mana.cbp
index 3416db7..692e3a7 100644
--- a/mana.cbp
+++ b/mana.cbp
@@ -98,6 +98,7 @@
<Unit filename="src\actor.h" />
<Unit filename="src\actorsprite.cpp" />
<Unit filename="src\actorsprite.h" />
+ <Unit filename="src\actorspritelistener.h" />
<Unit filename="src\actorspritemanager.cpp" />
<Unit filename="src\actorspritemanager.h" />
<Unit filename="src\animatedsprite.cpp" />
diff --git a/mana.files b/mana.files
index d27ca32..966e871 100644
--- a/mana.files
+++ b/mana.files
@@ -42,6 +42,7 @@
./src/actor.h
./src/actorsprite.cpp
./src/actorsprite.h
+./src/actorspritelistener.h
./src/actorspritemanager.cpp
./src/actorspritemanager.h
./src/animatedsprite.cpp
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2df9ef4..a3312b6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -406,6 +406,7 @@ SET(SRCS
actor.h
actorsprite.cpp
actorsprite.h
+ actorspritelistener.h
actorspritemanager.cpp
actorspritemanager.h
animatedsprite.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b18b69..2867257 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -305,6 +305,7 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \
actor.h \
actorsprite.cpp \
actorsprite.h \
+ actorspritelistener.h \
actorspritemanager.cpp \
actorspritemanager.h \
animatedsprite.cpp \
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp
index 13b7abf..6a1dcbc 100644
--- a/src/actorsprite.cpp
+++ b/src/actorsprite.cpp
@@ -19,6 +19,7 @@
*/
#include "actorsprite.h"
+#include "actorspritelistener.h"
#include "client.h"
#include "effectmanager.h"
@@ -64,6 +65,11 @@ ActorSprite::~ActorSprite()
if (player_node && player_node->getTarget() == this)
player_node->setTarget(NULL);
+
+ // Notify listeners of the destruction.
+ for (ActorSpriteListenerIterator iter = mActorSpriteListeners.begin(),
+ end = mActorSpriteListeners.end(); iter != end; ++iter)
+ (*iter)->actorSpriteDestroyed(*this);
}
bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const
@@ -358,6 +364,16 @@ void ActorSprite::unload()
loaded = false;
}
+void ActorSprite::addActorSpriteListener(ActorSpriteListener *listener)
+{
+ mActorSpriteListeners.push_front(listener);
+}
+
+void ActorSprite::removeActorSpriteListener(ActorSpriteListener *listener)
+{
+ mActorSpriteListeners.remove(listener);
+}
+
static const char *cursorType(int type)
{
switch (type)
diff --git a/src/actorsprite.h b/src/actorsprite.h
index e218ef7..7cc91c5 100644
--- a/src/actorsprite.h
+++ b/src/actorsprite.h
@@ -29,9 +29,11 @@
#include <SDL_types.h>
#include <set>
+#include <list>
class SimpleAnimation;
class StatusEffect;
+class ActorSpriteListener;
class ActorSprite : public CompoundSprite, public Actor
{
@@ -160,6 +162,16 @@ public:
static void unload();
+ /**
+ * Add an ActorSprite listener.
+ */
+ void addActorSpriteListener(ActorSpriteListener *listener);
+
+ /**
+ * Remove an ActorSprite listener.
+ */
+ void removeActorSpriteListener(ActorSpriteListener *listener);
+
protected:
/**
* Trigger visual effect, with components
@@ -227,6 +239,10 @@ private:
/** Target cursor being used */
SimpleAnimation *mUsedTargetCursor;
+
+ typedef std::list<ActorSpriteListener*> ActorSpriteListeners;
+ typedef ActorSpriteListeners::iterator ActorSpriteListenerIterator;
+ ActorSpriteListeners mActorSpriteListeners;
};
#endif // ACTORSPRITE_H
diff --git a/src/actorspritelistener.h b/src/actorspritelistener.h
new file mode 100644
index 0000000..994494f
--- /dev/null
+++ b/src/actorspritelistener.h
@@ -0,0 +1,42 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2010 The Mana Developers
+ *
+ * This file is part of The Mana Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ACTORSPRITELISTENER_H
+#define ACTORSPRITELISTENER_H
+
+class ActorSprite;
+
+class ActorSpriteListener
+{
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~ActorSpriteListener() {}
+
+ /**
+ * Called when the ActorSprite has been destroyed. The listener will
+ * have to be registered first.
+ * @param actorSprite the ActorSprite being destroyed.
+ */
+ virtual void actorSpriteDestroyed(const ActorSprite &actorSprite) = 0;
+};
+
+#endif // ACTORSPRITELISTENER_H
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 9606286..15047f5 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -686,6 +686,9 @@ void LocalPlayer::setInvItem(int index, int id, int amount)
void LocalPlayer::pickUp(FloorItem *item)
{
+ if (!item)
+ return;
+
int dx = item->getTileX() - (int) getPosition().x / 32;
int dy = item->getTileY() - (int) getPosition().y / 32;
@@ -700,16 +703,24 @@ void LocalPlayer::pickUp(FloorItem *item)
{
setDestination(item->getPixelX() + 16, item->getPixelY() + 16);
mPickUpTarget = item;
+ mPickUpTarget->addActorSpriteListener(this);
}
else
{
setDestination(item->getTileX(), item->getTileY());
mPickUpTarget = item;
+ mPickUpTarget->addActorSpriteListener(this);
stopAttack();
}
}
}
+void LocalPlayer::actorSpriteDestroyed(const ActorSprite &actorSprite)
+{
+ if (mPickUpTarget == &actorSprite)
+ mPickUpTarget = 0;
+}
+
Being *LocalPlayer::getTarget() const
{
return mTarget;
diff --git a/src/localplayer.h b/src/localplayer.h
index a7ed33f..95a5402 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -23,6 +23,7 @@
#define LOCALPLAYER_H
#include "being.h"
+#include "actorspritelistener.h"
#include "gui/userpalette.h"
@@ -109,7 +110,7 @@ enum
/**
* The local player character.
*/
-class LocalPlayer : public Being
+class LocalPlayer : public Being, public ActorSpriteListener
{
public:
/**
@@ -164,6 +165,11 @@ class LocalPlayer : public Being
void pickUp(FloorItem *item);
/**
+ * Called when the pick up target has been destroyed.
+ */
+ void actorSpriteDestroyed(const ActorSprite &actorSprite);
+
+ /**
* Sets the attack range.
*/
void setAttackRange(int range) { mAttackRange = range; }
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 60fa5b2..c6554cf 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -329,11 +329,14 @@ void PlayerHandler::increaseSkill(int skillId)
void PlayerHandler::pickUp(FloorItem *floorItem)
{
- int id = floorItem->getId();
- MessageOut msg(PGMSG_PICKUP);
- msg.writeInt16(id >> 16);
- msg.writeInt16(id & 0xFFFF);
- gameServerConnection->send(msg);
+ if (flooritem)
+ {
+ int id = floorItem->getId();
+ MessageOut msg(PGMSG_PICKUP);
+ msg.writeInt16(id >> 16);
+ msg.writeInt16(id & 0xFFFF);
+ gameServerConnection->send(msg);
+ }
}
void PlayerHandler::setDirection(char direction)
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index 26c7e92..d2bea45 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -582,8 +582,11 @@ void PlayerHandler::increaseSkill(int skillId)
void PlayerHandler::pickUp(FloorItem *floorItem)
{
- MessageOut outMsg(CMSG_ITEM_PICKUP);
- outMsg.writeInt32(floorItem->getId());
+ if (flooritem)
+ {
+ MessageOut outMsg(CMSG_ITEM_PICKUP);
+ outMsg.writeInt32(floorItem->getId());
+ }
}
void PlayerHandler::setDirection(char direction)
--
1.5.4.3
0002-Fix-crash-in-picking-up-an-item-that-no-longer-exist.patch [^] (9,562 bytes) 2010-07-07 11:06 [Show Content] [Hide Content]From 6f37219efdff91b866865710964ce535cb8c2abb Mon Sep 17 00:00:00 2001
From: remoitnane <remoit(DOT)nane(AT)gmail(DOT)com>
Date: Wed, 7 Jul 2010 03:59:33 -0700
Subject: [PATCH] Fix crash in picking up an item that no longer exists
Adds ActorSpriteListener to manage ActorSprite destruction as
recommended by Jaxad0127. This likewise includes the changes made by
Bertram.
Mantis Issue: 160
---
mana.cbp | 1 +
mana.files | 1 +
src/CMakeLists.txt | 1 +
src/Makefile.am | 1 +
src/actorsprite.cpp | 16 +++++++++++++
src/actorsprite.h | 16 +++++++++++++
src/actorspritelistener.h | 42 ++++++++++++++++++++++++++++++++++++
src/localplayer.cpp | 11 +++++++++
src/localplayer.h | 9 ++++++-
src/net/manaserv/playerhandler.cpp | 13 ++++++----
src/net/tmwa/playerhandler.cpp | 7 ++++-
11 files changed, 110 insertions(+), 8 deletions(-)
create mode 100644 src/actorspritelistener.h
diff --git a/mana.cbp b/mana.cbp
index 3416db7..692e3a7 100644
--- a/mana.cbp
+++ b/mana.cbp
@@ -98,6 +98,7 @@
<Unit filename="src\actor.h" />
<Unit filename="src\actorsprite.cpp" />
<Unit filename="src\actorsprite.h" />
+ <Unit filename="src\actorspritelistener.h" />
<Unit filename="src\actorspritemanager.cpp" />
<Unit filename="src\actorspritemanager.h" />
<Unit filename="src\animatedsprite.cpp" />
diff --git a/mana.files b/mana.files
index d27ca32..966e871 100644
--- a/mana.files
+++ b/mana.files
@@ -42,6 +42,7 @@
./src/actor.h
./src/actorsprite.cpp
./src/actorsprite.h
+./src/actorspritelistener.h
./src/actorspritemanager.cpp
./src/actorspritemanager.h
./src/animatedsprite.cpp
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2df9ef4..a3312b6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -406,6 +406,7 @@ SET(SRCS
actor.h
actorsprite.cpp
actorsprite.h
+ actorspritelistener.h
actorspritemanager.cpp
actorspritemanager.h
animatedsprite.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b18b69..2867257 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -305,6 +305,7 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \
actor.h \
actorsprite.cpp \
actorsprite.h \
+ actorspritelistener.h \
actorspritemanager.cpp \
actorspritemanager.h \
animatedsprite.cpp \
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp
index 13b7abf..6a1dcbc 100644
--- a/src/actorsprite.cpp
+++ b/src/actorsprite.cpp
@@ -19,6 +19,7 @@
*/
#include "actorsprite.h"
+#include "actorspritelistener.h"
#include "client.h"
#include "effectmanager.h"
@@ -64,6 +65,11 @@ ActorSprite::~ActorSprite()
if (player_node && player_node->getTarget() == this)
player_node->setTarget(NULL);
+
+ // Notify listeners of the destruction.
+ for (ActorSpriteListenerIterator iter = mActorSpriteListeners.begin(),
+ end = mActorSpriteListeners.end(); iter != end; ++iter)
+ (*iter)->actorSpriteDestroyed(*this);
}
bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const
@@ -358,6 +364,16 @@ void ActorSprite::unload()
loaded = false;
}
+void ActorSprite::addActorSpriteListener(ActorSpriteListener *listener)
+{
+ mActorSpriteListeners.push_front(listener);
+}
+
+void ActorSprite::removeActorSpriteListener(ActorSpriteListener *listener)
+{
+ mActorSpriteListeners.remove(listener);
+}
+
static const char *cursorType(int type)
{
switch (type)
diff --git a/src/actorsprite.h b/src/actorsprite.h
index e218ef7..7cc91c5 100644
--- a/src/actorsprite.h
+++ b/src/actorsprite.h
@@ -29,9 +29,11 @@
#include <SDL_types.h>
#include <set>
+#include <list>
class SimpleAnimation;
class StatusEffect;
+class ActorSpriteListener;
class ActorSprite : public CompoundSprite, public Actor
{
@@ -160,6 +162,16 @@ public:
static void unload();
+ /**
+ * Add an ActorSprite listener.
+ */
+ void addActorSpriteListener(ActorSpriteListener *listener);
+
+ /**
+ * Remove an ActorSprite listener.
+ */
+ void removeActorSpriteListener(ActorSpriteListener *listener);
+
protected:
/**
* Trigger visual effect, with components
@@ -227,6 +239,10 @@ private:
/** Target cursor being used */
SimpleAnimation *mUsedTargetCursor;
+
+ typedef std::list<ActorSpriteListener*> ActorSpriteListeners;
+ typedef ActorSpriteListeners::iterator ActorSpriteListenerIterator;
+ ActorSpriteListeners mActorSpriteListeners;
};
#endif // ACTORSPRITE_H
diff --git a/src/actorspritelistener.h b/src/actorspritelistener.h
new file mode 100644
index 0000000..994494f
--- /dev/null
+++ b/src/actorspritelistener.h
@@ -0,0 +1,42 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2010 The Mana Developers
+ *
+ * This file is part of The Mana Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ACTORSPRITELISTENER_H
+#define ACTORSPRITELISTENER_H
+
+class ActorSprite;
+
+class ActorSpriteListener
+{
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~ActorSpriteListener() {}
+
+ /**
+ * Called when the ActorSprite has been destroyed. The listener will
+ * have to be registered first.
+ * @param actorSprite the ActorSprite being destroyed.
+ */
+ virtual void actorSpriteDestroyed(const ActorSprite &actorSprite) = 0;
+};
+
+#endif // ACTORSPRITELISTENER_H
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 9606286..15047f5 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -686,6 +686,9 @@ void LocalPlayer::setInvItem(int index, int id, int amount)
void LocalPlayer::pickUp(FloorItem *item)
{
+ if (!item)
+ return;
+
int dx = item->getTileX() - (int) getPosition().x / 32;
int dy = item->getTileY() - (int) getPosition().y / 32;
@@ -700,16 +703,24 @@ void LocalPlayer::pickUp(FloorItem *item)
{
setDestination(item->getPixelX() + 16, item->getPixelY() + 16);
mPickUpTarget = item;
+ mPickUpTarget->addActorSpriteListener(this);
}
else
{
setDestination(item->getTileX(), item->getTileY());
mPickUpTarget = item;
+ mPickUpTarget->addActorSpriteListener(this);
stopAttack();
}
}
}
+void LocalPlayer::actorSpriteDestroyed(const ActorSprite &actorSprite)
+{
+ if (mPickUpTarget == &actorSprite)
+ mPickUpTarget = 0;
+}
+
Being *LocalPlayer::getTarget() const
{
return mTarget;
diff --git a/src/localplayer.h b/src/localplayer.h
index a7ed33f..403b453 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -23,6 +23,7 @@
#define LOCALPLAYER_H
#include "being.h"
+#include "actorspritelistener.h"
#include "gui/userpalette.h"
@@ -109,7 +110,7 @@ enum
/**
* The local player character.
*/
-class LocalPlayer : public Being
+class LocalPlayer : public Being, public ActorSpriteListener
{
public:
/**
@@ -164,6 +165,12 @@ class LocalPlayer : public Being
void pickUp(FloorItem *item);
/**
+ * Called when an ActorSprite has been destroyed.
+ * @param actorSprite the ActorSprite being destroyed.
+ */
+ void actorSpriteDestroyed(const ActorSprite &actorSprite);
+
+ /**
* Sets the attack range.
*/
void setAttackRange(int range) { mAttackRange = range; }
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 60fa5b2..c2803ce 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -329,11 +329,14 @@ void PlayerHandler::increaseSkill(int skillId)
void PlayerHandler::pickUp(FloorItem *floorItem)
{
- int id = floorItem->getId();
- MessageOut msg(PGMSG_PICKUP);
- msg.writeInt16(id >> 16);
- msg.writeInt16(id & 0xFFFF);
- gameServerConnection->send(msg);
+ if (floorItem)
+ {
+ int id = floorItem->getId();
+ MessageOut msg(PGMSG_PICKUP);
+ msg.writeInt16(id >> 16);
+ msg.writeInt16(id & 0xFFFF);
+ gameServerConnection->send(msg);
+ }
}
void PlayerHandler::setDirection(char direction)
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index 26c7e92..735da08 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -582,8 +582,11 @@ void PlayerHandler::increaseSkill(int skillId)
void PlayerHandler::pickUp(FloorItem *floorItem)
{
- MessageOut outMsg(CMSG_ITEM_PICKUP);
- outMsg.writeInt32(floorItem->getId());
+ if (floorItem)
+ {
+ MessageOut outMsg(CMSG_ITEM_PICKUP);
+ outMsg.writeInt32(floorItem->getId());
+ }
}
void PlayerHandler::setDirection(char direction)
--
1.5.4.3
|