alternateCosts = new CostsImpl<>();
protected Condition condition;
protected String rule;
@@ -159,6 +160,9 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
}
}
}
+
+ // save activated status
+ game.getState().setValue(getActivatedKey(ability), Boolean.TRUE);
} else {
return false;
}
@@ -169,6 +173,38 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
return isActivated(ability, game);
}
+ private String getActivatedKey(Ability source) {
+ return getActivatedKey(this.getOriginalId(), source.getSourceId(), source.getSourceObjectZoneChangeCounter());
+ }
+
+ private static String getActivatedKey(UUID alternativeCostOriginalId, UUID sourceId, int sourceZCC) {
+ // can't use sourceId cause copied cards are different...
+ // TODO: enable sourceId after copy card fix (it must copy cards with all related game state values)
+ return ALTERNATIVE_COST_ACTIVATION_KEY + "_" + alternativeCostOriginalId + "_" /*+ sourceId + "_"*/ + sourceZCC;
+ }
+
+ /**
+ * Search activated status of alternative cost.
+ *
+ * If you need it on resolve then use current ZCC (on stack)
+ * If you need it on battlefield then use previous ZCC (-1)
+ *
+ * @param game
+ * @param source
+ * @param alternativeCostOriginalId you must save originalId on card's creation
+ * @param searchPrevZCC true on battlefield, false on stack
+ * @return
+ */
+ public static boolean getActivatedStatus(Game game, Ability source, UUID alternativeCostOriginalId, boolean searchPrevZCC) {
+ String key = getActivatedKey(
+ alternativeCostOriginalId,
+ source.getSourceId(),
+ source.getSourceObjectZoneChangeCounter() + (searchPrevZCC ? -1 : 0)
+ );
+ Boolean status = (Boolean) game.getState().getValue(key);
+ return status != null && status;
+ }
+
@Override
public boolean isActivated(Ability source, Game game) {
Costs alternativeCostsToCheck;
diff --git a/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java b/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java
index 4ff4e4bac9..5db00825bc 100644
--- a/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java
+++ b/Mage/src/main/java/mage/abilities/effects/common/CopyEffect.java
@@ -78,7 +78,7 @@ public class CopyEffect extends ContinuousEffectImpl {
Permanent permanent = affectedObjectList.get(0).getPermanent(game);
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD, source.getSourceObjectZoneChangeCounter());
- // As long as the permanent is still in the LKI continue to copy to get triggered abilities to TriggeredAbilites for dies events.
+ // As long as the permanent is still in the LKI continue to copy to get triggered abilities to TriggeredAbilities for dies events.
if (permanent == null) {
discard();
return false;
diff --git a/Mage/src/main/java/mage/abilities/effects/common/OpponentsCantCastChosenUntilNextTurnEffect.java b/Mage/src/main/java/mage/abilities/effects/common/OpponentsCantCastChosenUntilNextTurnEffect.java
new file mode 100644
index 0000000000..2eba8953dc
--- /dev/null
+++ b/Mage/src/main/java/mage/abilities/effects/common/OpponentsCantCastChosenUntilNextTurnEffect.java
@@ -0,0 +1,55 @@
+package mage.abilities.effects.common;
+
+import mage.MageObject;
+import mage.abilities.Ability;
+import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
+import mage.constants.Duration;
+import mage.constants.Outcome;
+import mage.game.Game;
+import mage.game.events.GameEvent;
+import mage.util.CardUtil;
+
+/**
+ * This effect must be used in tandem with ChooseACardNameEffect
+ */
+public class OpponentsCantCastChosenUntilNextTurnEffect extends ContinuousRuleModifyingEffectImpl {
+
+ public OpponentsCantCastChosenUntilNextTurnEffect() {
+ super(Duration.UntilYourNextTurn, Outcome.Benefit);
+ staticText = "Until your next turn, your opponents can't cast spells with the chosen name";
+ }
+
+ public OpponentsCantCastChosenUntilNextTurnEffect(final OpponentsCantCastChosenUntilNextTurnEffect effect) {
+ super(effect);
+ }
+
+ @Override
+ public OpponentsCantCastChosenUntilNextTurnEffect copy() {
+ return new OpponentsCantCastChosenUntilNextTurnEffect(this);
+ }
+
+ @Override
+ public String getInfoMessage(Ability source, GameEvent event, Game game) {
+ MageObject mageObject = game.getObject(source.getSourceId());
+ String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
+ if (mageObject != null && cardName != null) {
+ return "You can't cast a card named " + cardName + " (" + mageObject.getIdName() + ").";
+ }
+ return null;
+ }
+
+ @Override
+ public boolean checksEventType(GameEvent event, Game game) {
+ return event.getType() == GameEvent.EventType.CAST_SPELL_LATE;
+ }
+
+ @Override
+ public boolean applies(GameEvent event, Ability source, Game game) {
+ String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
+ if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
+ MageObject object = game.getObject(event.getSourceId());
+ return object != null && CardUtil.haveSameNames(object, cardName, game);
+ }
+ return false;
+ }
+}