Compare commits

...

3 Commits

Author SHA1 Message Date
Pcornat 69aad6a416
Adding objects is done except for the dagger 2024-02-26 16:17:26 +01:00
Pcornat 88025baeff
Adding the future class which changes characteristics based on objects. 2024-02-26 12:17:19 +01:00
Pcornat cfd22179e9
Changing characteristics to try to deal with gameplay.
It is not a definitive changes, a refactoring is going to be made in the future.
2024-02-26 11:36:58 +01:00
9 changed files with 332 additions and 8 deletions

104
include/billy_objects.hpp Normal file
View File

@ -0,0 +1,104 @@
//
// Created by postaron on 20/02/24.
//
#ifndef BILLYSHEET_BILLY_OBJECTS_HPP
#define BILLYSHEET_BILLY_OBJECTS_HPP
#include <cstdint>
#include <array>
#include <functional>
#include <variant>
#include <string_view>
#include "characteristic/characteristic.hpp"
// helper type for the visitor
template<typename... Ts>
struct overloaded : Ts ... { using Ts::operator()...; };
template<typename... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
namespace character {
class CharacterSheet;
enum class weapons : std::uint8_t {
Sword = 0,
Lance = 1,
Morgenstern = 2,
Bow = 3
};
enum class equipments : std::uint8_t {
Chainmail = 0,
CookingPot = 1,
PamphletTourist = 2,
MedicKit = 3,
};
enum class tools : std::uint8_t {
Fourche = 0,
Dagger = 1,
RockClimbingKit = 2,
SackOfGrain = 3
};
class BillyObjects final {
public:
using billyObject = std::variant<weapons, equipments, tools>;
using container = std::array<billyObject, 3>;
static constexpr std::string_view sword{ "Sword" };
static constexpr std::string_view lance{ "Lance" };
static constexpr std::string_view morgenstern{ "Morgenstern" };
static constexpr std::string_view bow{ "Bow" };
static constexpr std::string_view chainmail{ "Chainmail" };
static constexpr std::string_view cooking_pot{ "Cooking pot" };
static constexpr std::string_view medic_kit{ "Medic kit" };
static constexpr std::string_view fourche{ "Fourche" };
static constexpr std::string_view dagger{ "Dagger" };
static constexpr std::string_view rock_climbing_kit{ "Rock climbing kit" };
static constexpr std::string_view sack_of_grain{ "Sack of grain" };
static std::string_view billy_object_to_string(const billyObject &object) noexcept;
void add_object(const billyObject &object, CharacterSheet &sheet) noexcept;
void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept;
private:
container objects;
std::plus<std::uint32_t> plus;
std::minus<std::uint32_t> minus;
std::uint8_t end_object{ 0 };
static void change_carac_weapon(CharacterSheet &sheet,
const weapons &arg,
characteristic::Characteristic &localHabilete,
characteristic::Characteristic &localAdresse,
characteristic::Characteristic &localEndurance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation) noexcept;
static void change_carac_equipment(const equipments &arg,
CharacterSheet &sheet,
characteristic::Characteristic &localHabilete,
characteristic::Characteristic &localAdresse,
characteristic::Characteristic &localEndurance,
characteristic::Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &primary,
const std::function<std::uint32_t(std::uint32_t,
std::uint32_t)> &complement) noexcept;
static void change_carac_tools(const tools &arg,
CharacterSheet &sheet,
characteristic::Characteristic &localHabilete,
characteristic::Characteristic &localAdresse,
characteristic::Characteristic &localEndurance,
characteristic::Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t,
std::uint32_t)> &operation) noexcept;
};
}
#endif //BILLYSHEET_BILLY_OBJECTS_HPP

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

