From 26c36f8ecec752fa50afc19d26f23d12ea295431 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 7 Mar 2021 11:56:07 +0100 Subject: [PATCH] Adds effect field to Items. Signed-off-by: Deukhoofd --- CInterface/Library/Item.cpp | 9 +++++++-- src/Library/Items/Item.cpp | 14 ++++++++++---- src/Library/Items/Item.hpp | 6 +++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CInterface/Library/Item.cpp b/CInterface/Library/Item.cpp index 9adf74e..3f32e93 100644 --- a/CInterface/Library/Item.cpp +++ b/CInterface/Library/Item.cpp @@ -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 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(effectParameters, effectParameters + effectParameterCount)), + conversedFlags); }; export void CreatureLib_Item_Destruct(const Item* p) { delete p; } diff --git a/src/Library/Items/Item.cpp b/src/Library/Items/Item.cpp index e7492c0..dc1501f 100644 --- a/src/Library/Items/Item.cpp +++ b/src/Library/Items/Item.cpp @@ -6,30 +6,36 @@ namespace CreatureLib::Library { ItemCategory _category; BattleItemCategory _battleCategory; int32_t _price; + + std::unique_ptr _effect = nullptr; std::unordered_set _flags; public: inline impl(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory, - int32_t price, const std::unordered_set& flags) noexcept - : _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {} + int32_t price, const SecondaryEffect* effect, const std::unordered_set& 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& 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& flags) noexcept - : _impl(new impl(name, category, battleCategory, price, flags)) {} + const SecondaryEffect* effect, const std::unordered_set& 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& 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); } diff --git a/src/Library/Items/Item.hpp b/src/Library/Items/Item.hpp index d092191..90870bc 100644 --- a/src/Library/Items/Item.hpp +++ b/src/Library/Items/Item.hpp @@ -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& flags) noexcept; + const SecondaryEffect* effect, const std::unordered_set& 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& GetEffect() const noexcept; bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept; bool HasFlag(uint32_t flag) const noexcept; };