From a66e4555793c084b1dd4bcb796a3b273e540de51 Mon Sep 17 00:00:00 2001 From: "Alex W. Jackson" Date: Thu, 29 Sep 2022 08:43:29 -0400 Subject: [PATCH] [ONS] Implemented Thoughtbound Primoc --- .../src/mage/cards/s/SokenzanRenegade.java | 83 +++++------- .../src/mage/cards/t/ThoughtboundPrimoc.java | 125 ++++++++++++++++++ Mage.Sets/src/mage/sets/Onslaught.java | 1 + 3 files changed, 159 insertions(+), 50 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/t/ThoughtboundPrimoc.java diff --git a/Mage.Sets/src/mage/cards/s/SokenzanRenegade.java b/Mage.Sets/src/mage/cards/s/SokenzanRenegade.java index e51dfa55c2..ed15987cce 100644 --- a/Mage.Sets/src/mage/cards/s/SokenzanRenegade.java +++ b/Mage.Sets/src/mage/cards/s/SokenzanRenegade.java @@ -12,12 +12,7 @@ import mage.abilities.effects.common.continuous.GainControlTargetEffect; import mage.abilities.keyword.BushidoAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.TargetController; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; @@ -31,16 +26,16 @@ public final class SokenzanRenegade extends CardImpl { public SokenzanRenegade(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{R}"); - this.subtype.add(SubType.OGRE); - this.subtype.add(SubType.SAMURAI); - this.subtype.add(SubType.MERCENARY); + this.subtype.add(SubType.OGRE, SubType.SAMURAI, SubType.MERCENARY); this.power = new MageInt(3); this.toughness = new MageInt(3); // Bushido 1 this.addAbility(new BushidoAbility(1)); - // At the beginning of your upkeep, if a player has more cards in hand than each other player, the player who has the most cards in hand gains control of Sokenzan Renegade. + + // At the beginning of your upkeep, if a player has more cards in hand than each other player, + // the player who has the most cards in hand gains control of Sokenzan Renegade. this.addAbility(new ConditionalInterveningIfTriggeredAbility( new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new SokenzanRenegadeEffect(), TargetController.YOU, false), OnePlayerHasTheMostCards.instance, @@ -77,32 +72,20 @@ class SokenzanRenegadeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - if (controller != null - && sourcePermanent != null) { - int max = Integer.MIN_VALUE; - Player newController = null; - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - if (player.getHand().size() > max) { - max = player.getHand().size(); - newController = player; - } - } - } - if (newController != null) { - ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, newController.getId()); - effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), game)); - game.addEffect(effect, source); - if (!source.isControlledBy(newController.getId())) { - game.informPlayers(newController.getLogName() + " got control of " + sourcePermanent.getLogName()); - } - return true; + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); + if (sourcePermanent == null) { + return false; + } + Player newController = OnePlayerHasTheMostCards.getPlayerWithMostCards(game, source); + if (newController != null) { + ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, newController.getId()); + effect.setTargetPointer(new FixedTarget(sourcePermanent, game)); + game.addEffect(effect, source); + if (!source.isControlledBy(newController.getId())) { + game.informPlayers(newController.getLogName() + " got control of " + sourcePermanent.getLogName()); } } - return false; + return true; } } @@ -112,29 +95,29 @@ enum OnePlayerHasTheMostCards implements Condition { @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - int max = Integer.MIN_VALUE; - boolean onlyOnePlayer = false; - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - if (player.getHand().size() > max) { - max = player.getHand().size(); - onlyOnePlayer = true; - } else if (player.getHand().size() == max) { - onlyOnePlayer = false; - } + return getPlayerWithMostCards(game, source) != null; + } + + public static Player getPlayerWithMostCards(Game game, Ability source) { + int max = Integer.MIN_VALUE; + Player playerWithMost = null; + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + int cards = player.getHand().size(); + if (cards > max) { + max = cards; + playerWithMost = player; + } else if (cards == max) { + playerWithMost = null; } } - return onlyOnePlayer; } - return false; + return playerWithMost; } @Override public String toString() { return "a player has more cards in hand than each other player"; } - } diff --git a/Mage.Sets/src/mage/cards/t/ThoughtboundPrimoc.java b/Mage.Sets/src/mage/cards/t/ThoughtboundPrimoc.java new file mode 100644 index 0000000000..a6f063db5e --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/ThoughtboundPrimoc.java @@ -0,0 +1,125 @@ +package mage.cards.t; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; +import mage.abilities.condition.Condition; +import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.GainControlTargetEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.targetpointer.FixedTarget; + +/** + * + * @author awjackson + */ +public final class ThoughtboundPrimoc extends CardImpl { + + public ThoughtboundPrimoc(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{R}"); + this.subtype.add(SubType.BIRD, SubType.BEAST); + + this.power = new MageInt(2); + this.toughness = new MageInt(3); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // At the beginning of your upkeep, if a player controls more Wizards than each other player, + // the player who controls the most Wizards gains control of Thoughtbound Primoc. + this.addAbility(new ConditionalInterveningIfTriggeredAbility( + new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new ThoughtboundPrimocEffect(), TargetController.YOU, false), + OnePlayerHasTheMostWizards.instance, + "At the beginning of your upkeep, if a player controls more Wizards than each other player, the player who controls the most Wizards gains control of {this}" + )); + + } + + private ThoughtboundPrimoc(final ThoughtboundPrimoc card) { + super(card); + } + + @Override + public ThoughtboundPrimoc copy() { + return new ThoughtboundPrimoc(this); + } +} + +class ThoughtboundPrimocEffect extends OneShotEffect { + + public ThoughtboundPrimocEffect() { + super(Outcome.GainControl); + this.staticText = "the player who controls the most Wizards gains control of {this}"; + } + + public ThoughtboundPrimocEffect(final ThoughtboundPrimocEffect effect) { + super(effect); + } + + @Override + public ThoughtboundPrimocEffect copy() { + return new ThoughtboundPrimocEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); + if (sourcePermanent == null) { + return false; + } + Player newController = OnePlayerHasTheMostWizards.getPlayerWithMostWizards(game, source); + if (newController != null) { + ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, newController.getId()); + effect.setTargetPointer(new FixedTarget(sourcePermanent, game)); + game.addEffect(effect, source); + if (!source.isControlledBy(newController.getId())) { + game.informPlayers(newController.getLogName() + " got control of " + sourcePermanent.getLogName()); + } + } + return true; + } +} + +enum OnePlayerHasTheMostWizards implements Condition { + instance; + + private static final FilterPermanent filter = new FilterPermanent(SubType.WIZARD, "Wizards"); + + @Override + public boolean apply(Game game, Ability source) { + return getPlayerWithMostWizards(game, source) != null; + } + + public static Player getPlayerWithMostWizards(Game game, Ability source) { + int max = Integer.MIN_VALUE; + Player playerWithMost = null; + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + int wizards = game.getBattlefield().countAll(filter, playerId, game); + if (wizards > max) { + max = wizards; + playerWithMost = player; + } else if (wizards == max) { + playerWithMost = null; + } + } + } + return playerWithMost; + } + + @Override + public String toString() { + return "a player controls more Wizards than each other player"; + } +} diff --git a/Mage.Sets/src/mage/sets/Onslaught.java b/Mage.Sets/src/mage/sets/Onslaught.java index c5d61e63b3..8bdbf7d9e2 100644 --- a/Mage.Sets/src/mage/sets/Onslaught.java +++ b/Mage.Sets/src/mage/sets/Onslaught.java @@ -328,6 +328,7 @@ public final class Onslaught extends ExpansionSet { cards.add(new SetCardInfo("Taunting Elf", 290, Rarity.COMMON, mage.cards.t.TauntingElf.class)); cards.add(new SetCardInfo("Tempting Wurm", 291, Rarity.RARE, mage.cards.t.TemptingWurm.class)); cards.add(new SetCardInfo("Tephraderm", 239, Rarity.RARE, mage.cards.t.Tephraderm.class)); + cards.add(new SetCardInfo("Thoughtbound Primoc", 240, Rarity.UNCOMMON, mage.cards.t.ThoughtboundPrimoc.class)); cards.add(new SetCardInfo("Thrashing Mudspawn", 177, Rarity.UNCOMMON, mage.cards.t.ThrashingMudspawn.class)); cards.add(new SetCardInfo("Threaten", 241, Rarity.UNCOMMON, mage.cards.t.Threaten.class)); cards.add(new SetCardInfo("Thunder of Hooves", 242, Rarity.UNCOMMON, mage.cards.t.ThunderOfHooves.class));