@ -8,6 +8,9 @@ namespace character::characteristic {
public:
Chance() noexcept: Characteristic(3, 0, 0, 0) {}
Chance(const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) :
Characteristic(3, carac, materiel, additional) {}
~Chance() noexcept final = default;
friend void from_json(const json &j, Chance &chance) {

View File

@ -6,9 +6,16 @@
using json = nlohmann::json;
namespace character {
class BillyObjects;
}
namespace character::characteristic {
class Characteristic {
protected:
friend character::BillyObjects;
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 +28,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 +37,7 @@ namespace character::characteristic {
carac = charac.carac;
materiel = charac.materiel;
additional = charac.additional;
total = charac.get_total();
return *this;
}
@ -43,11 +51,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 +75,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) {

163
src/billy_objects.cpp Normal file
View File

@ -0,0 +1,163 @@
//
// Created by postaron on 23/02/24.
//
#include "billy_objects.hpp"
#include "characteristic/characteristic.hpp"
#include "character_sheet.hpp"
namespace character {
using characteristic::Characteristic;
void BillyObjects::add_object(const billyObject &object, CharacterSheet &sheet) noexcept {
if (end_object < 3) {
objects.at(end_object) = object;
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
auto &local_endurance = static_cast<Characteristic &>(sheet.endurance);
auto &local_chance = static_cast<Characteristic &>(sheet.chance);
std::visit(overloaded{
[&](const weapons &arg) {
++sheet.nb_weapons;
change_carac_weapon(sheet, arg, local_habilete, local_adresse, local_endurance, plus);
},
[&](const equipments &arg) {
++sheet.nb_equipments;
change_carac_equipment(arg,
sheet,
local_habilete,
local_adresse,
local_endurance,
local_chance,
plus,
minus);
},
[&](const tools &arg) {
++sheet.nb_tools;
change_carac_tools(arg, sheet, local_habilete, local_adresse, local_endurance, plus);
},
}, object);
}
}
void BillyObjects::change_carac_tools(const tools &arg,
CharacterSheet &sheet,
Characteristic &localHabilete,
Characteristic &localAdresse,
Characteristic &localEndurance,
Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t,
std::uint32_t)> &operation) noexcept {
switch (arg) {
case tools::Fourche:
localHabilete.materiel = operation(localHabilete.materiel, 1);
localEndurance.materiel = operation(localEndurance.materiel, 3);
break;
case tools::Dagger:
break;
case tools::RockClimbingKit:
localAdresse.materiel = operation(localAdresse.materiel, 1);
break;
case tools::SackOfGrain:
localEndurance.materiel = operation(localEndurance.materiel, 2);
localChance.materiel = operation(localChance.materiel, 2);
break;
}
}
void BillyObjects::change_carac_equipment(const equipments &arg,
CharacterSheet &sheet,
Characteristic &localHabilete,
Characteristic &localAdresse,
Characteristic &localEndurance,
Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &primary,
const std::function<std::uint32_t(std::uint32_t,
std::uint32_t)> &complement) noexcept {
switch (arg) {
case equipments::Chainmail:
localHabilete.materiel = complement(localHabilete.materiel, 1);
localAdresse.materiel = complement(localAdresse.materiel, 1);
localEndurance.materiel = primary(localEndurance.materiel, 1);
sheet.armor = primary(sheet.armor, 2);
break;
case equipments::CookingPot:
localEndurance.materiel = primary(localEndurance.materiel, 2);
sheet.armor = primary(sheet.armor, 1);
break;
case equipments::PamphletTourist:
localChance.materiel = primary(localChance.materiel, 4);
break;
case equipments::MedicKit:
localChance.materiel = primary(localChance.materiel, 1);
break;
}
}
void BillyObjects::change_carac_weapon(CharacterSheet &sheet,
const weapons &arg,
Characteristic &localHabilete,
Characteristic &localAdresse,
Characteristic &localEndurance,
const std::function<std::uint32_t(std::uint32_t,
std::uint32_t)> &operation) noexcept {
switch (arg) {
case weapons::Sword:
localHabilete.materiel = operation(localHabilete.materiel, 4);
break;
case weapons::Lance:
localHabilete.materiel = operation(localHabilete.materiel, 3);
localAdresse.materiel = operation(localAdresse.materiel, 1);
break;
case weapons::Morgenstern:
localHabilete.materiel = operation(localHabilete.materiel, 1);
localEndurance.materiel = operation(localEndurance.materiel, 1);
sheet.damage = operation(sheet.damage, 1);
break;
case weapons::Bow:
localHabilete.materiel = operation(localHabilete.materiel, 3);
localAdresse.materiel = operation(localAdresse.materiel, 1);
break;
}
}
std::string_view BillyObjects::billy_object_to_string(const billyObject &object) noexcept {
return std::visit(overloaded{
[](const weapons &arg) {
switch (arg) {
case weapons::Sword:
return sword;
case weapons::Lance:
return lance;
case weapons::Morgenstern:
return morgenstern;
case weapons::Bow:
return bow;
}
},
[](const equipments &arg) {
switch (arg) {
case equipments::Chainmail:
return chainmail;
case equipments::CookingPot:
return cooking_pot;
case equipments::MedicKit:
return medic_kit;
}
},
[](const tools &arg) {
switch (arg) {
case tools::Fourche:
return fourche;
case tools::Dagger:
return dagger;
case tools::RockClimbingKit:
return rock_climbing_kit;
case tools::SackOfGrain:
return sack_of_grain;
}
}
}, object);
}
}

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