various "different name" refactors

This commit is contained in:
theelk801 2024-09-20 17:12:09 -04:00
parent d18bd25d21
commit 7d33b2230d
17 changed files with 222 additions and 255 deletions

View file

@ -103,7 +103,7 @@ class ApproachOfTheSecondSunWatcher extends Watcher {
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) { //A copy of a spell isnt cast, so it wont count as the first nor as the second Approach of the Second Sun. (2017-04-18)
Spell spell = game.getStack().getSpell(event.getSourceId());
if (spell != null && spell.getName().equals("Approach of the Second Sun")) {
if (spell != null && spell.hasName("Approach of the Second Sun", game)) {
approachesCast.put(event.getPlayerId(), getApproachesCast(event.getPlayerId()) + 1);
}
}

View file

@ -1,6 +1,5 @@
package mage.cards.a;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
@ -11,10 +10,12 @@ import mage.abilities.hint.ValueHint;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.filter.StaticFilters;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.PlantToken;
import mage.util.CardUtil;
import java.util.UUID;
@ -45,8 +46,14 @@ public final class AudienceWithTrostani extends CardImpl {
enum AudienceWithTrostaniValue implements DynamicValue {
instance;
private static final FilterPermanent filter = new FilterControlledCreaturePermanent();
static {
filter.add(TokenPredicate.TRUE);
}
private static final Hint hint = new ValueHint(
"Different names among creature tokens you control", instance
"Differently named creature tokens you control", instance
);
public static Hint getHint() {
@ -55,19 +62,11 @@ enum AudienceWithTrostaniValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game
.getBattlefield()
.getActivePermanents(
StaticFilters.FILTER_CONTROLLED_CREATURE,
sourceAbility.getControllerId(), sourceAbility, game
)
.stream()
.filter(PermanentToken.class::isInstance)
.map(MageObject::getName)
.filter(s -> !s.isEmpty())
.distinct()
.mapToInt(x -> 1)
.sum();
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
filter, sourceAbility.getControllerId(), sourceAbility, game
), game
);
}
@Override

View file

@ -1,25 +1,25 @@
package mage.cards.a;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.abilities.hint.Hint;
import mage.abilities.hint.ValueHint;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class AwakenedAmalgam extends CardImpl {
@ -32,8 +32,9 @@ public final class AwakenedAmalgam extends CardImpl {
this.toughness = new MageInt(0);
// Awakened Amalgam's power and toughness are each equal to the number of differently named lands you control.
DynamicValue value = (new AwakenedAmalgamLandNamesCount());
this.addAbility(new SimpleStaticAbility(Zone.ALL, new SetBasePowerToughnessSourceEffect(value)));
this.addAbility(new SimpleStaticAbility(
Zone.ALL, new SetBasePowerToughnessSourceEffect(AwakenedAmalgamValue.instance)
).addHint(AwakenedAmalgamValue.getHint()));
}
private AwakenedAmalgam(final AwakenedAmalgam card) {
@ -46,24 +47,26 @@ public final class AwakenedAmalgam extends CardImpl {
}
}
class AwakenedAmalgamLandNamesCount implements DynamicValue {
enum AwakenedAmalgamValue implements DynamicValue {
instance;
private static final Hint hint = new ValueHint("Differently named lands you control", instance);
public AwakenedAmalgamLandNamesCount() {
public static Hint getHint() {
return hint;
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Set<String> landNames = new HashSet<>();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(sourceAbility.getControllerId())) {
if (permanent.isLand(game)) {
landNames.add(permanent.getName());
}
}
return landNames.size();
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND,
sourceAbility.getControllerId(), sourceAbility, game
), game
);
}
@Override
public AwakenedAmalgamLandNamesCount copy() {
public AwakenedAmalgamValue copy() {
return this;
}

View file

@ -1,6 +1,5 @@
package mage.cards.b;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SagaAbility;
import mage.abilities.effects.OneShotEffect;
@ -131,33 +130,34 @@ class BattleForBretagardTarget extends TargetPermanent {
if (!super.canTarget(playerId, id, ability, game)) {
return false;
}
Set<String> names = this.getTargets()
Set<Permanent> permanents = this
.getTargets()
.stream()
.map(game::getPermanent)
.filter(Objects::nonNull)
.map(MageObject::getName)
.collect(Collectors.toSet());
names.removeIf(Objects::isNull);
names.removeIf(String::isEmpty);
Permanent permanent = game.getPermanent(id);
return permanent != null && !names.contains(permanent.getName());
return permanent != null
&& permanents
.stream()
.noneMatch(p -> p.sharesName(permanent, game));
}
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Ability source, Game game) {
Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, source, game);
Set<String> names = this.getTargets()
Set<Permanent> permanents = this.getTargets()
.stream()
.map(game::getPermanent)
.filter(Objects::nonNull)
.map(MageObject::getName)
.collect(Collectors.toSet());
names.removeIf(Objects::isNull);
names.removeIf(String::isEmpty);
possibleTargets.removeIf(uuid -> {
Permanent permanent = game.getPermanent(uuid);
return permanent == null || names.contains(permanent.getName());
return permanent == null
|| permanents
.stream()
.anyMatch(p -> p.sharesName(permanent, game));
});
return possibleTargets;
}

View file

@ -1,6 +1,5 @@
package mage.cards.e;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
@ -90,32 +89,33 @@ class EerieUltimatumTarget extends TargetCardInYourGraveyard {
@Override
public boolean canTarget(UUID playerId, UUID id, Ability ability, Game game) {
if (super.canTarget(playerId, id, ability, game)) {
Set<String> names = this.getTargets()
if (!super.canTarget(playerId, id, ability, game)) {
return false;
}
Set<Card> cards = this.getTargets()
.stream()
.map(game::getCard)
.map(MageObject::getName)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Card card = game.getCard(id);
return card != null && !names.contains(card.getName());
}
return false;
Card card = game.getCard(id);
return card != null
&& cards
.stream()
.noneMatch(c -> c.sharesName(card, game));
}
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Ability source, Game game) {
Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, source, game);
Set<String> names = this.getTargets()
Set<Card> cards = this.getTargets()
.stream()
.map(game::getCard)
.map(MageObject::getName)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
possibleTargets.removeIf(uuid -> {
Card card = game.getCard(uuid);
return card != null && names.contains(card.getName());
return card != null && cards.stream().anyMatch(c -> c.sharesName(card, game));
});
return possibleTargets;
}

View file

@ -13,7 +13,7 @@ import mage.constants.CardType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.token.ZombieToken;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID;
@ -56,17 +56,11 @@ enum FieldOfTheDeadCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
return game
.getBattlefield()
.getAllActivePermanents(StaticFilters.FILTER_LAND, source.getControllerId(), game)
.stream()
.map(permanent -> permanent.getName())
.filter(s -> s.length() > 0)
.distinct()
.count() > 6;
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND,
source.getControllerId(), source, game
), game
) >= 7;
}
}

View file

@ -1,7 +1,6 @@
package mage.cards.g;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfEndStepTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -12,14 +11,16 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterArtifactPermanent;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.GremlinArtifactToken;
import mage.game.permanent.token.Token;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
@ -60,6 +61,12 @@ public final class GimbalGremlinProdigy extends CardImpl {
class GimbalGremlinProdigyEffect extends OneShotEffect {
private static final FilterPermanent filter = new FilterArtifactPermanent();
static {
filter.add(TokenPredicate.TRUE);
}
GimbalGremlinProdigyEffect() {
super(Outcome.Benefit);
staticText = "create a 0/0 red Gremlin artifact creature token. Put X +1/+1 counters on it, " +
@ -79,20 +86,14 @@ class GimbalGremlinProdigyEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Token token = new GremlinArtifactToken();
token.putOntoBattlefield(1, game, source);
int amount = game
.getBattlefield()
.getActivePermanents(
StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT,
source.getControllerId(), source, game
)
.stream()
.filter(PermanentToken.class::isInstance)
.map(MageObject::getName)
.filter(Objects::nonNull)
.filter(s -> !s.isEmpty())
.distinct()
.mapToInt(i -> 1)
.sum();
int amount = CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
filter, source.getControllerId(), source, game
), game
);
if (amount < 1) {
return true;
}
for (UUID tokenId : token.getLastAddedTokenIds()) {
Permanent permanent = game.getPermanent(tokenId);
if (permanent != null) {

View file

@ -1,8 +1,5 @@
package mage.cards.l;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
@ -16,11 +13,14 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class LilianasContract extends CardImpl {
@ -46,8 +46,8 @@ public final class LilianasContract extends CardImpl {
TargetController.YOU, false
), LilianasContractCondition.instance,
"At the beginning of your upkeep, "
+ "if you control four or more Demons with different names, "
+ "you win the game."
+ "if you control four or more Demons with different names, "
+ "you win the game."
));
}
@ -62,24 +62,16 @@ public final class LilianasContract extends CardImpl {
}
enum LilianasContractCondition implements Condition {
instance;
private static final FilterPermanent filter = new FilterControlledPermanent(SubType.DEMON);
@Override
public boolean apply(Game game, Ability source) {
Set<String> demonNames = new HashSet<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
if (permanent == null
|| !permanent.isControlledBy(source.getControllerId())
|| !permanent.hasSubtype(SubType.DEMON, game)) {
continue;
}
demonNames.add(permanent.getName());
if (demonNames.size() > 3) {
return true;
}
}
return false;
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
filter, source.getControllerId(), source, game
), game
) >= 4;
}
@Override

