mirror of
https://github.com/correl/mage.git
synced 2024-12-28 11:14:13 +00:00
Rework Cryptic Gateway (fixes #7022)
This commit is contained in:
parent
09402609ef
commit
42f0b5ce17
1 changed files with 20 additions and 99 deletions
|
@ -1,31 +1,29 @@
|
|||
package mage.cards.c;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.CostImpl;
|
||||
import mage.abilities.costs.common.TapTargetCost;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterCreatureCard;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.filter.predicate.permanent.TappedPredicate;
|
||||
import mage.filter.predicate.mageobject.SharesCreatureTypePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.common.TargetControlledPermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author spjspj
|
||||
* @author awjackson
|
||||
*/
|
||||
public final class CrypticGateway extends CardImpl {
|
||||
|
||||
|
@ -33,7 +31,9 @@ public final class CrypticGateway extends CardImpl {
|
|||
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{5}");
|
||||
|
||||
// Tap two untapped creatures you control: You may put a creature card from your hand that shares a creature type with each creature tapped this way onto the battlefield.
|
||||
this.addAbility(new SimpleActivatedAbility(new CrypticGatewayEffect(), new CrypticGatewayCost()));
|
||||
this.addAbility(new SimpleActivatedAbility(new CrypticGatewayEffect(), new TapTargetCost(
|
||||
new TargetControlledPermanent(2, StaticFilters.FILTER_CONTROLLED_UNTAPPED_CREATURES)
|
||||
)));
|
||||
}
|
||||
|
||||
private CrypticGateway(final CrypticGateway card) {
|
||||
|
@ -46,70 +46,11 @@ public final class CrypticGateway extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class CrypticGatewayCost extends CostImpl {
|
||||
|
||||
private static final FilterControlledCreaturePermanent filter
|
||||
= new FilterControlledCreaturePermanent("untapped creatures you control");
|
||||
|
||||
static {
|
||||
filter.add(TappedPredicate.UNTAPPED);
|
||||
}
|
||||
|
||||
private final TargetControlledPermanent target = new TargetControlledPermanent(2, filter);
|
||||
private CrypticGatewayPredicate predicate;
|
||||
|
||||
public CrypticGatewayCost() {
|
||||
this.text = "Tap two untapped creatures you control";
|
||||
}
|
||||
|
||||
public CrypticGatewayCost(final CrypticGatewayCost cost) {
|
||||
super(cost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
int numTargets = 0;
|
||||
Set<Permanent> permanents = new HashSet<>();
|
||||
while (numTargets < 2 && target.choose(Outcome.Tap, controllerId, source.getSourceId(), source, game)) {
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
paid |= permanent.tap(source, game);
|
||||
if (paid) {
|
||||
numTargets++;
|
||||
target.clearChosen();
|
||||
permanents.add(permanent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (paid) {
|
||||
this.predicate = new CrypticGatewayPredicate(permanents);
|
||||
}
|
||||
return paid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
return target.canChoose(controllerId, source, game);
|
||||
}
|
||||
|
||||
public CrypticGatewayPredicate getPredicate() {
|
||||
return predicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CrypticGatewayCost copy() {
|
||||
return new CrypticGatewayCost(this);
|
||||
}
|
||||
}
|
||||
|
||||
class CrypticGatewayEffect extends OneShotEffect {
|
||||
|
||||
public CrypticGatewayEffect() {
|
||||
super(Outcome.PutCreatureInPlay);
|
||||
this.staticText = "Put a creature card from your hand that shares a creature type with each creature tapped this way onto the battlefield";
|
||||
this.staticText = "you may put a creature card from your hand that shares a creature type with each creature tapped this way onto the battlefield";
|
||||
}
|
||||
|
||||
public CrypticGatewayEffect(final CrypticGatewayEffect effect) {
|
||||
|
@ -123,36 +64,16 @@ class CrypticGatewayEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (source.getCosts() == null) {
|
||||
List<Permanent> tapped = (List<Permanent>) getValue("tappedPermanents");
|
||||
if (tapped == null || tapped.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
FilterCard filter = new FilterCreatureCard("creature card from your hand that shares a creature type with each creature tapped this way");
|
||||
for (Cost cost : source.getCosts()) {
|
||||
if (cost instanceof CrypticGatewayCost) {
|
||||
Predicate predicate = ((CrypticGatewayCost) cost).getPredicate();
|
||||
filter.add(predicate);
|
||||
FilterCreatureCard filter = new FilterCreatureCard("creature card that shares a creature type with "
|
||||
+ CardUtil.concatWithAnd(tapped.stream().map(MageObject::getName).collect(Collectors.toList()))
|
||||
);
|
||||
for (Permanent perm : tapped) {
|
||||
filter.add(new SharesCreatureTypePredicate(perm));
|
||||
}
|
||||
return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class CrypticGatewayPredicate implements Predicate<Card> {
|
||||
|
||||
private final Set<Permanent> permanents = new HashSet<>();
|
||||
|
||||
CrypticGatewayPredicate(Set<Permanent> permanents) {
|
||||
this.permanents.addAll(permanents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Card input, Game game) {
|
||||
for (Permanent permanent : permanents) {
|
||||
if (!permanent.shareCreatureTypes(game, input)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue