From 48a81650866ba545c12137263dcef0b52ad4e80c Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 6 Oct 2023 18:54:17 -0500 Subject: [PATCH] Added MP restore and consume functions. Converted old direct variable accesses to use these as well. Item restore script completed. --- Crawler/Item.cpp | 6 +++--- Crawler/Player.cpp | 14 +++++++++++--- Crawler/Player.h | 2 ++ Crawler/Version.h | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 38b74cde..a1c57ed9 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -97,9 +97,9 @@ std::string ItemProps::GetStringProp(std::string prop){ void ItemInfo::InitializeScripts(){ ITEM_SCRIPTS["Restore"]=[](Crawler*game,ItemProps props){ game->GetPlayer()->Heal(props.GetIntProp("HP Restore")); - game->GetPlayer()->Heal(props.GetIntProp("HP % Restore")); - game->GetPlayer()->Heal(props.GetIntProp("HP Restore")); - game->GetPlayer()->Heal(props.GetIntProp("HP % Restore")); + game->GetPlayer()->Heal(game->GetPlayer()->GetMaxHealth()*props.GetIntProp("HP % Restore")/100.f); + game->GetPlayer()->RestoreMana(props.GetIntProp("MP Restore")); + game->GetPlayer()->RestoreMana(game->GetPlayer()->GetMaxMana()*props.GetIntProp("MP % Restore")/100.f); return true; }; diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index d68f14e3..1762d2ac 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -195,7 +195,7 @@ void Player::Update(float fElapsedTime){ if(castInfo.castTimer<=0){ if(castPrepAbility->action(this,castInfo.castPos)){ castPrepAbility->cooldown=castPrepAbility->COOLDOWN_TIME; - mana-=castPrepAbility->manaCost; + ConsumeMana(castPrepAbility->manaCost); } castInfo.castTimer=0; SetState(State::NORMAL); @@ -203,7 +203,7 @@ void Player::Update(float fElapsedTime){ } while(manaTickTimer<=0){ manaTickTimer+=0.2; - mana=std::min(maxmana,mana+1); + RestoreMana(1); } for(std::vector::iterator it=buffList.begin();it!=buffList.end();++it){ Buff&b=*it; @@ -365,7 +365,7 @@ void Player::Update(float fElapsedTime){ } if(AllowedToCast(ability)&&ability.action(this,{})){ ability.cooldown=ability.COOLDOWN_TIME; - mana-=ability.manaCost; + ConsumeMana(ability.manaCost); }else if(ability.precastInfo.precastTargetingRequired&&GetState()==State::NORMAL){ PrepareCast(ability); @@ -704,4 +704,12 @@ void Player::SetIframes(float duration){ bool Player::Heal(int damage){ hp=std::clamp(hp+damage,0,maxhp); return true; +} + +void Player::RestoreMana(int amt){ + mana=std::clamp(mana+amt,0,maxmana); +} + +void Player::ConsumeMana(int amt){ + mana=std::clamp(mana-amt,0,maxmana); } \ No newline at end of file diff --git a/Crawler/Player.h b/Crawler/Player.h index 238942f7..e51999aa 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -134,6 +134,8 @@ public: bool CanAct(Ability&ability); void Knockback(vf2d vel); void SetIframes(float duration); + void RestoreMana(int amt); + void ConsumeMana(int amt); void AddBuff(BuffType type,float duration,float intensity); std::vectorGetBuffs(BuffType buff); diff --git a/Crawler/Version.h b/Crawler/Version.h index 2b3340fa..1fbfd29a 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1811 +#define VERSION_BUILD 1814 #define stringify(a) stringify_(a) #define stringify_(a) #a