From 298b0c4ca7dc71dacc7d69478e33dee2baf445a3 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 30 Nov 2023 23:33:40 -0600 Subject: [PATCH] Implemented equipping of items, reading of slot types from item database, and prepared set items and stats structures. --- Crawler/BitwiseEnum.h | 50 +++++++++++++++++ Crawler/Crawler.cpp | 7 ++- Crawler/Crawler.vcxproj | 4 ++ Crawler/Crawler.vcxproj.filters | 3 ++ Crawler/Item.cpp | 56 +++++++++++++++++++- Crawler/Item.h | 25 ++++++++- Crawler/MenuComponent.h | 23 +------- Crawler/Version.h | 2 +- Crawler/assets/config/items/ItemDatabase.txt | 5 +- 9 files changed, 147 insertions(+), 28 deletions(-) create mode 100644 Crawler/BitwiseEnum.h diff --git a/Crawler/BitwiseEnum.h b/Crawler/BitwiseEnum.h new file mode 100644 index 00000000..ef1c6e9c --- /dev/null +++ b/Crawler/BitwiseEnum.h @@ -0,0 +1,50 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2018 - 2022 OneLoneCoder.com + +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 © 2023 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion +#pragma once + +template +constexpr auto operator|(T attribute,T attribute2) noexcept +{ + return T(static_cast>(attribute)|static_cast>(attribute2)); +} + +template +constexpr auto operator&(T attribute,T attribute2) noexcept +{ + return static_cast>(attribute)&static_cast>(attribute2); +} \ No newline at end of file diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 7ecdd014..7349d3a1 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -199,7 +199,12 @@ bool Crawler::OnUserCreate(){ ItemDrop::Initialize(); ValidateGameStatus(); //Checks to make sure everything has been initialized properly. + + Item&it=Inventory::GetItem("Dummy Item 10"); + Inventory::EquipItem(it,EquipSlot::RING1); + Inventory::EquipItem(it,EquipSlot::RING2); + return true; } @@ -2138,7 +2143,7 @@ Item&Crawler::GetLoadoutItem(int slot){ void Crawler::SetLoadoutItem(int slot,std::string itemName){ if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+")."); if(Inventory::GetItemCount(itemName)>0){ - GetLoadoutItem(slot)=Inventory::GetItem(itemName); + GetLoadoutItem(slot)=Inventory::CopyItem(itemName); GetLoadoutItem(slot).amt=std::min((uint32_t)"Player.Item Loadout Limit"_I,GetLoadoutItem(slot).Amt()); //We are only allowed to have up to 10 maximum of an item on a journey. InputGroup*inputGroup=nullptr; switch(slot){ diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index c5511f98..49c03c99 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -283,6 +283,10 @@ + + + + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 7cf62bb6..f1065dcd 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -288,6 +288,9 @@ Header Files + + Header Files + diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index eeb35823..671c02ed 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -53,11 +53,25 @@ std::mapInventory::_inventory; std::map>Inventory::sortedInv; std::vectorItemOverlay::items; std::mapItemSet::sets; +std::mapInventory::equipment; +std::mapItemInfo::nameToEquipSlot; ItemInfo::ItemInfo() :customProps({nullptr,nullptr}),img(nullptr){} void ItemInfo::InitializeItems(){ + for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){ + Inventory::equipment[EquipSlot(i)]=nullptr; + } + + nameToEquipSlot["Helmet"]=EquipSlot::HELMET; + nameToEquipSlot["Weapon"]=EquipSlot::WEAPON; + nameToEquipSlot["Armor"]=EquipSlot::ARMOR; + nameToEquipSlot["Gloves"]=EquipSlot::GLOVES; + nameToEquipSlot["Pants"]=EquipSlot::PANTS; + nameToEquipSlot["Shoes"]=EquipSlot::SHOES; + nameToEquipSlot["Ring1"]=EquipSlot::RING1; + nameToEquipSlot["Ring2"]=EquipSlot::RING2; InitializeScripts(); @@ -74,6 +88,7 @@ void ItemInfo::InitializeItems(){ std::string scriptName="",description="",category=""; float castTime=0; + std::vector slot; float cooldownTime="Item.Item Cooldown Time"_F; for(auto&itemKey:DATA["ItemDatabase"][key.first].GetKeys()){ std::string keyName=itemKey.first; @@ -91,6 +106,11 @@ void ItemInfo::InitializeItems(){ }else if(keyName=="Cooldown Time"){ castTime=float(DATA["ItemDatabase"][key.first][keyName].GetReal()); + }else + if(keyName=="Slot"){ + for(auto&val:DATA["ItemDatabase"][key.first][keyName].GetValues()){ + slot.push_back(val); + } }else{ //THis is a custom override modifier for a script. NO-OP } } @@ -107,6 +127,13 @@ void ItemInfo::InitializeItems(){ it.category=category; it.castTime=castTime; it.cooldownTime=cooldownTime; + it.slot=EquipSlot::NONE; + if(slot.size()>0){ + for(std::string&s:slot){ + if(!nameToEquipSlot.count(s))ERR("WARNING! Tried to add item "<=9)ERR("Piece count is invalid! Expecting a value (1-8) but got "<slot&slot))return; + EquipSlot equippedSlot=GetSlotEquippedIn(it); + if(equippedSlot!=EquipSlot::NONE)UnequipItem(equippedSlot); + if(GetEquip(slot)!=nullptr)UnequipItem(slot); + Inventory::equipment[slot]=⁢ +}; +void Inventory::UnequipItem(EquipSlot slot){ + Inventory::equipment[slot]=nullptr; +}; +EquipSlot Inventory::GetSlotEquippedIn(Item&it){ + for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){ + EquipSlot slot=EquipSlot(i); + if(GetEquip(slot)==&it)return slot; + } + return EquipSlot::NONE; +}; +Item*Inventory::GetEquip(EquipSlot slot){ + return Inventory::equipment[slot]; } \ No newline at end of file diff --git a/Crawler/Item.h b/Crawler/Item.h index 58a7c2cf..bb465e36 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -42,6 +42,7 @@ All rights reserved. #include "olcPixelGameEngine.h" #include "olcUTIL_DataFile.h" #include "AttributableStat.h" +#include "BitwiseEnum.h" class Crawler; class ItemInfo; @@ -52,12 +53,25 @@ typedef std::string ITCategory; typedef std::function ItemScript; +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, +}; + struct Stats:ItemAttributable{ public: inline Stats&operator+=(const Stats&rhs){ for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a&get(ITCategory itemCategory); static void Clear(ITCategory itemCategory); + static void EquipItem(Item&it,EquipSlot slot); + static void UnequipItem(EquipSlot slot); + static EquipSlot GetSlotEquippedIn(Item&it); + static Item*GetEquip(EquipSlot slot); 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! @@ -130,6 +150,7 @@ private: static void InsertIntoStageInventoryCategory(IT item,uint32_t amt,bool monsterDrop); static bool ExecuteAction(IT item); static std::map_inventory; + static std::mapequipment; //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; }; @@ -152,6 +173,7 @@ class ItemInfo{ std::string category; float castTime=0; float cooldownTime=0; + EquipSlot slot; EnhancementInfo enhancement; Decal*img; //Returns true if the item can be used, false otherwise @@ -162,6 +184,7 @@ class ItemInfo{ private: static void InitializeScripts(); + static std::mapnameToEquipSlot; public: static void InitializeItems(); ItemInfo(); diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 53f926d4..b55e2399 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -37,6 +37,7 @@ All rights reserved. #pragma endregion #pragma once #include "Menu.h" +#include "BitwiseEnum.h" enum class ButtonAttr{ NONE=0b00, @@ -110,24 +111,4 @@ public: std::string GetName(); void Enable(bool enabled); virtual void Cleanup(); -}; - -constexpr auto operator|(ButtonAttr attribute,ButtonAttr attribute2) noexcept -{ - return ButtonAttr(static_cast>(attribute)|static_cast>(attribute2)); -} - -constexpr auto operator&(ButtonAttr attribute,ButtonAttr attribute2) noexcept -{ - return static_cast>(attribute)&static_cast>(attribute2); -} - - -constexpr auto operator|(ComponentAttr attribute,ComponentAttr attribute2) noexcept -{ - return ComponentAttr(static_cast>(attribute)|static_cast>(attribute2)); -} -constexpr auto operator&(ComponentAttr attribute,ComponentAttr attribute2) noexcept -{ - return static_cast>(attribute)&static_cast>(attribute2); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index b255ea56..8ec37cf2 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 3347 +#define VERSION_BUILD 3365 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/items/ItemDatabase.txt b/Crawler/assets/config/items/ItemDatabase.txt index 0b455fba..0aa98e1b 100644 --- a/Crawler/assets/config/items/ItemDatabase.txt +++ b/Crawler/assets/config/items/ItemDatabase.txt @@ -137,10 +137,9 @@ ItemDatabase } Dummy Item 10 { - ItemScript = Restore - HP Restore = 1 Description = Does nothing apparently. - ItemCategory = Consumables + ItemCategory = Equipment + Slot = Armor,Ring1,Ring2 Cooldown Time = 5.0 Cast Time = 0.0 }