diff --git a/src/Library/EffectParameter.hpp b/src/Library/EffectParameter.hpp index 4040a26..61736bd 100644 --- a/src/Library/EffectParameter.hpp +++ b/src/Library/EffectParameter.hpp @@ -34,6 +34,9 @@ namespace CreatureLib::Library { } int64_t AsInt() const { if (_type != EffectParameterType::Int) { + if (_type == EffectParameterType::Float) { + return static_cast(std::get(_value)); + } std::stringstream ss; ss << "Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type); throw CreatureException(ss.str()); @@ -42,6 +45,9 @@ namespace CreatureLib::Library { } float AsFloat() const { if (_type != EffectParameterType::Float) { + if (_type == EffectParameterType::Int) { + return static_cast(std::get(_value)); + } std::stringstream ss; ss << "Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type); throw CreatureException(ss.str()); diff --git a/tests/LibraryTests/EffectParameterTests.cpp b/tests/LibraryTests/EffectParameterTests.cpp index 6fb6669..a841e73 100644 --- a/tests/LibraryTests/EffectParameterTests.cpp +++ b/tests/LibraryTests/EffectParameterTests.cpp @@ -13,6 +13,7 @@ TEST_CASE("Bool EffectParameter", "[Library]") { TEST_CASE("Int EffectParameter", "[Library]") { auto p = EffectParameter((int64_t)684); REQUIRE(p.AsInt() == 684); + REQUIRE(p.AsFloat() == 684); } TEST_CASE("String EffectParameter", "[Library]") { @@ -23,6 +24,7 @@ TEST_CASE("String EffectParameter", "[Library]") { TEST_CASE("Float EffectParameter", "[Library]") { auto p = EffectParameter(1.5f); REQUIRE(p.AsFloat() == Approx(1.5f)); + REQUIRE(p.AsInt() == 1); } #endif \ No newline at end of file