diff --git a/Mage/src/main/java/mage/abilities/AbilitiesImpl.java b/Mage/src/main/java/mage/abilities/AbilitiesImpl.java index bec3cc96ef..3cee96563b 100644 --- a/Mage/src/main/java/mage/abilities/AbilitiesImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilitiesImpl.java @@ -24,8 +24,7 @@ * 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.abilities; import java.util.ArrayList; @@ -35,7 +34,6 @@ import java.util.Iterator; import java.util.List; import java.util.UUID; import mage.abilities.common.ZoneChangeTriggeredAbility; -import mage.abilities.costs.AlternativeCost; import mage.abilities.costs.Cost; import mage.abilities.keyword.ProtectionAbility; import mage.abilities.mana.ManaAbility; @@ -52,15 +50,16 @@ public class AbilitiesImpl extends ArrayList implements Ab private static final ThreadLocalStringBuilder threadLocalBuilder = new ThreadLocalStringBuilder(200); - public AbilitiesImpl() {} + public AbilitiesImpl() { + } public AbilitiesImpl(T... abilities) { addAll(Arrays.asList(abilities)); } public AbilitiesImpl(final AbilitiesImpl abilities) { - for (T ability: abilities) { - this.add((T)ability.copy()); + for (T ability : abilities) { + this.add((T) ability.copy()); } } @@ -73,7 +72,7 @@ public class AbilitiesImpl extends ArrayList implements Ab public List getRules(String source) { List rules = new ArrayList<>(); - for (T ability:this) { + for (T ability : this) { if (!ability.getRuleVisible()) { continue; } @@ -90,23 +89,9 @@ public class AbilitiesImpl extends ArrayList implements Ab continue; } if (ability instanceof SpellAbility) { - if (ability.getAlternativeCosts().size() > 0) { - StringBuilder sbRule = threadLocalBuilder.get(); - for (AlternativeCost cost: ability.getAlternativeCosts()) { - if (cost.getClass().getName().equals("mage.abilities.costs.AlternativeCostImpl")) - { // if the template class is used, the rule is in the getName() instead in the getText() - sbRule.append(cost.getName()).append(".
"); - } - else - { - sbRule.append(cost.getText()).append(".
"); - } - } - rules.add(sbRule.toString()); - } if (ability.getAdditionalCostsRuleVisible() && ability.getCosts().size() > 0) { StringBuilder sbRule = threadLocalBuilder.get(); - for (Cost cost: ability.getCosts()) { + for (Cost cost : ability.getCosts()) { if (cost.getText() != null && !cost.getText().isEmpty()) { if (!cost.getText().startsWith("As an additional cost")) { sbRule.append("As an additional cost to cast {this}, "); @@ -118,9 +103,9 @@ public class AbilitiesImpl extends ArrayList implements Ab } String rule = ability.getRule(); if (rule.length() > 0) { - rules.add(Character.toUpperCase(rule.charAt(0)) + rule.substring(1)); - } - } + rules.add(Character.toUpperCase(rule.charAt(0)) + rule.substring(1)); + } + } } return rules; @@ -129,9 +114,9 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getActivatedAbilities(Zone zone) { Abilities zonedAbilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if (ability instanceof ActivatedAbility && ability.getZone().match(zone)) { - zonedAbilities.add((ActivatedAbility)ability); + zonedAbilities.add((ActivatedAbility) ability); } } return zonedAbilities; @@ -140,10 +125,10 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getPlayableAbilities(Zone zone) { Abilities zonedAbilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if ((ability instanceof ActivatedAbility || (ability instanceof PlayLandAbility)) && ability.getZone().match(zone)) { - zonedAbilities.add((ActivatedAbility)ability); + zonedAbilities.add((ActivatedAbility) ability); } } return zonedAbilities; @@ -152,9 +137,9 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getManaAbilities(Zone zone) { Abilities abilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if (ability instanceof ManaAbility && ability.getZone().match(zone)) { - abilities.add((ManaAbility)ability); + abilities.add((ManaAbility) ability); } } return abilities; @@ -163,10 +148,10 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getAvailableManaAbilities(Zone zone, Game game) { Abilities abilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if (ability instanceof ManaAbility && ability.getZone().match(zone)) { - if ((((ManaAbility)ability).canActivate(ability.getControllerId(), game))) { - abilities.add((ManaAbility)ability); + if ((((ManaAbility) ability).canActivate(ability.getControllerId(), game))) { + abilities.add((ManaAbility) ability); } } } @@ -176,9 +161,9 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getEvasionAbilities() { Abilities abilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if (ability instanceof EvasionAbility) { - abilities.add((EvasionAbility)ability); + abilities.add((EvasionAbility) ability); } } return abilities; @@ -187,9 +172,9 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getStaticAbilities(Zone zone) { Abilities zonedAbilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if (ability instanceof StaticAbility && ability.getZone().match(zone)) { - zonedAbilities.add((StaticAbility)ability); + zonedAbilities.add((StaticAbility) ability); } } return zonedAbilities; @@ -198,14 +183,13 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getTriggeredAbilities(Zone zone) { Abilities zonedAbilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if (ability instanceof TriggeredAbility && ability.getZone().match(zone)) { - zonedAbilities.add((TriggeredAbility)ability); - } - else if (ability instanceof ZoneChangeTriggeredAbility) { - ZoneChangeTriggeredAbility zcAbility = (ZoneChangeTriggeredAbility)ability; + zonedAbilities.add((TriggeredAbility) ability); + } else if (ability instanceof ZoneChangeTriggeredAbility) { + ZoneChangeTriggeredAbility zcAbility = (ZoneChangeTriggeredAbility) ability; if (zcAbility.getToZone() != null && zcAbility.getToZone().match(zone)) { - zonedAbilities.add((ZoneChangeTriggeredAbility)ability); + zonedAbilities.add((ZoneChangeTriggeredAbility) ability); } } } @@ -215,9 +199,9 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getProtectionAbilities() { Abilities abilities = new AbilitiesImpl<>(); - for (T ability: this) { + for (T ability : this) { if (ability instanceof ProtectionAbility) { - abilities.add((ProtectionAbility)ability); + abilities.add((ProtectionAbility) ability); } } return abilities; @@ -225,28 +209,28 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public void setControllerId(UUID controllerId) { - for (Ability ability: this) { + for (Ability ability : this) { ability.setControllerId(controllerId); } } @Override public void setSourceId(UUID sourceId) { - for (Ability ability: this) { + for (Ability ability : this) { ability.setSourceId(sourceId); } } @Override public void newId() { - for (Ability ability: this) { + for (Ability ability : this) { ability.newId(); } } @Override public void newOriginalId() { - for (Ability ability: this) { + for (Ability ability : this) { ability.newOriginalId(); } } @@ -254,7 +238,7 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public boolean contains(T ability) { for (Iterator iterator = this.iterator(); iterator.hasNext();) { // simple loop can cause java.util.ConcurrentModificationException - T test = iterator.next(); + T test = iterator.next(); // Checking also by getRule() without other restrictions is a problem when a triggered ability will be copied to a permanent that had the same ability // already before the copy. Because then it keeps the triggered ability twice and it triggers twice. // e.g. 2 Biovisonary and one enchanted with Infinite Reflection @@ -273,7 +257,7 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public boolean containsRule(T ability) { - for (T test: this) { + for (T test : this) { if (ability.getRule().equals(test.getRule())) { return true; } @@ -286,7 +270,7 @@ public class AbilitiesImpl extends ArrayList implements Ab if (this.size() < abilities.size()) { return false; } - for (T ability: abilities) { + for (T ability : abilities) { if (!contains(ability)) { return false; } @@ -296,7 +280,7 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public boolean containsKey(UUID abilityId) { - for (T ability: this) { + for (T ability : this) { if (ability.getId().equals(abilityId)) { return true; } @@ -306,7 +290,7 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public boolean containsClass(Class classObject) { - for (T ability: this) { + for (T ability : this) { if (ability.getClass().equals(classObject)) { return true; } @@ -316,7 +300,7 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public T get(UUID abilityId) { - for (T ability: this) { + for (T ability : this) { if (ability.getId().equals(abilityId)) { return ability; } @@ -327,7 +311,7 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public int getOutcomeTotal() { int total = 0; - for (T ability: this) { + for (T ability : this) { total += ability.getEffects().getOutcomeTotal(); } return total; @@ -336,14 +320,14 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public String getValue() { List abilities = new ArrayList<>(); - for (T ability: this) { + for (T ability : this) { if (ability.toString() != null) { abilities.add(ability.toString()); } } Collections.sort(abilities); StringBuilder sb = threadLocalBuilder.get(); - for (String s: abilities) { + for (String s : abilities) { sb.append(s); } return sb.toString(); diff --git a/Mage/src/main/java/mage/abilities/Ability.java b/Mage/src/main/java/mage/abilities/Ability.java index c90dd52b5f..378551843e 100644 --- a/Mage/src/main/java/mage/abilities/Ability.java +++ b/Mage/src/main/java/mage/abilities/Ability.java @@ -31,7 +31,6 @@ import java.io.Serializable; import java.util.List; import java.util.UUID; import mage.MageObject; -import mage.abilities.costs.AlternativeCost; import mage.abilities.costs.Cost; import mage.abilities.costs.Costs; import mage.abilities.costs.mana.ManaCost; @@ -169,22 +168,6 @@ public interface Ability extends Controllable, Serializable { */ void addManaCost(ManaCost cost); - /** - * Gets all {@link AlternativeCost} associated with this ability. - * - * @return All {@link AlternativeCost}'s that can be paid instead of the - * {@link ManaCosts} - */ - List getAlternativeCosts(); - - /** - * Adds an {@link AlternativeCost} this ability that may be paid instead of - * any other cost. - * - * @param cost The {@link AlternativeCost} to add. - */ - void addAlternativeCost(AlternativeCost cost); - /** * TODO Method is unused, keep it around? * @@ -323,7 +306,6 @@ public interface Ability extends Controllable, Serializable { /** * Activates this ability prompting the controller to pay any mandatory - * {@link Costs} or {@link AlternativeCost} associated with this ability. * * @param game A reference the {@link Game} for which this ability should be * activated within. diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index 8b4f919f7b..90344ee1b6 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -34,7 +34,6 @@ import mage.MageObject; import mage.MageObjectReference; import mage.Mana; import mage.abilities.costs.AdjustingSourceCosts; -import mage.abilities.costs.AlternativeCost; import mage.abilities.costs.AlternativeSourceCosts; import mage.abilities.costs.Cost; import mage.abilities.costs.Costs; @@ -97,7 +96,6 @@ public abstract class AbilityImpl implements Ability { protected ManaCosts manaCosts; protected ManaCosts manaCostsToPay; protected Costs costs; - protected ArrayList alternativeCosts = new ArrayList<>(); protected Costs optionalCosts; protected Modes modes; protected Zone zone; @@ -141,9 +139,6 @@ public abstract class AbilityImpl implements Ability { this.manaCostsToPay = ability.manaCostsToPay.copy(); this.costs = ability.costs.copy(); this.optionalCosts = ability.optionalCosts.copy(); - for (AlternativeCost cost : ability.alternativeCosts) { - this.alternativeCosts.add((AlternativeCost) cost.copy()); - } if (ability.watchers != null) { this.watchers = new ArrayList<>(); for (Watcher watcher : ability.watchers) { @@ -398,12 +393,9 @@ public abstract class AbilityImpl implements Ability { activatorId = ((ActivatedAbilityImpl) this).getActivatorId(); } - if (!useAlternativeCost(game)) { // old way still used? - - //20100716 - 601.2f (noMana is not used here, because mana costs were cleared for this ability before adding additional costs and applying cost modification effects) - if (!manaCostsToPay.pay(this, game, sourceId, activatorId, false, null)) { - return false; // cancel during mana payment - } + //20100716 - 601.2f (noMana is not used here, because mana costs were cleared for this ability before adding additional costs and applying cost modification effects) + if (!manaCostsToPay.pay(this, game, sourceId, activatorId, false, null)) { + return false; // cancel during mana payment } //20100716 - 601.2g @@ -593,18 +585,6 @@ public abstract class AbilityImpl implements Ability { public void reset(Game game) { } - // Is this still needed? - protected boolean useAlternativeCost(Game game) { - for (AlternativeCost cost : alternativeCosts) { - if (cost.isAvailable(game, this)) { - if (game.getPlayer(this.controllerId).chooseUse(Outcome.Neutral, "Use alternative cost " + cost.getName(), this, game)) { - return cost.pay(this, game, sourceId, controllerId, false, null); - } - } - } - return false; - } - @Override public boolean checkIfClause(Game game) { return true; @@ -676,11 +656,6 @@ public abstract class AbilityImpl implements Ability { return manaCostsToPay; } - @Override - public List getAlternativeCosts() { - return alternativeCosts; - } - @Override public Costs getOptionalCosts() { return optionalCosts; @@ -843,13 +818,6 @@ public abstract class AbilityImpl implements Ability { } } - @Override - public void addAlternativeCost(AlternativeCost cost) { - if (cost != null) { - this.alternativeCosts.add(cost); - } - } - @Override public void addOptionalCost(Cost cost) { if (cost != null) { diff --git a/Mage/src/main/java/mage/abilities/costs/AlternativeCost.java b/Mage/src/main/java/mage/abilities/costs/AlternativeCost.java deleted file mode 100644 index c46a17a150..0000000000 --- a/Mage/src/main/java/mage/abilities/costs/AlternativeCost.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.abilities.costs; - -import mage.abilities.Ability; -import mage.game.Game; - -/** - * @author BetaSteward_at_googlemail.com - */ -public interface AlternativeCost extends Cost { - - boolean isAvailable(Game game, Ability source); - - String getName(); -} diff --git a/Mage/src/main/java/mage/abilities/costs/AlternativeCostImpl.java b/Mage/src/main/java/mage/abilities/costs/AlternativeCostImpl.java deleted file mode 100644 index 36e3d63d15..0000000000 --- a/Mage/src/main/java/mage/abilities/costs/AlternativeCostImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package mage.abilities.costs; - -import mage.abilities.Ability; -import mage.game.Game; - -public class AlternativeCostImpl extends CostsImpl implements AlternativeCost { - - protected String name; - - public AlternativeCostImpl(String name) { - this.name = name; - } - - public AlternativeCostImpl(String name, Cost cost) { - this.name = name; - this.add((T)cost); - } - - public AlternativeCostImpl(final AlternativeCostImpl cost) { - super(cost); - this.name = cost.name; - } - - @Override - public boolean isAvailable(Game game, Ability source) { - for (int x=0; x < ((Costs) this).size(); x++) { - Cost cost = (Cost) ((Costs) this).get(x); - if (!cost.canPay(source, source.getSourceId(), source.getControllerId(), game)) { - return false; - } - } - return true; - } - - @Override - public String getName() { - return this.name; - } - - @Override - public AlternativeCostImpl copy() { - return new AlternativeCostImpl(this); - } -} diff --git a/Mage/src/main/java/mage/game/stack/StackAbility.java b/Mage/src/main/java/mage/game/stack/StackAbility.java index ae46ddd1de..b9663190f3 100644 --- a/Mage/src/main/java/mage/game/stack/StackAbility.java +++ b/Mage/src/main/java/mage/game/stack/StackAbility.java @@ -40,7 +40,6 @@ import mage.abilities.MageSingleton; import mage.abilities.Mode; import mage.abilities.Modes; import mage.abilities.StateTriggeredAbility; -import mage.abilities.costs.AlternativeCost; import mage.abilities.costs.Cost; import mage.abilities.costs.Costs; import mage.abilities.costs.CostsImpl; @@ -317,15 +316,6 @@ public class StackAbility extends StackObjImpl implements Ability { public void addChoice(Choice choice) { } - @Override - public List getAlternativeCosts() { - return ability.getAlternativeCosts(); - } - - @Override - public void addAlternativeCost(AlternativeCost cost) { - } - @Override public ManaCosts getManaCosts() { return ability.getManaCosts(); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index b3cc247fb5..e33e8a5395 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -58,7 +58,6 @@ import mage.abilities.TriggeredAbility; import mage.abilities.common.PassAbility; import mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility; import mage.abilities.costs.AdjustingSourceCosts; -import mage.abilities.costs.AlternativeCost; import mage.abilities.costs.AlternativeCostSourceAbility; import mage.abilities.costs.AlternativeSourceCosts; import mage.abilities.costs.Cost; @@ -2437,7 +2436,7 @@ public abstract class PlayerImpl implements Player, Serializable { } } } - // old alternate costs + for (Ability objectAbility : sourceObject.getAbilities()) { if (objectAbility instanceof AlternativeCostSourceAbility) { if (objectAbility.getCosts().canPay(ability, ability.getSourceId(), playerId, game)) { @@ -2445,13 +2444,6 @@ public abstract class PlayerImpl implements Player, Serializable { } } } - - for (AlternativeCost cost : ability.getAlternativeCosts()) { - if (cost.isAvailable(game, ability) && cost.canPay(ability, ability.getSourceId(), playerId, game)) { - return true; - } - } - // new alternate costs if (canPlayCardByAlternateCost(card, available, ability, game)) { return true; } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index e03b1f1bde..f72da7e32e 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -29,7 +29,6 @@ package mage.util; import java.util.Arrays; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import java.util.UUID; import mage.MageObject; @@ -37,8 +36,6 @@ import mage.Mana; import mage.abilities.Ability; import mage.abilities.ActivatedAbility; import mage.abilities.SpellAbility; -import mage.abilities.costs.AlternativeCost; -import mage.abilities.costs.AlternativeCostImpl; import mage.abilities.costs.VariableCost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.HybridManaCost; @@ -151,7 +148,6 @@ public class CardUtil { */ public static void increaseCost(Ability ability, int increaseCount) { adjustAbilityCost(ability, -increaseCount); - adjustAlternativeCosts(ability, -increaseCount); } /** @@ -162,7 +158,6 @@ public class CardUtil { */ public static void reduceCost(Ability ability, int reduceCount) { adjustAbilityCost(ability, reduceCount); - adjustAlternativeCosts(ability, reduceCount); } /** @@ -173,7 +168,6 @@ public class CardUtil { */ public static void adjustCost(SpellAbility spellAbility, int reduceCount) { CardUtil.adjustAbilityCost((Ability) spellAbility, reduceCount); - adjustAlternativeCosts(spellAbility, reduceCount); } public static ManaCosts increaseCost(ManaCosts manaCosts, int increaseCount) { @@ -184,40 +178,6 @@ public class CardUtil { return adjustCost(manaCosts, reduceCount); } - private static void adjustAlternativeCosts(Ability ability, int reduceCount) { - for (AlternativeCost alternativeCost : ability.getAlternativeCosts()) { - if (alternativeCost instanceof AlternativeCostImpl) { - AlternativeCostImpl impl = (AlternativeCostImpl) alternativeCost; - ManaCosts adjustedCost = new ManaCostsImpl<>(); - boolean updated = false; - Iterator it = impl.iterator(); - while (it.hasNext()) { - Object cost = it.next(); - if (cost instanceof ManaCosts) { - for (Object object : ((ManaCosts) cost)) { - if (object instanceof ManaCost) { - ManaCost manaCost = (ManaCost) object; - Mana mana = manaCost.getOptions().get(0); - int colorless = mana != null ? mana.getGeneric() : 0; - if (!updated && colorless > 0) { - if ((colorless - reduceCount) > 0) { - int newColorless = colorless - reduceCount; - it.remove(); - adjustedCost.add(new GenericManaCost(newColorless)); - } - updated = true; - } else { - adjustedCost.add(manaCost); - } - } - } - } - } - impl.add(adjustedCost); - } - } - } - /** * Adjusts ability cost to be paid. *