fix for issue 210 was causing issues for AI's - added getX() utility method instead

This commit is contained in:
BetaSteward 2011-08-22 13:39:44 -04:00
parent b2d9b467ef
commit 37819c5088
23 changed files with 52 additions and 48 deletions

View file

@ -84,11 +84,7 @@ class MartialCoupEffect extends OneShotEffect<MartialCoupEffect> {
@Override
public boolean apply(Game game, Ability source) {
int amount = 0;
if (source.getManaCostsToPay().getVariableCosts().size() > 0) {
amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
}
int amount = source.getManaCostsToPay().getX();
if (amount > 4) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), source.getControllerId(), game)) {
permanent.destroy(source.getSourceId(), game, false);

View file

@ -88,7 +88,7 @@ class ConsumeSpiritEffect extends OneShotEffect<ConsumeSpiritEffect> {
@Override
public boolean apply(Game game, Ability source) {
int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int damage = source.getManaCostsToPay().getX();
if (damage > 0) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(source));
if (permanent != null) {

View file

@ -89,8 +89,7 @@ class EarthquakeEffect extends OneShotEffect<EarthquakeEffect> {
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
permanent.damage(amount, source.getId(), game, true, false);
}

View file

@ -87,7 +87,7 @@ class FireballEffect extends OneShotEffect<FireballEffect> {
@Override
public boolean apply(Game game, Ability source) {
int numTargets = source.getTargets().get(0).getTargets().size();
int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int damage = source.getManaCostsToPay().getX();
if (numTargets > 0) {
int damagePer = damage/numTargets;
if (damagePer > 0) {

View file

@ -80,7 +80,7 @@ class MindSpringEffect extends OneShotEffect<MindSpringEffect> {
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.drawCards(amount, game);

View file

@ -93,8 +93,8 @@ public class ProteanHydra extends CardImpl<ProteanHydra> {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && source.getManaCostsToPay().getVariableCosts().size() > 0) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
if (permanent != null && amount > 0) {
permanent.addCounters(CounterType.P1P1.createInstance(amount), game);
}
return true;

View file

@ -98,8 +98,7 @@ class VengefulArchonEffect extends PreventionEffectImpl<VengefulArchonEffect> {
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (source.getManaCostsToPay().getVariableCosts().size() > 0)
amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
amount = source.getManaCostsToPay().getX();
}
@Override

View file

@ -38,11 +38,8 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.HasCounterCondition;
import mage.abilities.decorator.ConditionalContinousEffect;
import mage.abilities.decorator.ConditionalStaticAbility;
import mage.abilities.dynamicvalue.common.CountersCount;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continious.GainAbilitySourceEffect;
import mage.abilities.keyword.TrampleAbility;
@ -96,7 +93,7 @@ class PrimordialHydraEntersEffect extends OneShotEffect<PrimordialHydraEntersEff
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
p.addCounters(CounterType.P1P1.createInstance(amount), game);

View file

@ -78,7 +78,7 @@ class BlackSunsZenithEffect extends OneShotEffect<BlackSunsZenithEffect> {
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) {
permanent.addCounters(CounterType.M1M1.createInstance(amount), game);

View file

@ -87,7 +87,7 @@ class GreenSunsZenithSearchEffect extends OneShotEffect<GreenSunsZenithSearchEff
filter.setUseColor(true);
filter.getCardType().add(CardType.CREATURE);
//Set the mana cost one higher to 'emulate' a less than or equal to comparison.
filter.setConvertedManaCost(source.getManaCostsToPay().getVariableCosts().get(0).getAmount() + 1);
filter.setConvertedManaCost(source.getManaCostsToPay().getX() + 1);
filter.setConvertedManaCostComparison(ComparisonType.LessThan);
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (player.searchLibrary(target, game)) {

View file

@ -91,7 +91,7 @@ class ChimericMassEffect extends OneShotEffect<ChimericMassEffect> {
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
p.addCounters(CounterType.CHARGE.createInstance(amount), game);

View file

@ -77,7 +77,7 @@ class ExsanguinateEffect extends OneShotEffect<ExsanguinateEffect> {
@Override
public boolean apply(Game game, Ability source) {
int loseLife = 0;
int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int damage = source.getManaCostsToPay().getX();
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
loseLife += game.getPlayer(opponentId).loseLife(damage, game);
}

View file

@ -83,7 +83,7 @@ class GenesisWaveEffect extends OneShotEffect<GenesisWaveEffect> {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards cards = new CardsImpl(Zone.PICK);
int count = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int count = source.getManaCostsToPay().getX();
for (int i = 0; i < count; i++) {
Card card = player.getLibrary().removeFromTop(game);
cards.add(card);

View file

@ -143,7 +143,7 @@ class MyrBattlesphereEffect extends OneShotEffect<MyrBattlesphereEffect> {
UUID defenderId = game.getCombat().getDefendingPlayer(source.getSourceId());
Player defender = game.getPlayer(defenderId);
if (defender != null) {
defender.damage(source.getManaCostsToPay().getVariableCosts().get(0).getAmount(), source.getSourceId(), game, false, false);
defender.damage(source.getManaCostsToPay().getX(), source.getSourceId(), game, false, false);
return true;
}
return false;

View file

@ -101,7 +101,7 @@ class SteelHellkiteDestroyEffect extends OneShotEffect {
SteelHellkiteWatcher watcher = (SteelHellkiteWatcher) game.getState().getWatchers().get(source.getControllerId(), "SteelHellkiteWatcher");
if (watcher != null && watcher.damagedPlayers.containsKey(source.getSourceId())) {
Set<UUID> players = watcher.damagedPlayers.get(source.getSourceId());
int xValue = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int xValue = source.getManaCostsToPay().getX();
for (UUID uuid : players) {
for (Permanent permanent: game.getBattlefield().getAllActivePermanents()) {
if (permanent.getControllerId().equals(uuid) && permanent.getManaCost().convertedManaCost() == xValue) {

View file

@ -93,7 +93,7 @@ class FlameblastDragonEffect extends OneShotEffect<FlameblastDragonEffect> {
if (player.chooseUse(Constants.Outcome.Damage, "Pay " + cost.getText() + "? If you do, Flameblast Dragon deals X damage to target creature or player", game)) {
cost.clearPaid();
if (cost.pay(source, game, source.getId(), source.getControllerId(), false)) {
int costX = ((VariableCost) cost.getVariableCosts().get(0)).getAmount();
int costX = cost.getX();
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
permanent.damage(costX, source.getId(), game, true, false);

View file

@ -84,7 +84,7 @@ class SigilOfDistinctionEffect extends OneShotEffect<SigilOfDistinctionEffect> {
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
p.addCounters(CounterType.CHARGE.createInstance(amount), game);

View file

@ -40,8 +40,12 @@ public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
public ManaCosts<T> getUnpaidVariableCosts();
public List<VariableCost> getVariableCosts();
public int getX();
public void load(String mana);
public List<String> getSymbols();
@Override
public Mana getMana();
@Override

View file

@ -146,6 +146,8 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
return unpaid;
}
@Override
public List<VariableCost> getVariableCosts() {
List<VariableCost> variableCosts = new ArrayList<VariableCost>();
@ -153,13 +155,22 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
if (cost instanceof VariableCost)
variableCosts.add((VariableCost) cost);
}
if (variableCosts.size() == 0) {
// add empty cost (#Issue 210)
variableCosts.add(new VariableManaCost());
}
// if (variableCosts.size() == 0) {
// // add empty cost (#Issue 210)
// variableCosts.add(new VariableManaCost());
// }
return variableCosts;
}
@Override
public int getX() {
int amount = 0;
List<VariableCost> variableCosts = getVariableCosts();
if (!variableCosts.isEmpty())
amount = variableCosts.get(0).getAmount();
return amount;
}
@Override
public void setPayment(Mana mana) {
}

View file

@ -7,7 +7,7 @@ import mage.game.Game;
public class ManacostVariableValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility) {
return sourceAbility.getManaCostsToPay().getVariableCosts().get(0).getAmount();
return sourceAbility.getManaCostsToPay().getX();
}
@Override

View file

@ -57,7 +57,7 @@ public class DamageXTargetEffect extends OneShotEffect<DamageXTargetEffect> {
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
int amount = source.getManaCostsToPay().getX();
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
permanent.damage(amount, source.getId(), game, true, false);

View file

@ -61,14 +61,14 @@ public class BoostPowerToughnessXTargetEffect extends ContinuousEffectImpl<Boost
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
if (amount == 0) {
int amountX = source.getManaCostsToPay().getX();
if (amountX == 0) {
return false;
}
Permanent target = game.getPermanent(source.getFirstTarget());
if (target != null) {
target.addPower(amount);
target.addToughness(amount);
target.addPower(amountX);
target.addToughness(amountX);
return true;
}
return false;

View file

@ -64,17 +64,15 @@ public class BoostPowerXSourceEffect extends ContinuousEffectImpl<BoostPowerXSou
@Override
public boolean apply(Game game, Ability source) {
if (source.getManaCostsToPay().getVariableCosts().size() > 0) {
int amountX = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
if (amountX == 0) {
return false;
}
Permanent target = (Permanent) game.getPermanent(source.getSourceId());
if (target != null) {
target.addPower(amountX);
return true;
}
}
int amountX = source.getManaCostsToPay().getX();
if (amountX == 0) {
return false;
}
Permanent target = (Permanent) game.getPermanent(source.getSourceId());
if (target != null) {
target.addPower(amountX);
return true;
}
return false;
}