mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Do not allow cast if it affects only "wrong" targets
This commit is contained in:
parent
7b7958c548
commit
5fa9d64d78
@ -710,7 +710,34 @@ ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCast(const CBat
|
||||
if(ctx.mode == ECastingMode::CREATURE_ACTIVE_CASTING || ctx.mode == ECastingMode::HERO_CASTING)
|
||||
{
|
||||
std::vector<const CStack *> affected = getAffectedStacks(cb, ctx);
|
||||
if(affected.empty())
|
||||
|
||||
//allow to cast spell if affects is at least one smart target
|
||||
bool targetExists = false;
|
||||
|
||||
for(const CStack * stack : affected)
|
||||
{
|
||||
bool casterStack = stack->owner == ctx.caster->getOwner();
|
||||
|
||||
switch (owner->positiveness)
|
||||
{
|
||||
case CSpell::POSITIVE:
|
||||
if(casterStack)
|
||||
targetExists = true;
|
||||
break;
|
||||
case CSpell::NEUTRAL:
|
||||
targetExists = true;
|
||||
break;
|
||||
case CSpell::NEGATIVE:
|
||||
if(!casterStack)
|
||||
targetExists = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(targetExists)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!targetExists)
|
||||
return ESpellCastProblem::NO_APPROPRIATE_TARGET;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ public:
|
||||
const std::vector<const CStack *> & attacked) const;
|
||||
|
||||
bool requiresCreatureTarget() const override;
|
||||
|
||||
protected:
|
||||
virtual void applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const;
|
||||
|
||||
|
@ -157,6 +157,7 @@ ESpellCastProblem::ESpellCastProblem CSpell::canBeCast(const CBattleInfoCallback
|
||||
return generalProblem;
|
||||
|
||||
//check for creature target existence
|
||||
//allow to cast spell if there is at least one smart target
|
||||
if(mechanics->requiresCreatureTarget())
|
||||
{
|
||||
switch(mode)
|
||||
@ -180,14 +181,14 @@ ESpellCastProblem::ESpellCastProblem CSpell::canBeCast(const CBattleInfoCallback
|
||||
switch (positiveness)
|
||||
{
|
||||
case CSpell::POSITIVE:
|
||||
if(casterStack || !tinfo.smart)
|
||||
if(casterStack)
|
||||
targetExists = true;
|
||||
break;
|
||||
case CSpell::NEUTRAL:
|
||||
targetExists = true;
|
||||
break;
|
||||
case CSpell::NEGATIVE:
|
||||
if(!casterStack || !tinfo.smart)
|
||||
if(!casterStack)
|
||||
targetExists = true;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user