From cfd22179e9ba7b2aaa8d9f343b021360c45f3608 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Mon, 26 Feb 2024 11:36:22 +0100 Subject: [PATCH] Changing characteristics to try to deal with gameplay. It is not a definitive changes, a refactoring is going to be made in the future. --- include/character_sheet.hpp | 37 ++++++++++++++++++++--- include/characteristic/adresse.hpp | 3 ++ include/characteristic/characteristic.hpp | 17 ++++++++++- include/characteristic/endurance.hpp | 3 ++ include/characteristic/habilete.hpp | 3 ++ src/gui/gui.cpp | 2 -- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/include/character_sheet.hpp b/include/character_sheet.hpp index ace76ed..b19ce82 100644 --- a/include/character_sheet.hpp +++ b/include/character_sheet.hpp @@ -23,12 +23,14 @@ namespace character { private: friend gui::Gui; - friend class Controller; + friend class BillyObjects; std::mt19937_64 engine{ std::random_device{ "rdseed" }() }; std::string caractere{}; + //TODO: bad design pour les caractéristiques. Je dois trouver autre chose. + characteristic::Adresse adresse; characteristic::Endurance endurance; @@ -37,8 +39,6 @@ namespace character { characteristic::Habilete habilete; - classe current_class{ classe::Guerrier }; - std::uint32_t health_point{ 0 }; std::uint32_t armor{ 0 }; @@ -48,6 +48,12 @@ namespace character { 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; @@ -71,7 +77,17 @@ namespace character { [[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; } - [[nodiscard]] classe get_current_class() const { return current_class; } + [[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; } @@ -83,18 +99,26 @@ namespace character { [[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("classe").get_to(billy.current_class); 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); } }; @@ -110,6 +134,9 @@ namespace character { 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(); } } diff --git a/include/characteristic/adresse.hpp b/include/characteristic/adresse.hpp index 4847854..dbb1ce9 100644 --- a/include/characteristic/adresse.hpp +++ b/include/characteristic/adresse.hpp @@ -11,6 +11,9 @@ namespace character::characteristic { public: Adresse() noexcept: Characteristic(1, 0, 0, 0) {} + Adresse(const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) : + Characteristic(1, carac, materiel, additional) {} + ~Adresse() noexcept final = default; friend void from_json(const json &j, Adresse &adresse) { diff --git a/include/characteristic/characteristic.hpp b/include/characteristic/characteristic.hpp index 495ee3a..ac85938 100644 --- a/include/characteristic/characteristic.hpp +++ b/include/characteristic/characteristic.hpp @@ -9,6 +9,8 @@ using json = nlohmann::json; namespace character::characteristic { class Characteristic { protected: + using defaultValue = std::numeric_limits; + mutable std::int32_t total{ defaultValue::max() }; const std::uint32_t base{ 0 }; std::uint32_t carac{ 0 }; std::uint32_t materiel{ 0 }; @@ -21,7 +23,7 @@ namespace character::characteristic { const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) noexcept: - base(base), carac(carac), materiel(materiel), additional(additional) {} + base(base), carac(carac), materiel(materiel), additional(additional) { (void) get_total(); } Characteristic(const Characteristic &charac) noexcept = default; @@ -30,6 +32,7 @@ namespace character::characteristic { carac = charac.carac; materiel = charac.materiel; additional = charac.additional; + total = charac.get_total(); return *this; } @@ -43,11 +46,22 @@ namespace character::characteristic { [[nodiscard]] std::uint32_t get_additional() const { return additional; } + [[nodiscard]] std::size_t get_total() const noexcept { + if (total == defaultValue::max()) { + total = static_cast(base + carac + materiel + additional); + if (total < 0) { + total = 0; + } + } + return total; + } + friend void from_json(const json &j, Characteristic &charac) { const_cast(charac.base) = j.at("base").get(); charac.carac = j.at("carac").get(); charac.materiel = j.at("materiel").get(); charac.additional = j.at("additional").get(); + charac.total = j.at("total").get(); } }; @@ -56,6 +70,7 @@ namespace character::characteristic { j["carac"] = charac.get_carac(); j["materiel"] = charac.get_materiel(); j["additional"] = charac.get_additional(); + j["total"] = charac.get_total(); } } diff --git a/include/characteristic/endurance.hpp b/include/characteristic/endurance.hpp index 2853a9b..91ad534 100644 --- a/include/characteristic/endurance.hpp +++ b/include/characteristic/endurance.hpp @@ -11,6 +11,9 @@ namespace character::characteristic { public: Endurance() noexcept: Characteristic(2, 0, 0, 0) {}; + Endurance(const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) noexcept: + Characteristic(2, carac, materiel, additional) {} + ~Endurance() noexcept final = default; [[nodiscard]] std::uint32_t get_max_lp() const noexcept; diff --git a/include/characteristic/habilete.hpp b/include/characteristic/habilete.hpp index dbde189..ef5d4ad 100644 --- a/include/characteristic/habilete.hpp +++ b/include/characteristic/habilete.hpp @@ -9,6 +9,9 @@ namespace character::characteristic { public: Habilete() noexcept: Characteristic(2, 0, 0, 0) {}; + Habilete(const uint32_t carac, const uint32_t materiel, const uint32_t additional) noexcept: + Characteristic(2, carac, materiel, additional) {} + ~Habilete() noexcept final = default; friend void from_json(const json &j, Habilete &habilete) { diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 17d1f68..000df05 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -53,8 +53,6 @@ void gui::Gui::render_gui(const Controller &controller) { ImGuiComboFlags_PopupAlignLeft)) { for (std::size_t i = 0; i < GuiData::classes.size(); ++i) { const bool is_selected = (data.billy.get_current_class() == static_cast(i)); - if (ImGui::Selectable(GuiData::classes[i].data(), is_selected)) - data.billy.current_class = static_cast(i); if (is_selected) ImGui::SetItemDefaultFocus();