Fix Containment Priest exiling itself (#3161)

Co-authored-by: tool4EvEr <tool4EvEr@192.168.0.59>
This commit is contained in:
tool4ever
2023-05-27 15:10:04 +02:00
committed by GitHub
parent a1a24b3270
commit 9105d2de4e
3 changed files with 26 additions and 17 deletions

View File

@@ -8,11 +8,9 @@ import com.google.common.base.Optional;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.card.CardCollectionView;
import forge.game.card.CounterType;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType;
/**
* TODO: Write javadoc for this type.
@@ -60,21 +58,8 @@ public class ReplaceAddCounter extends ReplacementEffect {
return false;
}
if (runParams.containsKey(AbilityKey.ETB) && (Boolean)runParams.get(AbilityKey.ETB)) {
// if Card does affect something other than itself
if (!hasParam("ValidCard") || !getParam("ValidCard").equals("Card.Self")) {
// and it self is entering, skip
if (getHostCard().equals(runParams.get(AbilityKey.Affected))) {
return false;
}
// and it wasn't already on the field, skip
if (getActiveZone().contains(ZoneType.Battlefield) && runParams.containsKey(AbilityKey.LastStateBattlefield)) {
CardCollectionView lastBattlefield = (CardCollectionView) runParams.get(AbilityKey.LastStateBattlefield);
if (!lastBattlefield.contains(getHostCard())) {
return false;
}
}
}
if (runParams.containsKey(AbilityKey.ETB) && (Boolean)runParams.get(AbilityKey.ETB) && !canReplaceETB(runParams)) {
return false;
}
return true;

View File

@@ -87,6 +87,10 @@ public class ReplaceMoved extends ReplacementEffect {
if (!val) { return false; }
}
if (runParams.get(AbilityKey.Destination) == ZoneType.Battlefield && !canReplaceETB(runParams)) {
return false;
}
return true;
}

View File

@@ -32,8 +32,10 @@ import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.Card;
import forge.game.card.CardCollectionView;
import forge.game.phase.PhaseType;
import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType;
import forge.util.CardTranslation;
import forge.util.Lang;
import forge.util.TextUtil;
@@ -319,4 +321,22 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
public List<Object> getTriggerRemembered() {
return ImmutableList.of();
}
protected boolean canReplaceETB(Map<AbilityKey, Object> runParams) {
// if Card does affect something other than itself
if (!hasParam("ValidCard") || !getParam("ValidCard").startsWith("Card.Self")) {
// and it self is entering, skip
if (getHostCard().equals(runParams.get(AbilityKey.Affected))) {
return false;
}
// and it wasn't already on the field, skip
if (getActiveZone().contains(ZoneType.Battlefield) && runParams.containsKey(AbilityKey.LastStateBattlefield)) {
CardCollectionView lastBattlefield = (CardCollectionView) runParams.get(AbilityKey.LastStateBattlefield);
if (!lastBattlefield.contains(getHostCard())) {
return false;
}
}
}
return true;
}
}