From 75c4ff7d8ecf4fc40de5902425786fa1c276e30f Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 17 Sep 2020 17:01:59 +0200 Subject: [PATCH] Using unique/special new event type for taking special actions and special mana payment(fixes #6753). --- Mage.Sets/src/mage/cards/c/Channel.java | 2 ++ Mage.Sets/src/mage/cards/d/DampingEngine.java | 3 +- .../mage/abilities/keyword/AssistAbility.java | 1 + .../abilities/keyword/ConvokeAbility.java | 1 + .../mage/abilities/keyword/DelveAbility.java | 1 + .../abilities/keyword/ImproviseAbility.java | 1 + .../main/java/mage/constants/AbilityType.java | 3 +- .../main/java/mage/game/events/GameEvent.java | 8 ++++- .../main/java/mage/players/PlayerImpl.java | 31 +++++++++++++++++-- 9 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/Channel.java b/Mage.Sets/src/mage/cards/c/Channel.java index 3842caf30f7..5bec98c7b1e 100644 --- a/Mage.Sets/src/mage/cards/c/Channel.java +++ b/Mage.Sets/src/mage/cards/c/Channel.java @@ -14,6 +14,7 @@ import mage.abilities.effects.common.CreateSpecialActionEffect; import mage.abilities.effects.common.RemoveSpecialActionEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.AbilityType; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; @@ -75,6 +76,7 @@ class ChannelSpecialAction extends SpecialAction { ChannelSpecialAction() { super(); + this.abilityType = AbilityType.SPECIAL_MANA_PAYMENT; this.addCost(new PayLifeCost(1)); this.addEffect(new BasicManaEffect(Mana.ColorlessMana(1))); } diff --git a/Mage.Sets/src/mage/cards/d/DampingEngine.java b/Mage.Sets/src/mage/cards/d/DampingEngine.java index 18546501f4a..e22b0e19e4b 100644 --- a/Mage.Sets/src/mage/cards/d/DampingEngine.java +++ b/Mage.Sets/src/mage/cards/d/DampingEngine.java @@ -56,7 +56,8 @@ public class DampingEngine extends CardImpl { public DampingEngine(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}"); - // A player who controls more permanents than each other player can't play lands or cast artifact, creature, or enchantment spells. That player may sacrifice a permanent for that player to ignore this effect until end of turn. + // A player who controls more permanents than each other player can't play lands or cast artifact, creature, or enchantment spells. + // That player may sacrifice a permanent for that player to ignore this effect until end of turn. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DampingEngineEffect())); this.addAbility(new DampingEngineSpecialAction()); diff --git a/Mage/src/main/java/mage/abilities/keyword/AssistAbility.java b/Mage/src/main/java/mage/abilities/keyword/AssistAbility.java index aec3f99d8b0..584d42e012e 100644 --- a/Mage/src/main/java/mage/abilities/keyword/AssistAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/AssistAbility.java @@ -127,6 +127,7 @@ class AssistSpecialAction extends SpecialAction { AssistSpecialAction(ManaCost unpaid, AlternateManaPaymentAbility manaAbility) { super(Zone.ALL, manaAbility); + this.abilityType = AbilityType.SPECIAL_MANA_PAYMENT; setRuleVisible(false); this.addEffect(new AssistEffect(unpaid)); } diff --git a/Mage/src/main/java/mage/abilities/keyword/ConvokeAbility.java b/Mage/src/main/java/mage/abilities/keyword/ConvokeAbility.java index 3aa290bba50..16d3a8e43ef 100644 --- a/Mage/src/main/java/mage/abilities/keyword/ConvokeAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/ConvokeAbility.java @@ -173,6 +173,7 @@ class ConvokeSpecialAction extends SpecialAction { public ConvokeSpecialAction(ManaCost unpaid, AlternateManaPaymentAbility manaAbility) { super(Zone.ALL, manaAbility); + this.abilityType = AbilityType.SPECIAL_MANA_PAYMENT; setRuleVisible(false); this.addEffect(new ConvokeEffect(unpaid)); } diff --git a/Mage/src/main/java/mage/abilities/keyword/DelveAbility.java b/Mage/src/main/java/mage/abilities/keyword/DelveAbility.java index 6f8002ed78e..66e2b42cb9c 100644 --- a/Mage/src/main/java/mage/abilities/keyword/DelveAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/DelveAbility.java @@ -126,6 +126,7 @@ class DelveSpecialAction extends SpecialAction { public DelveSpecialAction(AlternateManaPaymentAbility manaAbility) { super(Zone.ALL, manaAbility); + this.abilityType = AbilityType.SPECIAL_MANA_PAYMENT; this.addEffect(new DelveEffect()); } diff --git a/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java b/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java index 5d7d15a4e36..fe5625809dd 100644 --- a/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java @@ -115,6 +115,7 @@ class ImproviseSpecialAction extends SpecialAction { public ImproviseSpecialAction(ManaCost unpaid, AlternateManaPaymentAbility manaAbility) { super(Zone.ALL, manaAbility); + this.abilityType = AbilityType.SPECIAL_MANA_PAYMENT; setRuleVisible(false); this.addEffect(new ImproviseEffect(unpaid)); } diff --git a/Mage/src/main/java/mage/constants/AbilityType.java b/Mage/src/main/java/mage/constants/AbilityType.java index b0956e98ecd..3c169432beb 100644 --- a/Mage/src/main/java/mage/constants/AbilityType.java +++ b/Mage/src/main/java/mage/constants/AbilityType.java @@ -12,7 +12,8 @@ public enum AbilityType { TRIGGERED("Triggered", false), EVASION("Evasion", false), LOYALTY("Loyalty", false), - SPECIAL_ACTION("Special Action", false); + SPECIAL_ACTION("Special Action", false), + SPECIAL_MANA_PAYMENT("Special Mana Payment", false); // No activated ability and no special action. (e.g. Improvise, Delve) private final String text; private final boolean playCardAbility; diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index e5d26b2e924..ca94de2b0a1 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -156,12 +156,18 @@ public class GameEvent implements Serializable { sourceId sourceId of the object with that ability playerId player that tries to use this ability */ - TAKE_SPECIAL_ACTION, TAKEN_SPECIAL_ACTION, // not used in implementation yet + TAKE_SPECIAL_ACTION, TAKEN_SPECIAL_ACTION, /* TAKE_SPECIAL_ACTION, TAKEN_SPECIAL_ACTION, targetId id of the ability to activate / use sourceId sourceId of the object with that ability playerId player that tries to use this ability */ + TAKE_SPECIAL_MANA_PAYMENT, TAKEN_SPECIAL_MANA_PAYMENT, + /* TAKE_SPECIAL_MANA_PAYMENT, TAKEN_SPECIAL_MANA_PAYMENT + targetId id of the ability to activate / use + sourceId sourceId of the object with that ability + playerId player that tries to use this ability + */ TRIGGERED_ABILITY, RESOLVING_ABILITY, COPY_STACKOBJECT, COPIED_STACKOBJECT, diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 4ad40a4dff7..3c7ed7c5853 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -1378,11 +1378,11 @@ public abstract class PlayerImpl implements Player, Serializable { protected boolean specialAction(SpecialAction action, Game game) { //20091005 - 114 - if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY, + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TAKE_SPECIAL_ACTION, action.getId(), action.getSourceId(), getId()))) { int bookmark = game.bookmarkState(); if (action.activate(game, false)) { - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.TAKEN_SPECIAL_ACTION, action.getId(), action.getSourceId(), getId())); if (!game.isSimulation()) { game.informPlayers(getLogName() + action.getGameLogMessage(game)); @@ -1397,7 +1397,29 @@ public abstract class PlayerImpl implements Player, Serializable { } return false; } - + + protected boolean specialManaPayment(SpecialAction action, Game game) { + //20091005 - 114 + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TAKE_SPECIAL_MANA_PAYMENT, + action.getId(), action.getSourceId(), getId()))) { + int bookmark = game.bookmarkState(); + if (action.activate(game, false)) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.TAKEN_SPECIAL_MANA_PAYMENT, + action.getId(), action.getSourceId(), getId())); + if (!game.isSimulation()) { + game.informPlayers(getLogName() + action.getGameLogMessage(game)); + } + if (action.resolve(game)) { + game.removeBookmark(bookmark); + resetStoredBookmark(game); + return true; + } + } + restoreState(bookmark, action.getRule(), game); + } + return false; + } + @Override public boolean activateAbility(ActivatedAbility ability, Game game) { if (ability == null) { @@ -1445,6 +1467,9 @@ public abstract class PlayerImpl implements Player, Serializable { case SPECIAL_ACTION: result = specialAction((SpecialAction) ability.copy(), game); break; + case SPECIAL_MANA_PAYMENT: + result = specialManaPayment((SpecialAction) ability.copy(), game); + break; case MANA: result = playManaAbility((ActivatedManaAbilityImpl) ability.copy(), game); break;