浏览代码

Block self-casting, e.g. Archangels can't resurrect themselves

Ivan Savenko 1 年之前
父节点
当前提交
c839b397e8
共有 1 个文件被更改,包括 15 次插入1 次删除
  1. 15 1
      lib/spells/BattleSpellMechanics.cpp

+ 15 - 1
lib/spells/BattleSpellMechanics.cpp

@@ -213,7 +213,21 @@ bool BattleSpellMechanics::canBeCastAt(const Target & target, Problem & problem)
 
 	Target spellTarget = transformSpellTarget(target);
 
-    return effects->applicable(problem, this, target, spellTarget);
+	const battle::Unit * mainTarget = nullptr;
+
+	if(spellTarget.front().unitValue)
+	{
+		mainTarget = target.front().unitValue;
+	}
+	else if(spellTarget.front().hexValue.isValid())
+	{
+		mainTarget = battle()->battleGetUnitByPos(target.front().hexValue, true);
+	}
+
+	if (mainTarget && mainTarget == caster)
+		return false; // can't cast on self
+
+	return effects->applicable(problem, this, target, spellTarget);
 }
 
 std::vector<const CStack *> BattleSpellMechanics::getAffectedStacks(const Target & target) const