feat: add player upgrades
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "game/Team.h"
|
||||
#include "game/PlayerUpgrades.h"
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
@@ -11,17 +12,16 @@ namespace game {
|
||||
class Player {
|
||||
private:
|
||||
game::TeamColor m_TeamColor;
|
||||
PlayerUpgrades m_Upgrades;
|
||||
|
||||
std::uint32_t m_Gold;
|
||||
std::uint32_t m_Exp;
|
||||
std::string m_Name;
|
||||
PlayerID m_ID;
|
||||
|
||||
std::uint8_t m_GoldPerSecond;
|
||||
|
||||
public:
|
||||
|
||||
Player(std::uint8_t id = 0) : m_TeamColor(game::TeamColor::None), m_Gold(0), m_Exp(0), m_ID(id), m_GoldPerSecond(5) {}
|
||||
Player(std::uint8_t id = 0) : m_TeamColor(game::TeamColor::None), m_Gold(0), m_Exp(0), m_ID(id) {}
|
||||
|
||||
const std::string& GetName() const { return m_Name; }
|
||||
void SetName(const std::string& name) { m_Name = name; }
|
||||
@@ -29,9 +29,6 @@ public:
|
||||
game::TeamColor GetTeamColor() const { return m_TeamColor; }
|
||||
void SetTeamColor(game::TeamColor teamColor) { m_TeamColor = teamColor; }
|
||||
|
||||
std::uint8_t GetGoldPerSecond() const { return m_GoldPerSecond; }
|
||||
void SetGoldPerSecond(std::uint8_t goldPerSecond) { m_GoldPerSecond = goldPerSecond; }
|
||||
|
||||
std::uint32_t GetGold() const { return m_Gold; }
|
||||
void SetGold(std::uint32_t gold) { m_Gold = gold; }
|
||||
void AddGold(std::uint32_t gold) { m_Gold += gold; }
|
||||
@@ -42,6 +39,9 @@ public:
|
||||
void AddExp(std::uint32_t exp) { m_Exp += exp; }
|
||||
void RemoveExp(std::uint32_t exp) { m_Exp -= exp; }
|
||||
|
||||
const PlayerUpgrades& getUpgrades() const { return m_Upgrades; }
|
||||
PlayerUpgrades& getUpgrades() { return m_Upgrades; }
|
||||
|
||||
PlayerID GetID() const { return m_ID; }
|
||||
};
|
||||
|
||||
|
||||
34
include/game/PlayerUpgrades.h
Normal file
34
include/game/PlayerUpgrades.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "Mobs.h"
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
class PlayerUpgrades {
|
||||
private:
|
||||
std::uint8_t m_ClickerLevel;
|
||||
std::uint8_t m_GoldPerSecond;
|
||||
std::array<std::uint8_t, static_cast<std::size_t>(MobType::MOB_COUNT)> m_MobsUpgradeLevel;
|
||||
public:
|
||||
static const int MAX_MOB_LEVEL = 5;
|
||||
static const int MAX_CLICKER_LEVEL = 3;
|
||||
|
||||
PlayerUpgrades() : m_ClickerLevel(1), m_GoldPerSecond(5) {}
|
||||
|
||||
std::uint8_t GetClickerLevel() const { return m_ClickerLevel; }
|
||||
std::uint8_t GetMobUpgradeLevel(MobType mob) const { return m_MobsUpgradeLevel.at(static_cast<std::size_t>(mob)); }
|
||||
std::uint8_t GetGoldPerSecond() const { return m_GoldPerSecond; }
|
||||
|
||||
|
||||
void UpgradeMob(MobType mob) {
|
||||
std::uint8_t& mobLevel = m_MobsUpgradeLevel.at(static_cast<std::size_t>(mob));
|
||||
mobLevel = std::min(mobLevel + 1, MAX_MOB_LEVEL);
|
||||
}
|
||||
|
||||
void UpgradeClicker() { m_ClickerLevel = std::min(m_ClickerLevel + 1, MAX_CLICKER_LEVEL); }
|
||||
void SetGoldPerSecond(std::uint8_t goldPerSecond) { m_GoldPerSecond = goldPerSecond; }
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
@@ -42,7 +42,7 @@ void ServerGame::UpdatePlayerStats() {
|
||||
void ServerGame::UpdateGoldMines() {
|
||||
for (auto& pair : m_Server->GetPlayers()) {
|
||||
game::Player* player = &pair.second;
|
||||
player->AddGold(player->GetGoldPerSecond());
|
||||
player->AddGold(player->getUpgrades().GetGoldPerSecond());
|
||||
|
||||
// Update player money and exp every second
|
||||
protocol::UpdateMoneyPacket moneyPacket(player->GetGold());
|
||||
|
||||
Reference in New Issue
Block a user