mirror of
https://github.com/magefree/mage.git
synced 2026-01-24 04:09:54 -08:00
* Tawnos's Coffin - Fixed that it did not work correctly if abilities were copied by Mairsil, The Pretenderand and general rework.
This commit is contained in:
parent
34e9fb7296
commit
77f6f7b2b6
4 changed files with 232 additions and 102 deletions
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
package mage.cards.t;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
|
||||
|
|
@ -46,17 +48,16 @@ import mage.constants.Zone;
|
|||
import mage.counters.Counter;
|
||||
import mage.counters.Counters;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.common.FilterEnchantmentPermanent;
|
||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.filter.predicate.mageobject.SubtypePredicate;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.token.Token;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -64,14 +65,12 @@ import mage.target.common.TargetCreaturePermanent;
|
|||
*/
|
||||
public class TawnossCoffin extends CardImpl {
|
||||
|
||||
public Counters godHelpMe = null;
|
||||
|
||||
public TawnossCoffin(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{4}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
|
||||
|
||||
// You may choose not to untap Tawnos's Coffin during your untap step.
|
||||
this.addAbility(new SkipUntapOptionalAbility());
|
||||
// {3}, {tap}: Exile target creature and all Auras attached to it. Note the number and kind of counters that were on that creature.
|
||||
// {3}, {T}: Exile target creature and all Auras attached to it. Note the number and kind of counters that were on that creature.
|
||||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new TawnossCoffinEffect(), new TapSourceCost());
|
||||
ability.addCost(new ManaCostsImpl("{3}"));
|
||||
ability.addTarget(new TargetCreaturePermanent());
|
||||
|
|
@ -114,7 +113,7 @@ class TawnossCoffinTriggeredAbility extends LeavesBattlefieldTriggeredAbility {
|
|||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.UNTAPPED) {
|
||||
return event.getTargetId().equals(sourceId);
|
||||
return event.getTargetId().equals(getSourceId());
|
||||
} else {
|
||||
return super.checkTrigger(event, game);
|
||||
}
|
||||
|
|
@ -151,40 +150,25 @@ class TawnossCoffinEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
// Exile enchanted creature and all Auras attached to it.
|
||||
Permanent enchantment = game.getPermanent(source.getSourceId());
|
||||
if (enchantment == null) {
|
||||
enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
|
||||
}
|
||||
UUID targetId = source.getFirstTarget();
|
||||
|
||||
if (targetId == null) {
|
||||
return false; // if previous scan somehow failed, simply quit
|
||||
}
|
||||
if (enchantment != null) { //back to code (mostly) copied from Flickerform
|
||||
Permanent enchantedCreature = game.getPermanent(targetId);
|
||||
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null && sourceObject != null) {
|
||||
Permanent enchantedCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (enchantedCreature != null) {
|
||||
UUID exileZoneId = source.getSourceId();
|
||||
enchantedCreature.moveToExile(exileZoneId, enchantment.getName(), source.getSourceId(), game);
|
||||
UUID exileZoneId = CardUtil.getCardExileZoneId(game, source);
|
||||
Set<Card> toExile = new HashSet<>();
|
||||
toExile.add(enchantedCreature);
|
||||
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);
|
||||
if (attachment != null && attachment.hasSubtype(SubType.AURA, game)) {
|
||||
toExile.add(attachment);
|
||||
}
|
||||
}
|
||||
|
||||
//((TawnossCoffin)enchantment.getMainCard()).godHelpMe = enchantedCreature.getCounters(game); //why doesn't work? should return the same card, no?
|
||||
((TawnossCoffin) 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 TawnossCoffinReturnEffect(), false);
|
||||
enchantment.addAbility(triggeredAbility, source.getSourceId(), game);
|
||||
*/
|
||||
}
|
||||
return true;
|
||||
controller.moveCardsToExile(toExile, source, game, true, exileZoneId, sourceObject.getIdName());
|
||||
game.getState().setValue(exileZoneId.toString() + "NotedCounters", enchantedCreature.getCounters(game).copy());
|
||||
game.getState().setValue(exileZoneId.toString() + "EnchantedCreature", enchantedCreature.getId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -193,17 +177,9 @@ class TawnossCoffinEffect extends OneShotEffect {
|
|||
|
||||
class TawnossCoffinReturnEffect extends OneShotEffect {
|
||||
|
||||
private static final FilterCard filterAura = new FilterCard();
|
||||
|
||||
static {
|
||||
filterAura.add(new CardTypePredicate(CardType.ENCHANTMENT));
|
||||
filterAura.add(new SubtypePredicate(SubType.AURA));
|
||||
}
|
||||
|
||||
public TawnossCoffinReturnEffect() {
|
||||
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";
|
||||
|
||||
}
|
||||
|
||||
public TawnossCoffinReturnEffect(final TawnossCoffinReturnEffect effect) {
|
||||
|
|
@ -217,57 +193,66 @@ class TawnossCoffinReturnEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
UUID exileZoneId = CardUtil.getCardExileZoneId(game, source);
|
||||
ExileZone exileZone = game.getExile().getExileZone(exileZoneId);
|
||||
if (exileZone == null) {
|
||||
return true;
|
||||
}
|
||||
FilterCard filter = new FilterCard();
|
||||
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
|
||||
for (Card enchantedCard : exileZone.getCards(filter, game)) {
|
||||
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 : ((TawnossCoffin) oubliette).godHelpMe.values()) { //would be nice if could just use that copy function to set the whole field
|
||||
UUID enchantedCreatureId = (UUID) game.getState().getValue(exileZoneId.toString() + "EnchantedCreature");
|
||||
if (enchantedCreatureId == null) {
|
||||
return false;
|
||||
}
|
||||
if (!exileZone.contains(enchantedCreatureId)) {
|
||||
return true; // Card was removed from exile meanwhile, other card sstay in exile
|
||||
}
|
||||
Card enchantedCreature = game.getCard(enchantedCreatureId);
|
||||
if (enchantedCreature == null) {
|
||||
return false;
|
||||
}
|
||||
controller.moveCards(enchantedCreature, Zone.BATTLEFIELD, source, game, true, false, true, null);
|
||||
Permanent newPermanent = game.getPermanent(enchantedCreature.getId());
|
||||
if (newPermanent != null) {
|
||||
// Add the noted counters
|
||||
Counters notedCounters = (Counters) game.getState().getValue(exileZoneId.toString() + "NotedCounters");
|
||||
if (notedCounters != null) {
|
||||
for (Counter c : notedCounters.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 the exiled auras
|
||||
Set<Card> returningAuras = new HashSet<>();
|
||||
for (Card enchantment : exileZone.getCards(game)) {
|
||||
if (enchantment.hasSubtype(SubType.AURA, 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;
|
||||
}
|
||||
returningAuras.add(enchantment);
|
||||
game.getState().setValue("attachTo:" + enchantment.getId(), newPermanent);
|
||||
}
|
||||
}
|
||||
controller.moveCards(returningAuras, Zone.BATTLEFIELD, source, game, false, false, true, null);
|
||||
for (Card enchantment : returningAuras) {
|
||||
Permanent permanent = game.getPermanent(enchantment.getId());
|
||||
if (permanent != null) {
|
||||
newPermanent.addAttachment(permanent.getId(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue