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:
parent
97960cffc6
commit
cfd22179e9
6 changed files with 57 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue