diff --git a/Mage.Sets/src/mage/cards/z/ZimoneAllQuestioning.java b/Mage.Sets/src/mage/cards/z/ZimoneAllQuestioning.java new file mode 100644 index 00000000000..20366e1ee7d --- /dev/null +++ b/Mage.Sets/src/mage/cards/z/ZimoneAllQuestioning.java @@ -0,0 +1,109 @@ +package mage.cards.z; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfEndStepTriggeredAbility; +import mage.abilities.condition.Condition; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.PrimoTheIndivisibleToken; +import mage.game.permanent.token.Token; +import mage.util.CardUtil; +import mage.watchers.common.LandfallWatcher; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ZimoneAllQuestioning extends CardImpl { + + public ZimoneAllQuestioning(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{G}{U}"); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.WIZARD); + this.power = new MageInt(1); + this.toughness = new MageInt(1); + + // At the beginning of your end step, if a land entered the battlefield under your control this turn and you control a prime number of lands, create Primo, the Indivisible, a legendary 0/0 green and blue Fractal creature token, then put that many +1/+1 counters on it. + this.addAbility(new BeginningOfEndStepTriggeredAbility( + new ZimoneAllQuestioningEffect(), TargetController.YOU, + ZimoneAllQuestioningCondition.instance, false + ), new LandfallWatcher()); + } + + private ZimoneAllQuestioning(final ZimoneAllQuestioning card) { + super(card); + } + + @Override + public ZimoneAllQuestioning copy() { + return new ZimoneAllQuestioning(this); + } +} + +enum ZimoneAllQuestioningCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + return game + .getState() + .getWatcher(LandfallWatcher.class) + .landPlayed(source.getControllerId()) + && CardUtil.isPrime(game + .getBattlefield() + .count(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, source.getControllerId(), source, game)); + } + + @Override + public String toString() { + return "a land entered the battlefield under your control this turn and you control a prime number of lands"; + } +} + +class ZimoneAllQuestioningEffect extends OneShotEffect { + + ZimoneAllQuestioningEffect() { + super(Outcome.Benefit); + staticText = "create Primo, the Indivisible, a legendary 0/0 green and blue " + + "Fractal creature token, then put that many +1/+1 counters on it"; + } + + private ZimoneAllQuestioningEffect(final ZimoneAllQuestioningEffect effect) { + super(effect); + } + + @Override + public ZimoneAllQuestioningEffect copy() { + return new ZimoneAllQuestioningEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Token token = new PrimoTheIndivisibleToken(); + token.putOntoBattlefield(1, game, source); + int count = game.getBattlefield().count( + StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, + source.getControllerId(), source, game + ); + if (count < 1) { + return true; + } + for (UUID tokenId : token.getLastAddedTokenIds()) { + Permanent permanent = game.getPermanent(tokenId); + if (permanent != null) { + permanent.addCounters(CounterType.P1P1.createInstance(count), source, game); + } + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java b/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java index 9488e5781a0..d3f1b039b24 100644 --- a/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java +++ b/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java @@ -35,5 +35,6 @@ public final class DuskmournHouseOfHorror extends ExpansionSet { cards.add(new SetCardInfo("Swamp", 274, Rarity.LAND, mage.cards.basiclands.Swamp.class, FULL_ART_BFZ_VARIOUS)); cards.add(new SetCardInfo("The Wandering Rescuer", 41, Rarity.MYTHIC, mage.cards.t.TheWanderingRescuer.class)); cards.add(new SetCardInfo("Toby, Beastie Befriender", 35, Rarity.RARE, mage.cards.t.TobyBeastieBefriender.class)); + cards.add(new SetCardInfo("Zimone, All-Questioning", 241, Rarity.RARE, mage.cards.z.ZimoneAllQuestioning.class)); } } diff --git a/Mage/src/main/java/mage/game/permanent/token/PrimoTheIndivisibleToken.java b/Mage/src/main/java/mage/game/permanent/token/PrimoTheIndivisibleToken.java new file mode 100644 index 00000000000..82edcf14cb0 --- /dev/null +++ b/Mage/src/main/java/mage/game/permanent/token/PrimoTheIndivisibleToken.java @@ -0,0 +1,31 @@ +package mage.game.permanent.token; + +import mage.MageInt; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.SuperType; + +/** + * @author TheElk801 + */ +public final class PrimoTheIndivisibleToken extends TokenImpl { + + public PrimoTheIndivisibleToken() { + super("Primo, the Indivisible", "Primo, the Indivisible, a legendary 0/0 green and blue Fractal creature token"); + supertype.add(SuperType.LEGENDARY); + cardType.add(CardType.CREATURE); + subtype.add(SubType.FRACTAL); + color.setGreen(true); + color.setBlue(true); + power = new MageInt(0); + toughness = new MageInt(0); + } + + private PrimoTheIndivisibleToken(final PrimoTheIndivisibleToken token) { + super(token); + } + + public PrimoTheIndivisibleToken copy() { + return new PrimoTheIndivisibleToken(this); + } +} diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 1d905840986..f5c64098ab1 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -716,6 +716,30 @@ public final class CardUtil { } } + /** + * Checks if a given integer is prime + * + * @param number + * @return + */ + public static boolean isPrime(int number) { + // if it's 1 or less it's not prime + if (number < 2) { + return false; + } + // easy to check 2 and 3 first + if (number == 2 || number == 3) { + return true; + } + // sieve of eratosthenes, only need to check up to sqrt(x) to find a divisor + for (int i = 2; i * i <= number; i++) { + if (number % i == 0) { + return false; + } + } + return true; + } + public static String createObjectRealtedWindowTitle(Ability source, Game game, String textSuffix) { String title; if (source != null) {