From e575a51284146151470258c996f36b5b2ba856b4 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 6 Feb 2026 13:34:10 +0100 Subject: [PATCH 1/3] Simplify code --- src/billy_objects.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index d8cba8b..9bee152 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -99,13 +99,7 @@ namespace character { void BillyObjects::check_dagger_conditions(CharacterSheet &sheet) { if (const auto it_dagger = sheet.get_objects().find(tools::Dagger); it_dagger != sheet.get_objects().cend()) { - const std::size_t count_weapons = std::ranges::count_if(sheet.get_objects(), - [](container::const_reference node) { - return std::get_if(&node.first) != - nullptr; - } - ); - if (count_weapons > 1 || sheet.get_objects().contains(weapons::Bow)) { + if (sheet.get_nb_weapons() > 1 || sheet.get_objects().contains(weapons::Bow)) { sheet.habilete.materiel -= it_dagger->second->add_materiel(sheet.get_habilete().type); } } From f245f84601d04611d2083a6e37702447926e56ff Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 6 Feb 2026 13:34:27 +0100 Subject: [PATCH 2/3] Adding the max number of objects allowed --- include/billy_objects.hpp | 2 ++ src/billy_objects.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index 2bf1584..db4289a 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -45,6 +45,8 @@ namespace character { static constexpr std::string_view json_key{ "billy_objects" }; + static constexpr std::uint32_t max_obj{ 3 }; + static std::string_view billy_object_to_string(const billyObjects &object) noexcept; static void to_json(json &j, const container &billy); diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index 9bee152..7592c17 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -17,7 +17,7 @@ namespace character { bool BillyObjects::insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept { - if (sheet.objects.size() < 3) { + if (sheet.objects.size() < max_obj) { sheet.objects.emplace(objType, std::visit(overloaded{ [](const weapons &arg) { From d610ba376206577135c9f3a3e6cd7965ea97055a Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 6 Feb 2026 13:34:35 +0100 Subject: [PATCH 3/3] Adding nodiscard for erase --- include/billy_objects.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index db4289a..2dd3371 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -55,7 +55,7 @@ namespace character { [[nodiscard]] bool insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept; - bool erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept; + [[nodiscard]] bool erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept; [[nodiscard]] const std::plus &get_plus_operation() const { return plus; }