From e0c48bfa4e7c9e8024509b6da87556971e36eb83 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 21 Aug 2017 10:07:40 -0400 Subject: [PATCH 1/3] Implemented Mairsil almost --- .../src/mage/cards/m/MairsilThePretender.java | 185 ++++++++++++++++++ Mage.Sets/src/mage/sets/Commander2017.java | 1 + .../main/java/mage/counters/CounterType.java | 1 + 3 files changed, 187 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/m/MairsilThePretender.java diff --git a/Mage.Sets/src/mage/cards/m/MairsilThePretender.java b/Mage.Sets/src/mage/cards/m/MairsilThePretender.java new file mode 100644 index 0000000000..74d3bb2e99 --- /dev/null +++ b/Mage.Sets/src/mage/cards/m/MairsilThePretender.java @@ -0,0 +1,185 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.cards.m; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.ActivatedAbility; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; +import mage.constants.SubLayer; +import mage.constants.SuperType; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.filter.FilterCard; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.filter.predicate.other.CounterCardPredicate; +import mage.filter.predicate.other.OwnerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.Target; +import mage.target.common.TargetCardInHand; +import mage.target.common.TargetCardInYourGraveyard; + +/** + * + * @author TheElk801 + */ +public class MairsilThePretender extends CardImpl { + + public MairsilThePretender(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{B}{R}"); + + addSuperType(SuperType.LEGENDARY); + this.subtype.add("Human"); + this.subtype.add("Wizard"); + this.power = new MageInt(4); + this.toughness = new MageInt(4); + + // When Mairsil, the Pretender enters the battlefield, you may exile an artifact or creature card from your hand or graveyard and put a cage counter on it. + this.addAbility(new EntersBattlefieldTriggeredAbility(new MairsilThePretenderExileEffect(), true)); + + // Mairsil, the Pretender has all activated abilities of all cards you own in exile with cage counters on them. You may activate each of those abilities only once each turn. + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MairsilThePretenderGainAbilitiesEffect())); + } + + public MairsilThePretender(final MairsilThePretender card) { + super(card); + } + + @Override + public MairsilThePretender copy() { + return new MairsilThePretender(this); + } +} + +class MairsilThePretenderExileEffect extends OneShotEffect { + + private static final FilterCard filter = new FilterCard(); + + static { + filter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), new CardTypePredicate(CardType.CREATURE))); + } + + MairsilThePretenderExileEffect() { + super(Outcome.Benefit); + this.staticText = ""; + } + + MairsilThePretenderExileEffect(final MairsilThePretenderExileEffect effect) { + super(effect); + } + + @Override + public MairsilThePretenderExileEffect copy() { + return new MairsilThePretenderExileEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + if (controller.chooseUse(Outcome.PutCardInPlay, "Exile a card from your hand? (No = from graveyard)", source, game)) { + Target target = new TargetCardInHand(0, 1, filter); + controller.choose(outcome, target, source.getSourceId(), game); + Card card = controller.getHand().get(target.getFirstTarget(), game); + if (card != null) { + controller.moveCards(card, Zone.EXILED, source, game); + card.addCounters(CounterType.CAGE.createInstance(), source, game); + } + } else { + Target target = new TargetCardInYourGraveyard(0, 1, filter); + target.choose(Outcome.PutCardInPlay, source.getControllerId(), source.getSourceId(), game); + Card card = controller.getGraveyard().get(target.getFirstTarget(), game); + if (card != null) { + controller.moveCards(card, Zone.EXILED, source, game); + card.addCounters(CounterType.CAGE.createInstance(), source, game); + } + } + return true; + } + return false; + } +} + +class MairsilThePretenderGainAbilitiesEffect extends ContinuousEffectImpl { + + private static final FilterCard filter = new FilterCard(); + + static { + filter.add(new CounterCardPredicate(CounterType.CAGE)); + filter.add(new OwnerPredicate(TargetController.YOU)); + } + + public MairsilThePretenderGainAbilitiesEffect() { + super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + staticText = "{this} has all activated abilities of all cards you own in exile with cage counters on them. You may activate each of those abilities only once each turn"; + } + + public MairsilThePretenderGainAbilitiesEffect(final MairsilThePretenderGainAbilitiesEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent perm = game.getPermanent(source.getSourceId()); + if (perm != null) { + for (Card card : game.getExile().getAllCards(game)) { + if (filter.match(card, game)) { + for (Ability ability : card.getAbilities()) { + if (ability instanceof ActivatedAbility) { + ActivatedAbility copyAbility = (ActivatedAbility) ability.copy(); + perm.addAbility(copyAbility, card.getId(), game); + } + } + } + } + return true; + } + return false; + } + + @Override + public MairsilThePretenderGainAbilitiesEffect copy() { + return new MairsilThePretenderGainAbilitiesEffect(this); + } +} diff --git a/Mage.Sets/src/mage/sets/Commander2017.java b/Mage.Sets/src/mage/sets/Commander2017.java index 65065e1549..0355adfaf9 100644 --- a/Mage.Sets/src/mage/sets/Commander2017.java +++ b/Mage.Sets/src/mage/sets/Commander2017.java @@ -79,6 +79,7 @@ public class Commander2017 extends ExpansionSet { cards.add(new SetCardInfo("Kindred Summons", 32, Rarity.RARE, mage.cards.k.KindredSummons.class)); cards.add(new SetCardInfo("Licia, Sanguine Tribune", 40, Rarity.MYTHIC, mage.cards.l.LiciaSanguineTribune.class)); cards.add(new SetCardInfo("Magus of the Mind", 12, Rarity.RARE, mage.cards.m.MagusOfTheMind.class)); + cards.add(new SetCardInfo("Mairsil, the Pretender", 41, Rarity.MYTHIC, mage.cards.m.MairsilThePretender.class)); cards.add(new SetCardInfo("Mathas, Fiend Seeker", 42, Rarity.MYTHIC, mage.cards.m.MathasFiendSeeker.class)); cards.add(new SetCardInfo("Mirri, Weatherlight Duelist", 43, Rarity.MYTHIC, mage.cards.m.MirriWeatherlightDuelist.class)); cards.add(new SetCardInfo("Mirror of the Forebears", 54, Rarity.UNCOMMON, mage.cards.m.MirrorOfTheForebears.class)); diff --git a/Mage/src/main/java/mage/counters/CounterType.java b/Mage/src/main/java/mage/counters/CounterType.java index 24fcd178b2..18ad68d08b 100644 --- a/Mage/src/main/java/mage/counters/CounterType.java +++ b/Mage/src/main/java/mage/counters/CounterType.java @@ -42,6 +42,7 @@ public enum CounterType { BOUNTY("bounty"), BRIBERY("bribery"), BRICK("brick"), + CAGE("cage"), CARRION("carrion"), CHARGE("charge"), CORPSE("corpse"), From f33d9006c680466b6947394aa8a35276d16df577 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 21 Aug 2017 11:29:34 -0400 Subject: [PATCH 2/3] Implemented Mairsil but this is possibly game-breaking --- .../src/mage/cards/m/MairsilThePretender.java | 7 +- .../mage/abilities/ActivatedAbilityImpl.java | 141 ++++++++++++------ 2 files changed, 103 insertions(+), 45 deletions(-) diff --git a/Mage.Sets/src/mage/cards/m/MairsilThePretender.java b/Mage.Sets/src/mage/cards/m/MairsilThePretender.java index 74d3bb2e99..7ee0d81864 100644 --- a/Mage.Sets/src/mage/cards/m/MairsilThePretender.java +++ b/Mage.Sets/src/mage/cards/m/MairsilThePretender.java @@ -31,8 +31,8 @@ import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.ActivatedAbility; +import mage.abilities.ActivatedAbilityImpl; import mage.abilities.common.EntersBattlefieldTriggeredAbility; -import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect; @@ -102,7 +102,7 @@ class MairsilThePretenderExileEffect extends OneShotEffect { MairsilThePretenderExileEffect() { super(Outcome.Benefit); - this.staticText = ""; + this.staticText = "you may exile an artifact or creature card from your hand or graveyard and put a cage counter on it."; } MairsilThePretenderExileEffect(final MairsilThePretenderExileEffect effect) { @@ -167,7 +167,8 @@ class MairsilThePretenderGainAbilitiesEffect extends ContinuousEffectImpl { if (filter.match(card, game)) { for (Ability ability : card.getAbilities()) { if (ability instanceof ActivatedAbility) { - ActivatedAbility copyAbility = (ActivatedAbility) ability.copy(); + ActivatedAbilityImpl copyAbility = (ActivatedAbilityImpl) ability; + copyAbility.setMaxActivationsPerTurn(1); perm.addAbility(copyAbility, card.getId(), game); } } diff --git a/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java b/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java index 5021a83896..eb05b059e5 100644 --- a/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java @@ -45,6 +45,7 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.command.Emblem; import mage.game.permanent.Permanent; +import mage.util.CardUtil; /** * @@ -52,10 +53,22 @@ import mage.game.permanent.Permanent; */ public abstract class ActivatedAbilityImpl extends AbilityImpl implements ActivatedAbility { + static class ActivationInfo { + + public int turnNum; + public int activationCounter; + + public ActivationInfo(int turnNum, int activationCounter) { + this.turnNum = turnNum; + this.activationCounter = activationCounter; + } + } + protected TimingRule timing = TimingRule.INSTANT; protected TargetController mayActivate = TargetController.YOU; protected UUID activatorId; protected boolean checkPlayableMode; + private int maxActivationsPerTurn; protected ActivatedAbilityImpl(AbilityType abilityType, Zone zone) { super(abilityType, zone); @@ -159,55 +172,82 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa public abstract ActivatedAbilityImpl copy(); @Override - public boolean canActivate(UUID playerId, Game game) { - //20091005 - 602.2 - switch (mayActivate) { - case ANY: - break; - - case NOT_YOU: - if (controlsAbility(playerId, game)) { - return false; + public boolean activate(Game game, boolean noMana) { + if (hasMoreActivationsThisTurn(game)) { + if (super.activate(game, noMana)) { + ActivatedAbilityImpl.ActivationInfo activationInfo = getActivationInfo(game); + if (activationInfo == null) { + activationInfo = new ActivatedAbilityImpl.ActivationInfo(game.getTurnNum(), 1); + } else if (activationInfo.turnNum != game.getTurnNum()) { + activationInfo.turnNum = game.getTurnNum(); + activationInfo.activationCounter = 1; + } else { + activationInfo.activationCounter++; } - break; - - case OPPONENT: - if (!game.getPlayer(controllerId).hasOpponent(playerId, game)) { - return false; - } - break; - case OWNER: - Permanent permanent = game.getPermanent(getSourceId()); - if (!permanent.getOwnerId().equals(playerId)) { - return false; - } - break; - case YOU: - if (!controlsAbility(playerId, game)) { - return false; - } - break; - case CONTROLLER_ATTACHED_TO: - Permanent enchantment = game.getPermanent(getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent enchanted = game.getPermanent(enchantment.getAttachedTo()); - if (enchanted != null && enchanted.getControllerId().equals(playerId)) { - break; - } - } - return false; - } - //20091005 - 602.5d/602.5e - if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId) - || game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_AS_INSTANT, this, controllerId, game)) { - if (costs.canPay(this, sourceId, playerId, game) && canChooseTarget(game)) { - this.activatorId = playerId; + setActivationInfo(activationInfo, game); return true; } } return false; } + @Override + public boolean canActivate(UUID playerId, Game game) { + //20091005 - 602.2 + if (hasMoreActivationsThisTurn(game)) { + switch (mayActivate) { + case ANY: + break; + + case NOT_YOU: + if (controlsAbility(playerId, game)) { + return false; + } + break; + + case OPPONENT: + if (!game.getPlayer(controllerId).hasOpponent(playerId, game)) { + return false; + } + break; + case OWNER: + Permanent permanent = game.getPermanent(getSourceId()); + if (!permanent.getOwnerId().equals(playerId)) { + return false; + } + break; + case YOU: + if (!controlsAbility(playerId, game)) { + return false; + } + break; + case CONTROLLER_ATTACHED_TO: + Permanent enchantment = game.getPermanent(getSourceId()); + if (enchantment != null && enchantment.getAttachedTo() != null) { + Permanent enchanted = game.getPermanent(enchantment.getAttachedTo()); + if (enchanted != null && enchanted.getControllerId().equals(playerId)) { + break; + } + } + return false; + } + //20091005 - 602.5d/602.5e + if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId) + || game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_AS_INSTANT, this, controllerId, game)) { + if (costs.canPay(this, sourceId, playerId, game) && canChooseTarget(game)) { + this.activatorId = playerId; + return true; + } + } + } + return false; + } + + private boolean hasMoreActivationsThisTurn(Game game) { + ActivatedAbilityImpl.ActivationInfo activationInfo = this.getActivationInfo(game); + return activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < maxActivationsPerTurn; + } + @Override public ManaOptions getMinimumCostToActivate(UUID playerId, Game game) { return getManaCostsToPay().getOptions(); @@ -255,4 +295,21 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa return checkPlayableMode; } + public void setMaxActivationsPerTurn(int maxActivationsPerTurn) { + this.maxActivationsPerTurn = maxActivationsPerTurn; + } + + private ActivatedAbilityImpl.ActivationInfo getActivationInfo(Game game) { + Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn"+this.getOriginalId().toString(), sourceId, game)); + Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount"+this.getOriginalId().toString(), sourceId, game)); + if (turnNum == null || activationCount == null) { + return null; + } + return new ActivatedAbilityImpl.ActivationInfo(turnNum, activationCount); + } + + private void setActivationInfo(ActivatedAbilityImpl.ActivationInfo activationInfo, Game game) { + game.getState().setValue(CardUtil.getCardZoneString("activationsTurn"+this.getOriginalId().toString(), sourceId, game), activationInfo.turnNum); + game.getState().setValue(CardUtil.getCardZoneString("activationsCount"+this.getOriginalId().toString(), sourceId, game), activationInfo.activationCounter); + } } From 8d851892620f5068169eb8134a5b03ebcd7bdb3b Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 22 Aug 2017 09:27:07 -0400 Subject: [PATCH 3/3] Implemented Mairsil properly --- .../src/mage/cards/m/MairsilThePretender.java | 157 +++++++++++++++++- .../mage/abilities/ActivatedAbilityImpl.java | 141 +++++----------- 2 files changed, 195 insertions(+), 103 deletions(-) diff --git a/Mage.Sets/src/mage/cards/m/MairsilThePretender.java b/Mage.Sets/src/mage/cards/m/MairsilThePretender.java index 7ee0d81864..1002c53067 100644 --- a/Mage.Sets/src/mage/cards/m/MairsilThePretender.java +++ b/Mage.Sets/src/mage/cards/m/MairsilThePretender.java @@ -27,14 +27,21 @@ */ package mage.cards.m; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.ActivatedAbility; -import mage.abilities.ActivatedAbilityImpl; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; @@ -46,6 +53,7 @@ import mage.constants.Outcome; import mage.constants.SubLayer; import mage.constants.SuperType; import mage.constants.TargetController; +import mage.constants.WatcherScope; import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.FilterCard; @@ -54,11 +62,15 @@ import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.other.CounterCardPredicate; import mage.filter.predicate.other.OwnerPredicate; import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; +import mage.game.stack.StackAbility; import mage.players.Player; import mage.target.Target; import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInYourGraveyard; +import mage.watchers.Watcher; /** * @@ -79,7 +91,9 @@ public class MairsilThePretender extends CardImpl { this.addAbility(new EntersBattlefieldTriggeredAbility(new MairsilThePretenderExileEffect(), true)); // Mairsil, the Pretender has all activated abilities of all cards you own in exile with cage counters on them. You may activate each of those abilities only once each turn. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MairsilThePretenderGainAbilitiesEffect())); + Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new MairsilThePretenderGainAbilitiesEffect()); + ability.addEffect(new MairsilThePretenderRuleModifyingEffect()); + this.addAbility(ability, new MairsilThePretenderWatcher()); } public MairsilThePretender(final MairsilThePretender card) { @@ -167,8 +181,11 @@ class MairsilThePretenderGainAbilitiesEffect extends ContinuousEffectImpl { if (filter.match(card, game)) { for (Ability ability : card.getAbilities()) { if (ability instanceof ActivatedAbility) { - ActivatedAbilityImpl copyAbility = (ActivatedAbilityImpl) ability; - copyAbility.setMaxActivationsPerTurn(1); + UUID originaId = ability.getId(); + ActivatedAbility copyAbility = (ActivatedAbility) ability.copy(); + Effect effect = new DoNothingEffect(); + effect.setValue("key", originaId); + copyAbility.addEffect(effect); perm.addAbility(copyAbility, card.getId(), game); } } @@ -184,3 +201,135 @@ class MairsilThePretenderGainAbilitiesEffect extends ContinuousEffectImpl { return new MairsilThePretenderGainAbilitiesEffect(this); } } + +class MairsilThePretenderWatcher extends Watcher { + + public final Map> activatedThisTurnAbilities = new HashMap<>(); + + public MairsilThePretenderWatcher() { + super(MairsilThePretenderWatcher.class.getSimpleName(), WatcherScope.GAME); + } + + public MairsilThePretenderWatcher(final MairsilThePretenderWatcher watcher) { + super(watcher); + for (Entry> entry : watcher.activatedThisTurnAbilities.entrySet()) { + activatedThisTurnAbilities.put(entry.getKey(), entry.getValue()); + } + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event instanceof ZoneChangeEvent) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getFromZone() == Zone.BATTLEFIELD) { + Permanent permanent = zEvent.getTarget(); + if (permanent != null) { + this.activatedThisTurnAbilities.remove(permanent.getId()); + } + } + } + if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) { + Set permAbilities; + if (activatedThisTurnAbilities.keySet().contains(event.getSourceId())) { + permAbilities = activatedThisTurnAbilities.get(event.getSourceId()); + } else { + permAbilities = new HashSet<>(); + } + StackAbility ability = (StackAbility) game.getStack().getStackObject(event.getSourceId()); + if (ability != null && ability.getStackAbility().isActivated()) { + for (Effect effect : ability.getAllEffects()) { + if (effect instanceof DoNothingEffect) { + permAbilities.add((UUID) effect.getValue("key")); + this.activatedThisTurnAbilities.put(event.getSourceId(), permAbilities); + } + } + } + } + } + + @Override + public void reset() { + activatedThisTurnAbilities.clear(); + } + + public Map> getActivatedThisTurnAbilities() { + return this.activatedThisTurnAbilities; + } + + @Override + public MairsilThePretenderWatcher copy() { + return new MairsilThePretenderWatcher(this); + } + +} + +class MairsilThePretenderRuleModifyingEffect extends ContinuousRuleModifyingEffectImpl { + + public MairsilThePretenderRuleModifyingEffect() { + super(Duration.WhileOnBattlefield, Outcome.Detriment); + } + + public MairsilThePretenderRuleModifyingEffect(final MairsilThePretenderRuleModifyingEffect effect) { + super(effect); + } + + @Override + public MairsilThePretenderRuleModifyingEffect copy() { + return new MairsilThePretenderRuleModifyingEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ACTIVATE_ABILITY; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + Optional ability = game.getAbility(event.getTargetId(), event.getSourceId()); + MairsilThePretenderWatcher watcher = (MairsilThePretenderWatcher) game.getState().getWatchers().get(MairsilThePretenderWatcher.class.getSimpleName()); + if (watcher != null && ability != null && ability.isPresent()) { + for (Effect effect : ability.get().getAllEffects()) { + if (effect instanceof DoNothingEffect) { + UUID originalID = (UUID) effect.getValue("key"); + if (watcher.getActivatedThisTurnAbilities().keySet().contains(event.getSourceId())) { + if (watcher.getActivatedThisTurnAbilities().get(event.getSourceId()).contains(originalID)) { + return true; + } + } + } + } + } + return false; + } + + @Override + public String getInfoMessage(Ability source, GameEvent event, Game game) { + return "This ability can only be activated once each turn."; + } +} + +class DoNothingEffect extends OneShotEffect { + + DoNothingEffect() { + super(Outcome.Neutral); + } + + DoNothingEffect(final DoNothingEffect effect) { + super(effect); + } + + @Override + public DoNothingEffect copy() { + return new DoNothingEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } +} diff --git a/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java b/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java index eb05b059e5..5021a83896 100644 --- a/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java @@ -45,7 +45,6 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.command.Emblem; import mage.game.permanent.Permanent; -import mage.util.CardUtil; /** * @@ -53,22 +52,10 @@ import mage.util.CardUtil; */ public abstract class ActivatedAbilityImpl extends AbilityImpl implements ActivatedAbility { - static class ActivationInfo { - - public int turnNum; - public int activationCounter; - - public ActivationInfo(int turnNum, int activationCounter) { - this.turnNum = turnNum; - this.activationCounter = activationCounter; - } - } - protected TimingRule timing = TimingRule.INSTANT; protected TargetController mayActivate = TargetController.YOU; protected UUID activatorId; protected boolean checkPlayableMode; - private int maxActivationsPerTurn; protected ActivatedAbilityImpl(AbilityType abilityType, Zone zone) { super(abilityType, zone); @@ -172,82 +159,55 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa public abstract ActivatedAbilityImpl copy(); @Override - public boolean activate(Game game, boolean noMana) { - if (hasMoreActivationsThisTurn(game)) { - if (super.activate(game, noMana)) { - ActivatedAbilityImpl.ActivationInfo activationInfo = getActivationInfo(game); - if (activationInfo == null) { - activationInfo = new ActivatedAbilityImpl.ActivationInfo(game.getTurnNum(), 1); - } else if (activationInfo.turnNum != game.getTurnNum()) { - activationInfo.turnNum = game.getTurnNum(); - activationInfo.activationCounter = 1; - } else { - activationInfo.activationCounter++; + public boolean canActivate(UUID playerId, Game game) { + //20091005 - 602.2 + switch (mayActivate) { + case ANY: + break; + + case NOT_YOU: + if (controlsAbility(playerId, game)) { + return false; } - setActivationInfo(activationInfo, game); + break; + + case OPPONENT: + if (!game.getPlayer(controllerId).hasOpponent(playerId, game)) { + return false; + } + break; + case OWNER: + Permanent permanent = game.getPermanent(getSourceId()); + if (!permanent.getOwnerId().equals(playerId)) { + return false; + } + break; + case YOU: + if (!controlsAbility(playerId, game)) { + return false; + } + break; + case CONTROLLER_ATTACHED_TO: + Permanent enchantment = game.getPermanent(getSourceId()); + if (enchantment != null && enchantment.getAttachedTo() != null) { + Permanent enchanted = game.getPermanent(enchantment.getAttachedTo()); + if (enchanted != null && enchanted.getControllerId().equals(playerId)) { + break; + } + } + return false; + } + //20091005 - 602.5d/602.5e + if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId) + || game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_AS_INSTANT, this, controllerId, game)) { + if (costs.canPay(this, sourceId, playerId, game) && canChooseTarget(game)) { + this.activatorId = playerId; return true; } } return false; } - @Override - public boolean canActivate(UUID playerId, Game game) { - //20091005 - 602.2 - if (hasMoreActivationsThisTurn(game)) { - switch (mayActivate) { - case ANY: - break; - - case NOT_YOU: - if (controlsAbility(playerId, game)) { - return false; - } - break; - - case OPPONENT: - if (!game.getPlayer(controllerId).hasOpponent(playerId, game)) { - return false; - } - break; - case OWNER: - Permanent permanent = game.getPermanent(getSourceId()); - if (!permanent.getOwnerId().equals(playerId)) { - return false; - } - break; - case YOU: - if (!controlsAbility(playerId, game)) { - return false; - } - break; - case CONTROLLER_ATTACHED_TO: - Permanent enchantment = game.getPermanent(getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent enchanted = game.getPermanent(enchantment.getAttachedTo()); - if (enchanted != null && enchanted.getControllerId().equals(playerId)) { - break; - } - } - return false; - } - //20091005 - 602.5d/602.5e - if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId) - || game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_AS_INSTANT, this, controllerId, game)) { - if (costs.canPay(this, sourceId, playerId, game) && canChooseTarget(game)) { - this.activatorId = playerId; - return true; - } - } - } - return false; - } - - private boolean hasMoreActivationsThisTurn(Game game) { - ActivatedAbilityImpl.ActivationInfo activationInfo = this.getActivationInfo(game); - return activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < maxActivationsPerTurn; - } - @Override public ManaOptions getMinimumCostToActivate(UUID playerId, Game game) { return getManaCostsToPay().getOptions(); @@ -295,21 +255,4 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa return checkPlayableMode; } - public void setMaxActivationsPerTurn(int maxActivationsPerTurn) { - this.maxActivationsPerTurn = maxActivationsPerTurn; - } - - private ActivatedAbilityImpl.ActivationInfo getActivationInfo(Game game) { - Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn"+this.getOriginalId().toString(), sourceId, game)); - Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount"+this.getOriginalId().toString(), sourceId, game)); - if (turnNum == null || activationCount == null) { - return null; - } - return new ActivatedAbilityImpl.ActivationInfo(turnNum, activationCount); - } - - private void setActivationInfo(ActivatedAbilityImpl.ActivationInfo activationInfo, Game game) { - game.getState().setValue(CardUtil.getCardZoneString("activationsTurn"+this.getOriginalId().toString(), sourceId, game), activationInfo.turnNum); - game.getState().setValue(CardUtil.getCardZoneString("activationsCount"+this.getOriginalId().toString(), sourceId, game), activationInfo.activationCounter); - } }