diff options
Diffstat (limited to 'src/being')
-rw-r--r-- | src/being/localplayer.cpp | 82 | ||||
-rw-r--r-- | src/being/localplayer.h | 14 | ||||
-rw-r--r-- | src/being/playerinfo.cpp | 13 |
3 files changed, 42 insertions, 67 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index ad26a15c2..08dce56ad 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -97,6 +97,7 @@ extern SkillDialog *skillDialog; LocalPlayer::LocalPlayer(const int id, const int subtype) : Being(id, PLAYER, subtype, nullptr), AttributeListener(), + StatListener(), mGMLevel(0), mInvertDirection(0), mCrazyMoveType(config.getIntValue("crazyMoveType")), @@ -176,8 +177,6 @@ LocalPlayer::LocalPlayer(const int id, const int subtype) : { logger->log1("LocalPlayer::LocalPlayer"); - listen(CHANNEL_ATTRIBUTES); - mAttackRange = 0; mLevel = 1; mAdvanced = true; @@ -1025,59 +1024,42 @@ void LocalPlayer::optionChanged(const std::string &value) mShowServerPos = config.getBoolValue("showserverpos"); } -void LocalPlayer::processEvent(const Channels channel, - const DepricatedEvent &event) +void LocalPlayer::statChanged(const int id, + const int oldVal1, + const int oldVal2) { - if (channel == CHANNEL_ATTRIBUTES) + if (!mShowJobExp || id != Net::getPlayerHandler()->getJobLocation()) + return; + + const std::pair<int, int> exp = PlayerInfo::getStatExperience(id); + if (oldVal1 > exp.first || !oldVal2) + return; + + const int change = exp.first - oldVal1; + if (change != 0 && mMessages.size() < 20) { - if (event.getName() == EVENT_UPDATESTAT) + if (!mMessages.empty()) { - if (!mShowJobExp) - return; - - const int id = event.getInt("id"); - if (id == Net::getPlayerHandler()->getJobLocation()) + MessagePair pair = mMessages.back(); + // TRANSLATORS: this is normal experience + if (pair.first.find(strprintf(" %s", _("xp"))) + == pair.first.size() - strlen(_("xp")) - 1) { - const std::pair<int, int> exp - = PlayerInfo::getStatExperience(id); - if (event.getInt("oldValue1") > exp.first - || !event.getInt("oldValue2")) - { - return; - } - - const int change = exp.first - event.getInt("oldValue1"); - if (change != 0 && mMessages.size() < 20) - { - if (!mMessages.empty()) - { - MessagePair pair = mMessages.back(); - // TRANSLATORS: this is normal experience - if (pair.first.find(strprintf(" %s", - _("xp"))) == pair.first.size() - - strlen(_("xp")) - 1) - { - mMessages.pop_back(); - // TRANSLATORS: this is job experience - pair.first.append(strprintf(", %d %s", - change, _("job"))); - mMessages.push_back(pair); - } - else - { - // TRANSLATORS: this is job experience - addMessageToQueue(strprintf("%d %s", - change, _("job"))); - } - } - else - { - // TRANSLATORS: this is job experience - addMessageToQueue(strprintf( - "%d %s", change, _("job"))); - } - } + mMessages.pop_back(); + // TRANSLATORS: this is job experience + pair.first.append(strprintf(", %d %s", change, _("job"))); + mMessages.push_back(pair); } + else + { + // TRANSLATORS: this is job experience + addMessageToQueue(strprintf("%d %s", change, _("job"))); + } + } + else + { + // TRANSLATORS: this is job experience + addMessageToQueue(strprintf("%d %s", change, _("job"))); } } } diff --git a/src/being/localplayer.h b/src/being/localplayer.h index ecf118799..5e8e0e8fe 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -23,8 +23,6 @@ #ifndef BEING_LOCALPLAYER_H #define BEING_LOCALPLAYER_H -#include "listeners/depricatedlistener.h" - #include "being/being.h" #include "gui/userpalette.h" @@ -32,6 +30,7 @@ #include "listeners/actionlistener.h" #include "listeners/actorspritelistener.h" #include "listeners/attributelistener.h" +#include "listeners/statlistener.h" #include <vector> @@ -67,8 +66,8 @@ enum */ class LocalPlayer final : public Being, public ActorSpriteListener, - public DepricatedListener, - public AttributeListener + public AttributeListener, + public StatListener { public: /** @@ -379,9 +378,6 @@ class LocalPlayer final : public Being, */ void optionChanged(const std::string &value) override final; - void processEvent(const Channels channel, - const DepricatedEvent &event) override final; - /** * set a following player. */ @@ -515,6 +511,10 @@ class LocalPlayer final : public Being, const int oldVal, const int newVal) override final; + void statChanged(const int id, + const int oldVal1, + const int oldVal2) override final; + protected: void updateCoords() override final; diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 09604e971..ed52df6c0 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -39,6 +39,8 @@ #include "utils/delete2.h" +#include "listeners/statlistener.h" + #include "debug.h" namespace PlayerInfo @@ -64,16 +66,7 @@ void triggerAttr(const int id, const int old) void triggerStat(const int id, const int old1, const int old2) { - const StatMap::const_iterator it = mData.mStats.find(id); - if (it == mData.mStats.end()) - return; - - DepricatedEvent event(EVENT_UPDATESTAT); - event.setInt("id", id); - const Stat &stat = it->second; - event.setInt("oldValue1", old1); - event.setInt("oldValue2", old2); - DepricatedEvent::trigger(CHANNEL_ATTRIBUTES, event); + StatListener::distributeEvent(id, old1, old2); } // --- Attributes ------------------------------------------------------------- |