mirror of
https://github.com/correl/mage.git
synced 2025-03-17 01:06:26 -09:00
- Fixed #5392
This commit is contained in:
parent
d6b40d1654
commit
4c56baac03
1 changed files with 67 additions and 23 deletions
|
@ -2,24 +2,30 @@ package mage.cards.p;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.DelayedTriggeredAbility;
|
||||||
import mage.abilities.TriggeredAbility;
|
import mage.abilities.TriggeredAbility;
|
||||||
import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
|
import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
|
||||||
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
|
|
||||||
import mage.abilities.condition.Condition;
|
import mage.abilities.condition.Condition;
|
||||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||||
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
|
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
|
||||||
|
import mage.abilities.effects.Effect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.effects.common.ReturnFromExileForSourceEffect;
|
import mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
|
import mage.constants.Duration;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.constants.SetTargetPointer;
|
import mage.constants.SetTargetPointer;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
import mage.filter.common.FilterCreaturePermanent;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.game.events.GameEvent;
|
||||||
|
import mage.game.events.GameEvent.EventType;
|
||||||
|
import mage.game.events.ZoneChangeEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
import mage.target.targetpointer.FixedTarget;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,14 +40,14 @@ public final class Portcullis extends CardImpl {
|
||||||
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
|
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
|
||||||
|
|
||||||
// Whenever a creature enters the battlefield, if there are two or more other creatures on the battlefield, exile that creature.
|
// Whenever a creature enters the battlefield, if there are two or more other creatures on the battlefield, exile that creature.
|
||||||
String rule = "Whenever a creature enters the battlefield, if there are two or more other creatures on the battlefield, exile that creature";
|
|
||||||
TriggeredAbility ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new PortcullisExileEffect(), filter, false, SetTargetPointer.PERMANENT, rule);
|
|
||||||
MoreThanXCreaturesOnBFCondition condition = new MoreThanXCreaturesOnBFCondition(2);
|
|
||||||
this.addAbility(new ConditionalInterveningIfTriggeredAbility(ability, condition, rule));
|
|
||||||
|
|
||||||
// Return that card to the battlefield under its owner's control when Portcullis leaves the battlefield.
|
// Return that card to the battlefield under its owner's control when Portcullis leaves the battlefield.
|
||||||
Ability ability2 = new LeavesBattlefieldTriggeredAbility(new ReturnFromExileForSourceEffect(Zone.BATTLEFIELD), false);
|
String rule = "Whenever a creature enters the battlefield, if there are two or more other creatures on the battlefield, exile that creature.";
|
||||||
this.addAbility(ability2);
|
String rule2 = " Return that card to the battlefield under its owner's control when {this} leaves the battlefield.";
|
||||||
|
TriggeredAbility ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new PortcullisExileEffect(),
|
||||||
|
filter, false, SetTargetPointer.PERMANENT, rule);
|
||||||
|
MoreThanXCreaturesOnBFCondition condition = new MoreThanXCreaturesOnBFCondition(2);
|
||||||
|
this.addAbility(new ConditionalInterveningIfTriggeredAbility(ability, condition, rule + rule2));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Portcullis(final Portcullis card) {
|
public Portcullis(final Portcullis card) {
|
||||||
|
@ -74,8 +80,8 @@ class MoreThanXCreaturesOnBFCondition implements Condition {
|
||||||
class PortcullisExileEffect extends OneShotEffect {
|
class PortcullisExileEffect extends OneShotEffect {
|
||||||
|
|
||||||
public PortcullisExileEffect() {
|
public PortcullisExileEffect() {
|
||||||
super(Outcome.Neutral);
|
super(Outcome.Exile);
|
||||||
this.staticText = "Whenever a creature enters the battlefield, if there are two or more other creatures on the battlefield, exile that creature.";
|
this.staticText = "Whenever a creature enters the battlefield, if there are two or more other creatures on the battlefield, exile that creature";
|
||||||
}
|
}
|
||||||
|
|
||||||
public PortcullisExileEffect(final PortcullisExileEffect effect) {
|
public PortcullisExileEffect(final PortcullisExileEffect effect) {
|
||||||
|
@ -89,20 +95,58 @@ class PortcullisExileEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Permanent creature = game.getPermanent(targetPointer.getFirst(game, source));
|
Permanent creatureToExile = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||||
|
Permanent portcullis = game.getPermanent(source.getSourceId());
|
||||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (permanent == null) {
|
if (portcullis != null
|
||||||
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
|
&& creatureToExile != null
|
||||||
|
&& controller != null) {
|
||||||
|
UUID exileZoneId = CardUtil.getExileZoneId(game, creatureToExile.getId(), creatureToExile.getZoneChangeCounter(game));
|
||||||
|
controller.moveCardsToExile(creatureToExile, source, game, true, exileZoneId, portcullis.getName());
|
||||||
|
FixedTarget fixedTarget = new FixedTarget(portcullis, game);
|
||||||
|
Effect returnEffect = new ReturnToBattlefieldUnderOwnerControlTargetEffect();
|
||||||
|
returnEffect.setTargetPointer(new FixedTarget(creatureToExile.getId(), game.getState().getZoneChangeCounter(creatureToExile.getId())));
|
||||||
|
DelayedTriggeredAbility delayedAbility = new PortcullisReturnToBattlefieldTriggeredAbility(fixedTarget, returnEffect);
|
||||||
|
game.addDelayedTriggeredAbility(delayedAbility, source);
|
||||||
}
|
}
|
||||||
if (permanent != null && creature != null) {
|
|
||||||
Player controller = game.getPlayer(creature.getControllerId());
|
|
||||||
Zone currentZone = game.getState().getZone(creature.getId());
|
|
||||||
if (currentZone == Zone.BATTLEFIELD) {
|
|
||||||
controller.moveCardsToExile(creature, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PortcullisReturnToBattlefieldTriggeredAbility extends DelayedTriggeredAbility {
|
||||||
|
|
||||||
|
protected FixedTarget fixedTarget;
|
||||||
|
|
||||||
|
public PortcullisReturnToBattlefieldTriggeredAbility(FixedTarget fixedTarget, Effect effect) {
|
||||||
|
super(effect, Duration.OneUse);
|
||||||
|
this.fixedTarget = fixedTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PortcullisReturnToBattlefieldTriggeredAbility(final PortcullisReturnToBattlefieldTriggeredAbility ability) {
|
||||||
|
super(ability);
|
||||||
|
this.fixedTarget = ability.fixedTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PortcullisReturnToBattlefieldTriggeredAbility copy() {
|
||||||
|
return new PortcullisReturnToBattlefieldTriggeredAbility(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkEventType(GameEvent event, Game game) {
|
||||||
|
return event.getType() == EventType.ZONE_CHANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
|
if (((ZoneChangeEvent) event).getFromZone().match(Zone.BATTLEFIELD)) {
|
||||||
|
return (fixedTarget.getTarget().equals(event.getTargetId()));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRule() {
|
||||||
|
return "Return this card to the battlefield under its owner's control when Portcullis leaves the battlefield.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue