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.
126 lines
3.5 KiB
126 lines
3.5 KiB
#pragma once
|
|
#include "Item.h"
|
|
#include "safemap.h"
|
|
#include "DEFINES.h"
|
|
#include "Crawler.h"
|
|
|
|
INCLUDE_game
|
|
INCLUDE_DATA
|
|
INCLUDE_GFX
|
|
|
|
safemap<std::string,ItemInfo>ITEM_DATA;
|
|
safemap<std::string,std::function<bool(Crawler*,ItemProps)>>ITEM_SCRIPTS;
|
|
safemap<std::string,std::set<std::string>>ITEM_CATEGORIES;
|
|
|
|
typedef std::string IT;
|
|
|
|
ItemInfo::ItemInfo()
|
|
:customProps({nullptr,nullptr}){}
|
|
|
|
void ItemInfo::InitializeItems(){
|
|
|
|
InitializeScripts();
|
|
|
|
for(auto&key:DATA["ItemCategory"].GetKeys()){
|
|
ITEM_CATEGORIES[key.first];
|
|
}
|
|
|
|
for(auto&key:DATA["ItemDatabase"].GetKeys()){
|
|
std::string imgPath="assets/"+"item_img_directory"_S+key.first+".png";
|
|
Renderable&img=GFX["item_img_directory"_S+key.first+".png"];
|
|
img.Load(imgPath);
|
|
|
|
std::string scriptName="",description="",category="";
|
|
for(auto&itemKey:DATA["ItemDatabase"][key.first].GetKeys()){
|
|
std::string keyName=itemKey.first;
|
|
if(keyName=="Description"){
|
|
description=DATA["ItemDatabase"][key.first][keyName].GetString();
|
|
}else
|
|
if(keyName=="ItemCategory"){
|
|
category=DATA["ItemDatabase"][key.first][keyName].GetString();
|
|
}else
|
|
if(keyName=="ItemScript"){
|
|
scriptName=DATA["ItemDatabase"][key.first][keyName].GetString();
|
|
}else{ //THis is a custom override modifier for a script. NO-OP
|
|
}
|
|
}
|
|
|
|
if(scriptName!=""){
|
|
if(!ITEM_SCRIPTS.count(scriptName)){
|
|
std::cout<<"Could not load script "<<scriptName<<" for Item "<<key.first<<"!"<<std::endl;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
ItemInfo&it=ITEM_DATA[key.first];
|
|
it.name=key.first;
|
|
it.description=description;
|
|
it.category=category;
|
|
if(!ITEM_CATEGORIES.count(it.category)){
|
|
std::cout<<"WARNING! Tried to add item "<<it.name<<" to category "<<it.category<<" which does not exist!"<<std::endl;
|
|
throw;
|
|
}
|
|
ITEM_CATEGORIES.at(it.category).insert(it.name);
|
|
it.img=img.Decal();
|
|
it.script=scriptName;
|
|
ItemProps&props=it.customProps;
|
|
if(scriptName!=""){
|
|
props.scriptProps=&DATA["ItemScript"][scriptName];
|
|
props.customProps=&DATA["ItemDatabase"][key.first];
|
|
}
|
|
it.useFunc=scriptName;
|
|
}
|
|
|
|
ITEM_DATA.SetInitialized();
|
|
ITEM_CATEGORIES.SetInitialized();
|
|
|
|
std::cout<<ITEM_DATA.size()<<" items have been loaded."<<std::endl;
|
|
std::cout<<ITEM_CATEGORIES.size()<<" item categories have been loaded."<<std::endl;
|
|
}
|
|
|
|
ItemProps::ItemProps(utils::datafile*scriptProps,utils::datafile*customProps)
|
|
:scriptProps(scriptProps),customProps(customProps){}
|
|
|
|
int ItemProps::GetIntProp(std::string prop){
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetInt();
|
|
else return (*scriptProps)[prop].GetInt();
|
|
};
|
|
float ItemProps::GetFloatProp(std::string prop){
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetReal();
|
|
else return (*scriptProps)[prop].GetReal();
|
|
};
|
|
std::string ItemProps::GetStringProp(std::string prop){
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetString();
|
|
else return (*scriptProps)[prop].GetString();
|
|
};
|
|
|
|
void ItemInfo::InitializeScripts(){
|
|
ITEM_SCRIPTS["Restore"]=[](Crawler*game,ItemProps props){
|
|
game->GetPlayer()->Heal(props.GetIntProp("HP Restore"));
|
|
game->GetPlayer()->Heal(props.GetIntProp("HP % Restore"));
|
|
game->GetPlayer()->Heal(props.GetIntProp("HP Restore"));
|
|
game->GetPlayer()->Heal(props.GetIntProp("HP % Restore"));
|
|
return true;
|
|
};
|
|
|
|
ITEM_SCRIPTS.SetInitialized();
|
|
std::cout<<ITEM_SCRIPTS.size()<<" item scripts have been loaded."<<std::endl;
|
|
}
|
|
|
|
void Inventory::AddItem(IT it,int amt){
|
|
|
|
}
|
|
|
|
void Inventory::GetItemCount(IT it){
|
|
|
|
}
|
|
|
|
void Inventory::UseItem(IT it,int amt)
|
|
{
|
|
|
|
}
|
|
|
|
void Inventory::RemoveItem(IT it,int amt)
|
|
{
|
|
|
|
} |