This commit is contained in:
Jeff Wadsworth 2022-10-19 11:58:11 -05:00
parent 55d9bc6655
commit fadcd3f00a

View file

@ -2,7 +2,6 @@ package mage.cards.m;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.CompositeCost;
import mage.abilities.costs.common.ExileSourceCost;
@ -20,19 +19,19 @@ import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.token.MechtitanToken;
import mage.game.permanent.token.Token;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
import mage.target.targetpointer.FixedTargets;
import mage.util.CardUtil;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.target.targetpointer.FixedTarget;
/**
* @author TheElk801
@ -99,63 +98,31 @@ class MechtitanCoreTokenEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Token token = new MechtitanToken();
token.putOntoBattlefield(1, game, source);
game.addDelayedTriggeredAbility(new MechtitanCoreTriggeredAbility(token, source, game), source);
CreateTokenEffect createMechtitanToken = new CreateTokenEffect(new MechtitanToken());
createMechtitanToken.apply(game, source);
if (createMechtitanToken.getLastAddedTokenIds().isEmpty()) {
return false;
}
Effect mechtitanCoreReturnEffect = new MechtitanCoreReturnEffect();
mechtitanCoreReturnEffect.setTargetPointer(new FixedTargets(game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)), game));
LeavesBattlefieldTriggeredAbility triggerAbility = new LeavesBattlefieldTriggeredAbility(mechtitanCoreReturnEffect, false);
ContinuousEffect gainReturnTriggerEffect = new GainAbilityTargetEffect(triggerAbility, Duration.WhileOnBattlefield);
for (UUID tokenId : createMechtitanToken.getLastAddedTokenIds()) {
UUID tokenPermanentId = game.getPermanentOrLKIBattlefield(tokenId).getId();
if (tokenPermanentId != null) {
gainReturnTriggerEffect.setTargetPointer(new FixedTarget(tokenPermanentId, game));
}
}
game.addEffect(gainReturnTriggerEffect, source);
return true;
}
}
class MechtitanCoreTriggeredAbility extends DelayedTriggeredAbility {
private final Set<UUID> tokenIds = new HashSet<>();
MechtitanCoreTriggeredAbility(Token token, Ability source, Game game) {
super(new MechtitanCoreReturnEffect(), Duration.Custom, false, false);
this.getEffects().setTargetPointer(new FixedTargets(game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)), game));
tokenIds.addAll(token.getLastAddedTokenIds());
}
private MechtitanCoreTriggeredAbility(final MechtitanCoreTriggeredAbility ability) {
super(ability);
this.tokenIds.addAll(ability.tokenIds);
}
@Override
public MechtitanCoreTriggeredAbility copy() {
return new MechtitanCoreTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return tokenIds.contains(event.getTargetId())
&& ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD;
}
@Override
public boolean isInactive(Game game) {
return tokenIds
.stream()
.map(game::getPermanent)
.noneMatch(Objects::nonNull);
}
@Override
public String getRule() {
return "When that token leaves the battlefield, return all cards exiled with {this} except "
+ "{this} to the battlefield tapped under their owners' control";
}
}
class MechtitanCoreReturnEffect extends OneShotEffect {
MechtitanCoreReturnEffect() {
super(Outcome.Benefit);
staticText = "return all cards exiled with Mechtitan Core except Mechtitan Core to the battlefield tapped under their owner's control";
}
private MechtitanCoreReturnEffect(final MechtitanCoreReturnEffect effect) {