From 227143aacf00f23da3f34b3f3d58927557b02c77 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 4 Feb 2017 14:24:30 +0100 Subject: [PATCH] * Entwine - Fixed that for spells cast without mana costs entwine could wrongly be used for free. --- .../main/java/mage/abilities/AbilityImpl.java | 5 +++- Mage/src/main/java/mage/abilities/Modes.java | 12 +++++++- .../OptionalAdditionalModeSourceCosts.java | 6 ++-- .../abilities/keyword/EntwineAbility.java | 29 ++++++++++++------- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index a259bee667..7b2067a01b 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -30,7 +30,6 @@ package mage.abilities; import java.util.ArrayList; import java.util.List; import java.util.UUID; - import mage.MageObject; import mage.MageObjectReference; import mage.Mana; @@ -39,6 +38,7 @@ import mage.abilities.costs.AlternativeSourceCosts; import mage.abilities.costs.Cost; import mage.abilities.costs.Costs; import mage.abilities.costs.CostsImpl; +import mage.abilities.costs.OptionalAdditionalModeSourceCosts; import mage.abilities.costs.OptionalAdditionalSourceCosts; import mage.abilities.costs.VariableCost; import mage.abilities.costs.common.TapSourceCost; @@ -284,6 +284,9 @@ public abstract class AbilityImpl implements Ability { this.getManaCostsToPay().clear(); } } + if (modes.getAdditionalCost() != null) { + ((OptionalAdditionalModeSourceCosts) modes.getAdditionalCost()).addOptionalAdditionalModeCosts(this, game); + } // 20130201 - 601.2b // If the spell has alternative or additional costs that will be paid as it's being cast such // as buyback, kicker, or convoke costs (see rules 117.8 and 117.9), the player announces his diff --git a/Mage/src/main/java/mage/abilities/Modes.java b/Mage/src/main/java/mage/abilities/Modes.java index a10edeba12..7fc169dfd9 100644 --- a/Mage/src/main/java/mage/abilities/Modes.java +++ b/Mage/src/main/java/mage/abilities/Modes.java @@ -56,6 +56,7 @@ public class Modes extends LinkedHashMap { private boolean eachModeMoreThanOnce; // each mode can be selected multiple times during one choice private boolean eachModeOnlyOnce; // state if each mode can be chosen only once as long as the source object exists private final LinkedHashMap duplicateModes = new LinkedHashMap<>(); + private OptionalAdditionalModeSourceCosts optionalAdditionalModeSourceCosts = null; // only set if costs have to be paid public Modes() { this.currentMode = new Mode(); @@ -87,6 +88,7 @@ public class Modes extends LinkedHashMap { this.modeChooser = modes.modeChooser; this.eachModeOnlyOnce = modes.eachModeOnlyOnce; this.eachModeMoreThanOnce = modes.eachModeMoreThanOnce; + this.optionalAdditionalModeSourceCosts = modes.optionalAdditionalModeSourceCosts; } public Modes copy() { @@ -186,7 +188,7 @@ public class Modes extends LinkedHashMap { if (card != null) { for (Ability modeModifyingAbility : card.getAbilities()) { if (modeModifyingAbility instanceof OptionalAdditionalModeSourceCosts) { - ((OptionalAdditionalModeSourceCosts) modeModifyingAbility).addOptionalAdditionalModeCosts(source, game); + ((OptionalAdditionalModeSourceCosts) modeModifyingAbility).changeModes(source, game); } } } @@ -385,4 +387,12 @@ public class Modes extends LinkedHashMap { this.eachModeMoreThanOnce = eachModeMoreThanOnce; } + public OptionalAdditionalModeSourceCosts getAdditionalCost() { + return optionalAdditionalModeSourceCosts; + } + + public void setAdditionalCost(OptionalAdditionalModeSourceCosts optionalAdditionalModeSourceCosts) { + this.optionalAdditionalModeSourceCosts = optionalAdditionalModeSourceCosts; + } + } diff --git a/Mage/src/main/java/mage/abilities/costs/OptionalAdditionalModeSourceCosts.java b/Mage/src/main/java/mage/abilities/costs/OptionalAdditionalModeSourceCosts.java index e9c73f797c..b0dc7599e5 100644 --- a/Mage/src/main/java/mage/abilities/costs/OptionalAdditionalModeSourceCosts.java +++ b/Mage/src/main/java/mage/abilities/costs/OptionalAdditionalModeSourceCosts.java @@ -34,9 +34,11 @@ import mage.game.Game; * * @author LevelX2 */ - - public interface OptionalAdditionalModeSourceCosts { + void addOptionalAdditionalModeCosts(Ability ability, Game game); + + void changeModes(Ability ability, Game game); + String getCastMessageSuffix(); } diff --git a/Mage/src/main/java/mage/abilities/keyword/EntwineAbility.java b/Mage/src/main/java/mage/abilities/keyword/EntwineAbility.java index c98c6334ec..27d7c37b41 100644 --- a/Mage/src/main/java/mage/abilities/keyword/EntwineAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/EntwineAbility.java @@ -105,22 +105,17 @@ public class EntwineAbility extends StaticAbility implements OptionalAdditionalM } @Override - public void addOptionalAdditionalModeCosts(Ability ability, Game game) { + public void changeModes(Ability ability, Game game) { if (ability instanceof SpellAbility) { Player player = game.getPlayer(controllerId); if (player != null) { this.resetCosts(); if (additionalCost != null) { - if (player.chooseUse(Outcome.Benefit, "Pay " + additionalCost.getText(false) + " ?", ability, game)) { + if (additionalCost.canPay(ability, ability.getSourceId(), ability.getControllerId(), game) + && player.chooseUse(Outcome.Benefit, "Pay " + additionalCost.getText(false) + " ?", ability, game)) { + additionalCost.activate(); - for (Iterator it = ((Costs) additionalCost).iterator(); it.hasNext();) { - Cost cost = (Cost) it.next(); - if (cost instanceof ManaCostsImpl) { - ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy()); - } else { - ability.getCosts().add(cost.copy()); - } - } + ability.getModes().setAdditionalCost(this); ability.getModes().setMinModes(2); ability.getModes().setMaxModes(2); } @@ -129,6 +124,20 @@ public class EntwineAbility extends StaticAbility implements OptionalAdditionalM } } + @Override + public void addOptionalAdditionalModeCosts(Ability ability, Game game) { + if (additionalCost.isActivated()) { + for (Iterator it = ((Costs) additionalCost).iterator(); it.hasNext();) { + Cost cost = (Cost) it.next(); + if (cost instanceof ManaCostsImpl) { + ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy()); + } else { + ability.getCosts().add(cost.copy()); + } + } + } + } + @Override public String getRule() { StringBuilder sb = new StringBuilder();