diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index 5ab8532..2362639 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -83,8 +83,10 @@ float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling: mod *= critModifier; } Ensure(attack->GetUser()->GetBattle().GetValue()); - float randPercentage = 85 + attack->GetUser()->GetBattle().GetValue()->GetRandom()->Get(0, 16); - mod *= randPercentage / 100.0; + if (_hasRandomness) { + float randPercentage = 85 + attack->GetUser()->GetBattle().GetValue()->GetRandom()->Get(0, 16); + mod *= randPercentage / 100.0; + } if (attack->GetUser()->HasType(hitData.GetType())) { float stabModifier = 1.5; PKMN_HOOK(OverrideSTABModifier, attack, attack, target, hitIndex, &stabModifier); diff --git a/src/Battling/Library/DamageLibrary.hpp b/src/Battling/Library/DamageLibrary.hpp index 6eff51b..695c31f 100644 --- a/src/Battling/Library/DamageLibrary.hpp +++ b/src/Battling/Library/DamageLibrary.hpp @@ -4,7 +4,11 @@ #include namespace PkmnLib::Battling { class DamageLibrary final : public CreatureLib::Battling::DamageLibrary { + bool _hasRandomness; + public: + explicit DamageLibrary(bool hasRandomness = true) : _hasRandomness(hasRandomness) {} + uint32_t GetDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hitIndex, const CreatureLib::Battling::ExecutingAttack::HitData& hitData) const override; diff --git a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp index 94724db..ec07777 100644 --- a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp @@ -26,6 +26,7 @@ class testScript1 : PkmnScript { bool testMove(Pokemon@ p, uint index, LearnedMove@ move){ return p.GetMoves()[index] is move; } bool testHasHeldItem(Pokemon@ p, const constString &in item){ return p.HasHeldItem(item); } void testSetHeldItem(Pokemon@ p, const constString &in item){ p.SetHeldItem(item); } + void testSetHeldItem2(Pokemon@ p){ p.SetHeldItem("testItem"); } }} )"}}; @@ -347,11 +348,26 @@ TEST_CASE("Test Pokemon SetHeldItem in Script") { data.Context->SetArgAddress(1, &item); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); - REQUIRE((bool)data.Context->GetReturnDWord()); + REQUIRE(mon->HasHeldItem("testItem"_cnc)); + + delete mon; +} + +TEST_CASE("Test Pokemon SetHeldItem2 in Script") { + auto mainLib = TestLibrary::GetLibrary(); + + auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3"_cnc, 30) + .WithForme("default"_cnc) + .Build(); + auto data = GetScript(mainLib, "testSetHeldItem2"_cnc); + + data.Context->SetArgObject(0, const_cast(mon)); + REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(mon->HasHeldItem("testItem"_cnc)); delete mon; } + #endif \ No newline at end of file