mirror of
https://github.com/correl/mage.git
synced 2025-01-13 19:11:33 +00:00
Changes to some X spells because adjustTargets works now for X spells of AI. By the way cost reduction of X spells for the AI should work now also.
This commit is contained in:
parent
fab532cdb6
commit
b9257fffae
3 changed files with 108 additions and 97 deletions
|
@ -27,18 +27,15 @@
|
||||||
*/
|
*/
|
||||||
package mage.sets.gatecrash;
|
package mage.sets.gatecrash;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Outcome;
|
|
||||||
import mage.Constants.Rarity;
|
import mage.Constants.Rarity;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.SpellAbility;
|
||||||
|
import mage.abilities.effects.common.TapTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.filter.FilterPermanent;
|
|
||||||
import mage.filter.common.FilterNonlandPermanent;
|
import mage.filter.common.FilterNonlandPermanent;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +43,7 @@ import mage.target.TargetPermanent;
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
*/
|
*/
|
||||||
public class Gridlock extends CardImpl<Gridlock> {
|
public class Gridlock extends CardImpl<Gridlock> {
|
||||||
|
private static final FilterNonlandPermanent filter = new FilterNonlandPermanent("nonland permanents");
|
||||||
|
|
||||||
public Gridlock(UUID ownerId) {
|
public Gridlock(UUID ownerId) {
|
||||||
super(ownerId, 36, "Gridlock", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{X}{U}");
|
super(ownerId, 36, "Gridlock", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{X}{U}");
|
||||||
|
@ -54,56 +52,28 @@ public class Gridlock extends CardImpl<Gridlock> {
|
||||||
this.color.setBlue(true);
|
this.color.setBlue(true);
|
||||||
|
|
||||||
// Tap X target nonland permanents.
|
// Tap X target nonland permanents.
|
||||||
this.getSpellAbility().addEffect(new GridlockTapEffect());
|
this.getSpellAbility().addEffect(new TapTargetEffect());
|
||||||
// Target handling has to be changes once handling of X costs is improved, so that the targets are shown when the spell is on the stack.
|
// Correct number of targets will be set in adjustTargets
|
||||||
|
this.getSpellAbility().addTarget(new TargetPermanent(0, 1,filter, false));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gridlock(final Gridlock card) {
|
public Gridlock(final Gridlock card) {
|
||||||
super(card);
|
super(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void adjustTargets(Ability ability, Game game) {
|
||||||
|
if (ability instanceof SpellAbility) {
|
||||||
|
ability.getTargets().clear();
|
||||||
|
int numberToTap = ability.getManaCostsToPay().getX();
|
||||||
|
numberToTap = Math.min(game.getBattlefield().count(filter, ability.getSourceId(), ability.getControllerId(), game), numberToTap);
|
||||||
|
ability.addTarget(new TargetPermanent(numberToTap, filter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Gridlock copy() {
|
public Gridlock copy() {
|
||||||
return new Gridlock(this);
|
return new Gridlock(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GridlockTapEffect extends OneShotEffect<GridlockTapEffect> {
|
|
||||||
|
|
||||||
private static final FilterPermanent filter = new FilterNonlandPermanent();
|
|
||||||
|
|
||||||
public GridlockTapEffect() {
|
|
||||||
super(Outcome.Tap);
|
|
||||||
staticText = "Tap X target nonland permanents";
|
|
||||||
}
|
|
||||||
|
|
||||||
public GridlockTapEffect(final GridlockTapEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
int numberToTap = source.getManaCostsToPay().getX();
|
|
||||||
numberToTap = Math.min(game.getBattlefield().getAllActivePermanents(filter,game).size(), numberToTap);
|
|
||||||
TargetPermanent target = new TargetPermanent(numberToTap, filter);
|
|
||||||
if (target.canChoose(source.getControllerId(), game) && target.choose(Outcome.Tap, source.getControllerId(), source.getId(), game)) {
|
|
||||||
if (!target.getTargets().isEmpty()) {
|
|
||||||
List<UUID> targets = target.getTargets();
|
|
||||||
for (UUID targetId : targets) {
|
|
||||||
Permanent permanent = game.getPermanent(targetId);
|
|
||||||
if (permanent != null) {
|
|
||||||
permanent.tap(game);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GridlockTapEffect copy() {
|
|
||||||
return new GridlockTapEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -34,6 +34,7 @@ import mage.Constants.Rarity;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.SpellAbility;
|
import mage.abilities.SpellAbility;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
|
import mage.abilities.effects.common.DestroyTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.filter.Filter;
|
import mage.filter.Filter;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
import mage.filter.common.FilterCreaturePermanent;
|
||||||
|
@ -57,7 +58,8 @@ public class KillingGlare extends CardImpl<KillingGlare> {
|
||||||
this.color.setBlack(true);
|
this.color.setBlack(true);
|
||||||
|
|
||||||
// Destroy target creature with power X or less.
|
// Destroy target creature with power X or less.
|
||||||
this.getSpellAbility().addEffect(new KillingGlareDestroyEffect());
|
this.getSpellAbility().addEffect(new DestroyTargetEffect());
|
||||||
|
this.getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature with power X or less")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,13 +70,11 @@ public class KillingGlare extends CardImpl<KillingGlare> {
|
||||||
@Override
|
@Override
|
||||||
public void adjustTargets(Ability ability, Game game) {
|
public void adjustTargets(Ability ability, Game game) {
|
||||||
if (ability instanceof SpellAbility) {
|
if (ability instanceof SpellAbility) {
|
||||||
Player controller = game.getPlayer(ability.getControllerId());
|
int xValue = ability.getManaCostsToPay().getX();
|
||||||
if (controller.isHuman()) {
|
ability.getTargets().clear();
|
||||||
ability.getTargets().clear();
|
FilterCreaturePermanent filter = new FilterCreaturePermanent(new StringBuilder("creature with power ").append(xValue).append(" or less").toString());
|
||||||
FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
filter.add(new PowerPredicate(Filter.ComparisonType.LessThan, xValue + 1));
|
||||||
filter.add(new PowerPredicate(Filter.ComparisonType.LessThan, ability.getManaCostsToPay().getX() + 1));
|
ability.addTarget(new TargetCreaturePermanent(filter));
|
||||||
ability.addTarget(new TargetCreaturePermanent(filter));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,44 +84,3 @@ public class KillingGlare extends CardImpl<KillingGlare> {
|
||||||
return new KillingGlare(this);
|
return new KillingGlare(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KillingGlareDestroyEffect extends OneShotEffect<KillingGlareDestroyEffect> {
|
|
||||||
|
|
||||||
public KillingGlareDestroyEffect() {
|
|
||||||
super(Outcome.DestroyPermanent);
|
|
||||||
this.staticText = "Destroy target creature with power X or less";
|
|
||||||
}
|
|
||||||
|
|
||||||
public KillingGlareDestroyEffect(final KillingGlareDestroyEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KillingGlareDestroyEffect copy() {
|
|
||||||
return new KillingGlareDestroyEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
|
||||||
if (controller.isHuman()) {
|
|
||||||
Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
|
|
||||||
if (creature == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return creature.destroy(source.getSourceId(), game, false);
|
|
||||||
} else {
|
|
||||||
FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
|
||||||
filter.add(new PowerPredicate(Filter.ComparisonType.LessThan, source.getManaCostsToPay().getX() + 1));
|
|
||||||
Target target = new TargetCreaturePermanent(filter);
|
|
||||||
if (controller.chooseTarget(outcome, target, source, game)) {
|
|
||||||
Permanent creature = game.getPermanent(target.getFirstTarget());
|
|
||||||
if (creature == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return creature.destroy(source.getSourceId(), game, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
|
|
||||||
package mage.sets.magic2010;
|
package mage.sets.magic2010;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Outcome;
|
import mage.Constants.Outcome;
|
||||||
|
@ -51,7 +55,7 @@ public class Fireball extends CardImpl<Fireball> {
|
||||||
super(ownerId, 136, "Fireball", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{X}{R}");
|
super(ownerId, 136, "Fireball", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{X}{R}");
|
||||||
this.expansionSetCode = "M10";
|
this.expansionSetCode = "M10";
|
||||||
this.color.setRed(true);
|
this.color.setRed(true);
|
||||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer(0, Integer.MAX_VALUE));
|
this.getSpellAbility().addTarget(new FireballTargetCreatureOrPlayer(0, Integer.MAX_VALUE));
|
||||||
this.getSpellAbility().addEffect(new FireballEffect());
|
this.getSpellAbility().addEffect(new FireballEffect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,4 +118,82 @@ class FireballEffect extends OneShotEffect<FireballEffect> {
|
||||||
return new FireballEffect(this);
|
return new FireballEffect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class FireballTargetCreatureOrPlayer extends TargetCreatureOrPlayer {
|
||||||
|
|
||||||
|
public FireballTargetCreatureOrPlayer(int minNumTargets, int maxNumTargets) {
|
||||||
|
super(minNumTargets, maxNumTargets);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FireballTargetCreatureOrPlayer(final FireballTargetCreatureOrPlayer target) {
|
||||||
|
super(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is only used by AI players
|
||||||
|
*
|
||||||
|
* @param source
|
||||||
|
* @param game
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TargetCreatureOrPlayer> getTargetOptions(Ability source, Game game) {
|
||||||
|
|
||||||
|
List<TargetCreatureOrPlayer> options = new ArrayList<TargetCreatureOrPlayer>();
|
||||||
|
int xVal = source.getManaCostsToPay().getX();
|
||||||
|
|
||||||
|
if (xVal < 1) {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int numberTargets = 1; numberTargets == 1 || xVal / (numberTargets - 1) > 1 ; numberTargets++) {
|
||||||
|
Set<UUID> possibleTargets = possibleTargets(source.getSourceId(), source.getControllerId(), game);
|
||||||
|
// less possible targets than we're trying to set
|
||||||
|
if (possibleTargets.size() < numberTargets) {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
// less than 1 damage per target = 0, add no such options
|
||||||
|
if ((xVal -(numberTargets -1))/numberTargets < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
possibleTargets.removeAll(getTargets());
|
||||||
|
Iterator<UUID> it = possibleTargets.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
UUID targetId = it.next();
|
||||||
|
TargetCreatureOrPlayer target = this.copy();
|
||||||
|
target.clearChosen();
|
||||||
|
target.addTarget(targetId, source, game, true);
|
||||||
|
|
||||||
|
if (target.getTargets().size() == numberTargets) {
|
||||||
|
chosen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!target.isChosen()) {
|
||||||
|
Iterator<UUID> it2 = possibleTargets.iterator();
|
||||||
|
while (it2.hasNext()&& !target.isChosen()) {
|
||||||
|
UUID nextTargetId = it2.next();
|
||||||
|
target.addTarget(nextTargetId, source, game, true);
|
||||||
|
|
||||||
|
if (target.getTargets().size() == numberTargets) {
|
||||||
|
chosen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (target.isChosen()) {
|
||||||
|
options.add(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FireballTargetCreatureOrPlayer copy() {
|
||||||
|
return new FireballTargetCreatureOrPlayer(this);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue