Refactored stat system such that equip stats can be obtained easily, while base stats are hidden away to prevent accidental usage.

pull/28/head
sigonasr2 12 months ago
parent 808cc32418
commit 5eec1a21c5
  1. 2
      Crawler/CharacterMenuWindow.cpp
  2. 5
      Crawler/Crawler.cpp
  3. 1
      Crawler/Item.cpp
  4. 71
      Crawler/Player.cpp
  5. 29
      Crawler/Player.h
  6. 2
      Crawler/Version.h

@ -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+="%";
}

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

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

@ -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<DamageNumber>(GetPos(),damage,true,HEALTH_GAIN));
}
@ -851,4 +853,31 @@ void Player::SetItem2UseFunc(Ability a){
};
void Player::SetItem3UseFunc(Ability a){
useItem3=a;
};
};
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);
}

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

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

Loading…
Cancel
Save