You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
1.8 KiB

9 months ago
// Copyright Zelle Games
#include "StatsSubsystem.h"
bool UStatsSubsystem::IncreaseStat(FString StatName)
{
int32* StatToIncrease = &AttackPower;
int32 NextCost = 0;
if(StatName == "HP")
{
NextCost = GetNextCost(MaxHP, StatName);
StatToIncrease = &MaxHP;
} else if(StatName == "ATK")
{
NextCost = GetNextCost(AttackPower, StatName);
} else if(StatName == "ASPD")
{
NextCost = GetNextCostFloat(AttackSpeed, StatName);
} else if(StatName == "DEF")
{
NextCost = GetNextCost(DefensePower, StatName);
StatToIncrease = &DefensePower;
} else if(StatName == "DEX")
{
NextCost = GetNextCost(Dexterity, StatName);
StatToIncrease = &Dexterity;
} else if(StatName == "REC")
{
NextCost = GetNextCost(RecoveryPerTurn, StatName);
StatToIncrease = &RecoveryPerTurn;
}
if(XP >= NextCost)
{
XP -= NextCost;
if(StatName == "ASPD")
{
AttackSpeed += 0.01f;
} else if(StatName == "HP")
{
(*StatToIncrease) += 10;
}else
{
(*StatToIncrease)++;
}
return true;
}
return false;
}
int32 UStatsSubsystem::GetNextCost(int32 Input, FString StatName)
{
int32 Divisor;
float Multiplier;
if(StatName == "HP")
{
Divisor = 100;
Multiplier = 1.5f;
} else
{
Divisor = 10;
Multiplier = 1.5f;
}
int32 NumBreakpoints = FMath::DivideAndRoundDown(Input, Divisor);
return FMath::CeilToInt(NumBreakpoints * Multiplier) + 1;
}
int32 UStatsSubsystem::GetNextCostFloat(float Input, FString StatName)
{
int32 Divisor;
float Multiplier;
float Base;
if(StatName == "ASPD")
{
Divisor = 20;
Multiplier = 1.2f;
Base = 0.33f;
} else
{
Divisor = 10;
Multiplier = 1.5f;
Base = 0.33f;
}
int32 NumBreakpoints = FMath::DivideAndRoundDown(FMath::FloorToInt((Input - Base) * 100) , Divisor);
return FMath::CeilToInt(NumBreakpoints * Multiplier) + 1;
}