From 951d7da77dc965b615278bd837252e1da8819c46 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sun, 1 Nov 2020 19:58:03 -0500 Subject: [PATCH] [CMR] Implemented Port Razer --- Mage.Sets/src/mage/cards/p/PortRazer.java | 115 ++++++++++++++++++ Mage.Sets/src/mage/sets/CommanderLegends.java | 1 + 2 files changed, 116 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/p/PortRazer.java diff --git a/Mage.Sets/src/mage/cards/p/PortRazer.java b/Mage.Sets/src/mage/cards/p/PortRazer.java new file mode 100644 index 0000000000..917a3b0688 --- /dev/null +++ b/Mage.Sets/src/mage/cards/p/PortRazer.java @@ -0,0 +1,115 @@ +package mage.cards.p; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.RestrictionEffect; +import mage.abilities.effects.common.AdditionalCombatPhaseEffect; +import mage.abilities.effects.common.UntapAllControllerEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.SubType; +import mage.constants.WatcherScope; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.watchers.Watcher; + +import java.util.*; + +/** + * @author TheElk801 + */ +public final class PortRazer extends CardImpl { + + public PortRazer(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}{R}"); + + this.subtype.add(SubType.ORC); + this.subtype.add(SubType.PIRATE); + this.power = new MageInt(4); + this.toughness = new MageInt(4); + + // Whenever Port Razer deals combat damage to a player, untap each creature you control. After this combat phase, there is an additional combat phase. + Ability ability = new DealsCombatDamageToAPlayerTriggeredAbility( + new UntapAllControllerEffect( + StaticFilters.FILTER_CONTROLLED_CREATURES, + "untap all creatures you control" + ), false + ); + ability.addEffect(new AdditionalCombatPhaseEffect()); + this.addAbility(ability); + + // Port Razer can't attack a player it has already attacked this turn. + this.addAbility(new SimpleStaticAbility(new PortRazerEffect()), new PortRazerWatcher()); + } + + private PortRazer(final PortRazer card) { + super(card); + } + + @Override + public PortRazer copy() { + return new PortRazer(this); + } +} + +class PortRazerEffect extends RestrictionEffect { + + PortRazerEffect() { + super(Duration.WhileOnBattlefield); + staticText = "{this} can't attack a player it has already attacked this turn"; + } + + private PortRazerEffect(final PortRazerEffect effect) { + super(effect); + } + + @Override + public PortRazerEffect copy() { + return new PortRazerEffect(this); + } + + @Override + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) { + PortRazerWatcher watcher = game.getState().getWatcher(PortRazerWatcher.class); + return watcher != null && watcher.checkAttacker(attacker, defenderId); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return true; + } +} + +class PortRazerWatcher extends Watcher { + + private final Map> attackMap = new HashMap<>(); + + PortRazerWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() != GameEvent.EventType.ATTACKER_DECLARED + || game.getPlayer(event.getTargetId()) == null) { + return; + } + attackMap.computeIfAbsent(event.getSourceId(), x -> new HashSet<>()).add(event.getTargetId()); + } + + @Override + public void reset() { + attackMap.clear(); + super.reset(); + } + + boolean checkAttacker(Permanent permanent, UUID defenderId) { + return attackMap.computeIfAbsent(permanent.getId(), x -> new HashSet<>()).contains(defenderId); + } +} diff --git a/Mage.Sets/src/mage/sets/CommanderLegends.java b/Mage.Sets/src/mage/sets/CommanderLegends.java index ddff90c0fc..465d400efd 100644 --- a/Mage.Sets/src/mage/sets/CommanderLegends.java +++ b/Mage.Sets/src/mage/sets/CommanderLegends.java @@ -150,6 +150,7 @@ public final class CommanderLegends extends ExpansionSet { cards.add(new SetCardInfo("Phyrexian Rager", 142, Rarity.COMMON, mage.cards.p.PhyrexianRager.class)); cards.add(new SetCardInfo("Phyrexian Triniform", 331, Rarity.MYTHIC, mage.cards.p.PhyrexianTriniform.class)); cards.add(new SetCardInfo("Plague Reaver", 143, Rarity.RARE, mage.cards.p.PlagueReaver.class)); + cards.add(new SetCardInfo("Port Razer", 193, Rarity.MYTHIC, mage.cards.p.PortRazer.class)); cards.add(new SetCardInfo("Prava of the Steel Legion", 38, Rarity.UNCOMMON, mage.cards.p.PravaOfTheSteelLegion.class)); cards.add(new SetCardInfo("Preordain", 84, Rarity.COMMON, mage.cards.p.Preordain.class)); cards.add(new SetCardInfo("Profane Transfusion", 145, Rarity.MYTHIC, mage.cards.p.ProfaneTransfusion.class));