Bläddra i källkod

Fix possible crash on invalid SPELL_LIKE_ATTACK ability

Ivan Savenko 1 år sedan
förälder
incheckning
15f37f8c4b
2 ändrade filer med 9 tillägg och 6 borttagningar
  1. 7 4
      lib/constants/VariantIdentifier.h
  2. 2 2
      server/battles/BattleActionProcessor.cpp

+ 7 - 4
lib/constants/VariantIdentifier.h

@@ -32,18 +32,14 @@ public:
 	int32_t getNum() const
 	{
 		int32_t result;
-
 		std::visit([&result] (const auto& v) { result = v.getNum(); }, value);
-
 		return result;
 	}
 
 	std::string toString() const
 	{
 		std::string result;
-
 		std::visit([&result] (const auto& v) { result = v.encode(v.getNum()); }, value);
-
 		return result;
 	}
 
@@ -58,6 +54,13 @@ public:
 			return IdentifierType();
 	}
 
+	bool hasValue() const
+	{
+		bool result = false;
+		std::visit([&result] (const auto& v) { result = v.hasValue(); }, value);
+		return result;
+	}
+
 	template <typename Handler> void serialize(Handler &h)
 	{
 		h & value;

+ 2 - 2
server/battles/BattleActionProcessor.cpp

@@ -494,7 +494,7 @@ bool BattleActionProcessor::doHealAction(const CBattleInfoCallback & battle, con
 	else
 		destStack = battle.battleGetUnitByPos(target.at(0).hexValue);
 
-	if(stack == nullptr || destStack == nullptr || !healerAbility || healerAbility->subtype == BonusSubtypeID())
+	if(stack == nullptr || destStack == nullptr || !healerAbility || !healerAbility->subtype.hasValue())
 	{
 		gameHandler->complain("There is either no healer, no destination, or healer cannot heal :P");
 	}
@@ -971,7 +971,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
 	}
 
 	std::shared_ptr<const Bonus> bonus = attacker->getFirstBonus(Selector::type()(BonusType::SPELL_LIKE_ATTACK));
-	if(bonus && ranged) //TODO: make it work in melee?
+	if(bonus && ranged && bonus->subtype.hasValue()) //TODO: make it work in melee?
 	{
 		//this is need for displaying hit animation
 		bat.flags |= BattleAttack::SPELL_LIKE;