Adding objects is done except for the dagger
This commit is contained in:
parent
88025baeff
commit
69aad6a416
104
include/billy_objects.hpp
Normal file
104
include/billy_objects.hpp
Normal 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
|
@ -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) {
|
||||
|
163
src/billy_objects.cpp
Normal file
163
src/billy_objects.cpp
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user