View file

@ -10,7 +10,6 @@ import mage.constants.*;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.Collection;
import java.util.List;
@ -74,7 +73,7 @@ class MarvinMurderousMimicEffect extends ContinuousEffectImpl {
source.getControllerId(), source, game
)
.stream()
.filter(p -> !CardUtil.haveSameNames(p, permanent))
.filter(p -> !p.sharesName(permanent, game))
.map(p -> p.getAbilities(game))
.flatMap(Collection::stream)
.filter(Ability::isActivatedAbility)

View file

@ -10,6 +10,7 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.abilities.hint.Hint;
import mage.abilities.hint.ValueHint;
import mage.abilities.mana.ColorlessManaAbility;
import mage.cards.CardImpl;
@ -17,15 +18,14 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
@ -43,20 +43,20 @@ public final class MazesEnd extends CardImpl {
public MazesEnd(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.LAND}, "");
// Maze's End enters the battlefield tapped.
this.addAbility(new EntersBattlefieldTappedAbility());
// {T}: Add 1.
this.addAbility(new ColorlessManaAbility());
// 3, {T}, Return Maze's End to its owner's hand: Search your library for a Gate card, put it onto the battlefield, then shuffle your library. If you control ten or more Gates with different names, you win the game.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filterCard)), new GenericManaCost(3));
ability.addEffect(new MazesEndEffect());
// {3}, {T}, Return Maze's End to its owner's hand: Search your library for a Gate card, put it onto the battlefield, then shuffle your library. If you control ten or more Gates with different names, you win the game.
Ability ability = new SimpleActivatedAbility(
new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filterCard)), new GenericManaCost(3)
);
ability.addCost(new TapSourceCost());
ability.addCost(new ReturnToHandFromBattlefieldSourceCost());
ability.addHint(new ValueHint("Gates with different names you control", GatesWithDifferentNamesYouControlCount.instance));
this.addAbility(ability);
ability.addEffect(new MazesEndEffect());
this.addAbility(ability.addHint(GatesWithDifferentNamesYouControlCount.getHint()));
}
private MazesEnd(final MazesEnd card) {
@ -70,20 +70,21 @@ public final class MazesEnd extends CardImpl {
}
enum GatesWithDifferentNamesYouControlCount implements DynamicValue {
instance;
private static final FilterPermanent filter = new FilterControlledPermanent(SubType.GATE);
private static final Hint hint = new ValueHint("Gates with different names you control", instance);
public static Hint getHint() {
return hint;
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
List<String> names = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(sourceAbility.getControllerId())) {
if (permanent.hasSubtype(SubType.GATE, game)) {
if (!names.contains(permanent.getName())) {
names.add(permanent.getName());
}
}
}
return names.size();
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
filter, sourceAbility.getControllerId(), sourceAbility, game
), game
);
}
@Override
@ -121,13 +122,13 @@ class MazesEndEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
int count = GatesWithDifferentNamesYouControlCount.instance.calculate(game, source, this);
if (count >= 10) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.won(game);
}
if (GatesWithDifferentNamesYouControlCount.instance.calculate(game, source, this) < 10) {
return false;
}
return false;
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.won(game);
}
return true;
}
}

