mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 05:09:16 -08:00
Fixed spells with alternative casting costs.
This commit is contained in:
parent
4bd4ad3d8a
commit
02338d5e9e
16 changed files with 233 additions and 139 deletions
|
|
@ -93,9 +93,6 @@ public class ControlsPermanentCondition implements Condition {
|
|||
this.condition = conditionToDecorate;
|
||||
}
|
||||
|
||||
/*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean conditionApplies = false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* 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.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.predicate.permanent.ControllerPredicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class OpponentControlsPermanentCondition implements Condition {
|
||||
|
||||
public static enum CountType { MORE_THAN, FEWER_THAN, EQUAL_TO };
|
||||
private FilterPermanent filter;
|
||||
private Condition condition;
|
||||
private CountType type;
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* Applies a filter and delegates creation to
|
||||
* {@link #ControlsPermanent(mage.filter.FilterPermanent, mage.abilities.condition.common.ControlsPermanent.CountType, int)}
|
||||
* with {@link CountType#MORE_THAN}, and 0.
|
||||
*
|
||||
* @param filter
|
||||
*/
|
||||
public OpponentControlsPermanentCondition(FilterPermanent filter) {
|
||||
this(filter, CountType.MORE_THAN, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a filter, a {@link CountType}, and count to permanents on the
|
||||
* battlefield when checking the condition during the
|
||||
* {@link #apply(mage.game.Game, mage.abilities.Ability) apply} method invocation.
|
||||
*
|
||||
* @param filter
|
||||
* @param type
|
||||
* @param count
|
||||
*/
|
||||
public OpponentControlsPermanentCondition ( FilterPermanent filter, CountType type, int count ) {
|
||||
this.filter = filter;
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a filter, a {@link CountType}, and count to permanents on the
|
||||
* battlefield and calls the decorated condition to see if it
|
||||
* {@link #apply(mage.game.Game, mage.abilities.Ability) applies}
|
||||
* as well. This will force both conditions to apply for this to be true.
|
||||
*
|
||||
* @param filter
|
||||
* @param type
|
||||
* @param count
|
||||
* @param conditionToDecorate
|
||||
*/
|
||||
public OpponentControlsPermanentCondition ( FilterPermanent filter, CountType type, int count, Condition conditionToDecorate ) {
|
||||
this(filter, type, count);
|
||||
this.condition = conditionToDecorate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean conditionApplies = false;
|
||||
|
||||
FilterPermanent localFilter = filter.copy();
|
||||
localFilter.add(new ControllerPredicate(TargetController.OPPONENT));
|
||||
|
||||
switch ( this.type ) {
|
||||
case FEWER_THAN:
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) < this.count;
|
||||
break;
|
||||
case MORE_THAN:
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) > this.count;
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) == this.count;
|
||||
break;
|
||||
}
|
||||
|
||||
//If a decorated condition exists, check it as well and apply them together.
|
||||
if ( this.condition != null ) {
|
||||
conditionApplies = conditionApplies && this.condition.apply(game, source);
|
||||
}
|
||||
|
||||
return conditionApplies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return filter.getMessage();
|
||||
}
|
||||
}
|
||||
|
|
@ -72,8 +72,10 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
|
|||
}
|
||||
|
||||
private void convertToAlternativeCostAndAdd(Cost cost) {
|
||||
AlternativeCost2 alternativeCost = new AlternativeCost2Impl(null, null, cost);
|
||||
this.alternateCosts.add(alternativeCost);
|
||||
if (cost != null) {
|
||||
AlternativeCost2 alternativeCost = new AlternativeCost2Impl(null, null, cost);
|
||||
this.alternateCosts.add(alternativeCost);
|
||||
}
|
||||
}
|
||||
|
||||
public AlternativeCostSourceAbility(final AlternativeCostSourceAbility ability) {
|
||||
|
|
@ -141,7 +143,7 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
|
|||
if (rule != null) {
|
||||
return rule;
|
||||
}
|
||||
// If you control a Swamp, you may pay 4 life rather than pay Snuff Out's mana cost.
|
||||
// you may cast Massacre without paying its mana cost.
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (condition != null) {
|
||||
sb.append(condition.toString());
|
||||
|
|
@ -157,15 +159,24 @@ public class AlternativeCostSourceAbility extends StaticAbility<AlternativeCostS
|
|||
String remarkText = "";
|
||||
for (AlternativeCost2 alternativeCost : alternateCosts) {
|
||||
if (numberCosts == 0) {
|
||||
if (alternativeCost instanceof ManaCostsImpl) {
|
||||
sb.append("pay ");
|
||||
}
|
||||
sb.append(alternativeCost.getText(false));
|
||||
remarkText = alternativeCost.getReminderText();
|
||||
} else {
|
||||
sb.append(" and ").append(alternativeCost.getText(true));
|
||||
sb.append(" and ");
|
||||
if (alternativeCost instanceof ManaCostsImpl) {
|
||||
sb.append("pay ");
|
||||
}
|
||||
sb.append(alternativeCost.getText(true));
|
||||
}
|
||||
++numberCosts;
|
||||
}
|
||||
if (condition == null || alternateCosts.size() == 1) {
|
||||
sb.append(" rather than pay {source}'s mana cost");
|
||||
} else if (alternateCosts.isEmpty()) {
|
||||
sb.append("cast {this} without paying its mana cost");
|
||||
}
|
||||
sb.append(".");
|
||||
if (numberCosts == 1 && remarkText != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue