Implement basic structures for Items, Item Sets, and Equipment.

pull/28/head
sigonasr2 1 year ago
parent 47d7c02bb6
commit b97c63f7b0
  1. 73
      Crawler/AttributableStat.h
  2. 2
      Crawler/CharacterInfoWindow.cpp
  3. 16
      Crawler/CharacterMenuWindow.cpp
  4. 11
      Crawler/CharacterRotatingDisplay.h
  5. 4
      Crawler/Crawler.vcxproj
  6. 3
      Crawler/Crawler.vcxproj.filters
  7. 26
      Crawler/Item.cpp
  8. 33
      Crawler/Item.h
  9. 8
      Crawler/OverworldMenuWindow.cpp
  10. 2
      Crawler/Version.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::map<ItemAttribute,int>attributes;
public:
inline int&get(ItemAttribute a){
return attributes[a];
}
inline const int get_readOnly(ItemAttribute a)const{
return attributes.at(a);
}
};

@ -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);

@ -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);
}

@ -51,6 +51,9 @@ protected:
public:
inline CharacterRotatingDisplay(MenuType parent,geom2d::rect<float>rect,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<vf2d,4>{
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},
});
}
};

@ -279,6 +279,10 @@
<ClInclude Include="Ability.h" />
<ClInclude Include="Animation.h" />
<ClInclude Include="Attributable.h" />
<ClInclude Include="AttributableStat.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="Buff.h" />
<ClInclude Include="Bullet.h" />
<ClInclude Include="BulletTypes.h" />

@ -285,6 +285,9 @@
<ClInclude Include="miniaudio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AttributableStat.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">

@ -52,6 +52,7 @@ Item Item::BLANK;
std::map<IT,Item>Inventory::_inventory;
std::map<ITCategory,std::vector<Item>>Inventory::sortedInv;
std::vector<ItemOverlay>ItemOverlay::items;
std::map<std::string,ItemSet>ItemSet::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)
@ -401,3 +402,22 @@ 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 "<<pieceCount);
for(int i=pieceCount-1;i<setBonuses.size();i++){
setBonuses[i]+=bonuses;
}
}

@ -41,6 +41,7 @@ All rights reserved.
#include <map>
#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<bool(Crawler*,ItemProps)> ItemScript;
struct Stats:ItemAttributable{
public:
inline Stats&operator+=(const Stats&rhs){
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
A(a)+=rhs.A_Read(a);
}
};
};
struct EnhancementInfo{
private:
std::vector<Stats>enhancementStats;
public:
const Stats&operator[](int level)const;
};
class ItemSet{
friend class Item;
static std::map<std::string,ItemSet>sets;
std::array<Stats,8>setBonuses;
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="";

@ -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<CharacterRotatingDisplay>(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;});

@ -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

Loading…
Cancel
Save