View file

@ -1,8 +1,5 @@
package mage.cards.m;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.ActivateIfConditionActivatedAbility;
import mage.abilities.common.SimpleActivatedAbility;
@ -28,6 +25,9 @@ import mage.filter.predicate.Predicates;
import mage.game.Game;
import mage.game.permanent.token.custom.CreatureToken;
import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author TheElk801
@ -96,15 +96,11 @@ enum MonumentToPerfectionValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game
.getBattlefield()
.getActivePermanents(filter, sourceAbility.getControllerId(), game)
.stream()
.map(MageObject::getName)
.filter(s -> s.length() > 0)
.distinct()
.mapToInt(x -> 1)
.sum();
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
filter, sourceAbility.getControllerId(), sourceAbility, game
), game
);
}
@Override

View file

@ -1,7 +1,6 @@
package mage.cards.o;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -127,15 +126,14 @@ class OrmosArchiveKeeperTarget extends TargetCardInHand {
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Ability source, Game game) {
Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, source, game);
Set<String> names = this.getTargets()
Set<Card> cards = this.getTargets()
.stream()
.map(game::getCard)
.map(MageObject::getName)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
possibleTargets.removeIf(uuid -> {
Card card = game.getCard(uuid);
return card != null && names.contains(card.getName());
return card != null && cards.stream().anyMatch(c -> c.sharesName(card, game));
});
return possibleTargets;
}

View file

@ -1,7 +1,6 @@
package mage.cards.s;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfCombatTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
@ -19,8 +18,8 @@ import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledArtifactPermanent;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
@ -40,7 +39,9 @@ public final class SandsteppeWarRiders extends CardImpl {
this.addAbility(TrampleAbility.getInstance());
// At the beginning of combat on your turn, bolster X, where X is the number of differently named artifact tokens you control.
this.addAbility(new BeginningOfCombatTriggeredAbility(new BolsterEffect(SandsteppeWarRidersValue.instance), TargetController.YOU, false));
this.addAbility(new BeginningOfCombatTriggeredAbility(
new BolsterEffect(SandsteppeWarRidersValue.instance), TargetController.YOU, false
).addHint(SandsteppeWarRidersValue.getHint()));
}
private SandsteppeWarRiders(final SandsteppeWarRiders card) {
@ -63,18 +64,17 @@ enum SandsteppeWarRidersValue implements DynamicValue {
private static final Hint hint = new ValueHint("Different artifact token names you control", instance);
public static Hint getHint() {
return hint;
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game
.getBattlefield()
.getActivePermanents(filter, sourceAbility.getControllerId(), sourceAbility, game)
.stream()
.map(MageObject::getName)
.filter(Objects::nonNull)
.filter(s -> !s.isEmpty())
.distinct()
.mapToInt(x -> 1)
.sum();
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
filter, sourceAbility.getControllerId(), sourceAbility, game
), game
);
}
@Override

View file

@ -1,12 +1,11 @@
package mage.cards.s;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.SearchEffect;
import mage.cards.*;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -14,9 +13,11 @@ import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author Plopman
*/
public final class SignalTheClans extends CardImpl {
@ -61,32 +62,22 @@ class SignalTheClansEffect extends SearchEffect {
return false;
}
//Search your library for three creature cards
if (controller.searchLibrary(target, source, game)) {
boolean shuffleDone = false;
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl(target.getTargets());
//Reveal them
controller.revealCards(source, cards, game);
Card cardsArray[] = cards.getCards(game).toArray(new Card[0]);
//If you reveal three cards with different names
if (Stream.of(cardsArray).map(MageObject::getName).collect(Collectors.toSet()).size() == 3) {
//Choose one of them at random and put that card into your hand
Card randomCard = cards.getRandom(game);
controller.moveCards(randomCard, Zone.HAND, source, game);
cards.remove(randomCard);
}
// Shuffle the rest into your library
if (!cards.isEmpty()) {
controller.shuffleCardsToLibrary(cards, game, source);
shuffleDone = true;
}
}
if (!shuffleDone) {
controller.shuffleLibrary(source, game);
}
return true;
controller.searchLibrary(target, source, game);
Cards cards = new CardsImpl(target.getTargets());
//Reveal them
controller.revealCards(source, cards, game);
//If you reveal three cards with different names
if (CardUtil.differentlyNamedAmongCollection(cards.getCards(game), game) >= 3) {
//Choose one of them at random and put that card into your hand
controller.moveCards(cards.getRandom(game), Zone.HAND, source, game);
}
return false;
cards.retainZone(Zone.LIBRARY, game);
// Shuffle the rest into your library
if (!cards.isEmpty()) {
controller.shuffleCardsToLibrary(cards, game, source);
}
controller.shuffleLibrary(source, game);
return true;
}
}

