From 3d46ee3182f3ef42848e09afcebdce4e4af79003 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 3 May 2023 23:45:55 +0300 Subject: [PATCH] TargetCondition: units with 100% MR is immune Spells should not consider units with 100% MR as valid targets. --- lib/spells/TargetCondition.cpp | 19 +++++++++++++++++++ lib/spells/TargetCondition.h | 1 + test/spells/TargetConditionTest.cpp | 3 +++ 3 files changed, 23 insertions(+) diff --git a/lib/spells/TargetCondition.cpp b/lib/spells/TargetCondition.cpp index 444350b42..dddc0b167 100644 --- a/lib/spells/TargetCondition.cpp +++ b/lib/spells/TargetCondition.cpp @@ -89,6 +89,18 @@ private: si32 maxVal = std::numeric_limits::max(); }; +class ResistanceCondition : public TargetConditionItemBase +{ +protected: + bool check(const Mechanics * m, const battle::Unit * target) const override + { + if(m->isPositiveSpell()) //Always pass on positive + return true; + + return target->magicResistance() < 100; + } +}; + class CreatureCondition : public TargetConditionItemBase { public: @@ -319,6 +331,12 @@ public: return elementalCondition; } + Object createResistance() const override + { + static auto elementalCondition = std::make_shared(); + return elementalCondition; + } + Object createNormalLevel() const override { static std::shared_ptr nlCondition = std::make_shared(); @@ -451,6 +469,7 @@ void TargetCondition::serializeJson(JsonSerializeFormat & handler, const ItemFac absolute.push_back(itemFactory->createAbsoluteSpell()); absolute.push_back(itemFactory->createAbsoluteLevel()); normal.push_back(itemFactory->createElemental()); + normal.push_back(itemFactory->createResistance()); normal.push_back(itemFactory->createNormalLevel()); normal.push_back(itemFactory->createNormalSpell()); negation.push_back(itemFactory->createReceptiveFeature()); diff --git a/lib/spells/TargetCondition.h b/lib/spells/TargetCondition.h index 31ecaba06..1679a0c4b 100644 --- a/lib/spells/TargetCondition.h +++ b/lib/spells/TargetCondition.h @@ -49,6 +49,7 @@ public: virtual Object createElemental() const = 0; virtual Object createNormalLevel() const = 0; virtual Object createNormalSpell() const = 0; + virtual Object createResistance() const = 0; virtual Object createConfigurable(std::string scope, std::string type, std::string identifier) const = 0; virtual Object createFromJsonStruct(const JsonNode & jsonStruct) const = 0; diff --git a/test/spells/TargetConditionTest.cpp b/test/spells/TargetConditionTest.cpp index b74fa68b1..88abf7fcd 100644 --- a/test/spells/TargetConditionTest.cpp +++ b/test/spells/TargetConditionTest.cpp @@ -41,6 +41,7 @@ public: MOCK_CONST_METHOD0(createAbsoluteLevel, Object()); MOCK_CONST_METHOD0(createAbsoluteSpell, Object()); MOCK_CONST_METHOD0(createElemental, Object()); + MOCK_CONST_METHOD0(createResistance, Object()); MOCK_CONST_METHOD0(createNormalLevel, Object()); MOCK_CONST_METHOD0(createNormalSpell, Object()); MOCK_CONST_METHOD1(createFromJsonStruct, Object(const JsonNode &)); @@ -74,6 +75,7 @@ public: ON_CALL(factoryMock, createAbsoluteLevel()).WillByDefault(Return(itemStub)); ON_CALL(factoryMock, createAbsoluteSpell()).WillByDefault(Return(itemStub)); ON_CALL(factoryMock, createElemental()).WillByDefault(Return(itemStub)); + ON_CALL(factoryMock, createResistance()).WillByDefault(Return(itemStub)); ON_CALL(factoryMock, createNormalLevel()).WillByDefault(Return(itemStub)); ON_CALL(factoryMock, createNormalSpell()).WillByDefault(Return(itemStub)); @@ -139,6 +141,7 @@ TEST_F(TargetConditionTest, CreatesSpecialConditions) EXPECT_CALL(factoryMock, createAbsoluteLevel()).Times(1); EXPECT_CALL(factoryMock, createAbsoluteSpell()).Times(1); EXPECT_CALL(factoryMock, createElemental()).Times(1); + EXPECT_CALL(factoryMock, createResistance()).Times(1); EXPECT_CALL(factoryMock, createNormalLevel()).Times(1); EXPECT_CALL(factoryMock, createNormalSpell()).Times(1);