Reformat
This commit is contained in:
parent
b3c59ffe0d
commit
b050a7634d
8 changed files with 113 additions and 104 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "billy_objects.hpp"
|
||||
#include "characteristic.hpp"
|
||||
#include "character_sheet.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
constexpr std::uint32_t const_hash(const char *input) {
|
||||
|
|
@ -18,16 +19,24 @@ namespace character {
|
|||
bool BillyObjects::insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept {
|
||||
if (sheet.objects.size() < 3) {
|
||||
sheet.objects.emplace(objType,
|
||||
std::visit(overloaded{
|
||||
[](const weapons &arg) {
|
||||
return std::unique_ptr<GenericObject>(std::make_unique<Weapons>(arg));
|
||||
},
|
||||
[](const equipments &arg) {
|
||||
return std::unique_ptr<GenericObject>(std::make_unique<Equipments>(arg));
|
||||
},
|
||||
[](const tools &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Tools>(arg)); },
|
||||
},
|
||||
objType));
|
||||
std::visit(overloaded{
|
||||
[](const weapons &arg) {
|
||||
return std::unique_ptr<GenericObject>(
|
||||
std::make_unique<Weapons>(arg)
|
||||
);
|
||||
},
|
||||
[](const equipments &arg) {
|
||||
return std::unique_ptr<GenericObject>(
|
||||
std::make_unique<Equipments>(arg)
|
||||
);
|
||||
},
|
||||
[](const tools &arg) {
|
||||
return std::unique_ptr<GenericObject>(
|
||||
std::make_unique<Tools>(arg)
|
||||
);
|
||||
},
|
||||
},
|
||||
objType));
|
||||
const auto &object = sheet.objects[objType];
|
||||
sheet.available_objects.erase(objType);
|
||||
|
||||
|
|
@ -37,11 +46,11 @@ namespace character {
|
|||
auto &local_chance = static_cast<Characteristic &>(sheet.chance);
|
||||
|
||||
std::visit(overloaded{
|
||||
[&](const weapons &arg) { ++sheet.nb_weapons; },
|
||||
[&](const equipments &arg) { ++sheet.nb_equipments; },
|
||||
[&](const tools &arg) { ++sheet.nb_tools; },
|
||||
},
|
||||
objType);
|
||||
[&](const weapons &arg) { ++sheet.nb_weapons; },
|
||||
[&](const equipments &arg) { ++sheet.nb_equipments; },
|
||||
[&](const tools &arg) { ++sheet.nb_tools; },
|
||||
},
|
||||
objType);
|
||||
change_carac(object, sheet, local_habilete, local_adresse, local_endurance, local_chance, plus);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -60,22 +69,23 @@ namespace character {
|
|||
auto &local_chance = static_cast<Characteristic &>(sheet.chance);
|
||||
|
||||
std::visit(overloaded{
|
||||
[&](const weapons &arg) { --sheet.nb_weapons; },
|
||||
[&](const equipments &arg) { --sheet.nb_equipments; },
|
||||
[&](const tools &arg) { --sheet.nb_tools; }
|
||||
},
|
||||
objToErase);
|
||||
[&](const weapons &arg) { --sheet.nb_weapons; },
|
||||
[&](const equipments &arg) { --sheet.nb_equipments; },
|
||||
[&](const tools &arg) { --sheet.nb_tools; }
|
||||
},
|
||||
objToErase);
|
||||
change_carac(obj, sheet, local_habilete, local_adresse, local_endurance, local_chance, minus);
|
||||
}
|
||||
}
|
||||
|
||||
void BillyObjects::change_carac(const billyObjects &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 {
|
||||
CharacterSheet &sheet,
|
||||
Characteristic &localHabilete,
|
||||
Characteristic &localAdresse,
|
||||
Characteristic &localEndurance,
|
||||
Characteristic &localChance,
|
||||
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation)
|
||||
noexcept {
|
||||
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));
|
||||
|
|
@ -88,10 +98,10 @@ 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::count_if(sheet.get_objects().cbegin(),
|
||||
sheet.get_objects().cend(),
|
||||
[](container::const_reference node) {
|
||||
return std::get_if<weapons>(&node.first) != nullptr;
|
||||
}
|
||||
sheet.get_objects().cend(),
|
||||
[](container::const_reference node) {
|
||||
return std::get_if<weapons>(&node.first) != nullptr;
|
||||
}
|
||||
);
|
||||
if (const bool is_there_bow = sheet.get_objects().find(weapons::Bow) != sheet.get_objects().cend();
|
||||
count_weapons > 1 || is_there_bow) {
|
||||
|
|
@ -114,7 +124,7 @@ namespace character {
|
|||
break;
|
||||
case equipmentHash:
|
||||
billy.emplace(static_cast<equipments>(value),
|
||||
std::make_unique<Equipments>(static_cast<equipments>(value)));
|
||||
std::make_unique<Equipments>(static_cast<equipments>(value)));
|
||||
break;
|
||||
case toolsHash:
|
||||
billy.emplace(static_cast<tools>(value), std::make_unique<Tools>(static_cast<tools>(value)));
|
||||
|
|
@ -128,17 +138,17 @@ namespace character {
|
|||
void BillyObjects::to_json(json &j, const container &billy) {
|
||||
for (const auto &[object_type, _]: billy) {
|
||||
std::visit(overloaded{
|
||||
[&j](const weapons weapon) {
|
||||
j.emplace_back(std::pair{ weaponsHash, static_cast<std::uint8_t>(weapon) });
|
||||
},
|
||||
[&j](const equipments equipment) {
|
||||
j.emplace_back(std::pair{ equipmentHash, static_cast<std::uint8_t>(equipment) });
|
||||
},
|
||||
[&j](const tools tool) {
|
||||
j.emplace_back(std::pair{ toolsHash, static_cast<std::uint8_t>(tool) });
|
||||
}
|
||||
},
|
||||
object_type);
|
||||
[&j](const weapons weapon) {
|
||||
j.emplace_back(std::pair{ weaponsHash, static_cast<std::uint8_t>(weapon) });
|
||||
},
|
||||
[&j](const equipments equipment) {
|
||||
j.emplace_back(std::pair{ equipmentHash, static_cast<std::uint8_t>(equipment) });
|
||||
},
|
||||
[&j](const tools tool) {
|
||||
j.emplace_back(std::pair{ toolsHash, static_cast<std::uint8_t>(tool) });
|
||||
}
|
||||
},
|
||||
object_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,4 +166,4 @@ namespace character {
|
|||
return sackOfGrain;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue