diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-29 21:42:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-29 22:43:38 +0300 |
commit | 3411edb5d3ae07d247421e4b8f7936a22b7b4027 (patch) | |
tree | 63685d0979938a42a62b3f0a880663bb06f4e8ca | |
parent | 390e5da0f9ecc4407aa7d4bcba1af5730db56271 (diff) | |
download | mv-3411edb5d3ae07d247421e4b8f7936a22b7b4027.tar.gz mv-3411edb5d3ae07d247421e4b8f7936a22b7b4027.tar.bz2 mv-3411edb5d3ae07d247421e4b8f7936a22b7b4027.tar.xz mv-3411edb5d3ae07d247421e4b8f7936a22b7b4027.zip |
Convert Attributes enum into strong typed enum.
33 files changed, 171 insertions, 162 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 58b25630e..1374eefab 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -1117,7 +1117,7 @@ void LocalPlayer::addSpMessage(const int change) } } -void LocalPlayer::statChanged(const int id, +void LocalPlayer::statChanged(const AttributesT id, const int oldVal1, const int oldVal2) { @@ -1136,7 +1136,7 @@ void LocalPlayer::statChanged(const int id, addJobMessage(change); } -void LocalPlayer::attributeChanged(const int id, +void LocalPlayer::attributeChanged(const AttributesT id, const int oldVal, const int newVal) { diff --git a/src/being/localplayer.h b/src/being/localplayer.h index 093b188c4..84089984e 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -392,11 +392,11 @@ class LocalPlayer final : public Being, int getLastAttackY() const override final { return mTarget ? mTarget->getTileY() : mLastAttackY; } - void attributeChanged(const int id, + void attributeChanged(const AttributesT id, const int oldVal, const int newVal) override final; - void statChanged(const int id, + void statChanged(const AttributesT id, const int oldVal1, const int oldVal2) override final; diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index f11b6fe82..c86200219 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -33,8 +33,6 @@ #include "being/petinfo.h" #endif -#include "enums/being/attributes.h" - #include "gui/windows/inventorywindow.h" #include "gui/windows/npcdialog.h" @@ -72,29 +70,32 @@ std::set<int> mProtectedItems; // --- Triggers --------------------------------------------------------------- -void triggerAttr(const int id, const int old) +void triggerAttr(const AttributesT id, + const int old) { AttributeListener::distributeEvent(id, old, mData.mAttributes.find(id)->second); } -void triggerStat(const int id, const int old1, const int old2) +void triggerStat(const AttributesT id, + const int old1, + const int old2) { StatListener::distributeEvent(id, old1, old2); } // --- Attributes ------------------------------------------------------------- -int getAttribute(const int id) +int getAttribute(const AttributesT id) { - const IntMap::const_iterator it = mData.mAttributes.find(id); + const AtrIntMap::const_iterator it = mData.mAttributes.find(id); if (it != mData.mAttributes.end()) return it->second; else return 0; } -void setAttribute(const int id, +void setAttribute(const AttributesT id, const int value, const Notify notify) { @@ -120,7 +121,7 @@ void setSkillLevel(const int id, const int value) // --- Stats ------------------------------------------------------------------ -int getStatBase(const int id) +int getStatBase(const AttributesT id) { const StatMap::const_iterator it = mData.mStats.find(id); if (it != mData.mStats.end()) @@ -129,7 +130,7 @@ int getStatBase(const int id) return 0; } -void setStatBase(const int id, const int value, const Notify notify) +void setStatBase(const AttributesT id, const int value, const Notify notify) { const int old = mData.mStats[id].base; mData.mStats[id].base = value; @@ -137,7 +138,7 @@ void setStatBase(const int id, const int value, const Notify notify) triggerStat(id, old, 0); } -int getStatMod(const int id) +int getStatMod(const AttributesT id) { const StatMap::const_iterator it = mData.mStats.find(id); if (it != mData.mStats.end()) @@ -146,7 +147,7 @@ int getStatMod(const int id) return 0; } -void setStatMod(const int id, const int value, const Notify notify) +void setStatMod(const AttributesT id, const int value, const Notify notify) { const int old = mData.mStats[id].mod; mData.mStats[id].mod = value; @@ -154,7 +155,7 @@ void setStatMod(const int id, const int value, const Notify notify) triggerStat(id, old, 0); } -int getStatEffective(const int id) +int getStatEffective(const AttributesT id) { const StatMap::const_iterator it = mData.mStats.find(id); if (it != mData.mStats.end()) @@ -163,7 +164,7 @@ int getStatEffective(const int id) return 0; } -const std::pair<int, int> getStatExperience(const int id) +const std::pair<int, int> getStatExperience(const AttributesT id) { const StatMap::const_iterator it = mData.mStats.find(id); int a, b; @@ -180,7 +181,7 @@ const std::pair<int, int> getStatExperience(const int id) return std::pair<int, int>(a, b); } -void setStatExperience(const int id, +void setStatExperience(const AttributesT id, const int have, const int need, const Notify notify) diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h index ee963a5eb..d16bd6474 100644 --- a/src/being/playerinfo.h +++ b/src/being/playerinfo.h @@ -27,6 +27,8 @@ #include "enums/guildpositionflags.h" #include "enums/state.h" +#include "enums/being/attributes.h" + #include "enums/simpletypes/beingid.h" #include "enums/simpletypes/keep.h" #include "enums/simpletypes/notify.h" @@ -50,7 +52,8 @@ struct Stat final }; typedef std::map<int, int> IntMap; -typedef std::map<int, Stat> StatMap; +typedef std::map<Attributes, int> AtrIntMap; +typedef std::map<Attributes, Stat> StatMap; /** * Backend for core player information. @@ -64,7 +67,7 @@ struct PlayerInfoBackend final { } - IntMap mAttributes; + AtrIntMap mAttributes; StatMap mStats; IntMap mSkills; }; @@ -89,12 +92,12 @@ namespace PlayerInfo /** * Returns the value of the given attribute. */ - int getAttribute(const int id) A_WARN_UNUSED; + int getAttribute(const AttributesT id) A_WARN_UNUSED; /** * Changes the value of the given attribute. */ - void setAttribute(const int id, const int value, + void setAttribute(const AttributesT id, const int value, const Notify notify = Notify_true); int getSkillLevel(const int id) A_WARN_UNUSED; @@ -106,45 +109,48 @@ namespace PlayerInfo /** * Returns the base value of the given stat. */ - int getStatBase(const int id) A_WARN_UNUSED; + int getStatBase(const AttributesT id) A_WARN_UNUSED; /** * Changes the base value of the given stat. */ - void setStatBase(const int id, const int value, + void setStatBase(const AttributesT id, + const int value, const Notify notify = Notify_true); /** * Returns the modifier for the given stat. */ - int getStatMod(const int id) A_WARN_UNUSED; + int getStatMod(const AttributesT id) A_WARN_UNUSED; /** * Changes the modifier for the given stat. */ - void setStatMod(const int id, const int value, + void setStatMod(const AttributesT id, + const int value, const Notify notify = Notify_true); /** * Returns the current effective value of the given stat. Effective is base * + mod */ - int getStatEffective(const int id) A_WARN_UNUSED; + int getStatEffective(const AttributesT id) A_WARN_UNUSED; /** * Changes the level of the given stat. */ - void setStatLevel(int id, int value, Notify notify = Notify_true); + void setStatLevel(AttributesT id, int value, Notify notify = Notify_true); /** * Returns the experience of the given stat. */ - const std::pair<int, int> getStatExperience(const int id) A_WARN_UNUSED; + const std::pair<int, int> getStatExperience(const AttributesT id) + A_WARN_UNUSED; /** * Changes the experience of the given stat. */ - void setStatExperience(const int id, + void setStatExperience(const AttributesT id, const int have, const int need, const Notify notify = Notify_true); @@ -223,9 +229,12 @@ namespace PlayerInfo void stateChange(const State state); - void triggerAttr(const int id, const int old); + void triggerAttr(const AttributesT id, + const int old); - void triggerStat(const int id, const int old1, const int old2); + void triggerStat(const AttributesT id, + const int old1, + const int old2); void setEquipmentBackend(Equipment::Backend *const backend); diff --git a/src/enums/being/attributes.h b/src/enums/being/attributes.h index 45ac46d27..9ef5533bd 100644 --- a/src/enums/being/attributes.h +++ b/src/enums/being/attributes.h @@ -22,49 +22,46 @@ #ifndef ENUMS_BEING_ATTRIBUTES_H #define ENUMS_BEING_ATTRIBUTES_H -namespace Attributes +#include "enums/simpletypes/enumdefines.h" + +enumStart(Attributes) { - /** - * Standard attributes for players. - */ - enum Attributes - { - LEVEL = 0, - HP, - MAX_HP, - MP, - MAX_MP, - EXP, - EXP_NEEDED, - MONEY, - TOTAL_WEIGHT, - MAX_WEIGHT, - JOB = 10, - STR = 13, - AGI = 14, - VIT = 15, - INT = 16, - DEX = 17, - LUK = 18, - SKILL_POINTS, - CHAR_POINTS, - CORR_POINTS, - ATTACK_DELAY = 100, - ATTACK_RANGE = 101, - WALK_SPEED = 102, - ATTACK_SPEED = 103, - KARMA, - MANNER, - CRIT, - FLEE, - HIT, - MDEF, - MATK, - DEF, - ATK, - CART_TOTAL_WEIGHT = 1000, - CART_MAX_WEIGHT - }; -} // namespace Attributes + LEVEL = 0, + HP, + MAX_HP, + MP, + MAX_MP, + EXP, + EXP_NEEDED, + MONEY, + TOTAL_WEIGHT, + MAX_WEIGHT, + JOB = 10, + STR = 13, + AGI = 14, + VIT = 15, + INT = 16, + DEX = 17, + LUK = 18, + SKILL_POINTS, + CHAR_POINTS, + CORR_POINTS, + ATTACK_DELAY = 100, + ATTACK_RANGE = 101, + WALK_SPEED = 102, + ATTACK_SPEED = 103, + KARMA, + MANNER, + CRIT, + FLEE, + HIT, + MDEF, + MATK, + DEF, + ATK, + CART_TOTAL_WEIGHT = 1000, + CART_MAX_WEIGHT +} +enumEnd(Attributes); #endif // ENUMS_BEING_ATTRIBUTES_H diff --git a/src/gui/dialogsmanager.cpp b/src/gui/dialogsmanager.cpp index eab8c7387..91fb96103 100644 --- a/src/gui/dialogsmanager.cpp +++ b/src/gui/dialogsmanager.cpp @@ -143,7 +143,7 @@ void DialogsManager::playerDeath() } } -void DialogsManager::attributeChanged(const int id, +void DialogsManager::attributeChanged(const AttributesT id, const int oldVal, const int newVal) { diff --git a/src/gui/dialogsmanager.h b/src/gui/dialogsmanager.h index 34f8c8e40..11a4545ad 100644 --- a/src/gui/dialogsmanager.h +++ b/src/gui/dialogsmanager.h @@ -51,7 +51,7 @@ class DialogsManager final : public AttributeListener, void playerDeath() override final; - void attributeChanged(const int id, + void attributeChanged(const AttributesT id, const int oldVal, const int newVal) override final; }; diff --git a/src/gui/widgets/skillinfo.cpp b/src/gui/widgets/skillinfo.cpp index d16994bae..0778b6c12 100644 --- a/src/gui/widgets/skillinfo.cpp +++ b/src/gui/widgets/skillinfo.cpp @@ -37,12 +37,9 @@ SkillInfo::SkillInfo() : skillLevel(), - skillExp(), skillEffect(), useButton(), errorText(), - progress(0.0F), - color(), dataMap(), model(nullptr), data(nullptr), @@ -76,9 +73,7 @@ SkillInfo::~SkillInfo() void SkillInfo::update() { const int baseLevel = PlayerInfo::getSkillLevel(id); - const std::pair<int, int> exp = PlayerInfo::getStatExperience(id); - - if (modifiable == Modifiable_false && baseLevel == 0 && exp.second == 0) + if (modifiable == Modifiable_false && baseLevel == 0) { if (visible == Visible_true) { @@ -160,20 +155,6 @@ void SkillInfo::update() level = baseLevel; skillLevelWidth = -1; - if (exp.second) - { - skillExp = strprintf("%d / %d", exp.first, exp.second); - progress = static_cast<float>(exp.first) - / static_cast<float>(exp.second); - } - else - { - skillExp.clear(); - progress = 0.0F; - } - - color = Theme::getProgressColor(Theme::PROG_EXP, progress); - if (updateVisibility && model) model->updateVisibilities(); diff --git a/src/gui/widgets/skillinfo.h b/src/gui/widgets/skillinfo.h index e2679713d..038fc2a01 100644 --- a/src/gui/widgets/skillinfo.h +++ b/src/gui/widgets/skillinfo.h @@ -48,12 +48,9 @@ typedef SkillDataMap::const_iterator SkillDataMapCIter; struct SkillInfo final { std::string skillLevel; - std::string skillExp; std::string skillEffect; std::string useButton; std::string errorText; - float progress; - Color color; SkillDataMap dataMap; SkillModel *model; SkillData *data; diff --git a/src/gui/widgets/statuswindowattrs.h b/src/gui/widgets/statuswindowattrs.h index ee336c616..7359a1a86 100644 --- a/src/gui/widgets/statuswindowattrs.h +++ b/src/gui/widgets/statuswindowattrs.h @@ -23,6 +23,8 @@ #ifndef GUI_WIDGETS_STATUSWINDOWATTRS_H #define GUI_WIDGETS_STATUSWINDOWATTRS_H +#include "enums/being/attributes.h" + #include "gui/widgets/container.h" #include "gui/widgets/label.h" @@ -66,11 +68,11 @@ class AttrDisplay notfinal : public Container protected: AttrDisplay(const Widget2 *const widget, - const int id, + const AttributesT id, const std::string &restrict name, const std::string &restrict shortName); - const int mId; + const AttributesT mId; const std::string mName; const std::string mShortName; @@ -83,7 +85,8 @@ class DerDisplay final : public AttrDisplay { public: DerDisplay(const Widget2 *const widget, - const int id, const std::string &restrict name, + const AttributesT id, + const std::string &restrict name, const std::string &restrict shortName); A_DELETE_COPY(DerDisplay) @@ -97,7 +100,8 @@ class ChangeDisplay final : public AttrDisplay, { public: ChangeDisplay(const Widget2 *const widget, - const int id, const std::string &restrict name, + const AttributesT id, + const std::string &restrict name, const std::string &restrict shortName); A_DELETE_COPY(ChangeDisplay) diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 713ad5e53..31b874032 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -947,7 +947,7 @@ bool ChatWindow::addCurrentToHistory() return true; } -void ChatWindow::statChanged(const int id, +void ChatWindow::statChanged(const AttributesT id, const int oldVal1, const int oldVal2) { @@ -970,7 +970,7 @@ void ChatWindow::statChanged(const int id, } } -void ChatWindow::attributeChanged(const int id, +void ChatWindow::attributeChanged(const AttributesT id, const int oldVal, const int newVal) { diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index a91178a97..76e932525 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -299,11 +299,11 @@ class ChatWindow final : public Window, void selectTabByType(const ChatTabType::Type &type); - void attributeChanged(const int id, + void attributeChanged(const AttributesT id, const int oldVal, const int newVal) override final; - void statChanged(const int id, + void statChanged(const AttributesT id, const int oldVal1, const int oldVal2) override final; diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index ce954e7f3..63cde64f7 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -988,7 +988,7 @@ void InventoryWindow::unsetInventory() mInventory = nullptr; } -void InventoryWindow::attributeChanged(const int id, +void InventoryWindow::attributeChanged(const AttributesT id, const int oldVal A_UNUSED, const int newVal A_UNUSED) { diff --git a/src/gui/windows/inventorywindow.h b/src/gui/windows/inventorywindow.h index cb08a8fa2..c220b75aa 100644 --- a/src/gui/windows/inventorywindow.h +++ b/src/gui/windows/inventorywindow.h @@ -154,7 +154,7 @@ class InventoryWindow final : public Window, void unsetInventory(); - void attributeChanged(const int id, + void attributeChanged(const AttributesT id, const int oldVal, const int newVal) override final; diff --git a/src/gui/windows/killstats.cpp b/src/gui/windows/killstats.cpp index 919b11e9a..c765c5b5a 100644 --- a/src/gui/windows/killstats.cpp +++ b/src/gui/windows/killstats.cpp @@ -403,7 +403,7 @@ void KillStats::update() BLOCK_END("KillStats::update") } -void KillStats::attributeChanged(const int id, +void KillStats::attributeChanged(const AttributesT id, const int oldVal, const int newVal) { diff --git a/src/gui/windows/killstats.h b/src/gui/windows/killstats.h index a3e047553..ef784acf5 100644 --- a/src/gui/windows/killstats.h +++ b/src/gui/windows/killstats.h @@ -68,7 +68,7 @@ class KillStats final : public Window, void resetTimes(); - void attributeChanged(const int id, + void attributeChanged(const AttributesT id, const int oldVal, const int newVal) override final; diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index 80adb129c..250258ca7 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -252,7 +252,7 @@ void MiniStatusWindow::drawIcons(Graphics *const graphics) } } -void MiniStatusWindow::statChanged(const int id A_UNUSED, +void MiniStatusWindow::statChanged(const AttributesT id A_UNUSED, const int oldVal1 A_UNUSED, const int oldVal2 A_UNUSED) { @@ -261,7 +261,7 @@ void MiniStatusWindow::statChanged(const int id A_UNUSED, StatusWindow::updateJobBar(mJobBar); } -void MiniStatusWindow::attributeChanged(const int id, +void MiniStatusWindow::attributeChanged(const AttributesT id, const int oldVal A_UNUSED, const int newVal A_UNUSED) { diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h index d31783b63..bd1e6a393 100644 --- a/src/gui/windows/ministatuswindow.h +++ b/src/gui/windows/ministatuswindow.h @@ -92,11 +92,11 @@ class MiniStatusWindow final : public Window, Rect getChildrenArea() override final A_WARN_UNUSED; - void attributeChanged(const int id, + void attributeChanged(const AttributesT id, const int oldVal, const int newVal) override final; - void statChanged(const int id, + void statChanged(const AttributesT id, const int oldVal1, const int oldVal2) override final; diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index 7a1c798ec..fb28aacb7 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -257,7 +257,7 @@ void StatusWindow::updateLevelLabel() mLvlLabel->adjustSize(); } -void StatusWindow::statChanged(const int id, +void StatusWindow::statChanged(const AttributesT id, const int oldVal1, const int oldVal2 A_UNUSED) { @@ -305,7 +305,7 @@ void StatusWindow::statChanged(const int id, mJobLvlLabel->setCaption(strprintf(_("Job: %d"), lvl)); mJobLvlLabel->adjustSize(); - updateProgressBar(mJobBar, id, false); + updateJobBar(mJobBar, false); } } else @@ -317,7 +317,7 @@ void StatusWindow::statChanged(const int id, } } -void StatusWindow::attributeChanged(const int id, +void StatusWindow::attributeChanged(const AttributesT id, const int oldVal A_UNUSED, const int newVal) { @@ -385,7 +385,8 @@ void StatusWindow::attributeChanged(const int id, } } -void StatusWindow::setPointsNeeded(const int id, const int needed) +void StatusWindow::setPointsNeeded(const AttributesT id, + const int needed) { const Attrs::const_iterator it = mAttrs.find(id); @@ -397,7 +398,8 @@ void StatusWindow::setPointsNeeded(const int id, const int needed) } } -void StatusWindow::addAttribute(const int id, const std::string &restrict name, +void StatusWindow::addAttribute(const AttributesT id, + const std::string &restrict name, const std::string &restrict shortName, const Modifiable modifiable) { @@ -478,8 +480,10 @@ void StatusWindow::updateMPBar(ProgressBar *const bar, bar->setProgress(prog); } -void StatusWindow::updateProgressBar(ProgressBar *const bar, const int value, - const int max, const bool percent) +void StatusWindow::updateProgressBar(ProgressBar *const bar, + const int value, + const int max, + const bool percent) { if (!bar) return; @@ -527,7 +531,8 @@ void StatusWindow::updateJobBar(ProgressBar *const bar, const bool percent) updateProgressBar(bar, exp.first, exp.second, percent); } -void StatusWindow::updateProgressBar(ProgressBar *const bar, const int id, +void StatusWindow::updateProgressBar(ProgressBar *const bar, + const AttributesT id, const bool percent) { const std::pair<int, int> exp = PlayerInfo::getStatExperience(id); @@ -691,7 +696,8 @@ void StatusWindow::action(const ActionEvent &event) } AttrDisplay::AttrDisplay(const Widget2 *const widget, - const int id, const std::string &restrict name, + const AttributesT id, + const std::string &restrict name, const std::string &restrict shortName) : Container(widget), mId(id), @@ -724,7 +730,8 @@ std::string AttrDisplay::update() } DerDisplay::DerDisplay(const Widget2 *const widget, - const int id, const std::string &restrict name, + const AttributesT id, + const std::string &restrict name, const std::string &restrict shortName) : AttrDisplay(widget, id, name, shortName) { @@ -735,7 +742,8 @@ DerDisplay::DerDisplay(const Widget2 *const widget, } ChangeDisplay::ChangeDisplay(const Widget2 *const widget, - const int id, const std::string &restrict name, + const AttributesT id, + const std::string &restrict name, const std::string &restrict shortName) : AttrDisplay(widget, id, name, shortName), ActionListener(), diff --git a/src/gui/windows/statuswindow.h b/src/gui/windows/statuswindow.h index 44328e1df..2ec0a778b 100644 --- a/src/gui/windows/statuswindow.h +++ b/src/gui/windows/statuswindow.h @@ -56,9 +56,11 @@ class StatusWindow final : public Window, A_DELETE_COPY(StatusWindow) - void setPointsNeeded(const int id, const int needed); + void setPointsNeeded(const AttributesT id, + const int needed); - void addAttribute(const int id, const std::string &restrict name, + void addAttribute(const AttributesT id, + const std::string &restrict name, const std::string &restrict shortName = "", const Modifiable modifiable = Modifiable_false); @@ -75,21 +77,23 @@ class StatusWindow final : public Window, static void updateArrowsBar(ProgressBar *const bar); void updateStatusBar(ProgressBar *const bar, const bool percent = true) const; - static void updateProgressBar(ProgressBar *const bar, const int value, - const int max, const bool percent); static void updateProgressBar(ProgressBar *const bar, - const int id, + const int value, + const int max, + const bool percent); + static void updateProgressBar(ProgressBar *const bar, + const AttributesT id, const bool percent = true); void action(const ActionEvent &event) override; void clearAttributes(); - void attributeChanged(const int id, + void attributeChanged(const AttributesT id, const int oldVal, const int newVal) override final; - void statChanged(const int id, + void statChanged(const AttributesT id, const int oldVal1, const int oldVal2) override final; @@ -124,7 +128,7 @@ class StatusWindow final : public Window, Label *mCorrectionPointsLabel; Button *mCopyButton; - typedef std::map<int, AttrDisplay*> Attrs; + typedef std::map<Attributes, AttrDisplay*> Attrs; Attrs mAttrs; }; diff --git a/src/listeners/attributelistener.cpp b/src/listeners/attributelistener.cpp index 4026f09d5..4aa1a75a9 100644 --- a/src/listeners/attributelistener.cpp +++ b/src/listeners/attributelistener.cpp @@ -24,7 +24,7 @@ defineListener(AttributeListener) -void AttributeListener::distributeEvent(const int id, +void AttributeListener::distributeEvent(const AttributesT id, const int oldVal, const int newVal) { diff --git a/src/listeners/attributelistener.h b/src/listeners/attributelistener.h index b277fe876..704b722a7 100644 --- a/src/listeners/attributelistener.h +++ b/src/listeners/attributelistener.h @@ -21,6 +21,8 @@ #ifndef LISTENERS_ATTRIBUTELISTENER_H #define LISTENERS_ATTRIBUTELISTENER_H +#include "enums/being/attributes.h" + #include "listeners/baselistener.hpp" #include "localconsts.h" @@ -28,11 +30,11 @@ class AttributeListener notfinal { public: - virtual void attributeChanged(const int id, + virtual void attributeChanged(const AttributesT id, const int oldVal, const int newVal) = 0; - static void distributeEvent(const int id, + static void distributeEvent(const AttributesT id, const int oldVal, const int newVal); diff --git a/src/listeners/statlistener.cpp b/src/listeners/statlistener.cpp index f8200aa54..f5c0d57d0 100644 --- a/src/listeners/statlistener.cpp +++ b/src/listeners/statlistener.cpp @@ -24,7 +24,7 @@ defineListener(StatListener) -void StatListener::distributeEvent(const int id, +void StatListener::distributeEvent(const AttributesT id, const int oldVal1, const int oldVal2) { diff --git a/src/listeners/statlistener.h b/src/listeners/statlistener.h index 3ba1338cd..7e389a24f 100644 --- a/src/listeners/statlistener.h +++ b/src/listeners/statlistener.h @@ -21,6 +21,8 @@ #ifndef LISTENERS_STATLISTENER_H #define LISTENERS_STATLISTENER_H +#include "enums/being/attributes.h" + #include "listeners/baselistener.hpp" #include "localconsts.h" @@ -28,11 +30,11 @@ class StatListener notfinal { public: - virtual void statChanged(const int id, + virtual void statChanged(const AttributesT id, const int oldVal1, const int oldVal2) = 0; - static void distributeEvent(const int id, + static void distributeEvent(const AttributesT id, const int oldVal1, const int oldVal2); diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 0003a0a7e..8d4937236 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -61,7 +61,7 @@ PlayerHandler::PlayerHandler() { } -void PlayerHandler::decreaseAttribute(const int attr A_UNUSED) const +void PlayerHandler::decreaseAttribute(const AttributesT attr A_UNUSED) const { } @@ -198,13 +198,14 @@ void PlayerHandler::processPlayerStatUpdate3(Net::MessageIn &msg) void PlayerHandler::processPlayerStatUpdate4(Net::MessageIn &msg) { BLOCK_START("PlayerHandler::processPlayerStatUpdate4") - const int type = msg.readInt16("type"); + const uint16_t type = msg.readInt16("type"); const uint8_t ok = msg.readUInt8("flag"); const int value = msg.readUInt8("value"); if (ok != 1) { - const int oldValue = PlayerInfo::getStatBase(type); + const int oldValue = PlayerInfo::getStatBase( + static_cast<AttributesT>(type)); const int points = PlayerInfo::getAttribute(Attributes::CHAR_POINTS) + oldValue - value; PlayerInfo::setAttribute(Attributes::CHAR_POINTS, points); diff --git a/src/net/ea/playerhandler.h b/src/net/ea/playerhandler.h index 760f52af7..4f443c8bf 100644 --- a/src/net/ea/playerhandler.h +++ b/src/net/ea/playerhandler.h @@ -42,7 +42,7 @@ class PlayerHandler notfinal : public Net::PlayerHandler A_DELETE_COPY(PlayerHandler) - void decreaseAttribute(const int attr) const override final; + void decreaseAttribute(const AttributesT attr) const override final; void ignorePlayer(const std::string &player, const bool ignore) const override final; diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp index 76005d968..94530f407 100644 --- a/src/net/eathena/charserverhandler.cpp +++ b/src/net/eathena/charserverhandler.cpp @@ -257,11 +257,12 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, character->dummy = tempPlayer; - for (int i = 0; i < 6; i++) - { - character->data.mStats[i + Attributes::STR].base - = msg.readUInt8("stat"); - } + character->data.mStats[Attributes::STR].base = msg.readUInt8("str"); + character->data.mStats[Attributes::AGI].base = msg.readUInt8("agi"); + character->data.mStats[Attributes::VIT].base = msg.readUInt8("vit"); + character->data.mStats[Attributes::INT].base = msg.readUInt8("int"); + character->data.mStats[Attributes::DEX].base = msg.readUInt8("dex"); + character->data.mStats[Attributes::LUK].base = msg.readUInt8("luk"); character->slot = msg.readInt16("character slot id"); msg.readInt16("rename"); diff --git a/src/net/eathena/playerhandler.cpp b/src/net/eathena/playerhandler.cpp index a4e4586f2..f2627c605 100644 --- a/src/net/eathena/playerhandler.cpp +++ b/src/net/eathena/playerhandler.cpp @@ -227,7 +227,7 @@ void PlayerHandler::emote(const uint8_t emoteId) const outMsg.writeInt8(emoteId, "emote id"); } -void PlayerHandler::increaseAttribute(const int attr) const +void PlayerHandler::increaseAttribute(const AttributesT attr) const { if (attr >= Attributes::STR && attr <= Attributes::LUK) { diff --git a/src/net/eathena/playerhandler.h b/src/net/eathena/playerhandler.h index fc84db326..49572f0b1 100644 --- a/src/net/eathena/playerhandler.h +++ b/src/net/eathena/playerhandler.h @@ -44,7 +44,7 @@ class PlayerHandler final : public MessageHandler, public Ea::PlayerHandler void stopAttack() const override final; void emote(const uint8_t emoteId) const override final; - void increaseAttribute(const int attr) const override final; + void increaseAttribute(const AttributesT attr) const override final; void increaseSkill(const uint16_t skillId) const override final; void pickUp(const FloorItem *const floorItem) const override final; diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 5fde7db54..6f31cf7ac 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -25,6 +25,7 @@ #include "flooritem.h" +#include "enums/being/attributes.h" #include "enums/being/beingaction.h" #include "enums/simpletypes/beingid.h" @@ -49,9 +50,9 @@ class PlayerHandler notfinal virtual void emote(const uint8_t emoteId) const = 0; - virtual void increaseAttribute(const int attr) const = 0; + virtual void increaseAttribute(const AttributesT attr) const = 0; - virtual void decreaseAttribute(const int attr) const = 0; + virtual void decreaseAttribute(const AttributesT attr) const = 0; virtual void increaseSkill(const uint16_t skillId) const = 0; diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 0ae7bfc4f..6662009b3 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -147,7 +147,7 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, PlayerInfoBackend &data = character->data; data.mAttributes[Attributes::EXP] = msg.readInt32("exp"); data.mAttributes[Attributes::MONEY] = msg.readInt32("money"); - Stat &jobStat = data.mStats[static_cast<size_t>(Attributes::JOB)]; + Stat &jobStat = data.mStats[Attributes::JOB]; jobStat.exp = msg.readInt32("job"); const int temp = msg.readInt32("job level"); @@ -197,11 +197,12 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, character->dummy = tempPlayer; - for (int i = 0; i < 6; i++) - { - character->data.mStats[i + Attributes::STR].base - = msg.readUInt8("stat"); - } + character->data.mStats[Attributes::STR].base = msg.readUInt8("str"); + character->data.mStats[Attributes::AGI].base = msg.readUInt8("agi"); + character->data.mStats[Attributes::VIT].base = msg.readUInt8("vit"); + character->data.mStats[Attributes::INT].base = msg.readUInt8("int"); + character->data.mStats[Attributes::DEX].base = msg.readUInt8("dex"); + character->data.mStats[Attributes::LUK].base = msg.readUInt8("luk"); if (withColors) { diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 95b157c00..d2871a456 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -146,7 +146,7 @@ void PlayerHandler::emote(const uint8_t emoteId) const outMsg.writeInt8(emoteId, "emote id"); } -void PlayerHandler::increaseAttribute(const int attr) const +void PlayerHandler::increaseAttribute(const AttributesT attr) const { if (attr >= Attributes::STR && attr <= Attributes::LUK) { diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index d8f159e8b..d831d7ab3 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -44,7 +44,7 @@ class PlayerHandler final : public MessageHandler, public Ea::PlayerHandler void stopAttack() const override final; void emote(const uint8_t emoteId) const override final; - void increaseAttribute(const int attr) const override final; + void increaseAttribute(const AttributesT attr) const override final; void increaseSkill(const uint16_t skillId) const override final; void pickUp(const FloorItem *const floorItem) const override final; |