Added Merchant config files and parsing of config files to merchant structure.

This commit is contained in:
2023-12-17 20:49:22 -06:00
parent f3bfa81198
commit 2b3c1ea1b4
21 changed files with 280 additions and 68 deletions
+19 -9
View File
@@ -201,17 +201,17 @@ void ItemInfo::InitializeItems(){
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();
int ItemProps::GetIntProp(std::string prop,size_t index=0){
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetInt(index);
else return (*scriptProps)[prop].GetInt(index);
};
float ItemProps::GetFloatProp(std::string prop){
if(customProps->HasProperty(prop)) return float((*customProps)[prop].GetReal());
else return float((*scriptProps)[prop].GetReal());
float ItemProps::GetFloatProp(std::string prop,size_t index=0){
if(customProps->HasProperty(prop)) return float((*customProps)[prop].GetReal(index));
else return float((*scriptProps)[prop].GetReal(index));
};
std::string ItemProps::GetStringProp(std::string prop){
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetString();
else return (*scriptProps)[prop].GetString();
std::string ItemProps::GetStringProp(std::string prop,size_t index=0){
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetString(index);
else return (*scriptProps)[prop].GetString(index);
};
void ItemInfo::InitializeScripts(){
@@ -222,6 +222,10 @@ void ItemInfo::InitializeScripts(){
game->GetPlayer()->RestoreMana(int(game->GetPlayer()->GetMaxMana()*props.GetIntProp("MP % Restore")/100.f));
return true;
};
ITEM_SCRIPTS["Buff"]=[](Crawler*game,ItemProps props){
game->GetPlayer()->AddBuff(BuffType::ATTACK_PCT_UP,props.GetFloatProp("Attack %",1),props.GetFloatProp("Attack %",0)/100);
return true;
};
ITEM_SCRIPTS.SetInitialized();
std::cout<<ITEM_SCRIPTS.size()<<" item scripts have been loaded."<<std::endl;
@@ -234,6 +238,7 @@ 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){
if(!ITEM_DATA.count(it))ERR("Item "<<std::quoted(it)<<" does not exist in Item Database!");
//There are two places to manipulate items in (Both the sorted inventory and the actual inventory)
if(!_inventory.count(it)){
_inventory[it]=Item{amt,it};
@@ -654,4 +659,9 @@ const std::string Stats::GetStatsString(CompactText compact)const{
first=false;
}
return description;
}
ItemInfo&ItemInfo::operator[](const IT&item){
if(!ITEM_DATA.count(item))ERR("Item "<<std::quoted(item)<<" does not exist in the item database!");
return ITEM_DATA[item];
}