Adds effect field to Items.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
3a4171f565
commit
26c36f8ece
|
@ -3,13 +3,18 @@
|
|||
using namespace CreatureLib::Library;
|
||||
|
||||
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);
|
||||
for (size_t i = 0; i < flagsCount; 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; }
|
||||
|
|
|
@ -6,30 +6,36 @@ namespace CreatureLib::Library {
|
|||
ItemCategory _category;
|
||||
BattleItemCategory _battleCategory;
|
||||
int32_t _price;
|
||||
|
||||
std::unique_ptr<const SecondaryEffect> _effect = nullptr;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory,
|
||||
int32_t price, const std::unordered_set<uint32_t>& flags) noexcept
|
||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
|
||||
int32_t price, const SecondaryEffect* effect, const std::unordered_set<uint32_t>& flags) noexcept
|
||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _effect(effect),
|
||||
_flags(flags) {}
|
||||
|
||||
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||
inline ItemCategory GetCategory() const noexcept { return _category; }
|
||||
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
|
||||
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(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
|
||||
};
|
||||
Item::Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
||||
const std::unordered_set<uint32_t>& flags) noexcept
|
||||
: _impl(new impl(name, category, battleCategory, price, flags)) {}
|
||||
const SecondaryEffect* effect, const std::unordered_set<uint32_t>& flags) noexcept
|
||||
: _impl(new impl(name, category, battleCategory, price, effect, flags)) {}
|
||||
|
||||
Item::~Item() = default;
|
||||
const ArbUt::StringView& Item::GetName() const noexcept { return _impl->GetName(); }
|
||||
ItemCategory Item::GetCategory() const noexcept { return _impl->GetCategory(); }
|
||||
BattleItemCategory Item::GetBattleCategory() const noexcept { return _impl->GetBattleCategory(); }
|
||||
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(uint32_t flag) const noexcept { return _impl->HasFlag(flag); }
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef CREATURELIB_ITEM_HPP
|
||||
#define CREATURELIB_ITEM_HPP
|
||||
|
||||
#include "../Attacks/SecondaryEffect.hpp"
|
||||
#include "BattleItemCategory.hpp"
|
||||
#include "ItemCategory.hpp"
|
||||
|
||||
|
@ -12,7 +13,9 @@ namespace CreatureLib::Library {
|
|||
|
||||
public:
|
||||
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();
|
||||
|
||||
const ArbUt::StringView& GetName() const noexcept;
|
||||
|
@ -20,6 +23,7 @@ namespace CreatureLib::Library {
|
|||
BattleItemCategory GetBattleCategory() 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(uint32_t flag) const noexcept;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue