diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 0268aee..116d5ff 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -171,9 +171,11 @@ void Battling::Creature::Heal(uint32_t amount, bool canRevive) { void Battling::Creature::OverrideActiveTalent(const ArbUt::StringView& talent) { _hasOverridenTalent = true; - _activeTalent->OnRemove(); + if (_activeTalent != nullptr) { + _activeTalent->OnRemove(); + _activeTalent.reset(this->_library->LoadScript(ScriptCategory::Talent, talent)); + } _overridenTalentName = talent; - _activeTalent.reset(this->_library->LoadScript(ScriptCategory::Talent, talent)); } const std::unordered_set& Battling::Creature::GetTypes() const noexcept { return _types; } diff --git a/tests/BattleTests/CreatureTests.cpp b/tests/BattleTests/CreatureTests.cpp index 3ba17c8..a17697f 100644 --- a/tests/BattleTests/CreatureTests.cpp +++ b/tests/BattleTests/CreatureTests.cpp @@ -46,4 +46,12 @@ TEST_CASE("Increase creature stat boost", "[Library]") { delete creature; } +TEST_CASE("Override Creature talent", "[Library]") { + auto library = TestLibrary::Get(); + auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create(); + creature->OverrideActiveTalent("foobar"); + REQUIRE(creature->GetActiveTalent() == "foobar"); + delete creature; +} + #endif \ No newline at end of file