summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
Diffstat (limited to 'src/being')
-rw-r--r--src/being/localplayer.cpp56
-rw-r--r--src/being/localplayer.h8
-rw-r--r--src/being/playerinfo.cpp7
3 files changed, 38 insertions, 33 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index b75ee0ebd..ad26a15c2 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -96,6 +96,7 @@ extern SkillDialog *skillDialog;
LocalPlayer::LocalPlayer(const int id, const int subtype) :
Being(id, PLAYER, subtype, nullptr),
+ AttributeListener(),
mGMLevel(0),
mInvertDirection(0),
mCrazyMoveType(config.getIntValue("crazyMoveType")),
@@ -1029,33 +1030,7 @@ void LocalPlayer::processEvent(const Channels channel,
{
if (channel == CHANNEL_ATTRIBUTES)
{
- if (event.getName() == EVENT_UPDATEATTRIBUTE)
- {
- switch (event.getInt("id"))
- {
- case PlayerInfo::EXP:
- {
- if (event.getInt("oldValue") > event.getInt("newValue"))
- break;
-
- const int change = event.getInt("newValue")
- - event.getInt("oldValue");
-
- if (change != 0)
- {
- // TRANSLATORS: get xp message
- addMessageToQueue(strprintf("%d %s", change, _("xp")));
- }
- break;
- }
- case PlayerInfo::LEVEL:
- mLevel = event.getInt("newValue");
- break;
- default:
- break;
- };
- }
- else if (event.getName() == EVENT_UPDATESTAT)
+ if (event.getName() == EVENT_UPDATESTAT)
{
if (!mShowJobExp)
return;
@@ -1107,6 +1082,33 @@ void LocalPlayer::processEvent(const Channels channel,
}
}
+void LocalPlayer::attributeChanged(const int id,
+ const int oldVal,
+ const int newVal)
+{
+ switch (id)
+ {
+ case PlayerInfo::EXP:
+ {
+ if (oldVal > newVal)
+ break;
+
+ const int change = newVal - oldVal;
+ if (change != 0)
+ {
+ // TRANSLATORS: get xp message
+ addMessageToQueue(strprintf("%d %s", change, _("xp")));
+ }
+ break;
+ }
+ case PlayerInfo::LEVEL:
+ mLevel = newVal;
+ break;
+ default:
+ break;
+ }
+}
+
void LocalPlayer::moveTo(const int x, const int y)
{
setDestination(x, y);
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index 280e245cd..ecf118799 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -31,6 +31,7 @@
#include "listeners/actionlistener.h"
#include "listeners/actorspritelistener.h"
+#include "listeners/attributelistener.h"
#include <vector>
@@ -66,7 +67,8 @@ enum
*/
class LocalPlayer final : public Being,
public ActorSpriteListener,
- public DepricatedListener
+ public DepricatedListener,
+ public AttributeListener
{
public:
/**
@@ -509,6 +511,10 @@ class LocalPlayer final : public Being,
int getLastAttackY() const override final
{ return mTarget ? mTarget->getTileY() : mLastAttackY; }
+ void attributeChanged(const int id,
+ const int oldVal,
+ const int newVal) override final;
+
protected:
void updateCoords() override final;
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index 12ce1e6d3..d7652abe0 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -58,11 +58,8 @@ std::set<int> mProtectedItems;
void triggerAttr(const int id, const int old)
{
- DepricatedEvent event(EVENT_UPDATEATTRIBUTE);
- event.setInt("id", id);
- event.setInt("oldValue", old);
- event.setInt("newValue", mData.mAttributes.find(id)->second);
- DepricatedEvent::trigger(CHANNEL_ATTRIBUTES, event);
+ AttributeListener::distributeEvent(id, old,
+ mData.mAttributes.find(id)->second);
}
void triggerStat(const int id, const std::string &changed,