浏览代码

Do not allow rising of corpses below alive stack

Ivan Savenko 2 年之前
父节点
当前提交
1fab2e2e34
共有 1 个文件被更改,包括 18 次插入6 次删除
  1. 18 6
      lib/spells/effects/DemonSummon.cpp

+ 18 - 6
lib/spells/effects/DemonSummon.cpp

@@ -89,20 +89,32 @@ void DemonSummon::apply(ServerCallback * server, const Mechanics * m, const Effe
 		server->apply(&pack);
 }
 
-bool DemonSummon::isValidTarget(const Mechanics * m, const battle::Unit * s) const
+bool DemonSummon::isValidTarget(const Mechanics * m, const battle::Unit * unit) const
 {
-	if(!s->isDead())
-		return false;
+	if(!unit->isDead())
+	{
+		//check if alive unit blocks rising
+		for(const BattleHex & hex : battle::Unit::getHexes(unit->getPosition(), unit->doubleWide(), unit->unitSide()))
+		{
+			auto blocking = m->battle()->battleGetUnitsIf([hex, unit](const battle::Unit * other)
+			{
+				return other->isValidTarget(false) && other->coversPos(hex) && other != unit;
+			});
+
+			if(!blocking.empty())
+				return false;
+		}
+	}
 
-	if (s->isGhost())
+	if (unit->isGhost())
 		return false;
 
 	const auto *creatureType = creature.toCreature(m->creatures());
 
-	if (s->getTotalHealth() < creatureType->getMaxHealth())
+	if (unit->getTotalHealth() < creatureType->getMaxHealth())
 		return false;
 
-	return m->isReceptive(s);
+	return m->isReceptive(unit);
 }
 
 void DemonSummon::serializeJsonUnitEffect(JsonSerializeFormat & handler)