Fix changing stat falling through enum and throwing exception.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-01-05 14:25:48 +01:00
parent 568232c7a5
commit f9494d4c38
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 14 additions and 7 deletions

View File

@ -7,8 +7,7 @@
#include "Statistic.hpp" #include "Statistic.hpp"
namespace CreatureLib::Core { namespace CreatureLib::Core {
template <class T> template <class T> class StatisticSet {
class StatisticSet {
protected: protected:
T _health; T _health;
T _physicalAttack; T _physicalAttack;
@ -39,8 +38,8 @@ namespace CreatureLib::Core {
case MagicalAttack: return _magicalAttack; case MagicalAttack: return _magicalAttack;
case MagicalDefense: return _magicalDefense; case MagicalDefense: return _magicalDefense;
case Speed: return _speed; case Speed: return _speed;
default: throw NotReachableException();
} }
throw NotReachableException();
} }
inline void SetStat(Statistic stat, T value) { inline void SetStat(Statistic stat, T value) {
@ -51,8 +50,8 @@ namespace CreatureLib::Core {
case MagicalAttack: _magicalAttack = value; case MagicalAttack: _magicalAttack = value;
case MagicalDefense: _magicalDefense = value; case MagicalDefense: _magicalDefense = value;
case Speed: _speed = value; case Speed: _speed = value;
default: throw NotReachableException();
} }
throw NotReachableException();
} }
inline void IncreaseStatBy(Statistic stat, T amount) { inline void IncreaseStatBy(Statistic stat, T amount) {
@ -63,8 +62,8 @@ namespace CreatureLib::Core {
case MagicalAttack: _magicalAttack += amount; case MagicalAttack: _magicalAttack += amount;
case MagicalDefense: _magicalDefense += amount; case MagicalDefense: _magicalDefense += amount;
case Speed: _speed += amount; case Speed: _speed += amount;
default: throw NotReachableException();
} }
throw NotReachableException();
} }
inline void DecreaseStatBy(Statistic stat, T amount) { inline void DecreaseStatBy(Statistic stat, T amount) {
switch (stat) { switch (stat) {
@ -74,10 +73,10 @@ namespace CreatureLib::Core {
case MagicalAttack: _magicalAttack -= amount; case MagicalAttack: _magicalAttack -= amount;
case MagicalDefense: _magicalDefense -= amount; case MagicalDefense: _magicalDefense -= amount;
case Speed: _speed -= amount; case Speed: _speed -= amount;
default: throw NotReachableException();
} }
throw NotReachableException();
} }
}; };
} }
#endif //CREATURELIB_STATISTICSET_HPP #endif // CREATURELIB_STATISTICSET_HPP

View File

@ -38,4 +38,12 @@ TEST_CASE("Get creature nickname when unset", "[Library]") {
delete creature; delete creature;
} }
TEST_CASE("Increase creature stat boost", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
creature->ChangeStatBoost(CreatureLib::Core::Statistic::PhysicalAttack, 6);
REQUIRE(creature->GetStatBoost(CreatureLib::Core::Statistic::PhysicalAttack) == 6);
delete creature;
}
#endif #endif