Implemented equipping of items, reading of slot types from item database, and prepared set items and stats structures.
This commit is contained in:
parent
b97c63f7b0
commit
298b0c4ca7
50
Crawler/BitwiseEnum.h
Normal file
50
Crawler/BitwiseEnum.h
Normal file
@ -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<typename T>
|
||||
constexpr auto operator|(T attribute,T attribute2) noexcept
|
||||
{
|
||||
return T(static_cast<std::underlying_type_t<T>>(attribute)|static_cast<std::underlying_type_t<T>>(attribute2));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr auto operator&(T attribute,T attribute2) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<T>>(attribute)&static_cast<std::underlying_type_t<T>>(attribute2);
|
||||
}
|
@ -200,6 +200,11 @@ bool Crawler::OnUserCreate(){
|
||||
|
||||
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){
|
||||
|
@ -283,6 +283,10 @@
|
||||
<SubType>
|
||||
</SubType>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BitwiseEnum.h">
|
||||
<SubType>
|
||||
</SubType>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Buff.h" />
|
||||
<ClInclude Include="Bullet.h" />
|
||||
<ClInclude Include="BulletTypes.h" />
|
||||
|
@ -288,6 +288,9 @@
|
||||
<ClInclude Include="AttributableStat.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BitwiseEnum.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Player.cpp">
|
||||
|
@ -53,11 +53,25 @@ 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;
|
||||
std::map<EquipSlot,Item*>Inventory::equipment;
|
||||
std::map<std::string,EquipSlot>ItemInfo::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<std::string> 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 "<<it.name<<" to slot "<<s<<" which doesn't exist!");
|
||||
it.slot=it.slot|nameToEquipSlot[s];
|
||||
}
|
||||
}
|
||||
if(!ITEM_CATEGORIES.count(it.category)){
|
||||
ERR("WARNING! Tried to add item "<<it.name<<" to category "<<it.category<<" which does not exist!")
|
||||
}
|
||||
@ -174,7 +201,12 @@ void Inventory::AddItem(IT it,uint32_t amt,bool monsterDrop){
|
||||
InsertIntoStageInventoryCategory(it,amt,monsterDrop);
|
||||
}
|
||||
|
||||
Item Inventory::GetItem(IT it){
|
||||
Item Inventory::CopyItem(IT it){
|
||||
if(!_inventory.count(it))return Item::BLANK;
|
||||
return _inventory.at(it);
|
||||
}
|
||||
|
||||
Item&Inventory::GetItem(IT it){
|
||||
if(!_inventory.count(it))return Item::BLANK;
|
||||
return _inventory.at(it);
|
||||
}
|
||||
@ -412,6 +444,7 @@ const ItemSet&Item::GetItemSet()const{
|
||||
};
|
||||
|
||||
const Stats&ItemSet::operator[](int setPieces)const{
|
||||
if(setPieces<=0||setPieces>=9)ERR("Piece count is invalid! Expecting a value (1-8) but got "<<setPieces);
|
||||
return setBonuses[setPieces];
|
||||
};
|
||||
|
||||
@ -421,3 +454,24 @@ void ItemSet::AddSetBonus(int pieceCount,const Stats&bonuses){
|
||||
setBonuses[i]+=bonuses;
|
||||
}
|
||||
}
|
||||
|
||||
void Inventory::EquipItem(Item&it,EquipSlot slot){
|
||||
if(!(it.it->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];
|
||||
}
|
@ -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<bool(Crawler*,ItemProps)> 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<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
|
||||
A(a)+=rhs.A_Read(a);
|
||||
}
|
||||
return *this;
|
||||
};
|
||||
};
|
||||
|
||||
@ -75,6 +89,7 @@ class ItemSet{
|
||||
public:
|
||||
//Specify the piece count(1-8) for a set bonus to be applied.
|
||||
void AddSetBonus(int pieceCount,const Stats&bonuses);
|
||||
//Gets a set bonus based on number of pieces (1-8)
|
||||
const Stats&operator[](int setPieces)const;
|
||||
};
|
||||
|
||||
@ -111,13 +126,18 @@ public:
|
||||
static void AddItem(IT it,uint32_t amt=1,bool monsterDrop=false);
|
||||
//Returns the actual amount available in your main inventory.
|
||||
static uint32_t GetItemCount(IT it);
|
||||
static Item GetItem(IT it);
|
||||
static Item CopyItem(IT it);
|
||||
static Item&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);
|
||||
static bool RemoveItem(IT it,ITCategory inventory,uint32_t amt = 1);
|
||||
static bool RemoveItem(IT it,uint32_t amt=1);
|
||||
static std::vector<Item>&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<IT,Item>_inventory;
|
||||
static std::map<EquipSlot,Item*>equipment;
|
||||
//Only contains "1" of every item, as this is a map to index items and not the actual storage of items!
|
||||
static std::map<ITCategory,std::vector<Item>>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::map<std::string,EquipSlot>nameToEquipSlot;
|
||||
public:
|
||||
static void InitializeItems();
|
||||
ItemInfo();
|
||||
|
@ -37,6 +37,7 @@ All rights reserved.
|
||||
#pragma endregion
|
||||
#pragma once
|
||||
#include "Menu.h"
|
||||
#include "BitwiseEnum.h"
|
||||
|
||||
enum class ButtonAttr{
|
||||
NONE=0b00,
|
||||
@ -111,23 +112,3 @@ public:
|
||||
void Enable(bool enabled);
|
||||
virtual void Cleanup();
|
||||
};
|
||||
|
||||
constexpr auto operator|(ButtonAttr attribute,ButtonAttr attribute2) noexcept
|
||||
{
|
||||
return ButtonAttr(static_cast<std::underlying_type_t<ButtonAttr>>(attribute)|static_cast<std::underlying_type_t<ButtonAttr>>(attribute2));
|
||||
}
|
||||
|
||||
constexpr auto operator&(ButtonAttr attribute,ButtonAttr attribute2) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<ButtonAttr>>(attribute)&static_cast<std::underlying_type_t<ButtonAttr>>(attribute2);
|
||||
}
|
||||
|
||||
|
||||
constexpr auto operator|(ComponentAttr attribute,ComponentAttr attribute2) noexcept
|
||||
{
|
||||
return ComponentAttr(static_cast<std::underlying_type_t<ComponentAttr>>(attribute)|static_cast<std::underlying_type_t<ComponentAttr>>(attribute2));
|
||||
}
|
||||
constexpr auto operator&(ComponentAttr attribute,ComponentAttr attribute2) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<ComponentAttr>>(attribute)&static_cast<std::underlying_type_t<ComponentAttr>>(attribute2);
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user