diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index f09b282..d03879a 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -55,22 +55,8 @@ namespace character { static void from_json(const json &j, container &billy); - /*! - * \brief It inserts the object inside the sheet. - * - * This method changes values inside the sheet according to the book's rules. - * \param sheet sheet to insert object into - * \param objType the object to insert - * \return true: object inserted, false otherwise - */ [[nodiscard]] bool insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept; - /*! - * \brief - * \param sheet sheet to erase object from - * \param objToErase the object to erase - * \return true: object erased, false otherwise - */ [[nodiscard]] bool erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept; [[nodiscard]] static bool is_full(const CharacterSheet &sheet) noexcept; @@ -86,15 +72,13 @@ namespace character { std::minus minus; - /*! - * \brief - * \param arg object used to change values - * \param sheet sheet to change - * \param operation Operation to apply to change values - */ static void change_carac(const billyObjects &arg, CharacterSheet &sheet, - const std::function &operation) noexcept; + characteristic::Characteristic &localHabilete, + characteristic::Characteristic &localAdresse, + characteristic::Characteristic &localEndurance, + characteristic::Characteristic &localChance, + const std::function &operation) noexcept; }; } diff --git a/include/characteristic.hpp b/include/characteristic.hpp index f4d886d..65a208d 100644 --- a/include/characteristic.hpp +++ b/include/characteristic.hpp @@ -12,10 +12,6 @@ namespace character { } namespace character::characteristic { - - /*! - * \brief Different characteristic type - */ enum class characType : std::uint8_t { Adresse = 0, Endurance = 1, @@ -23,35 +19,17 @@ namespace character::characteristic { Habilete = 3 }; - /*! - * \brief This class represents a characteristic for Billy (one of characType) - */ class Characteristic { protected: - friend BillyObjects; + friend character::BillyObjects; using defaultValue = std::numeric_limits; - - //! Total point for this charac mutable std::int32_t total{ defaultValue::max() }; - - //! Base value const std::uint32_t base{ 0 }; - - //! Value depending of the characType for this characteristic. std::uint32_t carac{ 0 }; - - //! Value changed from a billyObjects (billyEnums) possessed std::uint32_t materiel{ 0 }; - - //! Additional value when creating the character std::uint32_t additional{ 0 }; - /*! - * \brief Get base value depending of the characType - * \param inType Characteristic type used to get base number - * \return Base value depending of the characType - */ - static constexpr std::uint32_t get_base(const characType inType) noexcept { + static std::uint32_t get_base(const characType inType) noexcept { switch (inType) { case characType::Adresse: return 1; @@ -66,21 +44,21 @@ namespace character::characteristic { public: const characType type{ characType::Adresse }; - constexpr Characteristic() noexcept = default; + Characteristic() noexcept = default; - constexpr Characteristic(const characType inType, - const std::uint32_t carac, - const std::uint32_t materiel, - const std::uint32_t additional) : + Characteristic(const characType inType, + const std::uint32_t carac, + const std::uint32_t materiel, + const std::uint32_t additional) : base(get_base(inType)), carac(carac), materiel(materiel), additional(additional), type(inType) { (void) get_total(); } - constexpr explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {} + explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {} - constexpr Characteristic(const Characteristic &charac) noexcept = default; + Characteristic(const Characteristic &charac) noexcept = default; Characteristic &operator=(const Characteristic &charac) noexcept { const_cast(base) = charac.base; @@ -131,4 +109,4 @@ namespace character::characteristic { } -#endif //BILLYSHEET_CHARACTERISTIC_HPP +#endif //BILLYSHEET_CHARACTERISTIC_HPP \ No newline at end of file diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index 526ba41..7fd747c 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -40,13 +40,18 @@ namespace character { const auto &object = sheet.objects[objType]; sheet.available_objects.erase(objType); + auto &local_habilete = static_cast(sheet.habilete); + auto &local_adresse = static_cast(sheet.adresse); + auto &local_endurance = static_cast(sheet.endurance); + auto &local_chance = static_cast(sheet.chance); + std::visit(overloaded{ [&](const weapons &) { ++sheet.nb_weapons; }, [&](const equipments &) { ++sheet.nb_equipments; }, [&](const tools &) { ++sheet.nb_tools; }, }, objType); - change_carac(object, sheet, plus); + change_carac(object, sheet, local_habilete, local_adresse, local_endurance, local_chance, plus); return true; } return false; @@ -58,13 +63,18 @@ namespace character { sheet.objects.erase(objToErase); sheet.available_objects.insert(objToErase); + auto &local_habilete = static_cast(sheet.habilete); + auto &local_adresse = static_cast(sheet.adresse); + auto &local_endurance = static_cast(sheet.endurance); + auto &local_chance = static_cast(sheet.chance); + std::visit(overloaded{ [&](const weapons &) { --sheet.nb_weapons; }, [&](const equipments &) { --sheet.nb_equipments; }, [&](const tools &) { --sheet.nb_tools; } }, objToErase); - change_carac(obj, sheet, minus); + change_carac(obj, sheet, local_habilete, local_adresse, local_endurance, local_chance, minus); return true; } return false; @@ -76,12 +86,16 @@ namespace character { void BillyObjects::change_carac(const billyObjects &arg, CharacterSheet &sheet, - const std::function &operation) + Characteristic &localHabilete, + Characteristic &localAdresse, + Characteristic &localEndurance, + Characteristic &localChance, + const std::function &operation) noexcept { - sheet.habilete.materiel = operation(sheet.habilete.materiel, arg->add_materiel(sheet.habilete.type)); - sheet.adresse.materiel = operation(sheet.adresse.materiel, arg->add_materiel(sheet.adresse.type)); - sheet.endurance.materiel = operation(sheet.endurance.materiel, arg->add_materiel(sheet.endurance.type)); - sheet.chance.materiel = operation(sheet.chance.materiel, arg->add_materiel(sheet.chance.type)); + localHabilete.materiel = operation(localHabilete.materiel, arg->add_materiel(localHabilete.type)); + localAdresse.materiel = operation(localAdresse.materiel, arg->add_materiel(localAdresse.type)); + localEndurance.materiel = operation(localEndurance.materiel, arg->add_materiel(localEndurance.type)); + localChance.materiel = operation(localChance.materiel, arg->add_materiel(localChance.type)); sheet.armor = operation(sheet.armor, arg->add_armor()); sheet.damage = operation(sheet.armor, arg->add_damage()); sheet.critique = operation(sheet.critique, arg->add_critique());