The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'! https://forums.lestoria.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
AdventuresInLestoria/Crawler/Item.h

81 lines
1.9 KiB

#pragma once
#include <string>
#include <functional>
#include <map>
#include "olcPixelGameEngine.h"
#include "olcUTIL_DataFile.h"
class Crawler;
class ItemInfo;
typedef std::string IT;
typedef std::string ITCategory;
class Item{
friend class Inventory;
private:
uint32_t amt;
ItemInfo*it;
public:
Item(uint32_t amt,IT item);
uint32_t Amt();
std::string Name();
std::string Description();
ITCategory Category();
Decal*Decal();
ItemScript&OnUseAction();
};
class Inventory{
public:
static void AddItem(IT it,int amt=1);
static uint32_t GetItemCount(IT it);
static Item GetItem(IT it)const;
//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 void UseItem(IT it,int amt=1);
static void RemoveItem(IT it,int amt=1);
static std::vector<IT>&get(ITCategory itemCategory);
static bool SwapItems(IT it,IT it2);
private:
static void InsertIntoSortedInv(IT item);
static bool ExecuteAction(IT item);
static std::map<IT,Item>_inventory;
static std::map<ITCategory,std::vector<IT>>sortedInv;
};
class ItemProps{
friend class ItemInfo;
utils::datafile*scriptProps;
utils::datafile*customProps;
public:
ItemProps(utils::datafile*scriptProps,utils::datafile*customProps);
int GetIntProp(std::string prop);
float GetFloatProp(std::string prop);
std::string GetStringProp(std::string prop);
};
typedef std::function<bool(Crawler*,ItemProps)> ItemScript;
class ItemInfo{
friend class Inventory;
std::string name;
std::string description;
std::string category;
Decal*img;
//Returns true if the item can be used, false otherwise
std::string useFunc="";
//Custom properties for this specific item's script.
static utils::datafile NOPROPS;
ItemProps customProps;
private:
static void InitializeScripts();
public:
static void InitializeItems();
ItemInfo();
/*
For the useFunc, return true if the item can be used, false otherwise.
*/
};