From b97c63f7b083ede07dcf26cbaf0e364bd1b501a4 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 30 Nov 2023 22:01:04 -0600 Subject: [PATCH] Implement basic structures for Items, Item Sets, and Equipment. --- Crawler/AttributableStat.h | 73 ++++++++++++++++++++++++++++++ Crawler/CharacterInfoWindow.cpp | 2 +- Crawler/CharacterMenuWindow.cpp | 16 ++++++- Crawler/CharacterRotatingDisplay.h | 11 +++-- Crawler/Crawler.vcxproj | 4 ++ Crawler/Crawler.vcxproj.filters | 3 ++ Crawler/Item.cpp | 26 +++++++++-- Crawler/Item.h | 33 +++++++++++++- Crawler/OverworldMenuWindow.cpp | 8 +++- Crawler/Version.h | 2 +- 10 files changed, 166 insertions(+), 12 deletions(-) create mode 100644 Crawler/AttributableStat.h diff --git a/Crawler/AttributableStat.h b/Crawler/AttributableStat.h new file mode 100644 index 00000000..5372d352 --- /dev/null +++ b/Crawler/AttributableStat.h @@ -0,0 +1,73 @@ +#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 +#include "olcPixelGameEngine.h" + +#define A(attr) get(attr) +#define A_Read(attr) get_readOnly(attr) + +enum class ItemAttribute{ +/*////////////////////////////////////////////*/ +/*//////*/ENUM_START,/*///////////////////////*/ +/*////////////////////////////////////////////*/ + + defense, + health, + attack, + moveSpdPct, + cdrPct, + critPct, + critDmgPct, + healthPct, //Percentage of health boost + healthPctRecoveryPer6sec, //Percentage of health recovered every 6 seconds. + +/*////////////////////////////////////////////*/ +/*//////*/ENUM_END/*//////////////////////////*/ +/*////////////////////////////////////////////*/ +}; + +class ItemAttributable{ + std::mapattributes; +public: + inline int&get(ItemAttribute a){ + return attributes[a]; + } + inline const int get_readOnly(ItemAttribute a)const{ + return attributes.at(a); + } +}; \ No newline at end of file diff --git a/Crawler/CharacterInfoWindow.cpp b/Crawler/CharacterInfoWindow.cpp index b2a380ab..6bd04345 100644 --- a/Crawler/CharacterInfoWindow.cpp +++ b/Crawler/CharacterInfoWindow.cpp @@ -57,7 +57,7 @@ void Menu::InitializeClassInfoWindow(){ classInfoWindow->AddComponent("Class Name",label); - CharacterRotatingDisplay*classDisplay=NEW CharacterRotatingDisplay(CLASS_INFO,{{0,0},{72,120}},GFX[data.classFullImgName].Decal()); + CharacterRotatingDisplay*classDisplay=NEW CharacterRotatingDisplay(CLASS_INFO,{{15,48},{72,120}},GFX[data.classFullImgName].Decal()); classInfoWindow->AddComponent("Rotating Character Display",classDisplay); diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp index 043381ba..50c7d41d 100644 --- a/Crawler/CharacterMenuWindow.cpp +++ b/Crawler/CharacterMenuWindow.cpp @@ -37,10 +37,24 @@ All rights reserved. #pragma endregion #include "Menu.h" #include "MenuComponent.h" +#include "MenuLabel.h" +#include "CharacterRotatingDisplay.h" #include "Crawler.h" +#include "ClassInfo.h" INCLUDE_game +INCLUDE_GFX void Menu::InitializeCharacterMenuWindow(){ - Menu*characterMenuWindow=CreateMenu(CHARACTER_MENU,CENTERED,game->GetScreenSize()-vf2d{52,52}); + vf2d windowSize=game->GetScreenSize()-vf2d{52,52}; + Menu*characterMenuWindow=CreateMenu(CHARACTER_MENU,CENTERED,windowSize); + + MenuLabel*characterLabel=NEW MenuLabel(CHARACTER_MENU,{{0,4},{float(windowSize.x)-1,24}},"Character",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND); + + MenuComponent*equipSlotOutline=NEW MenuComponent(CHARACTER_MENU,{{0,36},{120,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE); + CharacterRotatingDisplay*charDisplay=NEW CharacterRotatingDisplay(CHARACTER_MENU,{{135,36},{90,windowSize.y-37}},GFX[classutils::GetClassInfo(game->GetPlayer()->GetClassName()).classFullImgName].Decal()); + + characterMenuWindow->AddComponent("Character Label",characterLabel); + characterMenuWindow->AddComponent("Equip Slot Outline",equipSlotOutline); + characterMenuWindow->AddComponent("Character Rotating Display",charDisplay); } \ No newline at end of file diff --git a/Crawler/CharacterRotatingDisplay.h b/Crawler/CharacterRotatingDisplay.h index fe2685b2..9a22827a 100644 --- a/Crawler/CharacterRotatingDisplay.h +++ b/Crawler/CharacterRotatingDisplay.h @@ -51,6 +51,9 @@ protected: public: inline CharacterRotatingDisplay(MenuType parent,geom2d::rectrect,Decal*icon) :MenuComponent(parent,rect,"",DO_NOTHING),icon(icon){} + inline void SetIcon(Decal*icon){ + this->icon=icon; + } protected: virtual inline void Update(Crawler*game)override{ MenuComponent::Update(game); @@ -63,10 +66,10 @@ protected: virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{ //MenuComponent::DrawDecal(game,parentPos,focused); game->DrawWarpedDecal(icon,std::array{ - parentPos+rect.middle()+vf2d{abs(sin(timer)),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor}, - parentPos+rect.middle()+vf2d{0,rect.size.y}+vf2d{abs(sin(timer)),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor}, - parentPos+rect.middle()+rect.size+vf2d{-abs(sin(float(timer+PI))),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor}, - parentPos+rect.middle()+vf2d{rect.size.x,0}+vf2d{-abs(sin(float(timer+PI))),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor}, + Menu::menus[parentMenu]->pos+rect.pos+vf2d{abs(sin(timer)),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor}, + Menu::menus[parentMenu]->pos+rect.pos+vf2d{0,rect.size.y}+vf2d{abs(sin(timer)),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor}, + Menu::menus[parentMenu]->pos+rect.pos+rect.size+vf2d{-abs(sin(float(timer+PI))),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor}, + Menu::menus[parentMenu]->pos+rect.pos+vf2d{rect.size.x,0}+vf2d{-abs(sin(float(timer+PI))),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor}, }); } }; \ No newline at end of file diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index d21fcf63..c5511f98 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -279,6 +279,10 @@ + + + + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index cf490660..7cf62bb6 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -285,6 +285,9 @@ Header Files + + Header Files + diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 83ddf141..eeb35823 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -52,6 +52,7 @@ Item Item::BLANK; std::mapInventory::_inventory; std::map>Inventory::sortedInv; std::vectorItemOverlay::items; +std::mapItemSet::sets; ItemInfo::ItemInfo() :customProps({nullptr,nullptr}),img(nullptr){} @@ -157,10 +158,10 @@ void ItemInfo::InitializeScripts(){ } Item::Item() - :amt(0),it(nullptr){} + :amt(0),it(nullptr),enhancementLevel(0){} -Item::Item(uint32_t amt,IT item) - :amt(amt),it(&ITEM_DATA.at(item)){} +Item::Item(uint32_t amt,IT item,uint8_t enhancementLevel) + :amt(amt),it(&ITEM_DATA.at(item)),enhancementLevel(enhancementLevel){} void Inventory::AddItem(IT it,uint32_t amt,bool monsterDrop){ //There are two places to manipulate items in (Both the sorted inventory and the actual inventory) @@ -400,4 +401,23 @@ float Item::CastTime(){ float Item::CooldownTime(){ return it->CooldownTime(); +} + +const Stats&EnhancementInfo::operator[](int level)const{ + return enhancementStats[level]; +} + +const ItemSet&Item::GetItemSet()const{ + return ItemSet::sets[set]; +}; + +const Stats&ItemSet::operator[](int setPieces)const{ + return setBonuses[setPieces]; +}; + +void ItemSet::AddSetBonus(int pieceCount,const Stats&bonuses){ + if(pieceCount<=0||pieceCount>=9)ERR("Piece count is invalid! Expecting a value (1-8) but got "< #include "olcPixelGameEngine.h" #include "olcUTIL_DataFile.h" +#include "AttributableStat.h" class Crawler; class ItemInfo; @@ -51,22 +52,51 @@ typedef std::string ITCategory; typedef std::function ItemScript; +struct Stats:ItemAttributable{ +public: + inline Stats&operator+=(const Stats&rhs){ + for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);aenhancementStats; +public: + const Stats&operator[](int level)const; +}; + +class ItemSet{ + friend class Item; + static std::mapsets; + std::arraysetBonuses; +public: + //Specify the piece count(1-8) for a set bonus to be applied. + void AddSetBonus(int pieceCount,const Stats&bonuses); + const Stats&operator[](int setPieces)const; +}; + class Item{ friend class Inventory; friend class Crawler; private: //The amount in the current item stack. uint32_t amt; + uint8_t enhancementLevel; + std::string set; ItemInfo*it; public: Item(); - Item(uint32_t amt,IT item); + Item(uint32_t amt,IT item,uint8_t enhancementLevel=0); uint32_t Amt(); std::string Name(); std::string Description(); ITCategory Category(); Decal*Decal(); ItemScript&OnUseAction(); + const ItemSet&GetItemSet()const; float CastTime(); float CooldownTime(); bool IsBlank(); @@ -122,6 +152,7 @@ class ItemInfo{ std::string category; float castTime=0; float cooldownTime=0; + EnhancementInfo enhancement; Decal*img; //Returns true if the item can be used, false otherwise std::string useFunc=""; diff --git a/Crawler/OverworldMenuWindow.cpp b/Crawler/OverworldMenuWindow.cpp index 08a1b32d..c324e11a 100644 --- a/Crawler/OverworldMenuWindow.cpp +++ b/Crawler/OverworldMenuWindow.cpp @@ -38,14 +38,20 @@ All rights reserved. #include "Menu.h" #include "MenuComponent.h" #include "Crawler.h" +#include "CharacterRotatingDisplay.h" +#include "ClassInfo.h" INCLUDE_game +INCLUDE_GFX void Menu::InitializeOverworldMenuWindow(){ Menu*overworldMenuWindow=CreateMenu(OVERWORLD_MENU,CENTERED,vi2d{96,164}); MenuComponent*resumeButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*0},{88,24}},"Resume",[](MenuFuncData data){Menu::CloseMenu();return true;}); - MenuComponent*characterButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*1},{88,24}},"Character",[](MenuFuncData data){Menu::OpenMenu(CHARACTER_MENU);return true;}); + MenuComponent*characterButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*1},{88,24}},"Character",[](MenuFuncData data){ + Component(CHARACTER_MENU,"Character Rotating Display")->SetIcon(GFX[classutils::GetClassInfo(game->GetPlayer()->GetClassName()).classFullImgName].Decal()); + Menu::OpenMenu(CHARACTER_MENU); + return true;}); MenuComponent*inventoryButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*2},{88,24}},"Inventory",[](MenuFuncData data){/*Menu::OpenMenu(INVENTORY_MENU);*/return true;}); MenuComponent*settingsButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*3},{88,24}},"Settings",[](MenuFuncData data){/*Menu::OpenMenu(SETTINGS_MENU);*/return true;}); MenuComponent*quitButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*4},{88,24}},"Quit Game",[](MenuFuncData data){game->EndGame();return true;}); diff --git a/Crawler/Version.h b/Crawler/Version.h index 84073f83..b255ea56 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 3335 +#define VERSION_BUILD 3347 #define stringify(a) stringify_(a) #define stringify_(a) #a