diff --git a/src/common/commonitem.hpp b/src/common/commonitem.hpp index dd74d23..65a5a57 100644 --- a/src/common/commonitem.hpp +++ b/src/common/commonitem.hpp @@ -13,6 +13,9 @@ * as defined by the Mozilla Public License, v. 2.0. */ +#ifndef _H_COMMONITEM_ +#define _H_COMMONITEM_ + #include /** @@ -24,7 +27,7 @@ enum class ItemValidity { ONE_WEEK, //!< 7 days ONE_MONTH, //!< 30 days ONE_YEAR, //!< 365 days - LIMITLESS //!< maximum date we can put in db + LIMITLESS //!< 100 years }; /** @@ -42,8 +45,13 @@ enum class ItemType { class CommonItem { private: + Uint32 code; std::string name; std::string description; ItemType type; - int properties[8]; + int properties[8]{0, 0, 0, 0, 0, 0, 0, 0}; + unsigned int goldPrices[5]{ 0, 0, 0, 0, 0 }; + unsigned int cashPrices[5]{ 0, 0, 0, 0, 0 }; }; + +#endif //! _H_COMMONITEM_ diff --git a/src/common/commonplayer.cpp b/src/common/commonplayer.cpp new file mode 100644 index 0000000..e8c8bd4 --- /dev/null +++ b/src/common/commonplayer.cpp @@ -0,0 +1,36 @@ +/** + * \file commonplayer.cpp + * \brief Common definitions for a player in client and server side + * \author G. B. + * \version 0.1a + * \date 14/04/2020 + */ +/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + * If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", + * as defined by the Mozilla Public License, v. 2.0. + */ + +#include "commonplayer.hpp" + +CommonPlayer::CommonPlayer() { +} + +void CommonPlayer::setInfo(const PlayerBasicInfo& newInfo) { + info = newInfo; +} + +void CommonPlayer::setTeam(char newTeam) { + team = newTeam; +} + +/** + * \brief Adjust the amount of a reward/penalty according to the enabled items + * \param baseAmount amount of the reward + * \return actual amount to use for this player + */ +int CommonPlayer::getRewardAmount(const int baseAmount) { + return baseAmount * (100 + properties[0]) / 100; +} diff --git a/src/common/commonplayer.hpp b/src/common/commonplayer.hpp index 6de61ba..a2e3b88 100644 --- a/src/common/commonplayer.hpp +++ b/src/common/commonplayer.hpp @@ -5,26 +5,34 @@ * \version 0.1a * \date 25/01/2020 */ - /* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. - * If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This Source Code Form is "Incompatible With Secondary Licenses", - * as defined by the Mozilla Public License, v. 2.0. - */ +/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + * If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", + * as defined by the Mozilla Public License, v. 2.0. + */ #ifndef _H_COMMONPLAYER_ #define _H_COMMONPLAYER_ #include +#include #include +#include "commonitem.hpp" -enum class PlayerLevel { +enum class PlayerLevel : unsigned int { ROOKIE, WOOD_HAMMER, WOOD_HAMMER2, STONE_HAMMER, - STONE_HAMMER2, // TBC + STONE_HAMMER2, + AXE, + AXE_DOUBLE, + SILVER_AXE, + SILVER_AXE_DOUBLE, + GOLDEN_AXE, + GOLDEN_AXE_DOUBLE, // TBC ADMIN }; @@ -34,9 +42,16 @@ enum class PlayerLocationType { ROOM }; +/** + * Data for the player currently connected to a client app + * Sent by the server + */ struct PlayerBasicInfo { std::string name; PlayerLevel level; + std::string guild; + Uint8 rankingInGuild; + Uint8 totalInGuild; Uint32 points; Uint32 gold; Uint32 cash; //! only here for compatibility, but unsupported @@ -63,4 +78,20 @@ struct PlayerResult { bool wins; }; +/** + * Common class for server and client representing a Player + */ +class CommonPlayer { +public: + CommonPlayer(); + void setInfo(const PlayerBasicInfo &newInfo); + void setTeam(char newTeam); + int getRewardAmount(const int baseAmount); +private: + PlayerBasicInfo info; + char team = 'A'; + std::vector items; + int properties[8]{ 0, 0, 0, 0, 0, 0, 0, 0 }; // convenience; sum computed from items +}; + #endif //! _H_COMMONPLAYER_