mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Fix #9666 properly
This commit is contained in:
parent
75c39c87be
commit
6008e77d72
2 changed files with 56 additions and 59 deletions
|
@ -2,6 +2,7 @@ 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;
|
||||
|
@ -19,19 +20,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
|
||||
|
@ -98,31 +99,63 @@ class MechtitanCoreTokenEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability 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);
|
||||
Token token = new MechtitanToken();
|
||||
token.putOntoBattlefield(1, game, source);
|
||||
game.addDelayedTriggeredAbility(new MechtitanCoreTriggeredAbility(token, source, game), 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) {
|
||||
if (tokenIds.contains(event.getTargetId()) && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
|
||||
tokenIds.remove(event.getTargetId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInactive(Game game) {
|
||||
return tokenIds.isEmpty();
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
package mage.game.permanent.token;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.keyword.VigilanceAbility;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class AstartesWarriorToken extends TokenImpl {
|
||||
|
||||
public AstartesWarriorToken() {
|
||||
super("Astartes Warrior Token", "2/2 white Astartes Warrior creature tokens with vigilance");
|
||||
cardType.add(CardType.CREATURE);
|
||||
color.setWhite(true);
|
||||
subtype.add(SubType.ASTARTES);
|
||||
subtype.add(SubType.WARRIOR);
|
||||
power = new MageInt(2);
|
||||
toughness = new MageInt(2);
|
||||
addAbility(VigilanceAbility.getInstance());
|
||||
|
||||
availableImageSetCodes.addAll(Arrays.asList("40K"));
|
||||
}
|
||||
|
||||
public AstartesWarriorToken(final AstartesWarriorToken token) {
|
||||
super(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AstartesWarriorToken copy() {
|
||||
return new AstartesWarriorToken(this);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue