From 5eec1a21c5ba33f3145b2c5424a90db57929626f Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 6 Dec 2023 19:51:38 -0600 Subject: [PATCH] Refactored stat system such that equip stats can be obtained easily, while base stats are hidden away to prevent accidental usage. --- Crawler/CharacterMenuWindow.cpp | 2 +- Crawler/Crawler.cpp | 5 ++- Crawler/Item.cpp | 1 + Crawler/Player.cpp | 71 +++++++++++++++++++++++---------- Crawler/Player.h | 29 +++++++++++--- Crawler/Version.h | 2 +- 6 files changed, 79 insertions(+), 31 deletions(-) diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp index cdb69b21..6b6ef8f7 100644 --- a/Crawler/CharacterMenuWindow.cpp +++ b/Crawler/CharacterMenuWindow.cpp @@ -180,7 +180,7 @@ void Menu::InitializeCharacterMenuWindow(){ for(ItemAttribute attribute:displayAttrs){ AttributeData data=ItemAttributable::GetDisplayInfo(attribute); std::string attrStr=data.name+":\n "; - attrStr+=std::to_string(game->GetPlayer()->A(attribute)); + attrStr+=std::to_string(game->GetPlayer()->GetStat(attribute)); if(data.displayAsPercent){ attrStr+="%"; } diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 31524a56..ebc0f906 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -1699,8 +1699,9 @@ void Crawler::ChangePlayerClass(Class cl){ player.reset(NEW Witch(player.get())); }break; } - player->hp=player->A(ItemAttribute::health)=DATA.GetProperty(player->GetClassName()+".BaseHealth").GetInt(); - player->A(ItemAttribute::attack)=DATA.GetProperty(player->GetClassName()+".BaseAtk").GetInt(); + player->SetBaseStat(ItemAttribute::health,DATA.GetProperty(player->GetClassName()+".BaseHealth").GetInt()); + player->hp=player->GetBaseStat(ItemAttribute::health); + player->SetBaseStat(ItemAttribute::attack,DATA.GetProperty(player->GetClassName()+".BaseAtk").GetInt()); player->hpGrowthRate=float(DATA.GetProperty(player->GetClassName()+".HealthGrowthRate").GetReal()); player->atkGrowthRate=float(DATA.GetProperty(player->GetClassName()+".AtkGrowthRate").GetReal()); sig::Animation::SetupPlayerAnimations(); diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 8aaeb0db..84261c97 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -500,6 +500,7 @@ void Inventory::EquipItem(Item&it,EquipSlot slot){ if(equippedSlot!=EquipSlot::NONE)UnequipItem(equippedSlot); if(GetEquip(slot)!=nullptr)UnequipItem(slot); Inventory::equipment[slot]=⁢ + PlayerStats::RecalculateEquipStats(); }; void Inventory::UnequipItem(EquipSlot slot){ Inventory::equipment[slot]=nullptr; diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 1c22dea6..9fc02a4c 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -68,6 +68,9 @@ InputGroup Player::KEY_ITEM1; InputGroup Player::KEY_ITEM2; InputGroup Player::KEY_ITEM3; +ItemAttributable PlayerStats::equipStats; +ItemAttributable PlayerStats::baseStats; + Player::Player() :lastReleasedMovementKey(DOWN),facingDirection(DOWN),state(State::NORMAL){ Initialize(); @@ -76,21 +79,20 @@ Player::Player() Player::Player(Player*player) :pos(player->GetPos()),vel(player->GetVelocity()),iframe_time(player->iframe_time),lastReleasedMovementKey(DOWN), facingDirection(DOWN),state(State::NORMAL){ - player->copyTo(*this); Initialize(); } void Player::Initialize(){ Player::GROUND_SLAM_SPIN_TIME="Warrior.Ability 2.SpinTime"_F; - A(ItemAttribute::health)=hp; - A(ItemAttribute::defense)=0; - A(ItemAttribute::attack)="Warrior.BaseAtk"_I; - A(ItemAttribute::moveSpdPct)=100; - A(ItemAttribute::cdrPct)=0; - A(ItemAttribute::critPct)=0; - A(ItemAttribute::critDmgPct)=0; - A(ItemAttribute::healthPct)=0; - A(ItemAttribute::healthPctRecoveryPer6sec)=0; + SetBaseStat(ItemAttribute::health,hp); + SetBaseStat(ItemAttribute::defense,0); + SetBaseStat(ItemAttribute::attack,"Warrior.BaseAtk"_I); + SetBaseStat(ItemAttribute::moveSpdPct,100); + SetBaseStat(ItemAttribute::cdrPct,0); + SetBaseStat(ItemAttribute::critPct,0); + SetBaseStat(ItemAttribute::critDmgPct,0); + SetBaseStat(ItemAttribute::healthPct,0); + SetBaseStat(ItemAttribute::healthPctRecoveryPer6sec,0); } bool Player::SetX(float x){ @@ -174,32 +176,32 @@ float Player::GetZ(){ return z; } -int Player::GetHealth(){ +const int Player::GetHealth()const{ return hp; } -int Player::GetMaxHealth(){ - return A(ItemAttribute::health); +const int Player::GetMaxHealth()const{ + return GetStat(ItemAttribute::health); } -int Player::GetMana(){ +const int Player::GetMana()const{ return mana; } -int Player::GetMaxMana() { +const int Player::GetMaxMana()const{ return maxmana; } -int Player::GetAttack(){ - float mod_atk=float(A(ItemAttribute::attack)); +const int Player::GetAttack(){ + float mod_atk=float(GetStat(ItemAttribute::attack)); for(Buff&b:GetBuffs(BuffType::ATTACK_UP)){ - mod_atk+=A(ItemAttribute::attack)*b.intensity; + mod_atk+=GetStat(ItemAttribute::attack)*b.intensity; } return int(mod_atk); } float Player::GetMoveSpdMult(){ - float mod_moveSpd=A(ItemAttribute::moveSpdPct)/100.f; + float mod_moveSpd=GetStat(ItemAttribute::moveSpdPct)/100.f; for(Buff&b:GetBuffs(BuffType::SLOWDOWN)){ mod_moveSpd-=mod_moveSpd*b.intensity; } @@ -789,7 +791,7 @@ void Player::SetIframes(float duration){ } bool Player::Heal(int damage){ - hp=std::clamp(hp+damage,0,A(ItemAttribute::health)); + hp=std::clamp(hp+damage,0,GetStat(ItemAttribute::health)); if(damage>0){ DAMAGENUMBER_LIST.push_back(std::make_shared(GetPos(),damage,true,HEALTH_GAIN)); } @@ -851,4 +853,31 @@ void Player::SetItem2UseFunc(Ability a){ }; void Player::SetItem3UseFunc(Ability a){ useItem3=a; -}; \ No newline at end of file +}; + +const int Player::GetStat(ItemAttribute a)const{ + return PlayerStats::GetStat(a); +} + +const int Player::GetBaseStat(ItemAttribute a)const{ + return PlayerStats::GetBaseStat(a); +} + + +void PlayerStats::RecalculateEquipStats(){ + baseStats.copyTo(equipStats); +} +const int PlayerStats::GetStat(ItemAttribute stat){ + return equipStats.A(stat); +} +const int PlayerStats::GetBaseStat(ItemAttribute stat){ + return baseStats.A(stat); +} + +void PlayerStats::SetBaseStat(ItemAttribute stat,int val){ + baseStats.A(stat)=val; + RecalculateEquipStats(); +} +void Player::SetBaseStat(ItemAttribute a,int val){ + PlayerStats::SetBaseStat(a,val); +} \ No newline at end of file diff --git a/Crawler/Player.h b/Crawler/Player.h index d974e55f..539c2662 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -49,6 +49,7 @@ All rights reserved. #include "Item.h" #include "AttributableStat.h" + #undef GetClassName struct DamageNumber; @@ -59,7 +60,19 @@ struct CastInfo{ vf2d castPos; }; -struct Player:ItemAttributable{ +class PlayerStats{ + friend class Inventory; + static ItemAttributable equipStats; //The stats after gear calculations are applied. + static ItemAttributable baseStats; + + static void RecalculateEquipStats(); //Called when equipment is updated. +public: + static const int GetStat(ItemAttribute stat); //Get stats with equipment applied. + static const int GetBaseStat(ItemAttribute stat); + static void SetBaseStat(ItemAttribute stat,int val); +}; + +struct Player{ friend class Crawler; friend class sig::Animation; friend struct Warrior; @@ -69,6 +82,7 @@ struct Player:ItemAttributable{ friend struct Wizard; friend struct Witch; friend class State_GameRun; + friend class Inventory; private: int hp="Warrior.BaseHealth"_I; int mana="Player.BaseMana"_I,maxmana=mana; @@ -149,11 +163,14 @@ public: float GetX(); float GetY(); float GetZ(); - int GetHealth(); - int GetMaxHealth(); - int GetMana(); - int GetMaxMana(); - int GetAttack(); + const int GetStat(ItemAttribute a)const; + const int GetBaseStat(ItemAttribute a)const; + void SetBaseStat(ItemAttribute a,int val); + const int GetMaxHealth()const; + const int GetHealth()const; + const int GetMana()const; + const int GetMaxMana()const; + const int GetAttack(); float GetMoveSpdMult(); float GetSizeMult(); void SetSizeMult(float size); diff --git a/Crawler/Version.h b/Crawler/Version.h index f8183211..9a2edfbc 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 3510 +#define VERSION_BUILD 3517 #define stringify(a) stringify_(a) #define stringify_(a) #a