* Declaration in Stone - Fixed some problems with moving permanents to exile and etb trigger timing.

This commit is contained in:
LevelX2 2017-02-04 19:56:50 +01:00
parent b3200f8e37
commit a3a6760f4a

View file

@ -27,22 +27,23 @@
*/
package mage.cards.d;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.ClueArtifactToken;
import mage.game.permanent.token.Token;
import mage.players.Player;
import mage.target.common.TargetCreaturePermanent;
@ -53,7 +54,7 @@ import mage.target.common.TargetCreaturePermanent;
public class DeclarationInStone extends CardImpl {
public DeclarationInStone(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{1}{W}");
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{W}");
// Exile target creature and all other creatures its controller controls with the same name as that creature.
// That player investigates for each nontoken creature exiled this way.
@ -73,12 +74,6 @@ public class DeclarationInStone extends CardImpl {
class DeclarationInStoneEffect extends OneShotEffect {
private static final FilterCreaturePermanent creaturesOnly = new FilterCreaturePermanent();
private static final FilterCreaturePermanent nonTokenFilter = new FilterCreaturePermanent("nontoken creature");
static{
nonTokenFilter.add(Predicates.not(new TokenPredicate()));
}
public DeclarationInStoneEffect() {
super(Outcome.Exile);
staticText = "Exile target creature and all other creatures its controller controls with the same name as that creature. That player investigates for each nontoken creature exiled this way.";
@ -90,39 +85,34 @@ class DeclarationInStoneEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
UUID exileId = source.getSourceId();
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) {
UUID controllerPermanentId = targetPermanent.getControllerId();
Player you = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && exileId != null && you != null) {
int exiledCount = 0;
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) {
Set<Card> cardsToExile = new HashSet<>();
int nonTokenCount = 0;
if (targetPermanent.getName().isEmpty()) { // face down creature
you.moveCardToExileWithInfo(targetPermanent, exileId, sourceObject.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true);
exiledCount = 1; // will always be 1 with a face down creature (has no name)
cardsToExile.add(targetPermanent);
if (!(targetPermanent instanceof PermanentToken)) {
nonTokenCount++;
}
} else {
String name = targetPermanent.getName();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerPermanentId)) {
if (permanent != null && permanent.getName().equals(name)) {
// only exile creatures (reported bug on awakened lands targetted exiling all other lands of same name)
if (creaturesOnly.match(permanent, game)) {
you.moveCardToExileWithInfo(permanent, null, "", source.getSourceId(), game, Zone.BATTLEFIELD, true);
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), targetPermanent.getControllerId(), game)) {
if (!permanent.getId().equals(targetPermanent.getId())
&& permanent.getName().equals(targetPermanent.getName())) {
cardsToExile.add(permanent);
// exiled count only matters for non-tokens
if (nonTokenFilter.match(permanent, game)) {
exiledCount++;
if (!(permanent instanceof PermanentToken)) {
nonTokenCount++;
}
}
}
}
if (exiledCount > 0) {
Token token = new ClueArtifactToken();
token.putOntoBattlefield(exiledCount, game, source.getSourceId(), controllerPermanentId, false, false);
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
game.applyEffects();
if (nonTokenCount > 0) {
new ClueArtifactToken().putOntoBattlefield(nonTokenCount, game, source.getSourceId(), targetPermanent.getControllerId(), false, false);
}
return true;
}
@ -135,4 +125,4 @@ class DeclarationInStoneEffect extends OneShotEffect {
public DeclarationInStoneEffect copy() {
return new DeclarationInStoneEffect(this);
}
}
}