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

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