mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
- More Redirecting of targeting checks to the new function.
This commit is contained in:
@@ -16,7 +16,6 @@ import forge.CardList;
|
||||
import forge.CardListFilter;
|
||||
import forge.CardUtil;
|
||||
import forge.Command;
|
||||
import forge.CommandReturn;
|
||||
import forge.ComputerUtil;
|
||||
import forge.Constant;
|
||||
import forge.Constant.Zone;
|
||||
@@ -461,48 +460,7 @@ public class CardFactoryCreatures {
|
||||
|
||||
// *************** START *********** START **************************
|
||||
else if (cardName.equals("Phylactery Lich")) {
|
||||
final CommandReturn getArt = new CommandReturn() {
|
||||
// get target card, may be null
|
||||
@Override
|
||||
public Object execute() {
|
||||
CardList art = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield);
|
||||
art = art.filter(new CardListFilter() {
|
||||
@Override
|
||||
public boolean addCard(final Card c) {
|
||||
return c.isArtifact();
|
||||
}
|
||||
});
|
||||
|
||||
CardList list = new CardList(art.toArray());
|
||||
list = list.filter(new CardListFilter() {
|
||||
@Override
|
||||
public boolean addCard(final Card c) {
|
||||
return c.getIntrinsicKeyword().contains("Indestructible");
|
||||
}
|
||||
});
|
||||
|
||||
Card target = null;
|
||||
if (!list.isEmpty()) {
|
||||
target = list.get(0);
|
||||
} else if (!art.isEmpty()) {
|
||||
target = art.get(0);
|
||||
}
|
||||
|
||||
return target;
|
||||
} // execute()
|
||||
}; // CommandReturn
|
||||
|
||||
final SpellAbility ability = new Ability(card, "0") {
|
||||
@Override
|
||||
public void resolve() {
|
||||
final Card c = this.getTargetCard();
|
||||
|
||||
if (AllZoneUtil.isCardInPlay(c) && c.isArtifact()) {
|
||||
c.addCounter(Counters.PHYLACTERY, 1);
|
||||
card.setFinishedEnteringBF(true);
|
||||
}
|
||||
} // resolve()
|
||||
}; // SpellAbility
|
||||
final Command intoPlay = new Command() {
|
||||
private static final long serialVersionUID = -1601957445498569156L;
|
||||
|
||||
@@ -572,8 +530,8 @@ public class CardFactoryCreatures {
|
||||
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
final Object o = getArt.execute();
|
||||
return (o != null) && AllZone.getZoneOf(this.getSourceCard()).is(Constant.Zone.Hand);
|
||||
return (!AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield).getType("Artifact").isEmpty()
|
||||
&& AllZone.getZoneOf(this.getSourceCard()).is(Constant.Zone.Hand));
|
||||
}
|
||||
});
|
||||
card.addComesIntoPlayCommand(intoPlay);
|
||||
@@ -1163,7 +1121,7 @@ public class CardFactoryCreatures {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(CardFactoryUtil.canTarget(card, target) && AllZoneUtil.isCardInPlay(target))) {
|
||||
if (!(target.canTarget(this) && AllZoneUtil.isCardInPlay(target))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1351,7 +1309,7 @@ public class CardFactoryCreatures {
|
||||
final int total = card.getCounters(Counters.P1P1);
|
||||
if (this.getTargetCard() != null) {
|
||||
if (AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
&& CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
&& this.getTargetCard().canTarget(this)) {
|
||||
this.getTargetCard().addDamage(total, card);
|
||||
}
|
||||
} else {
|
||||
@@ -2036,7 +1994,7 @@ public class CardFactoryCreatures {
|
||||
if (p.canTarget(this)) {
|
||||
p.setSkipNextUntap(true);
|
||||
for (final Card c : targetPerms) {
|
||||
if (AllZoneUtil.isCardInPlay(c) && CardFactoryUtil.canTarget(card, c)) {
|
||||
if (AllZoneUtil.isCardInPlay(c) && c.canTarget(this)) {
|
||||
c.tap();
|
||||
}
|
||||
}
|
||||
@@ -2079,7 +2037,7 @@ public class CardFactoryCreatures {
|
||||
@Override
|
||||
public void selectCard(final Card c, final PlayerZone zone) {
|
||||
if (zone.is(Constant.Zone.Battlefield, ability.getTargetPlayer()) && !targetPerms.contains(c)) {
|
||||
if (CardFactoryUtil.canTarget(card, c)) {
|
||||
if (c.canTarget(ability)) {
|
||||
targetPerms.add(c);
|
||||
}
|
||||
}
|
||||
@@ -2498,7 +2456,7 @@ public class CardFactoryCreatures {
|
||||
final Card equipment = this.getParent().getTargetCard();
|
||||
final Card creature = this.getTargetCard();
|
||||
if (AllZoneUtil.isCardInPlay(equipment) && AllZoneUtil.isCardInPlay(creature)) {
|
||||
if (CardFactoryUtil.canTarget(card, equipment) && CardFactoryUtil.canTarget(card, creature)) {
|
||||
if (CardFactoryUtil.canTarget(card, equipment) && creature.canTarget(this)) {
|
||||
if (equipment.isEquipping()) {
|
||||
final Card equipped = equipment.getEquipping().get(0);
|
||||
if (!equipped.equals(creature)) {
|
||||
@@ -2554,7 +2512,7 @@ public class CardFactoryCreatures {
|
||||
public void resolve() {
|
||||
final Card target = this.getTargetCard();
|
||||
|
||||
if (AllZoneUtil.isCardInPlay(target) && CardFactoryUtil.canTarget(card, target)) {
|
||||
if (AllZoneUtil.isCardInPlay(target) && target.canTarget(this)) {
|
||||
target.addCounter(Counters.M1M1, 1);
|
||||
if (target.getNetDefense() >= 1) {
|
||||
target.addShield();
|
||||
|
||||
@@ -77,7 +77,7 @@ class CardFactoryEquipment {
|
||||
@Override
|
||||
public void resolve() {
|
||||
if (AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
&& CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
&& this.getTargetCard().canTarget(this)) {
|
||||
|
||||
if (card.isEquipping()) {
|
||||
final Card crd = card.getEquipping().get(0);
|
||||
@@ -185,7 +185,7 @@ class CardFactoryEquipment {
|
||||
@Override
|
||||
public void resolve() {
|
||||
if (AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
&& CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
&& this.getTargetCard().canTarget(this)) {
|
||||
|
||||
if (card.isEquipping()) {
|
||||
final Card crd = card.getEquipping().get(0);
|
||||
|
||||
@@ -249,7 +249,7 @@ public class CardFactoryInstants {
|
||||
@Override
|
||||
public void resolve() {
|
||||
if (AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
&& CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
&& this.getTargetCard().canTarget(this)) {
|
||||
final Card c = this.getTargetCard();
|
||||
|
||||
c.addTempAttackBoost(-2);
|
||||
@@ -347,7 +347,7 @@ public class CardFactoryInstants {
|
||||
public void resolve() {
|
||||
// if target card is not in play, just quit
|
||||
if (!AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
|| !CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
|| !this.getTargetCard().canTarget(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -528,93 +528,6 @@ public class CardFactoryInstants {
|
||||
card.addSpellAbility(spell);
|
||||
} // *************** END ************ END **************************
|
||||
|
||||
// *************** START *********** START **************************
|
||||
/*
|
||||
* else if (cardName.equals("Echoing Courage")) { Cost cost = new
|
||||
* Cost(card.getManaCost(), cardName, false); Target tgt = new
|
||||
* Target(card, "C"); final SpellAbility spell = new Spell(card, cost,
|
||||
* tgt) { private static final long serialVersionUID =
|
||||
* -8649611733196156346L;
|
||||
*
|
||||
* public boolean canPlayAI() { CardList list =
|
||||
* AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer()); if
|
||||
* (list.isEmpty()) { return false; } else {
|
||||
* setTargetCard(CardFactoryUtil.AI_getBestCreature(list)); return true;
|
||||
* } } //canPlayAI()
|
||||
*
|
||||
* public void resolve() { if (AllZoneUtil.isCardInPlay(getTargetCard())
|
||||
* && CardFactoryUtil.canTarget(card, getTargetCard())) { final Card c =
|
||||
* getTargetCard();
|
||||
*
|
||||
* c.addTempAttackBoost(2); c.addTempDefenseBoost(2);
|
||||
*
|
||||
* AllZone.getEndOfTurn().addUntil(new Command() { private static final
|
||||
* long serialVersionUID = 1327455269456577020L;
|
||||
*
|
||||
* public void execute() { c.addTempAttackBoost(-2);
|
||||
* c.addTempDefenseBoost(-2); } });
|
||||
*
|
||||
* //get all creatures CardList list =
|
||||
* AllZoneUtil.getCardsIn(Zone.Battlefield, getTargetCard().getName());
|
||||
* list.remove(getTargetCard());
|
||||
*
|
||||
* if (!getTargetCard().isFaceDown()) { for (int i = 0; i < list.size();
|
||||
* i++) { final Card crd = list.get(i);
|
||||
*
|
||||
* crd.addTempAttackBoost(2); crd.addTempDefenseBoost(2);
|
||||
*
|
||||
* AllZone.getEndOfTurn().addUntil(new Command() { private static final
|
||||
* long serialVersionUID = 5151337777143949221L;
|
||||
*
|
||||
* public void execute() { crd.addTempAttackBoost(-2);
|
||||
* crd.addTempDefenseBoost(-2); } }); } }
|
||||
*
|
||||
* } //in play? } //resolve() }; //SpellAbility
|
||||
*
|
||||
* card.addSpellAbility(spell); }
|
||||
*/// *************** END ************ END **************************
|
||||
|
||||
// *************** START *********** START **************************
|
||||
else if (cardName.equals("Hurkyl's Recall")) {
|
||||
/*
|
||||
* Return all artifacts target player owns to his or her hand.
|
||||
*/
|
||||
final Target t = new Target(card, "Select target player", "Player");
|
||||
final Cost cost = new Cost("1 U", cardName, false);
|
||||
|
||||
final SpellAbility spell = new Spell(card, cost, t) {
|
||||
private static final long serialVersionUID = -4098702062413878046L;
|
||||
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
CardList humanArts = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield);
|
||||
humanArts = humanArts.getType("Artifact");
|
||||
return humanArts.size() > 0;
|
||||
} // canPlayAI
|
||||
|
||||
@Override
|
||||
public void chooseTargetAI() {
|
||||
this.setTargetPlayer(AllZone.getHumanPlayer());
|
||||
} // chooseTargetAI()
|
||||
|
||||
@Override
|
||||
public void resolve() {
|
||||
final Player player = this.getTargetPlayer();
|
||||
CardList artifacts = AllZoneUtil.getCardsIn(Zone.Battlefield);
|
||||
artifacts = artifacts.getType("Artifact");
|
||||
|
||||
for (int i = 0; i < artifacts.size(); i++) {
|
||||
final Card thisArtifact = artifacts.get(i);
|
||||
if (thisArtifact.getOwner().equals(player)) {
|
||||
// moveToHand handles tokens
|
||||
AllZone.getGameAction().moveToHand(thisArtifact);
|
||||
}
|
||||
}
|
||||
} // resolve()
|
||||
};
|
||||
|
||||
card.addSpellAbility(spell);
|
||||
} // *************** END ************ END **************************
|
||||
|
||||
// *************** START *********** START **************************
|
||||
else if (cardName.equals("Suffer the Past")) {
|
||||
@@ -949,7 +862,7 @@ public class CardFactoryInstants {
|
||||
@Override
|
||||
public void resolve() {
|
||||
if (AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
&& CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
&& this.getTargetCard().canTarget(this)) {
|
||||
final Card c = this.getTargetCard();
|
||||
c.addDamage(this.damage, card);
|
||||
if (c.hasKeyword("Infect")) {
|
||||
@@ -1026,7 +939,7 @@ public class CardFactoryInstants {
|
||||
final Card myc = this.getParent().getTargetCard();
|
||||
final Card tgt = this.getTargetCard();
|
||||
if (AllZoneUtil.isCardInPlay(myc) && AllZoneUtil.isCardInPlay(tgt)) {
|
||||
if (CardFactoryUtil.canTarget(card, myc) && CardFactoryUtil.canTarget(card, tgt)) {
|
||||
if (myc.canTarget(this) && tgt.canTarget(this)) {
|
||||
tgt.addDamage(myc.getNetAttack(), myc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class CardFactorySorceries {
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.isLand() && zone.is(Constant.Zone.Battlefield) && CardFactoryUtil.canTarget(card, c)) {
|
||||
if (c.isLand() && zone.is(Constant.Zone.Battlefield) && c.canTarget(spell)) {
|
||||
target[index[0]] = c;
|
||||
index[0]++;
|
||||
this.showMessage();
|
||||
@@ -827,7 +827,7 @@ public class CardFactorySorceries {
|
||||
|
||||
if (this.getTargetCard() != null) {
|
||||
if (AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
&& CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
&& this.getTargetCard().canTarget(this)) {
|
||||
javax.swing.JOptionPane.showMessageDialog(null, "Erratic Explosion causes " + damage
|
||||
+ " to " + this.getTargetCard());
|
||||
|
||||
@@ -1318,7 +1318,7 @@ public class CardFactorySorceries {
|
||||
public void resolve() {
|
||||
final Card c = this.getTargetCard();
|
||||
|
||||
if ((c != null) && AllZoneUtil.isCardInPlay(c) && CardFactoryUtil.canTarget(card, c)) {
|
||||
if ((c != null) && AllZoneUtil.isCardInPlay(c) && c.canTarget(this)) {
|
||||
// Donate should target both the player and the creature
|
||||
c.addController(card.getController().getOpponent());
|
||||
/*
|
||||
@@ -1625,7 +1625,7 @@ public class CardFactorySorceries {
|
||||
|
||||
if (this.getTargetCard() != null) {
|
||||
if (AllZoneUtil.isCardInPlay(this.getTargetCard())
|
||||
&& CardFactoryUtil.canTarget(card, this.getTargetCard())) {
|
||||
&& this.getTargetCard().canTarget(this)) {
|
||||
javax.swing.JOptionPane.showMessageDialog(null, cardName + " causes " + damage + " to "
|
||||
+ this.getTargetCard());
|
||||
|
||||
@@ -1716,7 +1716,7 @@ public class CardFactorySorceries {
|
||||
sb.append(cardName + " - Computer causes " + damage + " to:\n\n");
|
||||
for (int i = 0; i < targets.size(); i++) {
|
||||
final Card target = targets.get(i);
|
||||
if (AllZoneUtil.isCardInPlay(target) && CardFactoryUtil.canTarget(card, target)) {
|
||||
if (AllZoneUtil.isCardInPlay(target) && target.canTarget(this)) {
|
||||
sb.append(target + "\n");
|
||||
}
|
||||
}
|
||||
@@ -1730,7 +1730,7 @@ public class CardFactorySorceries {
|
||||
}
|
||||
for (int i = 0; i < targets.size(); i++) {
|
||||
final Card target = targets.get(i);
|
||||
if (AllZoneUtil.isCardInPlay(target) && CardFactoryUtil.canTarget(card, target)) {
|
||||
if (AllZoneUtil.isCardInPlay(target) && target.canTarget(this)) {
|
||||
// DEBUG
|
||||
Log.debug("Fireball", "Fireball does " + damage + " to: " + target);
|
||||
target.addDamage(damage, card);
|
||||
@@ -1809,7 +1809,7 @@ public class CardFactorySorceries {
|
||||
|
||||
@Override
|
||||
public void selectCard(final Card c, final PlayerZone zone) {
|
||||
if (!CardFactoryUtil.canTarget(card, c)) {
|
||||
if (!c.canTarget(spell)) {
|
||||
AllZone.getDisplay().showMessage("Cannot target this card.");
|
||||
return; // cannot target
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user