diff --git a/Mage.Sets/src/mage/cards/b/BeardedAxe.java b/Mage.Sets/src/mage/cards/b/BeardedAxe.java new file mode 100644 index 00000000000..de5ae961f52 --- /dev/null +++ b/Mage.Sets/src/mage/cards/b/BeardedAxe.java @@ -0,0 +1,60 @@ +package mage.cards.b; + +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; +import mage.abilities.effects.common.continuous.BoostEquippedEffect; +import mage.abilities.hint.Hint; +import mage.abilities.hint.ValueHint; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.Predicates; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class BeardedAxe extends CardImpl { + + private static final FilterPermanent filter = new FilterControlledPermanent(); + + static { + filter.add(Predicates.or( + SubType.DWARF.getPredicate(), + SubType.EQUIPMENT.getPredicate(), + SubType.VEHICLE.getPredicate() + )); + } + + private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter); + private static final Hint hint = new ValueHint("Dwarves, Equipment, and/or Vehicles you control", xValue); + + public BeardedAxe(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}{R}"); + + this.subtype.add(SubType.EQUIPMENT); + + // Equipped creature gets +1/+1 for each Dwarf, Equipment, and/or Vehicle you control. + this.addAbility(new SimpleStaticAbility(new BoostEquippedEffect(xValue, xValue) + .setText("equipped creature gets +1/+1 for each Dwarf, Equipment, and/or Vehicle you control") + ).addHint(hint)); + + // Equip {2} + this.addAbility(new EquipAbility(2)); + } + + private BeardedAxe(final BeardedAxe card) { + super(card); + } + + @Override + public BeardedAxe copy() { + return new BeardedAxe(this); + } +} diff --git a/Mage.Sets/src/mage/cards/g/GildedAssaultCart.java b/Mage.Sets/src/mage/cards/g/GildedAssaultCart.java new file mode 100644 index 00000000000..8ba3ff8fffe --- /dev/null +++ b/Mage.Sets/src/mage/cards/g/GildedAssaultCart.java @@ -0,0 +1,56 @@ +package mage.cards.g; + +import mage.MageInt; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.common.SacrificeTargetCost; +import mage.abilities.effects.common.ReturnSourceFromGraveyardToHandEffect; +import mage.abilities.keyword.CrewAbility; +import mage.abilities.keyword.TrampleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.Zone; +import mage.filter.common.FilterControlledPermanent; +import mage.target.common.TargetControlledPermanent; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class GildedAssaultCart extends CardImpl { + + private static final FilterControlledPermanent filter + = new FilterControlledPermanent(SubType.TREASURE, "treasures"); + + public GildedAssaultCart(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{1}{R}{R}"); + + this.subtype.add(SubType.VEHICLE); + this.power = new MageInt(5); + this.toughness = new MageInt(1); + + // Trample + this.addAbility(TrampleAbility.getInstance()); + + // Crew 2 + this.addAbility(new CrewAbility(2)); + + // Sacrifice two Treasures: Return Gilded Assault Cart from your graveyard to your hand. + this.addAbility(new SimpleActivatedAbility( + Zone.GRAVEYARD, + new ReturnSourceFromGraveyardToHandEffect(), + new SacrificeTargetCost(new TargetControlledPermanent(2, filter)) + )); + } + + private GildedAssaultCart(final GildedAssaultCart card) { + super(card); + } + + @Override + public GildedAssaultCart copy() { + return new GildedAssaultCart(this); + } +} diff --git a/Mage.Sets/src/mage/cards/g/GladewalkerRitualist.java b/Mage.Sets/src/mage/cards/g/GladewalkerRitualist.java new file mode 100644 index 00000000000..4b747334e27 --- /dev/null +++ b/Mage.Sets/src/mage/cards/g/GladewalkerRitualist.java @@ -0,0 +1,56 @@ +package mage.cards.g; + +import mage.MageInt; +import mage.abilities.common.EntersBattlefieldControlledTriggeredAbility; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.keyword.ChangelingAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.mageobject.NamePredicate; +import mage.filter.predicate.permanent.AnotherPredicate; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class GladewalkerRitualist extends CardImpl { + + private static final FilterPermanent filter + = new FilterCreaturePermanent("another creature named Gladewalker Ritualist"); + + static { + filter.add(AnotherPredicate.instance); + filter.add(new NamePredicate("Gladewalker Ritualist")); + } + + public GladewalkerRitualist(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}"); + + this.subtype.add(SubType.SHAPESHIFTER); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // Changeling + this.setIsAllCreatureTypes(true); + this.addAbility(ChangelingAbility.getInstance()); + + // Whenever another creature named Gladewalker Ritualist enters the battlefield under your control, draw a card. + this.addAbility(new EntersBattlefieldControlledTriggeredAbility( + new DrawCardSourceControllerEffect(1), filter + )); + } + + private GladewalkerRitualist(final GladewalkerRitualist card) { + super(card); + } + + @Override + public GladewalkerRitualist copy() { + return new GladewalkerRitualist(this); + } +} diff --git a/Mage.Sets/src/mage/cards/r/RenegadeReaper.java b/Mage.Sets/src/mage/cards/r/RenegadeReaper.java new file mode 100644 index 00000000000..dbfcfa7457b --- /dev/null +++ b/Mage.Sets/src/mage/cards/r/RenegadeReaper.java @@ -0,0 +1,78 @@ +package mage.cards.r; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.game.Game; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class RenegadeReaper extends CardImpl { + + public RenegadeReaper(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}"); + + this.subtype.add(SubType.ANGEL); + this.subtype.add(SubType.BERSERKER); + this.power = new MageInt(2); + this.toughness = new MageInt(3); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // When Renegade Reaper enters the battlefield, mill four cards. If at least one Angel card is milled this way, you gain 4 life. + this.addAbility(new EntersBattlefieldTriggeredAbility(new RenegadeReaperEffect())); + } + + private RenegadeReaper(final RenegadeReaper card) { + super(card); + } + + @Override + public RenegadeReaper copy() { + return new RenegadeReaper(this); + } +} + +class RenegadeReaperEffect extends OneShotEffect { + + RenegadeReaperEffect() { + super(Outcome.Benefit); + staticText = "mill four cards. If at least one Angel card is milled this way, you gain 4 life"; + } + + private RenegadeReaperEffect(final RenegadeReaperEffect effect) { + super(effect); + } + + @Override + public RenegadeReaperEffect copy() { + return new RenegadeReaperEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + if (player.millCards(4, source, game) + .getCards(game) + .stream() + .anyMatch(card -> card.hasSubtype(SubType.ANGEL, game))) { + player.gainLife(4, game, source); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/Kaldheim.java b/Mage.Sets/src/mage/sets/Kaldheim.java index 732f60a2c64..957f6c48996 100644 --- a/Mage.Sets/src/mage/sets/Kaldheim.java +++ b/Mage.Sets/src/mage/sets/Kaldheim.java @@ -29,11 +29,15 @@ public final class Kaldheim extends ExpansionSet { this.maxCardNumberInBooster = 285; cards.add(new SetCardInfo("Barkchannel Pathway", 251, Rarity.RARE, mage.cards.b.BarkchannelPathway.class)); + cards.add(new SetCardInfo("Bearded Axe", 388, Rarity.UNCOMMON, mage.cards.b.BeardedAxe.class)); cards.add(new SetCardInfo("Blightstep Pathway", 252, Rarity.RARE, mage.cards.b.BlightstepPathway.class)); cards.add(new SetCardInfo("Canopy Tactician", 378, Rarity.RARE, mage.cards.c.CanopyTactician.class)); cards.add(new SetCardInfo("Darkbore Pathway", 254, Rarity.RARE, mage.cards.d.DarkborePathway.class)); cards.add(new SetCardInfo("Elven Ambush", 391, Rarity.UNCOMMON, mage.cards.e.ElvenAmbush.class)); + cards.add(new SetCardInfo("Gilded Assault Cart", 390, Rarity.UNCOMMON, mage.cards.g.GildedAssaultCart.class)); + cards.add(new SetCardInfo("Gladewalker Ritualist", 392, Rarity.UNCOMMON, mage.cards.g.GladewalkerRitualist.class)); cards.add(new SetCardInfo("Hengegate Pathway", 260, Rarity.RARE, mage.cards.h.HengegatePathway.class)); + cards.add(new SetCardInfo("Renegade Reaper", 386, Rarity.UNCOMMON, mage.cards.r.RenegadeReaper.class)); cards.add(new SetCardInfo("Showdown of the Skalds", 229, Rarity.RARE, mage.cards.s.ShowdownOfTheSkalds.class)); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/gnt/MilitantAngelTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/gnt/MilitantAngelTest.java new file mode 100644 index 00000000000..0221ab5a935 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/gnt/MilitantAngelTest.java @@ -0,0 +1,73 @@ +package org.mage.test.cards.single.gnt; + +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.dynamicvalue.common.AttackedThisTurnOpponentsCount; +import mage.abilities.effects.Effect; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.game.Game; +import mage.players.Player; +import mage.watchers.common.PlayersAttackedThisTurnWatcher; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestCommander4Players; + +/** + * @author JayDi85 + */ +public class MilitantAngelTest extends CardTestCommander4Players { + + @Test + public void test_AttackedThisTurnOpponentsCount() { + // Player order: A -> D -> C -> B + + // it's testing counter only (no need to test card -- it's same) + // When Militant Angel enters the battlefield, create a number of 2/2 white Knight creature tokens + // with vigilance equal to the number of opponents you attacked this turn. + //addCard(Zone.BATTLEFIELD, playerA, "Militant Angel", 2); + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); + addCard(Zone.BATTLEFIELD, playerA, "Kitesail Corsair", 1); + + // turn 1: 2x attack -> 1 player = 1 value + mustHaveValue("2x->1 = 1", 1, PhaseStep.PRECOMBAT_MAIN, 0); + attack(1, playerA, "Balduvian Bears", playerB); + attack(1, playerA, "Kitesail Corsair", playerB); + mustHaveValue("2x->1 = 1", 1, PhaseStep.POSTCOMBAT_MAIN, 1); + + // between attacks - no value + mustHaveValue("no attacks = 0", 2, PhaseStep.PRECOMBAT_MAIN, 0); + + // turn 5: 2x attack -> 2 players = 2 value + mustHaveValue("2x->2 = 2", 5, PhaseStep.PRECOMBAT_MAIN, 0); + attack(5, playerA, "Balduvian Bears", playerB); + attack(5, playerA, "Kitesail Corsair", playerC); + mustHaveValue("2x->2 = 2", 5, PhaseStep.POSTCOMBAT_MAIN, 2); + runCode("watcher must be copyable", 5, PhaseStep.POSTCOMBAT_MAIN, playerA, (info, player, game) -> { + PlayersAttackedThisTurnWatcher watcher = game.getState().getWatcher(PlayersAttackedThisTurnWatcher.class); + PlayersAttackedThisTurnWatcher newWatcher = watcher.copy(); + Assert.assertEquals("old watcher", 2, watcher.getAttackedOpponentsCount(player.getId())); + Assert.assertEquals("new watcher", 2, newWatcher.getAttackedOpponentsCount(player.getId())); + }); + + // between attacks - no value + mustHaveValue("no attacks = 0", 6, PhaseStep.PRECOMBAT_MAIN, 0); + + setStrictChooseMode(true); + setStopAt(6, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + } + + private void mustHaveValue(String needInfo, int turnNum, PhaseStep step, int needValue) { + runCode(needInfo, turnNum, step, playerA, (info, player, game) -> { + assertCounterValue(info, player, game, needValue); + }); + } + + private void assertCounterValue(String checkName, Player player, Game game, int needValue) { + Ability fakeAbility = new SimpleStaticAbility((Effect) null); // dynamic value need ability's controllerId + fakeAbility.setControllerId(player.getId()); + Assert.assertEquals(checkName, needValue, AttackedThisTurnOpponentsCount.instance.calculate(game, fakeAbility, null)); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/player/PlayerAction.java b/Mage.Tests/src/test/java/org/mage/test/player/PlayerAction.java index a3509cd70b5..c5debf2d59e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/PlayerAction.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/PlayerAction.java @@ -2,6 +2,7 @@ package org.mage.test.player; import mage.constants.PhaseStep; import mage.game.Game; +import org.mage.test.serverside.base.CardTestCodePayload; /** * @author BetaSteward_at_googlemail.com @@ -12,12 +13,18 @@ public class PlayerAction { private final int turnNum; private final PhaseStep step; private final String action; + private final CardTestCodePayload codePayload; // special code to execute (e.g. on dynamic check) public PlayerAction(String actionName, int turnNum, PhaseStep step, String action) { + this(actionName, turnNum, step, action, null); + } + + public PlayerAction(String actionName, int turnNum, PhaseStep step, String action, CardTestCodePayload codePayload) { this.actionName = actionName; this.turnNum = turnNum; this.step = step; this.action = action; + this.codePayload = codePayload; } public int getTurnNum() { @@ -33,7 +40,11 @@ public class PlayerAction { } public String getActionName() { - return this.actionName; + return actionName; + } + + public CardTestCodePayload getCodePayload() { + return codePayload; } /** diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 4f131a22830..e51d0bbb3fa 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -738,6 +738,18 @@ public class TestPlayer implements Player { } Assert.fail("Unknow ai command: " + command); + } else if (action.getAction().startsWith(RUN_PREFIX)) { + String command = action.getAction(); + command = command.substring(command.indexOf(RUN_PREFIX) + RUN_PREFIX.length()); + + // custom code execute + if (command.equals(RUN_COMMAND_CODE)) { + action.getCodePayload().run(action.getActionName(), computerPlayer, game); + actions.remove(action); + return true; + } + + Assert.fail("Unknow run command: " + command); } else if (action.getAction().startsWith(CHECK_PREFIX)) { String command = action.getAction(); command = command.substring(command.indexOf(CHECK_PREFIX) + CHECK_PREFIX.length()); diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestCodePayload.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestCodePayload.java new file mode 100644 index 00000000000..d536097cb71 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestCodePayload.java @@ -0,0 +1,21 @@ +package org.mage.test.serverside.base; + +import mage.game.Game; +import mage.players.Player; + +/** + * @author JayDi85 + */ +@FunctionalInterface +public interface CardTestCodePayload { + + /** + * Run dynamic code in unit tests on player's priority. + * + * @param info + * @param player activate player who would execute the code on their priority + * @param game + */ + void run(String info, Player player, Game game); + +} diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java index 8e8fe061f9a..d5e72df385c 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java @@ -34,6 +34,7 @@ import org.junit.Before; import org.mage.test.player.PlayerAction; import org.mage.test.player.TestPlayer; import org.mage.test.serverside.base.CardTestAPI; +import org.mage.test.serverside.base.CardTestCodePayload; import org.mage.test.serverside.base.MageTestPlayerBase; import java.io.FileNotFoundException; @@ -57,6 +58,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement public static final String CHECK_PREFIX = "check:"; // prefix for all check commands public static final String SHOW_PREFIX = "show:"; // prefix for all show commands public static final String AI_PREFIX = "ai:"; // prefix for all ai commands + public static final String RUN_PREFIX = "run:"; // prefix for all run commands static { // aliases can be used in check commands, so all prefixes and delimeters must be unique @@ -77,6 +79,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement public static final String AI_COMMAND_PLAY_PRIORITY = "play priority"; public static final String AI_COMMAND_PLAY_STEP = "play step"; + // commands for run + public static final String RUN_COMMAND_CODE = "code"; + static { // cards can be played/casted by activate ability command too Assert.assertTrue("musts contains activate ability part", ACTIVATE_PLAY.startsWith(ACTIVATE_ABILITY)); @@ -375,6 +380,24 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement addPlayerAction(player, checkName, turnNum, step, res); } + /** + * Execute custom code under player's priority. You can stop debugger on it. + *
+ * Example 1: check some conditions in the middle of the test + * Example 2: make game modifications (if you don't want to use custom abilities) + * Example 3: stop debugger in the middle of the game + * + * @param info + * @param turnNum + * @param step + * @param player + * @param codePayload code to execute + */ + public void runCode(String info, int turnNum, PhaseStep step, TestPlayer player, CardTestCodePayload codePayload) { + PlayerAction playerAction = new PlayerAction(info, turnNum, step, RUN_PREFIX + RUN_COMMAND_CODE, codePayload); + addPlayerAction(player, playerAction); + } + public void checkPT(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, Integer power, Integer toughness) { //Assert.assertNotEquals("", permanentName); check(checkName, turnNum, step, player, CHECK_COMMAND_PT, permanentName, power.toString(), toughness.toString()); diff --git a/Mage/src/main/java/mage/watchers/Watcher.java b/Mage/src/main/java/mage/watchers/Watcher.java index 2b75cba4d87..96743ceeb5a 100644 --- a/Mage/src/main/java/mage/watchers/Watcher.java +++ b/Mage/src/main/java/mage/watchers/Watcher.java @@ -1,12 +1,14 @@ package mage.watchers; +import mage.constants.WatcherScope; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.PlayerList; +import org.apache.log4j.Logger; + import java.io.Serializable; import java.lang.reflect.*; import java.util.*; -import mage.constants.WatcherScope; -import mage.game.Game; -import mage.game.events.GameEvent; -import org.apache.log4j.Logger; /** * watches for certain game events to occur and flags condition @@ -123,6 +125,14 @@ public abstract class Watcher implements Serializable { set.addAll(e.getValue()); target.put(e.getKey(), set); } + } else if (valueType.getTypeName().contains("PlayerList")) { + Map