diff --git a/Mage.Sets/src/mage/cards/k/KeenEaredSentry.java b/Mage.Sets/src/mage/cards/k/KeenEaredSentry.java new file mode 100644 index 0000000000..b6418feca2 --- /dev/null +++ b/Mage.Sets/src/mage/cards/k/KeenEaredSentry.java @@ -0,0 +1,118 @@ +package mage.cards.k; + +import mage.MageInt; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.common.continuous.GainAbilityControllerEffect; +import mage.abilities.keyword.HexproofAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class KeenEaredSentry extends CardImpl { + + public KeenEaredSentry(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}"); + + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.SOLDIER); + this.power = new MageInt(2); + this.toughness = new MageInt(1); + + // You have hexproof. + this.addAbility(new SimpleStaticAbility(new GainAbilityControllerEffect(HexproofAbility.getInstance()))); + + // Your opponents can't venture into the dungeon more than once each turn. + this.addAbility(new SimpleStaticAbility(new KeenEaredSentryEffect()), new KeenEaredSentryWatcher()); + } + + private KeenEaredSentry(final KeenEaredSentry card) { + super(card); + } + + @Override + public KeenEaredSentry copy() { + return new KeenEaredSentry(this); + } +} + +class KeenEaredSentryEffect extends ContinuousRuleModifyingEffectImpl { + + KeenEaredSentryEffect() { + super(Duration.WhileOnBattlefield, Outcome.Detriment); + staticText = "your opponents can't venture into the dungeon more than once each turn"; + } + + private KeenEaredSentryEffect(final KeenEaredSentryEffect effect) { + super(effect); + } + + @Override + public KeenEaredSentryEffect copy() { + return new KeenEaredSentryEffect(this); + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.VENTURE; + } + + @Override + public String getInfoMessage(Ability source, GameEvent event, Game game) { + MageObject sourceObject = source.getSourceObject(game); + if (sourceObject == null) { + return null; + } + return "You can't venture into the dungeon more than once each turn. (" + sourceObject.getName() + ')'; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return game.getOpponents(source.getControllerId()).contains(event.getTargetId()) + && KeenEaredSentryWatcher.checkPlayer(event.getTargetId(), game); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } +} + +class KeenEaredSentryWatcher extends Watcher { + + private final Set playerSet = new HashSet<>(); + + KeenEaredSentryWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.VENTURED) { + playerSet.add(event.getTargetId()); + } + } + + @Override + public void reset() { + super.reset(); + playerSet.clear(); + } + + static boolean checkPlayer(UUID playerId, Game game) { + KeenEaredSentryWatcher watcher = game.getState().getWatcher(KeenEaredSentryWatcher.class); + return watcher != null && watcher.playerSet.contains(playerId); + } +} diff --git a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java index ccc81630c7..c079352110 100644 --- a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java +++ b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java @@ -133,6 +133,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet { cards.add(new SetCardInfo("Island", 266, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Iymrith, Desert Doom", 62, Rarity.MYTHIC, mage.cards.i.IymrithDesertDoom.class)); cards.add(new SetCardInfo("Jaded Sell-Sword", 152, Rarity.COMMON, mage.cards.j.JadedSellSword.class)); + cards.add(new SetCardInfo("Keen-Eared Sentry", 22, Rarity.UNCOMMON, mage.cards.k.KeenEaredSentry.class)); cards.add(new SetCardInfo("Kick in the Door", 153, Rarity.COMMON, mage.cards.k.KickInTheDoor.class)); cards.add(new SetCardInfo("Krydle of Baldur's Gate", 226, Rarity.UNCOMMON, mage.cards.k.KrydleOfBaldursGate.class)); cards.add(new SetCardInfo("Leather Armor", 248, Rarity.COMMON, mage.cards.l.LeatherArmor.class)); diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index c4da068ba5..9c414c05fe 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -478,7 +478,11 @@ public abstract class GameImpl implements Game, Serializable { @Override public void ventureIntoDungeon(UUID playerId) { + if (replaceEvent(GameEvent.getEvent(GameEvent.EventType.VENTURE, playerId, null, playerId))) { + return; + } this.getOrCreateDungeon(playerId).moveToNextRoom(playerId, this); + fireEvent(GameEvent.getEvent(GameEvent.EventType.VENTURED, playerId, null, playerId)); } @Override diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index 51985cef0e..5b266493ff 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -454,6 +454,7 @@ public class GameEvent implements Serializable { playerId player in the dungeon */ ROOM_ENTERED, + VENTURE, VENTURED, DUNGEON_COMPLETED, //custom events CUSTOM_EVENT