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. 35
      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,
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::function<void(Crawler*,int)>repeatAction;
};

@ -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::function<void(Crawler*,int)>action,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){

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

@ -272,14 +272,14 @@ void Player::Update(float fElapsedTime){
manaTickTimer+=0.2f;
RestoreMana(1,true);
}
for(std::vector<Buff>::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.duration<b.nextTick){
b.repeatAction(game,b.intensity);
b.nextTick-=b.timeBetweenTicks;
}
}
std::erase_if(buffList,[](Buff&b){return b.duration<=0;});
//Class-specific update events.
OnUpdate(fElapsedTime);
switch(state){
@ -705,7 +705,10 @@ void Player::UpdateIdleAnimation(Key direction){
}
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(){

@ -205,6 +205,7 @@ public:
void SetState(State::State newState);
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);
void RemoveBuff(BuffType type); //Removes the first buff found.
void RemoveAllBuffs(BuffType type); //Removes all buffs of a certain type.

@ -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

Loading…
Cancel
Save