|
|
@ -212,25 +212,46 @@ void ItemInfo::InitializeItems(){ |
|
|
|
ItemProps::ItemProps(utils::datafile*scriptProps,utils::datafile*customProps) |
|
|
|
ItemProps::ItemProps(utils::datafile*scriptProps,utils::datafile*customProps) |
|
|
|
:scriptProps(scriptProps),customProps(customProps){} |
|
|
|
:scriptProps(scriptProps),customProps(customProps){} |
|
|
|
|
|
|
|
|
|
|
|
int ItemProps::GetIntProp(std::string prop,size_t index=0){ |
|
|
|
int ItemProps::GetIntProp(const std::string&prop,size_t index)const{ |
|
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetInt(index); |
|
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetInt(index); |
|
|
|
else return (*scriptProps)[prop].GetInt(index); |
|
|
|
else return (*scriptProps)[prop].GetInt(index); |
|
|
|
}; |
|
|
|
}; |
|
|
|
float ItemProps::GetFloatProp(std::string prop,size_t index=0){ |
|
|
|
float ItemProps::GetFloatProp(const std::string&prop,size_t index)const{ |
|
|
|
if(customProps->HasProperty(prop)) return float((*customProps)[prop].GetReal(index)); |
|
|
|
if(customProps->HasProperty(prop)) return float((*customProps)[prop].GetReal(index)); |
|
|
|
else return float((*scriptProps)[prop].GetReal(index)); |
|
|
|
else return float((*scriptProps)[prop].GetReal(index)); |
|
|
|
}; |
|
|
|
}; |
|
|
|
std::string ItemProps::GetStringProp(std::string prop,size_t index=0){ |
|
|
|
std::string ItemProps::GetStringProp(const std::string&prop,size_t index)const{ |
|
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetString(index); |
|
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetString(index); |
|
|
|
else return (*scriptProps)[prop].GetString(index); |
|
|
|
else return (*scriptProps)[prop].GetString(index); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint32_t ItemProps::PropCount(const std::string&prop)const{ |
|
|
|
|
|
|
|
if(customProps->HasProperty(prop)) return (*customProps)[prop].GetValueCount(); |
|
|
|
|
|
|
|
else return (*scriptProps)[prop].GetValueCount(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ItemInfo::InitializeScripts(){ |
|
|
|
void ItemInfo::InitializeScripts(){ |
|
|
|
|
|
|
|
|
|
|
|
ITEM_SCRIPTS["Restore"]=[](Crawler*game,ItemProps props){ |
|
|
|
ITEM_SCRIPTS["Restore"]=[](Crawler*game,ItemProps props){ |
|
|
|
game->GetPlayer()->Heal(props.GetIntProp("HP Restore")); |
|
|
|
auto ParseItemScriptData=[&](const std::string&propName,std::function<void(Crawler*,int)>action,BuffType type){ |
|
|
|
game->GetPlayer()->Heal(int(game->GetPlayer()->GetMaxHealth()*props.GetIntProp("HP % Restore")/100.f)); |
|
|
|
int restoreAmt=props.GetIntProp(propName); |
|
|
|
game->GetPlayer()->RestoreMana(props.GetIntProp("MP Restore")); |
|
|
|
action(game,restoreAmt); |
|
|
|
game->GetPlayer()->RestoreMana(int(game->GetPlayer()->GetMaxMana()*props.GetIntProp("MP % Restore")/100.f)); |
|
|
|
if(restoreAmt>0&&props.PropCount(propName)==3){ |
|
|
|
|
|
|
|
game->GetPlayer()->AddBuff(type,props.GetFloatProp(propName,2),restoreAmt,props.GetFloatProp(propName,1),action); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
ParseItemScriptData("HP Restore",[&](Crawler*game,int restoreAmt){ |
|
|
|
|
|
|
|
game->GetPlayer()->Heal(restoreAmt); |
|
|
|
|
|
|
|
},RESTORATION); |
|
|
|
|
|
|
|
ParseItemScriptData("HP % Restore",[&](Crawler*game,int restoreAmt){ |
|
|
|
|
|
|
|
game->GetPlayer()->Heal(int(game->GetPlayer()->GetMaxHealth()*restoreAmt/100.0f)); |
|
|
|
|
|
|
|
},RESTORATION); |
|
|
|
|
|
|
|
ParseItemScriptData("MP Restore",[&](Crawler*game,int restoreAmt){ |
|
|
|
|
|
|
|
game->GetPlayer()->RestoreMana(restoreAmt); |
|
|
|
|
|
|
|
},RESTORATION); |
|
|
|
|
|
|
|
ParseItemScriptData("MP % Restore",[&](Crawler*game,int restoreAmt){ |
|
|
|
|
|
|
|
game->GetPlayer()->RestoreMana(int(game->GetPlayer()->GetMaxMana()*props.GetIntProp("MP % Restore")/100.f)); |
|
|
|
|
|
|
|
},RESTORATION); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
ITEM_SCRIPTS["Buff"]=[](Crawler*game,ItemProps props){ |
|
|
|
ITEM_SCRIPTS["Buff"]=[](Crawler*game,ItemProps props){ |
|
|
|