Adds effect field to Items.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-03-07 11:56:07 +01:00
parent 3a4171f565
commit 26c36f8ece
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 22 additions and 7 deletions

View File

@ -3,13 +3,18 @@
using namespace CreatureLib::Library; using namespace CreatureLib::Library;
export Item* CreatureLib_Item_Construct(const char* name, ItemCategory category, BattleItemCategory battleCategory, export Item* CreatureLib_Item_Construct(const char* name, ItemCategory category, BattleItemCategory battleCategory,
int32_t price, const char* flags[], size_t flagsCount) { int32_t price, const char* effectName, EffectParameter* effectParameters[],
size_t effectParameterCount, const char* flags[], size_t flagsCount) {
std::unordered_set<uint32_t> conversedFlags(flagsCount); std::unordered_set<uint32_t> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) { for (size_t i = 0; i < flagsCount; i++) {
conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i])); conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i]));
} }
return new Item(ArbUt::StringView(name), category, battleCategory, price, conversedFlags); return new Item(
ArbUt::StringView(name), category, battleCategory, price,
new SecondaryEffect(100, effectName,
ArbUt::List<EffectParameter*>(effectParameters, effectParameters + effectParameterCount)),
conversedFlags);
}; };
export void CreatureLib_Item_Destruct(const Item* p) { delete p; } export void CreatureLib_Item_Destruct(const Item* p) { delete p; }

View File

@ -6,30 +6,36 @@ namespace CreatureLib::Library {
ItemCategory _category; ItemCategory _category;
BattleItemCategory _battleCategory; BattleItemCategory _battleCategory;
int32_t _price; int32_t _price;
std::unique_ptr<const SecondaryEffect> _effect = nullptr;
std::unordered_set<uint32_t> _flags; std::unordered_set<uint32_t> _flags;
public: public:
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory,
int32_t price, const std::unordered_set<uint32_t>& flags) noexcept int32_t price, const SecondaryEffect* effect, const std::unordered_set<uint32_t>& flags) noexcept
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {} : _name(name), _category(category), _battleCategory(battleCategory), _price(price), _effect(effect),
_flags(flags) {}
inline const ArbUt::StringView& GetName() const noexcept { return _name; } inline const ArbUt::StringView& GetName() const noexcept { return _name; }
inline ItemCategory GetCategory() const noexcept { return _category; } inline ItemCategory GetCategory() const noexcept { return _category; }
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; } inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
inline int32_t GetPrice() const noexcept { return _price; } inline int32_t GetPrice() const noexcept { return _price; }
inline const std::unique_ptr<const SecondaryEffect>& GetEffect() const noexcept { return _effect; }
inline bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); } inline bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); }
inline bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); } inline bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
}; };
Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price, Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
const std::unordered_set<uint32_t>& flags) noexcept const SecondaryEffect* effect, const std::unordered_set<uint32_t>& flags) noexcept
: _impl(new impl(name, category, battleCategory, price, flags)) {} : _impl(new impl(name, category, battleCategory, price, effect, flags)) {}
Item::~Item() = default; Item::~Item() = default;
const ArbUt::StringView& Item::GetName() const noexcept { return _impl->GetName(); } const ArbUt::StringView& Item::GetName() const noexcept { return _impl->GetName(); }
ItemCategory Item::GetCategory() const noexcept { return _impl->GetCategory(); } ItemCategory Item::GetCategory() const noexcept { return _impl->GetCategory(); }
BattleItemCategory Item::GetBattleCategory() const noexcept { return _impl->GetBattleCategory(); } BattleItemCategory Item::GetBattleCategory() const noexcept { return _impl->GetBattleCategory(); }
int32_t Item::GetPrice() const noexcept { return _impl->GetPrice(); } int32_t Item::GetPrice() const noexcept { return _impl->GetPrice(); }
const std::unique_ptr<const SecondaryEffect>& Item::GetEffect() const noexcept { return _impl->GetEffect(); }
bool Item::HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return _impl->HasFlag(flag); } bool Item::HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return _impl->HasFlag(flag); }
bool Item::HasFlag(uint32_t flag) const noexcept { return _impl->HasFlag(flag); } bool Item::HasFlag(uint32_t flag) const noexcept { return _impl->HasFlag(flag); }

View File

@ -1,6 +1,7 @@
#ifndef CREATURELIB_ITEM_HPP #ifndef CREATURELIB_ITEM_HPP
#define CREATURELIB_ITEM_HPP #define CREATURELIB_ITEM_HPP
#include "../Attacks/SecondaryEffect.hpp"
#include "BattleItemCategory.hpp" #include "BattleItemCategory.hpp"
#include "ItemCategory.hpp" #include "ItemCategory.hpp"
@ -12,7 +13,9 @@ namespace CreatureLib::Library {
public: public:
Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price, Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
const std::unordered_set<uint32_t>& flags) noexcept; const SecondaryEffect* effect, const std::unordered_set<uint32_t>& flags) noexcept;
NO_COPY_OR_MOVE(Item)
virtual ~Item(); virtual ~Item();
const ArbUt::StringView& GetName() const noexcept; const ArbUt::StringView& GetName() const noexcept;
@ -20,6 +23,7 @@ namespace CreatureLib::Library {
BattleItemCategory GetBattleCategory() const noexcept; BattleItemCategory GetBattleCategory() const noexcept;
int32_t GetPrice() const noexcept; int32_t GetPrice() const noexcept;
const std::unique_ptr<const SecondaryEffect>& GetEffect() const noexcept;
bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept; bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept;
bool HasFlag(uint32_t flag) const noexcept; bool HasFlag(uint32_t flag) const noexcept;
}; };