Skip to content

Commit

Permalink
[common] Initiating CommonPlayer datatype #21
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaudic committed Apr 14, 2020
1 parent 0cfd00e commit 4d79b4a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/common/commonitem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* as defined by the Mozilla Public License, v. 2.0.
*/

#ifndef _H_COMMONITEM_
#define _H_COMMONITEM_

#include <string>

/**
Expand All @@ -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
};

/**
Expand All @@ -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_
36 changes: 36 additions & 0 deletions src/common/commonplayer.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
49 changes: 40 additions & 9 deletions src/common/commonplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>
#include <vector>
#include <SDL2/SDL.h>
#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
};

Expand All @@ -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
Expand All @@ -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<CommonItem*> items;
int properties[8]{ 0, 0, 0, 0, 0, 0, 0, 0 }; // convenience; sum computed from items
};

#endif //! _H_COMMONPLAYER_

0 comments on commit 4d79b4a

Please sign in to comment.