diff --git a/Crawler/Buff.h b/Crawler/Buff.h index 5f9bd5d2..914183cc 100644 --- a/Crawler/Buff.h +++ b/Crawler/Buff.h @@ -42,10 +42,16 @@ enum BuffType{ DAMAGE_REDUCTION, SLOWDOWN, BLOCK_SLOWDOWN, + RESTORATION, }; +class Crawler; + struct Buff{ BuffType type; - float duration; - float intensity; + float duration=1; + float timeBetweenTicks=1; + float intensity=1; + float nextTick=0; + std::functionrepeatAction; }; \ No newline at end of file diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 4b9f5fdb..ebed674c 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -212,25 +212,46 @@ void ItemInfo::InitializeItems(){ ItemProps::ItemProps(utils::datafile*scriptProps,utils::datafile*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); 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)); 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); 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(){ + ITEM_SCRIPTS["Restore"]=[](Crawler*game,ItemProps props){ - game->GetPlayer()->Heal(props.GetIntProp("HP Restore")); - game->GetPlayer()->Heal(int(game->GetPlayer()->GetMaxHealth()*props.GetIntProp("HP % Restore")/100.f)); - game->GetPlayer()->RestoreMana(props.GetIntProp("MP Restore")); - game->GetPlayer()->RestoreMana(int(game->GetPlayer()->GetMaxMana()*props.GetIntProp("MP % Restore")/100.f)); + auto ParseItemScriptData=[&](const std::string&propName,std::functionaction,BuffType type){ + int restoreAmt=props.GetIntProp(propName); + action(game,restoreAmt); + 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; }; ITEM_SCRIPTS["Buff"]=[](Crawler*game,ItemProps props){ diff --git a/Crawler/Item.h b/Crawler/Item.h index 4b2ecbd2..b5f3a8f7 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -223,9 +223,10 @@ class ItemProps{ utils::datafile*customProps; public: ItemProps(utils::datafile*scriptProps,utils::datafile*customProps); - int GetIntProp(std::string prop,size_t index); - float GetFloatProp(std::string prop,size_t index); - std::string GetStringProp(std::string prop,size_t index); + int GetIntProp(const std::string&prop,size_t index=0)const; + float GetFloatProp(const std::string&prop,size_t index=0)const; + std::string GetStringProp(const std::string&prop,size_t index=0)const; + const uint32_t PropCount(const std::string&prop)const; }; class ItemInfo{ diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 641d75f5..c5b13cc6 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -272,14 +272,14 @@ void Player::Update(float fElapsedTime){ manaTickTimer+=0.2f; RestoreMana(1,true); } - for(std::vector::iterator it=buffList.begin();it!=buffList.end();++it){ - Buff&b=*it; + for(Buff&b:buffList){ b.duration-=fElapsedTime; - if(b.duration<=0){ - it=buffList.erase(it); - if(it==buffList.end())break; + if(b.nextTick>0&&b.durationrepeatAction){ + buffList.push_back(Buff{.type=type,.duration=duration,.timeBetweenTicks=timeBetweenTicks,.intensity=intensity,.nextTick=duration-timeBetweenTicks,.repeatAction=repeatAction}); } bool Player::OnUpperLevel(){ diff --git a/Crawler/Player.h b/Crawler/Player.h index 8303addd..91bd5c09 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -203,8 +203,9 @@ public: //Returns true if the move was valid and successful. bool SetPos(vf2d pos); void SetState(State::State newState); - + void AddBuff(BuffType type,float duration,float intensity); + void AddBuff(BuffType type,float duration,float intensity,float timeBetweenTicks,std::functionrepeatAction); std::vectorGetBuffs(BuffType buff); void RemoveBuff(BuffType type); //Removes the first buff found. void RemoveAllBuffs(BuffType type); //Removes all buffs of a certain type. diff --git a/Crawler/Version.h b/Crawler/Version.h index 040da977..0a8b2cf7 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 4521 +#define VERSION_BUILD 4530 #define stringify(a) stringify_(a) #define stringify_(a) #a