BillySheet/include/character_sheet.hpp

150 lines
5.1 KiB
C++

#ifndef BILLYSHEET_CHARACTER_SHEET_HPP
#define BILLYSHEET_CHARACTER_SHEET_HPP
#include "characteristic/characteristic.hpp"
#include "billy_objects.hpp"
#include <unordered_set>
namespace character {
enum class classe : std::uint8_t {
Guerrier = 0,
Prudent = 1,
Paysan = 2,
Debrouillard = 3,
};
class CharacterSheet final {
private:
friend BillyObjects;
std::string caractere{};
//TODO: bad design pour les caractéristiques. Je dois trouver autre chose.
characteristic::Characteristic adresse{ characteristic::characType::Adresse };
characteristic::Characteristic endurance{ characteristic::characType::Endurance };
characteristic::Characteristic chance{ characteristic::characType::Chance };
characteristic::Characteristic habilete{ characteristic::characType::Habilete };
BillyObjects::container objects;
std::unordered_set<BillyObjects::billyObject> available_objects{
BillyObjects::all_objects.cbegin(),
BillyObjects::all_objects.cend()
};
std::uint32_t health_point{ 0 };
std::uint32_t armor{ 0 };
std::uint32_t damage{ 0 };
std::uint32_t critique{ 0 };
std::uint32_t glory{ 0 };
std::uint32_t money{ 0 };
std::uint32_t nb_weapons{ 0 };
std::uint32_t nb_equipments{ 0 };
std::uint32_t nb_tools{ 0 };
public:
CharacterSheet() = default;
CharacterSheet(const CharacterSheet &sheet) noexcept = default;
CharacterSheet(CharacterSheet &&sheet) noexcept = default;
CharacterSheet &operator=(const CharacterSheet &characterSheet) noexcept = default;
CharacterSheet &operator=(CharacterSheet &&characterSheet) noexcept = default;
~CharacterSheet() noexcept = default;
[[nodiscard]] const std::string &get_caractere() const { return caractere; }
[[nodiscard]] const characteristic::Characteristic &get_adresse() const { return adresse; }
[[nodiscard]] const characteristic::Characteristic &get_endurance() const { return endurance; }
[[nodiscard]] const characteristic::Characteristic &get_chance() const { return chance; }
[[nodiscard]] const characteristic::Characteristic &get_habilete() const { return habilete; }
[[nodiscard]] const BillyObjects::container &get_objects() const { return objects; }
[[nodiscard]] classe get_current_class() const {
if (nb_weapons >= 2) {
return classe::Guerrier;
} else if (nb_equipments >= 2) {
return classe::Prudent;
} else if (nb_tools >= 2) {
return classe::Paysan;
} else {
return classe::Debrouillard;
}
}
[[nodiscard]] std::uint32_t get_health_point() const { return health_point; }
[[nodiscard]] std::uint32_t get_armor() const { return armor; }
[[nodiscard]] std::uint32_t get_damage() const { return damage; }
[[nodiscard]] std::uint32_t get_glory() const { return glory; }
[[nodiscard]] std::uint32_t get_money() const { return money; }
[[nodiscard]] std::uint32_t get_nb_weapons() const { return nb_weapons; }
[[nodiscard]] std::uint32_t get_nb_equipments() const { return nb_equipments; }
[[nodiscard]] std::uint32_t get_nb_tools() const { return nb_tools; }
friend void from_json(const json &j, CharacterSheet &billy) {
j.at("caractere").get_to(billy.caractere);
j.at("adresse").get_to(billy.adresse);
j.at("endurance").get_to(billy.endurance);
j.at("chance").get_to(billy.chance);
j.at("habilete").get_to(billy.habilete);
j.at("health_point").get_to(billy.health_point);
j.at("armor").get_to(billy.armor);
j.at("damage").get_to(billy.damage);
j.at("glory").get_to(billy.glory);
j.at("money").get_to(billy.money);
j.at("nb_weapons").get_to(billy.nb_weapons);
j.at("nb_equipments").get_to(billy.nb_equipments);
j.at("nb_tools").get_to(billy.nb_tools);
BillyObjects::from_json(j.at(BillyObjects::json_key), billy.objects);
}
};
static void to_json(json &j, const CharacterSheet &billy) {
j["caractere"] = billy.get_caractere();
j["adresse"] = billy.get_adresse();
j["endurance"] = billy.get_endurance();
j["chance"] = billy.get_chance();
j["habilete"] = billy.get_habilete();
j["classe"] = billy.get_current_class();
j["health_point"] = billy.get_health_point();
j["armor"] = billy.get_armor();
j["damage"] = billy.get_damage();
j["glory"] = billy.get_glory();
j["money"] = billy.get_money();
j["nb_weapons"] = billy.get_nb_weapons();
j["nb_equipments"] = billy.get_nb_equipments();
j["nb_tools"] = billy.get_nb_tools();
j.emplace(std::pair{ BillyObjects::json_key, json::array() });
BillyObjects::to_json(j.at(BillyObjects::json_key), billy.get_objects());
}
}
#endif //BILLYSHEET_CHARACTER_SHEET_HPP