mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Fix possible crash on invalid SPELL_LIKE_ATTACK ability
This commit is contained in:
@@ -32,18 +32,14 @@ public:
|
|||||||
int32_t getNum() const
|
int32_t getNum() const
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
|
||||||
std::visit([&result] (const auto& v) { result = v.getNum(); }, value);
|
std::visit([&result] (const auto& v) { result = v.getNum(); }, value);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toString() const
|
std::string toString() const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
std::visit([&result] (const auto& v) { result = v.encode(v.getNum()); }, value);
|
std::visit([&result] (const auto& v) { result = v.encode(v.getNum()); }, value);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +54,13 @@ public:
|
|||||||
return IdentifierType();
|
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)
|
template <typename Handler> void serialize(Handler &h)
|
||||||
{
|
{
|
||||||
h & value;
|
h & value;
|
||||||
|
|||||||
@@ -494,7 +494,7 @@ bool BattleActionProcessor::doHealAction(const CBattleInfoCallback & battle, con
|
|||||||
else
|
else
|
||||||
destStack = battle.battleGetUnitByPos(target.at(0).hexValue);
|
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");
|
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));
|
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
|
//this is need for displaying hit animation
|
||||||
bat.flags |= BattleAttack::SPELL_LIKE;
|
bat.flags |= BattleAttack::SPELL_LIKE;
|
||||||
|
|||||||
Reference in New Issue
Block a user