Add Heal function for monsters. Make player stat functions const return. Add Missing Health bonus stat from buffs. Refactor names of stat functions to be more explicit. Add more stat buff and pct buff checks. Fix up discrepancies with how stat up buffs work for the player. 53/53 passing tests.

This commit is contained in:
2024-06-28 01:59:18 -05:00
parent 048f2cce74
commit 6ea8588feb
14 changed files with 225 additions and 88 deletions
@@ -93,6 +93,7 @@ class AiL : public olc::PixelGameEngine
friend class sig::Animation;
friend class Audio;
friend class Minimap;
friend class MonsterTests::MonsterTest;
friend class PlayerTests::PlayerTest;
std::unique_ptr<Player>player;
SplashScreen splash;
+10 -2
View File
@@ -94,6 +94,12 @@ const bool ItemAttribute::operator<(const ItemAttribute&rhs)const{
return originalName<rhs.originalName;
};
float operator+(const float&lhs,const ItemAttribute&rhs){
float result{lhs};
result+=rhs;
return result;
};
const std::string_view ItemAttribute::Modifies()const{
return modifies;
};
@@ -118,10 +124,11 @@ float&operator+=(float&lhs,const ItemAttribute&rhs){
}
#pragma endregion
if(rhs.DisplayAsPercent()){ //This is a percentage-based stat modifier.
statModifierTotal+=stats->A_Read(rhs)/100.f;
if(rhs.Modifies().length()>0){
lhs+=stats->A_Read(rhs.Modifies())*statModifierTotal;
}else{
lhs+=stats->A_Read(rhs)*statModifierTotal;
lhs*=statModifierTotal;
}
}else{ //This is a flat stat modifier.
lhs+=statModifierTotal;
@@ -152,10 +159,11 @@ float&operator-=(float&lhs,const ItemAttribute&rhs){
}
#pragma endregion
if(rhs.DisplayAsPercent()){ //This is a percentage-based stat modifier.
statModifierTotal+=stats->A_Read(rhs)/100.f;
if(rhs.Modifies().length()>0){
lhs-=stats->A_Read(rhs.Modifies())*statModifierTotal;
}else{
lhs-=stats->A_Read(rhs)*statModifierTotal;
lhs/=statModifierTotal;
}
}else{ //This is a flat stat modifier.
lhs-=statModifierTotal;
@@ -69,6 +69,7 @@ public:
friend float&operator+=(float&lhs,const ItemAttribute&rhs);
friend float&operator-=(float&lhs,const ItemAttribute&rhs);
const bool operator==(const ItemAttribute&rhs)const;
friend float operator+(const float&lhs,const ItemAttribute&rhs);
static void Initialize();
};
@@ -76,6 +77,7 @@ struct Stats;
class ItemAttributable{
friend class ItemInfo;
friend class EntityStats;
protected:
std::map<ItemAttribute,float>attributes;
public:
@@ -65,7 +65,7 @@ namespace CharacterMenuWindow{
const static std::array<AttributeData,7>displayAttrs{
AttributeData{"Health",[]()->int{return game->GetPlayer()->GetMaxHealth();}},
AttributeData{"Attack",[]()->int{return game->GetPlayer()->GetAttack();}},
AttributeData{"Defense",[]()->int{return game->GetPlayer()->GetStat("Defense");}},
AttributeData{"Defense",[]()->int{return game->GetPlayer()->GetDefense();}},
AttributeData{"Move Spd %",[]()->int{return ceil(game->GetPlayer()->GetMoveSpdMult()*100);}},
AttributeData{"CDR",[]()->int{return ceil(game->GetPlayer()->GetCooldownReductionPct()*100);}},
AttributeData{"Crit Rate",[]()->int{return ceil(game->GetPlayer()->GetCritRatePct()*100);}},
@@ -178,7 +178,7 @@ void Menu::InitializeCharacterMenuWindow(){
const static auto GetLabelText=[](ItemAttribute attribute){
std::string attrStr=std::string(attribute.Name())+"\n ";
attrStr+=std::to_string(game->GetPlayer()->GetStat(attribute));
attrStr+=std::to_string(game->GetPlayer()->GetEquipStat(attribute));
if(attribute.DisplayAsPercent()){
attrStr+="%";
}
+1 -1
View File
@@ -54,7 +54,7 @@ DamageNumber::DamageNumber(vf2d pos,int damage,bool friendly,DamageNumberType ty
}
void DamageNumber::RecalculateSize(){
float damageMultRatio=damage/game->GetPlayer()->GetStat("Attack")/2.f;
float damageMultRatio=damage/game->GetPlayer()->GetEquipStat("Attack")/2.f;
riseSpd=originalRiseSpd;
if(!friendly){
float newSize=std::clamp(roundf(damageMultRatio),1.0f,4.0f);
+1
View File
@@ -46,6 +46,7 @@ namespace MonsterTests{
class ItemDrop{
friend class AiL;
friend class MonsterTests::MonsterTest;
friend class PlayerTests::PlayerTest;
vf2d pos;
vf2d speed{};
float zSpeed=0;
+12 -4
View File
@@ -91,8 +91,8 @@ const int Monster::GetMaxHealth()const{
}
int Monster::GetAttack(){
float mod_atk=float(stats.A("Attack"));
mod_atk+=Get("Attack %");
mod_atk+=Get("Attack");
mod_atk+=GetBonusStat("Attack %");
mod_atk+=GetBonusStat("Attack");
return int(mod_atk);
}
float Monster::GetMoveSpdMult(){
@@ -723,6 +723,10 @@ void Monster::AddBuff(BuffType type,float duration,float intensity,std::set<Item
buffList.push_back(Buff{type,duration,intensity,attr});
}
void Monster::AddBuff(BuffType type,float duration,float intensity,std::set<std::string>attr){
buffList.push_back(Buff{type,duration,intensity,attr});
}
void Monster::RemoveBuff(BuffType type){
std::erase_if(buffList,[&](const Buff&buff){return buff.type==type;});
}
@@ -909,8 +913,8 @@ const ItemAttributable&Monster::GetStats()const{
return stats;
}
ItemAttribute&Monster::Get(std::string_view attr){
return ItemAttribute::Get(attr,this);
const ItemAttribute&Monster::GetBonusStat(std::string_view attr)const{
return ItemAttribute::Get(attr,const_cast<Monster*>(this));
}
const uint32_t MonsterData::GetXP()const{
@@ -1146,3 +1150,7 @@ const bool Monster::IsSolid()const{
void Monster::_DealTrueDamage(const uint32_t damageAmt){
_Hurt(damageAmt,OnUpperLevel(),GetZ(),TrueDamageFlag::IGNORE_DAMAGE_RULES);
}
void Monster::Heal(const int healAmt){
hp=std::clamp(hp+healAmt,0,int(GetMaxHealth()));
}
+5 -1
View File
@@ -137,7 +137,10 @@ public:
bool StartPathfinding(float pathingTime);
void PathAroundBehavior(float fElapsedTime);
void AddBuff(BuffType type,float duration,float intensity);
//NOTE: If adding a % increase stat, please use the percentage version! 100% = 1!!
void AddBuff(BuffType type,float duration,float intensity,std::set<ItemAttribute>attr);
//NOTE: If adding a % increase stat, please use the percentage version! 100% = 1!!
void AddBuff(BuffType type,float duration,float intensity,std::set<std::string>attr);
std::vector<Buff>GetBuffs(BuffType buff)const;
//Removes all buffs of a given type.
void RemoveBuff(BuffType type);
@@ -193,6 +196,7 @@ public:
const bool ReachedTargetPos(const float maxDistanceFromTarget=4.f)const;
const float GetHealthRatio()const;
void _DealTrueDamage(const uint32_t damageAmt);
void Heal(const int healAmt);
private:
//NOTE: Marking a monster for deletion does not trigger any death events. It just simply removes the monster from the field!!
// The way this works is that monsters marked for deletion will cause the monster update loop to detect there's at least one or more monsters that must be deleted and will call erase_if on the list at the end of the iteration loop.
@@ -246,7 +250,7 @@ private:
std::function<bool(GameEvent&,Monster&,const std::string&)>strategyDeathFunc{};
void SetStrategyDeathFunction(std::function<bool(GameEvent&,Monster&,const std::string&)>func);
//If you are trying to change a Get() stat, use the STAT_UP buff (and the optional argument) to supply an attribute you want to apply.
ItemAttribute&Get(std::string_view attr);
const ItemAttribute&GetBonusStat(std::string_view attr)const;
//Returns false if the monster could not be moved to the requested location due to collision.
//If monsterInvoked is true, this means the monster was the one that instantiated this input, and it's not an extra movement done via collision.
//Set monsterInvoked to false when you don't want a movement loop due to collisions.
+54 -28
View File
@@ -255,8 +255,7 @@ const int Player::GetHealth()const{
}
const int Player::GetMaxHealth()const{
const float hpPctIncrease=GetStat("Health")*GetStat("Health %")/100.f;
return int(GetStat("Health")+hpPctIncrease);
return int(GetModdedStatBonuses("Health"));
}
const int Player::GetMana()const{
@@ -264,20 +263,21 @@ const int Player::GetMana()const{
}
const int Player::GetMaxMana()const{
return GetStat("Mana");
return GetEquipStat("Mana");
}
const int Player::GetAttack(){
float mod_atk=float(GetStat("Attack"));
mod_atk+=Get("Attack");
mod_atk+=Get("Attack %");
return int(mod_atk);
const int Player::GetAttack()const{
return int(GetModdedStatBonuses("Attack"));
}
const int Player::GetDefense()const{
return int(GetModdedStatBonuses("Defense"));
}
float Player::GetMoveSpdMult(){
float moveSpdPct=GetStat("Move Spd %")/100.f;
float moveSpdPct=GetEquipStat("Move Spd %")/100.f;
float mod_moveSpd=moveSpdPct;
mod_moveSpd+=ItemAttribute::Get("Move Spd %",this);
mod_moveSpd+=GetBonusStat("Move Spd %");
for(const Buff&b:GetBuffs(BuffType::SLOWDOWN)){
mod_moveSpd-=moveSpdPct*b.intensity;
}
@@ -759,7 +759,7 @@ bool Player::Hurt(int damage,bool onUpperLevel,float z){
finalPctDmgTaken=std::max(6.25_Pct,finalPctDmgTaken);//Apply Damage Cap.
float minPctDmgReduction=0.05_Pct*GetStat("Defense");
float minPctDmgReduction=0.05_Pct*GetDefense();
float finalPctDmgReduction=1-finalPctDmgTaken;
float pctDmgReductionDiff=finalPctDmgReduction-minPctDmgReduction;
@@ -1129,12 +1129,12 @@ void Player::SetItem3UseFunc(Ability a){
useItem3=a;
};
const float&Player::GetStat(std::string_view a)const{
return GetStat(ItemAttribute::Get(a));
const float&Player::GetEquipStat(std::string_view a)const{
return GetEquipStat(ItemAttribute::Get(a));
}
const float&Player::GetStat(ItemAttribute a)const{
return stats.GetStat(a);
const float&Player::GetEquipStat(ItemAttribute a)const{
return stats.GetEquipStat(a);
}
const float&Player::GetBaseStat(std::string_view a)const{
@@ -1172,11 +1172,11 @@ void EntityStats::RecalculateEquipStats(){
}
}
const float&EntityStats::GetStat(ItemAttribute stat)const{
const float&EntityStats::GetEquipStat(ItemAttribute stat)const{
return equipStats.A_Read(stat);
}
const float&EntityStats::GetStat(std::string_view stat)const{
const float&EntityStats::GetEquipStat(std::string_view stat)const{
return equipStats.A_Read(stat);
}
@@ -1233,7 +1233,7 @@ const float Player::GetDamageReductionFromBuffs()const{
const float Player::GetDamageReductionFromArmor()const{
float dmgReduction=0;
dmgReduction+=Stats::GetDamageReductionPct(GetStat("Defense"));
dmgReduction+=Stats::GetDamageReductionPct(GetDefense());
return std::min(0.75f,dmgReduction);
};
@@ -1265,8 +1265,8 @@ const ItemAttributable&Player::GetBaseStats()const{
return stats.GetBaseStats();
};
ItemAttribute&Player::Get(std::string_view attr){
return ItemAttribute::Get(attr,this);
const ItemAttribute&Player::GetBonusStat(std::string_view attr)const{
return ItemAttribute::Get(attr,const_cast<Player*>(this));
}
const float Player::GetCooldownReductionPct()const{
@@ -1275,34 +1275,34 @@ const float Player::GetCooldownReductionPct()const{
for(const Buff&b:buffs){
modCDRPct+=b.intensity;
}
modCDRPct+=GetStat("CDR")/100;
modCDRPct+=GetEquipStat("CDR")/100;
return modCDRPct;
}
const float Player::GetCritRatePct()const{
float modCritRatePct=0;
modCritRatePct+=GetStat("Crit Rate")/100;
modCritRatePct+=GetEquipStat("Crit Rate")/100;
return modCritRatePct;
}
const float Player::GetCritDmgPct()const{
float modCritDmgPct=0;
modCritDmgPct+=GetStat("Crit Dmg")/100;
modCritDmgPct+=GetEquipStat("Crit Dmg")/100;
return modCritDmgPct;
}
const float Player::GetHPRecoveryPct()const{
float modHPRecoveryPct=0;
modHPRecoveryPct+=GetStat("HP Recovery %")/100;
modHPRecoveryPct+=GetEquipStat("HP Recovery %")/100;
return modHPRecoveryPct;
}
const float Player::GetHP6RecoveryPct()const{
float modHPRecoveryPct=0;
modHPRecoveryPct+=GetStat("HP6 Recovery %")/100;
modHPRecoveryPct+=GetEquipStat("HP6 Recovery %")/100;
return modHPRecoveryPct;
}
const float Player::GetHP4RecoveryPct()const{
float modHPRecoveryPct=0;
modHPRecoveryPct+=GetStat("HP4 Recovery %")/100;
modHPRecoveryPct+=GetEquipStat("HP4 Recovery %")/100;
return modHPRecoveryPct;
}
@@ -1337,7 +1337,7 @@ void Player::PerformHPRecovery(){
const float Player::GetDamageReductionPct()const{
float modDmgReductionPct=0;
modDmgReductionPct+=GetStat("Damage Reduction")/100;
modDmgReductionPct+=GetEquipStat("Damage Reduction")/100;
return modDmgReductionPct;
}
@@ -1418,7 +1418,7 @@ const uint32_t Player::GetAccumulatedXP()const{
}
const float Player::GetAttackRecoveryRateReduction()const{
return GetStat("Attack Spd");
return GetEquipStat("Attack Spd");
}
void EntityStats::Reset(){
@@ -1601,4 +1601,30 @@ void Player::CheckAndPerformAbility(Ability&ability,InputGroup key){
}else
if(key.Released()||!key.Held())ability.waitForRelease=false;
}
}
const float Player::GetModdedStatBonuses(std::string_view stat)const{
if(ItemAttribute::Get(stat).DisplayAsPercent())ERR(std::format("WARNING! Stat {} was provided. A percentage-based stat should not be supplied here! GetModdedStatBonuses() is supposed to calculate using a BASE stat and includes the percentage modifier already! Please fix this!",stat))
float flatBonuses{GetEquipStat(stat)+GetBonusStat(stat)};
float pctBonusSum{};
for(const auto&[attrName,attr]:ItemAttribute::attributes){
if(stat==attrName)continue; //Ignore self.
if(attr.Modifies()==stat){
pctBonusSum+=stats.GetStats().A_Read(attrName);
}
}
for(const Buff&buff:GetBuffs(BuffType::STAT_UP)){
for(const ItemAttribute&attr:buff.attr){
if(attr.Modifies()==stat){
if(attr.DisplayAsPercent()){
pctBonusSum+=buff.intensity*100.f;
}
}
}
}
return flatBonuses+flatBonuses*pctBonusSum/100.f;
}
const float Player::GetModdedStatBonuses(ItemAttribute stat)const{
return GetModdedStatBonuses(stat.ActualName());
}
+18 -6
View File
@@ -81,8 +81,10 @@ public:
void RecalculateEquipStats(); //Called when equipment is updated.
const ItemAttributable&GetStats()const;
const ItemAttributable&GetBaseStats()const;
const float&GetStat(ItemAttribute stat)const; //Get stats with equipment applied.
const float&GetStat(std::string_view stat)const; //Get stats with equipment applied.
//Get stats with equipment applied.
const float&GetEquipStat(ItemAttribute stat)const;
//Get stats with equipment applied.
const float&GetEquipStat(std::string_view stat)const;
const float&GetBaseStat(ItemAttribute stat)const;
const float&GetBaseStat(std::string_view stat)const;
void SetBaseStat(ItemAttribute a,float val);
@@ -114,8 +116,8 @@ public:
float GetX();
float GetY();
float GetZ();
const float&GetStat(ItemAttribute a)const;
const float&GetStat(std::string_view a)const;
const float&GetEquipStat(ItemAttribute a)const;
const float&GetEquipStat(std::string_view a)const;
const float&GetBaseStat(ItemAttribute a)const;
const float&GetBaseStat(std::string_view a)const;
void SetBaseStat(std::string_view a,float val);
@@ -124,7 +126,8 @@ public:
const int GetHealth()const;
const int GetMana()const;
const int GetMaxMana()const;
const int GetAttack();
const int GetAttack()const;
const int GetDefense()const;
const float GetDamageReductionFromBuffs()const;
const float GetDamageReductionFromArmor()const;
float GetMoveSpdMult();
@@ -171,7 +174,9 @@ public:
void SetState(State::State newState);
void AddBuff(BuffType type,float duration,float intensity);
//NOTE: If adding a % increase stat, please use the percentage version! 100% = 1!!
void AddBuff(BuffType type,float duration,float intensity,std::set<ItemAttribute>attr);
//NOTE: If adding a % increase stat, please use the percentage version! 100% = 1!!
void AddBuff(BuffType type,float duration,float intensity,std::set<std::string>attr);
void AddBuff(BuffType type,float duration,float intensity,float timeBetweenTicks,std::function<void(AiL*,int)>repeatAction);
@@ -271,6 +276,10 @@ public:
void AddVelocity(vf2d vel);
const float GetHealthRatio()const;
const bool IsAlive()const;
//An all-in-one function that applies a stat plus any % modifiers the stat may have as well.
const float GetModdedStatBonuses(std::string_view stat)const;
//An all-in-one function that applies a stat plus any % modifiers the stat may have as well.
const float GetModdedStatBonuses(ItemAttribute stat)const;
private:
int hp="Warrior.BaseHealth"_I;
int mana="Player.BaseMana"_I;
@@ -318,7 +327,10 @@ private:
Ability useItem3;
uint32_t money="Player.Starting Money"_I;
EntityStats stats;
ItemAttribute&Get(std::string_view attr);
//So this is kind of a stupid one...
//If the attr provided is a % modifier, it will take the lhs in a += operation and multiply it by the % modifier from player's actual stats.
//If the attr provided is not a % modifier, it will add in a +=/+ operation...
const ItemAttribute&GetBonusStat(std::string_view attr)const;
bool rendered=false;
bool invisibility=false;
//Returns true if the move was valid and successful.
-1
View File
@@ -109,7 +109,6 @@ public:
inline SetLoadoutItemTask():TutorialTask(){};
private:
virtual inline void Initialize()override final{
if(game->TestingModeEnabled())return;
Component<MenuComponent>(ITEM_LOADOUT,"Start Level Button")->SetGrayedOut(true);
}
virtual inline bool CompleteCondition()override final{
+1 -1
View File
@@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 3
#define VERSION_BUILD 9852
#define VERSION_BUILD 9896
#define stringify(a) stringify_(a)
#define stringify_(a) #a