Implemented equipping of items, reading of slot types from item database, and prepared set items and stats structures.

This commit is contained in:
2023-11-30 23:33:40 -06:00
parent b97c63f7b0
commit 298b0c4ca7
9 changed files with 147 additions and 28 deletions
+24 -1
View File
@@ -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();