View file

@ -18,6 +18,7 @@ import mage.game.Game;
import mage.game.permanent.token.PlantToken;
import mage.game.permanent.token.ZombieToken;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID;
@ -63,18 +64,12 @@ enum TheNecrobloomCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
return game
.getBattlefield()
.getAllActivePermanents(StaticFilters.FILTER_LAND, source.getControllerId(), game)
.stream()
.map(permanent -> permanent.getName())
.filter(s -> s.length() > 0)
.distinct()
.count() > 6;
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND,
source.getControllerId(), source, game
), game
) >= 7;
}
}

View file

@ -1,9 +1,5 @@
package mage.cards.t;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.ApprovingObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
@ -12,9 +8,6 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.filter.FilterCard;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.ExileZone;
import mage.game.Game;
import mage.game.stack.Spell;
@ -23,8 +16,11 @@ import mage.target.TargetSpell;
import mage.util.CardUtil;
import mage.util.RandomUtil;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author weirddan455
*/
public final class TibaltsTrickery extends CardImpl {
@ -72,43 +68,40 @@ class TibaltsTrickeryEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
if (spell != null) {
String spellName = spell.getName();
Player controller = game.getPlayer(spell.getControllerId());
game.getStack().counter(spell.getId(), source, game);
if (controller != null) {
int random = RandomUtil.nextInt(3) + 1;
game.informPlayers(random + " was chosen at random");
controller.millCards(random, source, game);
Card cardToCast = null;
Set<Card> cardsToExile = new HashSet<>();
FilterCard filter = new FilterCard();
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new NamePredicate(spellName)));
for (Card card : controller.getLibrary().getCards(game)) {
cardsToExile.add(card);
if (filter.match(card, game)) {
cardToCast = card;
break;
}
}
controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(),
CardUtil.createObjectRealtedWindowTitle(source, game, null));
if (cardToCast != null) {
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true),
game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
}
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
if (exile != null) {
controller.putCardsOnBottomOfLibrary(exile, game, source, false);
}
}
if (spell == null) {
return false;
}
Player controller = game.getPlayer(spell.getControllerId());
game.getStack().counter(spell.getId(), source, game);
if (controller == null) {
return true;
}
return false;
int random = RandomUtil.nextInt(3) + 1;
game.informPlayers(random + " was chosen at random");
controller.millCards(random, source, game);
Card cardToCast = null;
Set<Card> cardsToExile = new HashSet<>();
for (Card card : controller.getLibrary().getCards(game)) {
cardsToExile.add(card);
if (card != null && !card.isLand(game) && !card.sharesName(spell, game)) {
cardToCast = card;
break;
}
}
controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(),
CardUtil.createObjectRealtedWindowTitle(source, game, null));
if (cardToCast != null) {
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true),
game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
}
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
if (exile != null) {
controller.putCardsOnBottomOfLibrary(exile, game, source, false);
}
return true;
}
}

View file

@ -794,6 +794,11 @@ public final class CardUtil {
return object == null || haveEmptyName(object.getName());
}
public static int differentlyNamedAmongCollection(Collection<? extends MageObject> collection, Game game) {
// TODO: Implement this
return 0;
}
public static UUID getMainCardId(Game game, UUID objectId) {
Card card = game.getCard(objectId);
return card != null ? card.getMainCard().getId() : objectId;