Added duration-based restoration buffs for the Restore Item Script.

pull/28/head
sigonasr2 11 months ago
parent 70423be9d4
commit fd96b23110
  1. 10
      Crawler/Buff.h
  2. 33
      Crawler/Item.cpp
  3. 7
      Crawler/Item.h
  4. 15
      Crawler/Player.cpp
  5. 1
      Crawler/Player.h
  6. 2
      Crawler/Version.h

@ -42,10 +42,16 @@ enum BuffType{
DAMAGE_REDUCTION, DAMAGE_REDUCTION,
SLOWDOWN, SLOWDOWN,
BLOCK_SLOWDOWN, BLOCK_SLOWDOWN,
RESTORATION,
}; };
class Crawler;
struct Buff{ struct Buff{
BuffType type; BuffType type;
float duration; float duration=1;
float intensity; float timeBetweenTicks=1;
float intensity=1;
float nextTick=0;
std::function<void(Crawler*,int)>repeatAction;
}; };

@ -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);
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)); 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){

@ -223,9 +223,10 @@ class ItemProps{
utils::datafile*customProps; utils::datafile*customProps;
public: public:
ItemProps(utils::datafile*scriptProps,utils::datafile*customProps); ItemProps(utils::datafile*scriptProps,utils::datafile*customProps);
int GetIntProp(std::string prop,size_t index); int GetIntProp(const std::string&prop,size_t index=0)const;
float GetFloatProp(std::string prop,size_t index); float GetFloatProp(const std::string&prop,size_t index=0)const;
std::string GetStringProp(std::string prop,size_t index); std::string GetStringProp(const std::string&prop,size_t index=0)const;
const uint32_t PropCount(const std::string&prop)const;
}; };
class ItemInfo{ class ItemInfo{

@ -272,14 +272,14 @@ void Player::Update(float fElapsedTime){
manaTickTimer+=0.2f; manaTickTimer+=0.2f;
RestoreMana(1,true); RestoreMana(1,true);
} }
for(std::vector<Buff>::iterator it=buffList.begin();it!=buffList.end();++it){ for(Buff&b:buffList){
Buff&b=*it;
b.duration-=fElapsedTime; b.duration-=fElapsedTime;
if(b.duration<=0){ if(b.nextTick>0&&b.duration<b.nextTick){
it=buffList.erase(it); b.repeatAction(game,b.intensity);
if(it==buffList.end())break; b.nextTick-=b.timeBetweenTicks;
} }
} }
std::erase_if(buffList,[](Buff&b){return b.duration<=0;});
//Class-specific update events. //Class-specific update events.
OnUpdate(fElapsedTime); OnUpdate(fElapsedTime);
switch(state){ switch(state){
@ -705,7 +705,10 @@ void Player::UpdateIdleAnimation(Key direction){
} }
void Player::AddBuff(BuffType type,float duration,float intensity){ void Player::AddBuff(BuffType type,float duration,float intensity){
buffList.push_back(Buff{type,duration,intensity}); buffList.push_back(Buff{.type=type,.duration=duration,.intensity=intensity});
}
void Player::AddBuff(BuffType type,float duration,float intensity,float timeBetweenTicks,std::function<void(Crawler*,int)>repeatAction){
buffList.push_back(Buff{.type=type,.duration=duration,.timeBetweenTicks=timeBetweenTicks,.intensity=intensity,.nextTick=duration-timeBetweenTicks,.repeatAction=repeatAction});
} }
bool Player::OnUpperLevel(){ bool Player::OnUpperLevel(){

@ -205,6 +205,7 @@ public:
void SetState(State::State newState); void SetState(State::State newState);
void AddBuff(BuffType type,float duration,float intensity); void AddBuff(BuffType type,float duration,float intensity);
void AddBuff(BuffType type,float duration,float intensity,float timeBetweenTicks,std::function<void(Crawler*,int)>repeatAction);
std::vector<Buff>GetBuffs(BuffType buff); std::vector<Buff>GetBuffs(BuffType buff);
void RemoveBuff(BuffType type); //Removes the first buff found. void RemoveBuff(BuffType type); //Removes the first buff found.
void RemoveAllBuffs(BuffType type); //Removes all buffs of a certain type. void RemoveAllBuffs(BuffType type); //Removes all buffs of a certain type.

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 4521 #define VERSION_BUILD 4530
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save