mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
[THS] Fixed Training Grounds. Issue #110
This commit is contained in:
parent
128bc3cafa
commit
971d54e9aa
1 changed files with 52 additions and 49 deletions
|
@ -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()){
|
||||||
|
reduceMax--;
|
||||||
|
}
|
||||||
|
if(reduceMax > 2){
|
||||||
|
reduceMax = 2;
|
||||||
|
}
|
||||||
|
Player player = game.getPlayer(abilityToModify.getControllerId());
|
||||||
|
if(player != null){
|
||||||
|
ChoiceImpl choice = new ChoiceImpl(true);
|
||||||
|
LinkedHashSet<String> set = new LinkedHashSet<String>();
|
||||||
|
|
||||||
if ( permanents != null && !permanents.isEmpty() ) {
|
for(int i = 0; i <= reduceMax; i++){
|
||||||
for ( Permanent permanent : permanents ) {
|
set.add(String.valueOf(i));
|
||||||
for ( Ability ability : permanent.getAbilities() ) {
|
|
||||||
if ( !(ability instanceof SpellAbility) && ability.getManaCosts() != null ) {
|
|
||||||
int costCount = ability.getManaCosts().size();
|
|
||||||
for ( Cost cost : ability.getManaCosts() ) {
|
|
||||||
if ( cost instanceof GenericManaCost ) {
|
|
||||||
GenericManaCost costCasted = (GenericManaCost)cost;
|
|
||||||
int amount = costCasted.convertedManaCost();
|
|
||||||
int adjustedAmount = 0;
|
|
||||||
if ( costCount == 1 && (amount - 2) <= 0 ) {
|
|
||||||
adjustedAmount = 1;
|
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue