#pragma region License /* License (OLC-3) ~~~~~~~~~~~~~~~ Copyright 2024 Joshua Sigona Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions or derivations of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions or derivative works in binary form must reproduce the above copyright notice. This list of conditions and the following disclaimer must be reproduced in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Portions of this software are copyright © 2024 The FreeType Project (www.freetype.org). Please see LICENSE_FT.txt for more information. All rights reserved. */ #pragma endregion #pragma once #include #include #include #include "olcUTIL_DataFile.h" #include "AttributableStat.h" #include "BitwiseEnum.h" #include #include "Merchant.h" #include "CraftingRequirement.h" #include "FunctionPriming.h" #include "IT.h" #include #include "Buff.h" #include "ItemEnchant.h" class AiL; class ItemInfo; class ItemProps; using ITCategory=std::string; using EventName=std::string; using ItemScript=std::function; enum class EquipSlot{ HELMET= 0b0000'0001, WEAPON= 0b0000'0010, ARMOR= 0b0000'0100, GLOVES= 0b0000'1000, PANTS= 0b0001'0000, SHOES= 0b0010'0000, RING1= 0b0100'0000, RING2= 0b1000'0000, NONE= 0b0000'0000, }; enum class CompactText{ COMPACT, NON_COMPACT, CRAFTING_INFO }; using enum CompactText; struct Stats:ItemAttributable{ static safemapmaxDamageReductionTable; static void InitializeDamageReductionTable(); static Stats NO_MAX_HIGHLIGHT; public: inline static const float&GetDamageReductionPct(int defense){ return maxDamageReductionTable.at(std::clamp(defense,0,1000)); } inline Stats&operator+=(Stats&rhs){ for(auto&[key,value]:ItemAttribute::attributes){ A(value)+=rhs.get_readOnly(value); } return *this; }; inline Stats&operator+=(ItemAttributable&rhs){ for(auto&[key,value]:ItemAttribute::attributes){ A(value)+=rhs.get_readOnly(value); } return *this; }; auto begin()const{ return attributes.begin(); } auto end()const{ return attributes.end(); } const size_t size()const{ return attributes.size(); } const std::string GetStatsString(const Stats&maxStats,CompactText compact=NON_COMPACT)const; friend const bool operator==(const Stats&lhs,const Stats&rhs){return lhs.attributes==rhs.attributes;} }; struct Stats; class CraftingRequirement; struct EnhancementLevelInfo{ const Stats&stats; const CraftingRequirement&craftingRequirement; const uint8_t chapterAvailable; EnhancementLevelInfo(const Stats&stats,const CraftingRequirement&craftingRequirement,const uint8_t chapterAvailable); }; struct EnhancementInfo{ private: std::vectorenhancementStats; std::vectorcraftingRequirements; public: void SetAttribute(int enhanceLevel,ItemAttribute attribute,float value); void SetCraftingRequirements(const int enhanceLevel,const std::vector&requiredItems,const uint32_t goldCost,const uint8_t availableChapter); const bool CanBeEnhanced()const; const EnhancementLevelInfo operator[](int level)const; const size_t size()const; }; class ItemSortRules{ friend class ItemInfo; public: static std::vectorprimarySort; static std::vectorsecondarySort; //Returns a number based on what the equipment type of an item is. The lower the number, the earlier it should appear in the list. static uint16_t GetItemSortRanking(const std::weak_ptr&it); static uint16_t MaxSortRanking(); }; //You cannot create instances of this class, access sets from ItemSet::sets and add the appropriate set bonuses. class ItemSet{ friend class ItemInfo; static std::mapsets; std::arraysetBonuses; //Stores the set bonuses with the amount of pieces being the index array - 1 internally. So if we wanted the set bonus for having 1 of this set equipped, we ask for [1] (and it's stored internally at index 0.) std::string name; std::vector>setBonusBreakpoints; public: //NO CONSTRUCTOR REQUIRED! //Specify the piece count(1-8) for a set bonus to be applied. static void AddSetBonus(std::string setName,int pieceCount,Stats&bonuses); //Gets a set bonus based on number of pieces (1-8) const Stats&operator[](int setPieces)const; const std::string&GetSetName()const; bool operator<(const ItemSet&rhs)const{ return name>&GetSetBonusBreakpoints()const; }; namespace PlayerTests{ class PlayerTest; }; namespace EnchantTests{ class EnchantTest; }; using IncreaseAmount=int; using RefineResult=std::pair; class Item{ friend class Inventory; friend class AiL; friend class Menu; friend class SaveFile; friend void Merchant::PurchaseItem(IT item,uint32_t amt); friend void Merchant::SellItem(std::weak_ptr,uint32_t amt); friend class PlayerTests::PlayerTest; friend class EnchantTests::EnchantTest; private: //The amount in the current item stack. uint32_t amt; uint8_t enhancementLevel; ItemInfo*it; Stats randomizedStats; bool locked=false; std::optionalenchant; void SetAmt(uint32_t newAmt); static ItemEnhancementFunctionPrimingData enhanceFunctionPrimed; static int IsBlankStaticCallCounter; const bool _IsBlank()const; public: static const std::string BLANK_ITEM_NAME; Item(); Item(uint32_t amt,IT item,uint8_t enhancementLevel=0); uint32_t Amt()const; //Use this for places where the item name is used for item tracking. NOT for drawing. Hooks directly into item info's base item name. const std::string&ActualName()const; //Use for places where the item name is actually displayed. Provides modified text that shows additional information like enhancement levels. const std::string DisplayName()const; const std::string Description(CompactText compact=COMPACT)const; const EventName&UseSound()const; const ITCategory Category()const; const EquipSlot GetEquipSlot()const; const::Decal*const Decal()const; const Stats GetStats()const; const ItemScript&OnUseAction()const; const float CastTime()const; const bool UseDuringCast()const; //When true, the item is activated during the cast instead of after the cast. const float CooldownTime()const; //Use ISBLANK macro instead!! This should not be called directly!! const bool IsBlank()const; const uint8_t EnhancementLevel()const; //NOTE: This function must be primed with CanEnhanceItem()! Otherwise it will cause a runtime error. void EnhanceItem(uint8_t qty=1); //Whether or not this item can be enhanced/crafted. const bool EnhancementIsPossible()const; //A verification function that confirms if we are allowed to perform an enhancement. MUST BE CALLED to prime EnhanceItem() function!! const bool CanEnhanceItem(uint8_t qty=1)const; static std::shared_ptrBLANK; const std::optionalItemSet()const; const bool IsEquippable()const; const bool IsCraftable()const; const bool IsWeapon()const; const bool IsArmor()const; const bool IsAccessory()const; const uint32_t BuyValue()const; const uint32_t SellValue()const; const bool CanBeSold()const; const bool CanBePurchased()const; const Stats&RandomStats()const; const std::unordered_set&GetClass()const; void RandomizeStats(); const bool HasRandomizedStats()const; const EnhancementInfo&GetEnhancementInfo()const; //Use ISBLANK macro instead!! This should not be called directly!! static bool IsBlank(std::shared_ptritem); //Use ISBLANK macro instead!! This should not be called directly!! static bool IsBlank(std::weak_ptritem); const bool IsLocked()const; const std::string&FragmentName()const; const bool CanBeRefined()const; //An item can be refined if the item has less than max stats and the player has enough fragments in their inventory. //Assumes an item can be refined. CHECK WITH CanBeRefined() First!!! //Refines a random stat by the parameters defined in the Accessories.txt configuration file. Also takes away the costs required to refine the item. RefineResult Refine(); void Lock(); void Unlock(); void EnchantItem(const std::string_view enchantName); std::optionalGetEnchant()const; const bool HasEnchant()const; friend const bool operator==(std::shared_ptrlhs,std::shared_ptrrhs){return lhs->it==rhs->it&&lhs->randomizedStats==rhs->randomizedStats;}; friend const bool operator==(std::shared_ptrlhs,const IT&rhs){return lhs->ActualName()==const_cast(rhs);}; friend const bool operator==(std::weak_ptrlhs,std::weak_ptrrhs){return !lhs.expired()&&!rhs.expired()&&lhs.lock()->it==rhs.lock()->it&&lhs.lock()->randomizedStats==rhs.lock()->randomizedStats;}; friend const bool operator==(std::weak_ptrlhs,const IT&rhs){return !lhs.expired()&&lhs.lock()->ActualName()==const_cast(rhs);}; friend const bool operator==(const IT&lhs,std::weak_ptrrhs){return operator==(rhs,lhs);}; friend const bool operator==(const IT&lhs,std::shared_ptrrhs){return operator==(rhs,lhs);}; const Pixel GetDisplayNameColor()const; }; class Inventory{ friend class ItemInfo; friend class Item; friend class SaveFile; friend class InventoryCreator; friend class ItemTests::ItemTest; public: static std::weak_ptrAddItem(IT it,uint32_t amt=1,bool monsterDrop=false); //Returns the actual amount available in your main inventory. [[nodiscard]] static uint32_t GetItemCount(IT it); static std::vector>CopyItem(IT it); static std::vector>GetItem(IT it); //Auto-executes its use function and removes the amt specified from the inventory. Multiple amounts will cause the item to execute its useFunc multiple times. static bool UseItem(IT it,uint32_t amt=1); //Returns true if the item has been consumed completely and there are 0 remaining of that type in our inventory. static bool RemoveItem(std::weak_ptritemRef,ITCategory inventory,uint32_t amt = 1); //Returns true if the item has been consumed completely and there are 0 remaining of that type in our inventory. static bool RemoveItem(std::weak_ptritemRef,uint32_t amt=1); //Returns true if the item has been consumed completely and there are 0 remaining of that type in our inventory. static bool RemoveItem(IT it,uint32_t amt=1); static const std::vector>&get(ITCategory itemCategory); static const std::weak_ptrGetInventorySlot(ITCategory itemCategory,size_t slot); static void Clear(ITCategory itemCategory); static void EquipItem(const std::weak_ptrit,EquipSlot slot); static void UnequipItem(EquipSlot slot); static EquipSlot GetSlotEquippedIn(const std::weak_ptrit); static std::weak_ptrGetEquip(EquipSlot slot); static const std::mapGetEquippedItemSets(); //Gets all items currently on inventory (Ignores Stage Loot and Monster Loot Inventories) static const std::vector>GetInventory(); static void UpdateBlacksmithInventoryLists(); static void AddLoadoutItemUsed(IT item,int slot); static void ResetLoadoutItemsUsed(); static void GivePlayerLoadoutItemsUsed(); static const bool EquipsFullyMaxedOut(int maxWeaponLevel=10,int maxArmorLevel=10); static void Disassemble(std::weak_ptritemRef); static bool SwapItems(ITCategory itemCategory,uint32_t slot1,uint32_t slot2); //Makes sure this is a valid category. Will error out if it doesn't exist! Use for ERROR HANDLING! static bool ValidateItemCategory(ITCategory itemCategory){ get(itemCategory); return true; } private: static void InsertIntoSortedInv(std::shared_ptritemRef); static void InsertIntoStageInventoryCategory(std::shared_ptritemRef,const bool monsterDrop); static bool ExecuteAction(IT item); static std::multimap>_inventory; static std::vector>blacksmithInventory; static std::map>equipment; static std::array,3U>loadoutItemsUsed; //Only contains "1" of every item, as this is a map to index items and not the actual storage of items! static std::map>>sortedInv; }; class ItemProps{ friend class ItemInfo; utils::datafile*scriptProps; utils::datafile*customProps; public: ItemProps(utils::datafile*scriptProps,utils::datafile*customProps); int GetIntProp(const std::string&prop,size_t index=0)const; float GetFloatProp(const std::string&prop,size_t index=0)const; std::string GetStringProp(const std::string&prop,size_t index=0)const; const uint32_t PropCount(const std::string&prop)const; }; class ItemInfo{ friend class Inventory; friend class Menu; std::string name; std::string description; std::string category; float castTime=0; float cooldownTime=0; EquipSlot slot=EquipSlot::NONE; EnhancementInfo enhancement; ::Decal*img; EventName useSound=""; std::string set=""; //Returns true if the item can be used, false otherwise std::string useFunc=""; //Custom properties for this specific item's script. static utils::datafile NOPROPS; ItemProps customProps; uint32_t buyValue=0; uint32_t sellValue=0; //If true, this item's action is activated at the beginning of the cast instead of after the cast completes. bool useDuringCast=false; //If blank, any class can equip this item. std::unordered_setequippableClass; Stats minStats; Stats maxStats; std::optionalfragmentName; private: static void InitializeScripts(); static void InitializeSets(); static std::mapnameToEquipSlot; static std::vector>craftableConsumables; const static std::unordered_mapNameToBuffType; public: static void InitializeItems(); ItemInfo(); const std::string&Name()const; const std::string&Description()const; const ITCategory Category()const; const::Decal*const Decal()const; static const EquipSlot StringToEquipSlot(std::string_view slotName); /* For the useFunc, return true if the item can be used, false otherwise. */ const EventName&UseSound()const; const ItemScript&OnUseAction()const; const Stats GetStats(int enhancementLevel)const; const float CastTime()const; const float CooldownTime()const; const EquipSlot Slot()const; const std::optionalItemSet()const; ItemInfo&operator[](const IT&item); const uint32_t GetBuyValue()const; const uint32_t GetSellValue()const; const bool CanBeSold()const; const bool CanBePurchased()const; const bool UseDuringCast()const; const EnhancementInfo&GetEnhancementInfo()const; const bool IsEquippable()const; const bool IsCraftable()const; const bool IsWeapon()const; const bool IsArmor()const; const bool IsAccessory()const; const Stats GetMinStats()const; const Stats GetMaxStats()const; //Get the class that can equip this item. const std::unordered_set&GetClass()const; Stats RandomizeStats(); const std::string&FragmentName()const; }; class ItemOverlay{ friend class ItemInfo; ItemInfo it; float timer=0; float xOffset=0; float width=0; //How wide the entire label is. static std::vectoritems; ItemOverlay(ItemInfo item); public: static void AddToItemOverlay(const ItemInfo&it); static void Update(); static void Draw(); void ResetTimer(); }; #define ISBLANK(itemRef) Item::IsBlank(itemRef)