From 9429dc4f5b5b6102a8b575de25ce5d8e7170551f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 27 Sep 2017 22:35:38 +0300 Subject: Change player job level, exp from stat object to attribute. --- src/being/localplayer.cpp | 37 +++++----- src/being/localplayer.h | 8 +-- src/being/playerinfo.cpp | 2 + src/enums/being/attributes.h | 2 + src/enums/being/attributesstrings.cpp | 2 + src/gui/windows/chatwindow.cpp | 42 +++++------- src/gui/windows/chatwindow.h | 6 -- src/gui/windows/ministatuswindow.cpp | 28 +++++--- src/gui/windows/statuswindow.cpp | 126 +++++++++++++++++----------------- src/gui/windows/statuswindow.h | 8 +-- src/net/eathena/charserverrecv.cpp | 16 +++-- src/net/eathena/playerhandler.cpp | 10 +-- src/net/tmwa/charserverrecv.cpp | 10 +-- src/net/tmwa/playerhandler.cpp | 9 +-- src/net/tmwa/sp.h | 2 +- 15 files changed, 145 insertions(+), 163 deletions(-) (limited to 'src') diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index e1ba96893..2fc20f6f2 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -116,7 +116,6 @@ LocalPlayer::LocalPlayer(const BeingId id, ActorSpriteListener(), AttributeListener(), PlayerDeathListener(), - StatListener(), mMoveState(0), mLastTargetX(0), mLastTargetY(0), @@ -1226,25 +1225,6 @@ void LocalPlayer::addSpMessage(const int change) } } -void LocalPlayer::statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) -{ - if (!mShowJobExp || - id != Attributes::PLAYER_JOB || - Net::getNetworkType() != ServerType::TMWATHENA) - { - return; - } - - const std::pair exp = PlayerInfo::getStatExperience(id); - if (oldVal1 > exp.first || (oldVal2 == 0)) - return; - - const int change = exp.first - oldVal1; - addJobMessage(change); -} - void LocalPlayer::attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal) @@ -1271,6 +1251,23 @@ void LocalPlayer::attributeChanged(const AttributesT id, if (oldVal != 0 && newVal == 0) PlayerDeathListener::distributeEvent(); break; + case Attributes::PLAYER_JOB_EXP: + { + if (!mShowJobExp || + Net::getNetworkType() != ServerType::TMWATHENA) + { + return; + } + if (oldVal > newVal || + PlayerInfo::getAttribute( + Attributes::PLAYER_JOB_EXP_NEEDED) == 0) + { + return; + } + const int64_t change = newVal - oldVal; + addJobMessage(change); + break; + } default: break; } diff --git a/src/being/localplayer.h b/src/being/localplayer.h index 9af5b9d3c..897e4dc00 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -34,7 +34,6 @@ #include "listeners/actorspritelistener.h" #include "listeners/attributelistener.h" #include "listeners/playerdeathlistener.h" -#include "listeners/statlistener.h" #include "localconsts.h" @@ -50,8 +49,7 @@ class OkDialog; class LocalPlayer final : public Being, public ActorSpriteListener, public AttributeListener, - public PlayerDeathListener, - public StatListener + public PlayerDeathListener { public: /** @@ -402,10 +400,6 @@ class LocalPlayer final : public Being, const int64_t oldVal, const int64_t newVal) override final; - void statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) override final; - void updateMusic() const; void setAfkTime(const int v) noexcept2 diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index f24d97331..0a89bd7e1 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -33,6 +33,8 @@ #include "gui/windows/inventorywindow.h" #include "gui/windows/npcdialog.h" +#include "listeners/statlistener.h" + #include "net/homunculushandler.h" #include "net/inventoryhandler.h" #include "net/mercenaryhandler.h" diff --git a/src/enums/being/attributes.h b/src/enums/being/attributes.h index 7252a539a..7cda13284 100644 --- a/src/enums/being/attributes.h +++ b/src/enums/being/attributes.h @@ -62,6 +62,8 @@ enumStart(Attributes) PLAYER_ATK, CART_TOTAL_WEIGHT = 1000, CART_MAX_WEIGHT, + PLAYER_JOB_EXP, + PLAYER_JOB_EXP_NEEDED, // homunculus attributes HOMUN_LEVEL, diff --git a/src/enums/being/attributesstrings.cpp b/src/enums/being/attributesstrings.cpp index 51c116355..6dd24eef9 100644 --- a/src/enums/being/attributesstrings.cpp +++ b/src/enums/being/attributesstrings.cpp @@ -42,6 +42,8 @@ namespace AttributesEnum strEnumDef(Attributes, TOTAL_WEIGHT) strEnumDef(Attributes, MAX_WEIGHT) strEnumDef(Attributes, PLAYER_JOB) + strEnumDef(Attributes, PLAYER_JOB_EXP) + strEnumDef(Attributes, PLAYER_JOB_EXP_NEEDED) strEnumDef(Attributes, PLAYER_STR) strEnumDef(Attributes, PLAYER_AGI) strEnumDef(Attributes, PLAYER_VIT) diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index a3bb4829b..aa899202d 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -999,29 +999,6 @@ bool ChatWindow::addCurrentToHistory() return true; } -void ChatWindow::statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) -{ - if (!mShowBattleEvents || !config.getBoolValue("showJobExp")) - return; - - if (id != Attributes::PLAYER_JOB) - return; - - const std::pair exp = PlayerInfo::getStatExperience(id); - if (oldVal1 > exp.first || (oldVal2 == 0)) - return; - - const int change = exp.first - oldVal1; - if (change != 0) - { - battleChatLog(std::string("+").append(toString( - change)).append(" job"), - ChatMsgType::BY_SERVER); - } -} - void ChatWindow::attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal) @@ -1051,6 +1028,25 @@ void ChatWindow::attributeChanged(const AttributesT id, newVal))), ChatMsgType::BY_SERVER); break; + case Attributes::PLAYER_JOB_EXP: + { + if (!config.getBoolValue("showJobExp")) + return; + if (oldVal > newVal || + PlayerInfo::getAttribute( + Attributes::PLAYER_JOB_EXP_NEEDED) == 0) + { + return; + } + const int64_t change = newVal - oldVal; + if (change != 0) + { + battleChatLog(std::string("+").append(toString(CAST_U64( + change))).append(" job"), + ChatMsgType::BY_SERVER); + } + break; + } default: break; }; diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index 2328a012f..7d02e0fd3 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -35,7 +35,6 @@ #include "listeners/attributelistener.h" #include "listeners/debugmessagelistener.h" #include "listeners/keylistener.h" -#include "listeners/statlistener.h" class Button; class ChannelTab; @@ -57,7 +56,6 @@ class ChatWindow final : public Window, public KeyListener, public ConfigListener, public AttributeListener, - public StatListener, public DebugMessageListener { public: @@ -298,10 +296,6 @@ class ChatWindow final : public Window, const int64_t oldVal, const int64_t newVal) override final; - void statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) override final; - void postConnection(); void showGMTab(); diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index fcaff8759..c97fa1cd4 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -407,24 +407,36 @@ void MiniStatusWindow::mouseMoved(MouseEvent &event) } else if (event.getSource() == mJobBar) { - const std::pair exp = PlayerInfo::getStatExperience( + const int64_t exp = PlayerInfo::getAttribute64( + Attributes::PLAYER_JOB_EXP); + const int64_t expNeed = PlayerInfo::getAttribute64( + Attributes::PLAYER_JOB_EXP_NEEDED); + const int32_t jobLevel = PlayerInfo::getAttribute( Attributes::PLAYER_JOB); + const std::string expStr = toString(CAST_U64(exp)); + const std::string expNeedStr = toString(CAST_U64(expNeed)); + const std::string jobLevelStr = toString(CAST_U64(jobLevel)); + const std::string expLeftStr = toString(CAST_U64(expNeed - exp)); // TRANSLATORS: job bar label const std::string level = strprintf(_("Job level: %d"), - PlayerInfo::getStatBase(Attributes::PLAYER_JOB)); + jobLevel); - if (exp.first > exp.second) + if (exp > expNeed) { - textPopup->show(x + rect.x, y + rect.y, level, - strprintf("%d/%d", exp.first, exp.second)); + textPopup->show(x + rect.x, + y + rect.y, + level, + strprintf("%s/%s", expStr.c_str(), expNeedStr.c_str())); } else { - textPopup->show(x + rect.x, y + rect.y, level, - strprintf("%d/%d", exp.first, exp.second), + textPopup->show(x + rect.x, + y + rect.y, + level, + strprintf("%s/%s", expStr.c_str(), expNeedStr.c_str()), // TRANSLATORS: status bar label - strprintf("%s: %d", _("Need"), exp.second - exp.first)); + strprintf("%s: %s", _("Need"), expLeftStr.c_str())); } mStatusPopup->hide(); } diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index 462f22021..f096a3dd1 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -68,7 +68,6 @@ StatusWindow::StatusWindow() : "?", Modal_false, nullptr, "status.xml"), ActionListener(), AttributeListener(), - StatListener(), mPages(), mTabs(CREATEWIDGETR(TabbedArea, this)), // TRANSLATORS: status window label @@ -284,67 +283,12 @@ void StatusWindow::updateLevelLabel() mLvlLabel->adjustSize(); } -void StatusWindow::statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2 A_UNUSED) -{ - static bool blocked = false; - if (blocked) - return; - - if (id == Attributes::PLAYER_JOB) - { - if (mJobLvlLabel != nullptr) - { - int lvl = PlayerInfo::getStatBase(id); - const int oldExp = oldVal1; - const std::pair exp = PlayerInfo::getStatExperience(id); - - if (lvl == 0) - { - // possible server broken and don't send job level, - // then we fixing it :) - if (exp.second < 20000) - { - lvl = 0; - } - else - { - lvl = (exp.second - 20000) / 150; - blocked = true; - PlayerInfo::setStatBase(id, lvl); - blocked = false; - } - } - - if (exp.first < oldExp && exp.second >= 20000) - { // possible job level up. but server broken and don't send - // new job exp limit, we fixing it - lvl ++; - blocked = true; - PlayerInfo::setStatExperience( - id, exp.first, 20000 + lvl * 150); - PlayerInfo::setStatBase(id, lvl); - blocked = false; - } - - // TRANSLATORS: status window label - mJobLvlLabel->setCaption(strprintf(_("Job: %d"), lvl)); - mJobLvlLabel->adjustSize(); - - updateJobBar(mJobBar, false); - } - } - else - { - updateMPBar(mMpBar, true); - } -} - void StatusWindow::attributeChanged(const AttributesT id, - const int64_t oldVal A_UNUSED, + const int64_t oldVal, const int64_t newVal) { + static bool blocked = false; + PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wswitch-enum") switch (id) @@ -378,6 +322,57 @@ void StatusWindow::attributeChanged(const AttributesT id, mLvlLabel->adjustSize(); break; + case Attributes::PLAYER_JOB: + case Attributes::PLAYER_JOB_EXP: + case Attributes::PLAYER_JOB_EXP_NEEDED: + if (blocked) + return; + if (mJobLvlLabel != nullptr) + { + int lvl = PlayerInfo::getAttribute(Attributes::PLAYER_JOB); + const int64_t exp = PlayerInfo::getAttribute( + Attributes::PLAYER_JOB_EXP); + const int64_t expNeed = PlayerInfo::getAttribute( + Attributes::PLAYER_JOB_EXP_NEEDED); + + if (lvl == 0) + { + // possible server broken and don't send job level, + // then we fixing it. + if (expNeed < 20000) + { + lvl = 0; + } + else + { + lvl = (expNeed - 20000) / 150; + blocked = true; + PlayerInfo::setAttribute(Attributes::PLAYER_JOB, lvl); + blocked = false; + } + } + + if (id == Attributes::PLAYER_JOB_EXP && + exp < oldVal && + expNeed >= 20000) + { // possible job level up. but server broken and don't send + // new job exp limit, we fixing it + lvl ++; + blocked = true; + PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED, + 20000 + lvl * 150); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB, lvl); + blocked = false; + } + + // TRANSLATORS: status window label + mJobLvlLabel->setCaption(strprintf(_("Job: %d"), lvl)); + mJobLvlLabel->adjustSize(); + + updateJobBar(mJobBar, false); + } + break; + default: break; } @@ -481,8 +476,10 @@ void StatusWindow::updateXPBar(ProgressBar *const bar, const bool percent) if (bar == nullptr) return; - updateProgressBar(bar, PlayerInfo::getAttribute(Attributes::PLAYER_EXP), - PlayerInfo::getAttribute(Attributes::PLAYER_EXP_NEEDED), percent); + updateProgressBar(bar, + PlayerInfo::getAttribute(Attributes::PLAYER_EXP), + PlayerInfo::getAttribute(Attributes::PLAYER_EXP_NEEDED), + percent); } void StatusWindow::updateJobBar(ProgressBar *const bar, const bool percent) @@ -490,9 +487,10 @@ void StatusWindow::updateJobBar(ProgressBar *const bar, const bool percent) if (bar == nullptr) return; - const std::pair exp = PlayerInfo::getStatExperience( - Attributes::PLAYER_JOB); - updateProgressBar(bar, exp.first, exp.second, percent); + updateProgressBar(bar, + PlayerInfo::getAttribute(Attributes::PLAYER_JOB_EXP), + PlayerInfo::getAttribute(Attributes::PLAYER_JOB_EXP_NEEDED), + percent); } void StatusWindow::updateProgressBar(ProgressBar *const bar, diff --git a/src/gui/windows/statuswindow.h b/src/gui/windows/statuswindow.h index daced90b2..233840d17 100644 --- a/src/gui/windows/statuswindow.h +++ b/src/gui/windows/statuswindow.h @@ -27,7 +27,6 @@ #include "listeners/actionlistener.h" #include "listeners/attributelistener.h" -#include "listeners/statlistener.h" class Button; class Label; @@ -43,8 +42,7 @@ class TabbedArea; */ class StatusWindow final : public Window, public ActionListener, - public AttributeListener, - public StatListener + public AttributeListener { public: /** @@ -86,10 +84,6 @@ class StatusWindow final : public Window, const int64_t oldVal, const int64_t newVal) override final; - void statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) override final; - void updateLevelLabel(); private: diff --git a/src/net/eathena/charserverrecv.cpp b/src/net/eathena/charserverrecv.cpp index 3178a6d5f..f60fb1ff0 100644 --- a/src/net/eathena/charserverrecv.cpp +++ b/src/net/eathena/charserverrecv.cpp @@ -91,15 +91,17 @@ void CharServerRecv::readPlayerData(Net::MessageIn &msg, else data.mAttributes[Attributes::PLAYER_EXP] = msg.readInt32("exp"); data.mAttributes[Attributes::MONEY] = msg.readInt32("money"); - Stat &jobStat = data.mStats[Attributes::PLAYER_JOB]; if (packetVersion >= 20170830) - jobStat.exp = msg.readInt64("job exp"); + { + data.mAttributes[Attributes::PLAYER_JOB_EXP] = + msg.readInt64("job exp"); + } else - jobStat.exp = msg.readInt32("job exp"); - - const int temp = msg.readInt32("job level"); - jobStat.base = temp; - jobStat.mod = temp; + { + data.mAttributes[Attributes::PLAYER_JOB_EXP] = + msg.readInt32("job exp"); + } + data.mAttributes[Attributes::PLAYER_JOB] =msg.readInt32("job level"); msg.readInt16("shoes?"); const int gloves = msg.readInt16("gloves"); diff --git a/src/net/eathena/playerhandler.cpp b/src/net/eathena/playerhandler.cpp index c7361e1b0..9106fce26 100644 --- a/src/net/eathena/playerhandler.cpp +++ b/src/net/eathena/playerhandler.cpp @@ -532,8 +532,7 @@ void PlayerHandler::setStat(Net::MessageIn &msg, PlayerInfo::setAttribute(Attributes::PLAYER_EXP, base); break; case Sp::JOBEXP: - PlayerInfo::setStatExperience(Attributes::PLAYER_JOB, base, - PlayerInfo::getStatExperience(Attributes::PLAYER_JOB).second); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP, base); break; case Sp::KARMA: PlayerInfo::setStatBase(Attributes::PLAYER_KARMA, base); @@ -632,11 +631,8 @@ void PlayerHandler::setStat(Net::MessageIn &msg, case Sp::NEXTBASEEXP: PlayerInfo::setAttribute(Attributes::PLAYER_EXP_NEEDED, base); break; - // ++ here used in wrong way. Need like Sp::NEXTBASEEXP? case Sp::NEXTJOBEXP: - PlayerInfo::setStatExperience(Attributes::PLAYER_JOB, - PlayerInfo::getStatExperience(Attributes::PLAYER_JOB).first, - base); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED, base); break; case Sp::WEIGHT: PlayerInfo::setAttribute(Attributes::TOTAL_WEIGHT, base); @@ -708,7 +704,7 @@ void PlayerHandler::setStat(Net::MessageIn &msg, PlayerInfo::updateAttrs(); break; case Sp::JOBLEVEL: - PlayerInfo::setStatBase(Attributes::PLAYER_JOB, base); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB, base); break; default: diff --git a/src/net/tmwa/charserverrecv.cpp b/src/net/tmwa/charserverrecv.cpp index 50571b29c..474595bf0 100644 --- a/src/net/tmwa/charserverrecv.cpp +++ b/src/net/tmwa/charserverrecv.cpp @@ -72,14 +72,10 @@ void CharServerRecv::readPlayerData(Net::MessageIn &msg, msg.readBeingId("account id"), BeingTypeId_zero); PlayerInfoBackend &data = character->data; - data.mAttributes[Attributes::PLAYER_EXP] = msg.readInt32("exp"); + data.mAttributes[Attributes::PLAYER_EXP] = msg.readInt32("base exp"); data.mAttributes[Attributes::MONEY] = msg.readInt32("money"); - Stat &jobStat = data.mStats[Attributes::PLAYER_JOB]; - jobStat.exp = msg.readInt32("job"); - - const int temp = msg.readInt32("job level"); - jobStat.base = temp; - jobStat.mod = temp; + data.mAttributes[Attributes::PLAYER_JOB_EXP] = msg.readInt32("job exp"); + data.mAttributes[Attributes::PLAYER_JOB] = msg.readInt32("job level"); const int shoes = msg.readInt16("shoes"); const int gloves = msg.readInt16("gloves"); diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index d234a6a4a..e31539cd6 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -233,8 +233,7 @@ void PlayerHandler::setStat(Net::MessageIn &msg, PlayerInfo::setAttribute(Attributes::PLAYER_EXP, base); break; case Sp::JOBEXP: - PlayerInfo::setStatExperience(Attributes::PLAYER_JOB, base, - PlayerInfo::getStatExperience(Attributes::PLAYER_JOB).second); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP, base); break; case Sp::KARMA: PlayerInfo::setStatBase(Attributes::PLAYER_KARMA, base); @@ -334,9 +333,7 @@ void PlayerHandler::setStat(Net::MessageIn &msg, PlayerInfo::setAttribute(Attributes::PLAYER_EXP_NEEDED, base); break; case Sp::JOB_MOD: - PlayerInfo::setStatExperience(Attributes::PLAYER_JOB, - PlayerInfo::getStatExperience(Attributes::PLAYER_JOB).first, - base); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED, base); break; case Sp::WEIGHT: PlayerInfo::setAttribute(Attributes::TOTAL_WEIGHT, base); @@ -408,7 +405,7 @@ void PlayerHandler::setStat(Net::MessageIn &msg, PlayerInfo::updateAttrs(); break; case Sp::JOBLEVEL: - PlayerInfo::setStatBase(Attributes::PLAYER_JOB, base); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB, base); break; case Sp::GM_LEVEL: localPlayer->setGroupId(base); diff --git a/src/net/tmwa/sp.h b/src/net/tmwa/sp.h index 018504e05..10711bfce 100644 --- a/src/net/tmwa/sp.h +++ b/src/net/tmwa/sp.h @@ -49,7 +49,7 @@ namespace Sp ZENY = 20, SEX = 21, NEXTBASEEXP = 22, - JOB_MOD = 23, + JOB_MOD = 23, // SP_NEXTJOBEXP WEIGHT = 24, MAXWEIGHT = 25, USTR = 32, -- cgit v1.2.3-70-g09d2