* Oubliette - Fixed some problems, reworked the card.

This commit is contained in:
LevelX2 2018-04-25 23:56:35 +02:00
parent 58d40c8531
commit 41e8a0b896

View file

@ -27,7 +27,10 @@
*/ */
package mage.cards.o; package mage.cards.o;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.LeavesBattlefieldTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
@ -42,16 +45,13 @@ import mage.constants.Zone;
import mage.counters.Counter; import mage.counters.Counter;
import mage.counters.Counters; import mage.counters.Counters;
import mage.filter.Filter; import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterEnchantmentPermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.ExileZone; import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent;
import mage.util.CardUtil;
/** /**
* *
@ -59,17 +59,12 @@ import mage.target.TargetPermanent;
*/ */
public class Oubliette extends CardImpl { public class Oubliette extends CardImpl {
public Counters godHelpMe = null;
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("target creature");
public Oubliette(UUID ownerId, CardSetInfo setInfo) { public Oubliette(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{B}{B}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{B}{B}");
// When Oubliette enters the battlefield, exile target creature and all Auras attached to it. Note the number and kind of counters that were on that creature. // When Oubliette enters the battlefield, exile target creature and all Auras attached to it. Note the number and kind of counters that were on that creature.
Ability ability1 = new EntersBattlefieldTriggeredAbility(new OublietteEffect(), false); Ability ability1 = new EntersBattlefieldTriggeredAbility(new OublietteEffect(), false);
Target target = new TargetPermanent(filter); ability1.addTarget(new TargetCreaturePermanent());
ability1.addTarget(target);
this.addAbility(ability1); this.addAbility(ability1);
// When Oubliette leaves the battlefield, return the exiled card to the battlefield under its owner's control tapped with the noted number and kind of counters on it. If you do, return the exiled Aura cards to the battlefield under their owner's control attached to that permanent. // When Oubliette leaves the battlefield, return the exiled card to the battlefield under its owner's control tapped with the noted number and kind of counters on it. If you do, return the exiled Aura cards to the battlefield under their owner's control attached to that permanent.
@ -89,12 +84,6 @@ public class Oubliette extends CardImpl {
class OublietteEffect extends OneShotEffect { class OublietteEffect extends OneShotEffect {
private static final FilterEnchantmentPermanent filter = new FilterEnchantmentPermanent();
static {
filter.add(new SubtypePredicate(SubType.AURA));
}
public OublietteEffect() { public OublietteEffect() {
super(Outcome.Detriment); super(Outcome.Detriment);
this.staticText = "exile target creature and all Auras attached to it. Note the number and kind of counters that were on that creature"; this.staticText = "exile target creature and all Auras attached to it. Note the number and kind of counters that were on that creature";
@ -111,63 +100,35 @@ class OublietteEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
// Exile enchanted creature and all Auras attached to it. Player controller = game.getPlayer(source.getControllerId());
Permanent enchantment = game.getPermanent(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
if (enchantment == null) { if (controller == null || sourceObject == null) {
enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); return false;
} }
UUID targetId = source.getFirstTarget(); Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
if (targetId == null) { game.getState().setValue(CardUtil.getCardZoneString("savedCounters", source.getSourceId(), game), targetCreature.getCounters(game).copy());
return false; // if previous scan somehow failed, simply quit game.getState().setValue(CardUtil.getCardZoneString("targetId", source.getSourceId(), game), targetCreature.getId());
} Set<Card> toExile = new HashSet<>();
if (enchantment != null) { //back to code (mostly) copied from Flickerform toExile.add(targetCreature);
Permanent enchantedCreature = game.getPermanent(targetId); for (UUID attachementId : targetCreature.getAttachments()) {
if (enchantedCreature != null) { Permanent attachment = game.getPermanent(attachementId);
UUID exileZoneId = source.getSourceId(); if (attachment != null && attachment.getSubtype(game).contains(SubType.AURA)) {
enchantedCreature.moveToExile(exileZoneId, enchantment.getName(), source.getSourceId(), game); toExile.add(attachment);
for (UUID attachementId : enchantedCreature.getAttachments()) {
Permanent attachment = game.getPermanent(attachementId);
if (attachment != null && filter.match(attachment, game)) {
attachment.moveToExile(exileZoneId, enchantment.getName(), source.getSourceId(), game);
}
} }
//((Oubliette)enchantment.getMainCard()).godHelpMe = enchantedCreature.getCounters(game); //why doesn't work? should return the same card, no?
((Oubliette) game.getCard(source.getSourceId())).godHelpMe = enchantedCreature.getCounters(game).copy();
/*
if (!(enchantedCreature instanceof Token)) {
// If you do, return the other cards exiled this way to the battlefield under their owners' control attached to that creature
LeavesBattlefieldTriggeredAbility triggeredAbility = new LeavesBattlefieldTriggeredAbility(
new OublietteReturnEffect(), false);
//enchantment.addAbility(triggeredAbility, source.getSourceId(), game, false);
//Card card = game.getCard(source.getSourceId());
//game.getState().addOtherAbility(card, triggeredAbility);
}*/
return true;
} }
controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), sourceObject.getIdName());
} }
return false; return true;
} }
} }
class OublietteReturnEffect extends OneShotEffect { class OublietteReturnEffect extends OneShotEffect {
private static final FilterCard filterAura = new FilterCard();
static {
filterAura.add(new CardTypePredicate(CardType.ENCHANTMENT));
filterAura.add(new SubtypePredicate(SubType.AURA));
}
public OublietteReturnEffect() { public OublietteReturnEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
this.staticText = "return the exiled card to the battlefield under its owner's control tapped with the noted number and kind of counters on it. If you do, return the exiled Aura cards to the battlefield under their owner's control attached to that permanent"; this.staticText = "return the exiled card to the battlefield under its owner's control tapped with the noted number and kind of counters on it. If you do, return the exiled Aura cards to the battlefield under their owner's control attached to that permanent";
} }
public OublietteReturnEffect(final OublietteReturnEffect effect) { public OublietteReturnEffect(final OublietteReturnEffect effect) {
@ -181,55 +142,60 @@ class OublietteReturnEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
ExileZone exileZone = game.getExile().getExileZone(source.getSourceId()); Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
FilterCard filter = new FilterCard(); return false;
filter.add(new CardTypePredicate(CardType.CREATURE)); }
//There should be only 1 there, but the for each loop seems the most practical to get to it ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId(), true));
for (Card enchantedCard : exileZone.getCards(filter, game)) { if (exileZone == null) {
if (enchantedCard == null) {
continue;
}
enchantedCard.putOntoBattlefield(game, Zone.EXILED, source.getSourceId(), enchantedCard.getOwnerId());
Permanent newPermanent = game.getPermanent(enchantedCard.getId());
if (newPermanent != null) {
newPermanent.tap(game);
for (Card enchantment : exileZone.getCards(game)) {
if (filterAura.match(enchantment, game)) {
boolean canTarget = false;
for (Target target : enchantment.getSpellAbility().getTargets()) {
Filter filter2 = target.getFilter();
if (filter2.match(newPermanent, game)) {
canTarget = true;
break;
}
}
if (!canTarget) {
// Aura stays exiled
continue;
}
game.getState().setValue("attachTo:" + enchantment.getId(), newPermanent);
}
if (enchantment.putOntoBattlefield(game, Zone.EXILED, source.getSourceId(), enchantment.getOwnerId())) {
if (filterAura.match(enchantment, game)) {
newPermanent.addAttachment(enchantment.getId(), game);
}
}
}
Card oubliette = game.getCard(source.getSourceId());
if (oubliette == null) {
return false;//1st stab at getting those counters back
}
for (Counter c : ((Oubliette) oubliette).godHelpMe.values()) { //would be nice if could just use that copy function to set the whole field
if (c != null) {
newPermanent.getCounters(game).addCounter(c);
}
}
}
return true; return true;
} }
return false; Card exiledCreatureCard = exileZone.get((UUID) game.getState().getValue(CardUtil.getCardZoneString("targetId", source.getSourceId(), game, true)), game);
if (exiledCreatureCard == null) {
return false;
}
controller.moveCards(exiledCreatureCard, Zone.BATTLEFIELD, source, game, true, false, true, null);
Permanent newPermanent = game.getPermanent(exiledCreatureCard.getId());
if (newPermanent != null) {
// Restore the counters
Counters counters = (Counters) game.getState().getValue(CardUtil.getCardZoneString("savedCounters", source.getSourceId(), game, true));
if (counters != null) {
for (Counter counter : counters.values()) {
if (counter != null) {
newPermanent.getCounters(game).addCounter(counter);
}
}
}
// readd the attachments
Set<Card> toBattlefield = new HashSet<>();
for (Card enchantment : exileZone.getCards(game)) {
if (enchantment.getSubtype(game).contains(SubType.AURA)) {
boolean canTarget = false;
for (Target target : enchantment.getSpellAbility().getTargets()) {
Filter filter2 = target.getFilter();
if (filter2.match(newPermanent, game)) {
canTarget = true;
break;
}
}
if (!canTarget) {
// Aura stays exiled
continue;
}
game.getState().setValue("attachTo:" + enchantment.getId(), newPermanent);
toBattlefield.add(enchantment);
}
}
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, true, false, true, null);
for (Card enchantmentCard : toBattlefield) {
Permanent permanent = game.getPermanent(enchantmentCard.getId());
if (permanent != null) {
newPermanent.addAttachment(permanent.getId(), game);
}
}
}
return true;
} }
} }