Changing characteristics to try to deal with gameplay.

It is not a definitive changes, a refactoring is going to be made in the future.
This commit is contained in:
Pcornat 2024-02-26 11:36:22 +01:00
parent 97960cffc6
commit cfd22179e9
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
6 changed files with 57 additions and 8 deletions

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -9,6 +9,8 @@ using json = nlohmann::json;
namespace character::characteristic {
class Characteristic {
protected:
using defaultValue = std::numeric_limits<std::int32_t>;
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<std::int32_t>(base + carac + materiel + additional);
if (total < 0) {
total = 0;
}
}
return total;
}
friend void from_json(const json &j, Characteristic &charac) {
const_cast<std::uint32_t &>(charac.base) = j.at("base").get<std::uint32_t>();
charac.carac = j.at("carac").get<std::uint32_t>();
charac.materiel = j.at("materiel").get<std::uint32_t>();
charac.additional = j.at("additional").get<std::uint32_t>();
charac.total = j.at("total").get<std::uint32_t>();
}
};
@ -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();
}
}

View File

@ -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;

View File

@ -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) {

View File

@ -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<character::classe>(i));
if (ImGui::Selectable(GuiData::classes[i].data(), is_selected))
data.billy.current_class = static_cast<character::classe>(i);
if (is_selected)
ImGui::SetItemDefaultFocus();