summaryrefslogtreecommitdiff
path: root/src/gui/windows/statuswindow.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-09-27 22:35:38 +0300
committerAndrei Karas <akaras@inbox.ru>2017-09-27 22:35:38 +0300
commit9429dc4f5b5b6102a8b575de25ce5d8e7170551f (patch)
treed4603ddbea06f75e8637a1ff94da4432d7b96951 /src/gui/windows/statuswindow.cpp
parent64d30eda264c342aced8d791b47a35def0e4d15c (diff)
downloadmanaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.tar.gz
manaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.tar.bz2
manaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.tar.xz
manaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.zip
Change player job level, exp from stat object to attribute.
Diffstat (limited to 'src/gui/windows/statuswindow.cpp')
-rw-r--r--src/gui/windows/statuswindow.cpp126
1 files changed, 62 insertions, 64 deletions
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<int, int> 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<int, int> 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,