[THS] Fixed Training Grounds. Issue #110

This commit is contained in:
Plopman 2013-09-19 13:30:40 +02:00
parent 128bc3cafa
commit 971d54e9aa

View file

@ -28,25 +28,24 @@
package mage.sets.riseoftheeldrazi; package mage.sets.riseoftheeldrazi;
import java.util.List; import java.util.LinkedHashSet;
import java.util.UUID; import java.util.UUID;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.CostModificationEffectImpl;
import mage.cards.CardImpl;
import mage.choices.ChoiceImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player;
/** /**
* *
@ -59,7 +58,7 @@ public class TrainingGrounds extends CardImpl<TrainingGrounds> {
this.expansionSetCode = "ROE"; this.expansionSetCode = "ROE";
this.color.setBlue(true); this.color.setBlue(true);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new TrainingGroundsCostReductionEffect())); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new TrainingGroundsEffect()));
} }
public TrainingGrounds (final TrainingGrounds card) { public TrainingGrounds (final TrainingGrounds card) {
@ -72,61 +71,65 @@ public class TrainingGrounds extends CardImpl<TrainingGrounds> {
} }
} }
class TrainingGroundsCostReductionEffect extends ContinuousEffectImpl<TrainingGroundsCostReductionEffect> { class TrainingGroundsEffect extends CostModificationEffectImpl<TrainingGroundsEffect> {
private static final String effectText = "Activated abilities of creatures you control cost up to {2} less to activate. This effect can't reduce the amount of mana an ability costs to activate to less than one mana"; private static final String effectText = "Activated abilities of creatures you control cost up to {2} less to activate. This effect can't reduce the amount of mana an ability costs to activate to less than one mana";
private static final FilterControlledCreaturePermanent filter; private static final FilterControlledCreaturePermanent filter;
static { static {
filter = new FilterControlledCreaturePermanent(); filter = new FilterControlledCreaturePermanent();
} }
TrainingGroundsCostReductionEffect ( ) { public TrainingGroundsEffect() {
super(Duration.WhileOnBattlefield, Layer.TextChangingEffects_3, SubLayer.NA, Outcome.Benefit); super(Duration.Custom, Outcome.Benefit);
staticText = effectText; staticText = effectText;
} }
TrainingGroundsCostReductionEffect ( TrainingGroundsCostReductionEffect effect ) { public TrainingGroundsEffect(final TrainingGroundsEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source, Ability abilityToModify) {
boolean applied = false; Mana mana = abilityToModify.getManaCostsToPay().getMana();
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game); int reduceMax = mana.getColorless();
if(mana.count() == mana.getColorless()){
if ( permanents != null && !permanents.isEmpty() ) { reduceMax--;
for ( Permanent permanent : permanents ) { }
for ( Ability ability : permanent.getAbilities() ) { if(reduceMax > 2){
if ( !(ability instanceof SpellAbility) && ability.getManaCosts() != null ) { reduceMax = 2;
int costCount = ability.getManaCosts().size(); }
for ( Cost cost : ability.getManaCosts() ) { Player player = game.getPlayer(abilityToModify.getControllerId());
if ( cost instanceof GenericManaCost ) { if(player != null){
GenericManaCost costCasted = (GenericManaCost)cost; ChoiceImpl choice = new ChoiceImpl(true);
int amount = costCasted.convertedManaCost(); LinkedHashSet<String> set = new LinkedHashSet<String>();
int adjustedAmount = 0;
if ( costCount == 1 && (amount - 2) <= 0 ) { for(int i = 0; i <= reduceMax; i++){
adjustedAmount = 1; set.add(String.valueOf(i));
} }
else { choice.setChoices(set);
//In case the adjusted amount goes below 0. choice.setMessage("Reduce ability cost");
adjustedAmount = Math.max(0, amount - 2); if(player.choose(Outcome.Benefit, choice, game)){
} int reduce = Integer.parseInt(choice.getChoice());
costCasted.setMana(adjustedAmount); mana.setColorless(mana.getColorless() - reduce);
applied = true; abilityToModify.getManaCostsToPay().load(mana.toString());
} return true;
}
}
}
} }
} }
return false;
return applied;
} }
@Override @Override
public TrainingGroundsCostReductionEffect copy() { public boolean applies(Ability abilityToModify, Ability source, Game game) {
return new TrainingGroundsCostReductionEffect(this); //Activated abilities of creatures you control
Permanent permanent = game.getPermanent(abilityToModify.getSourceId());
if (abilityToModify instanceof ActivatedAbility && permanent != null && filter.match(permanent, source.getId(), source.getControllerId(), game)) {
return true;
}
return false;
} }
} @Override
public TrainingGroundsEffect copy() {
return new TrainingGroundsEffect(this);
}
}