- Convert cycling and typecycling to AF Scripts

This commit is contained in:
Sol
2012-04-29 03:29:49 +00:00
parent 1c953be4cc
commit d7ecbd0b41
2 changed files with 26 additions and 118 deletions

View File

@@ -1024,58 +1024,16 @@ public class CardFactoryUtil {
* @return a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.spellability.SpellAbility} object.
*/ */
public static SpellAbility abilityCycle(final Card sourceCard, String cycleCost) { public static SpellAbility abilityCycle(final Card sourceCard, String cycleCost) {
cycleCost += " Discard<1/CARDNAME>"; StringBuilder sb = new StringBuilder();
final Cost abCost = new Cost(sourceCard, cycleCost, true); sb.append("AB$ Draw | Cost$ ");
sb.append(cycleCost);
sb.append(" Discard<1/CARDNAME> | ActivationZone$ Hand | PrecostDesc$ Cycling ");
sb.append("| SpellDescription$ Draw a card.");
final SpellAbility cycle = new AbilityActivated(sourceCard, abCost, null) { AbilityFactory af = new AbilityFactory();
private static final long serialVersionUID = -4960704261761785512L; SpellAbility cycle = af.getAbility(sb.toString(), sourceCard);
@Override
public boolean canPlayAI() {
if (Singletons.getModel().getGameState().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)) {
return false;
}
// The AI should cycle lands if it has 6 already and no cards in
// hand with higher CMC
final CardList hand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand);
CardList lands = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
lands.addAll(hand);
lands = lands.getType("Land");
if (sourceCard.isLand() && (lands.size() >= Math.max(hand.getHighestConvertedManaCost(), 6))) {
return true;
}
// TODO - When else should AI Cycle?
return false;
}
@Override
public boolean canPlay() {
if (AllZoneUtil.isCardInPlay("Stabilizer")) {
return false;
}
return super.canPlay();
}
@Override
public void resolve() {
sourceCard.getController().drawCard();
}
};
cycle.setIsCycling(true); cycle.setIsCycling(true);
final StringBuilder sbDesc = new StringBuilder();
sbDesc.append("Cycling ").append(cycle.getManaCost()).append(" (");
sbDesc.append(abCost.toString()).append(" Draw a card.)");
cycle.setDescription(sbDesc.toString());
final StringBuilder sbStack = new StringBuilder();
sbStack.append(sourceCard).append(" Cycling: Draw a card");
cycle.setStackDescription(sbStack.toString());
cycle.getRestrictions().setZone(ZoneType.Hand);
return cycle; return cycle;
} // abilityCycle() } // abilityCycle()
@@ -1093,76 +1051,23 @@ public class CardFactoryUtil {
* @return a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.spellability.SpellAbility} object.
*/ */
public static SpellAbility abilityTypecycle(final Card sourceCard, String cycleCost, final String type) { public static SpellAbility abilityTypecycle(final Card sourceCard, String cycleCost, final String type) {
String description; StringBuilder sb = new StringBuilder();
cycleCost += " Discard<1/CARDNAME>"; sb.append("AB$ ChangeZone | Cost$ ").append(cycleCost);
final Cost abCost = new Cost(sourceCard, cycleCost, true);
final SpellAbility cycle = new AbilityActivated(sourceCard, abCost, null) { String desc = type;
private static final long serialVersionUID = -4960704261761785512L; if (type.equals("Basic")) {
desc = "Basic land";
@Override
public boolean canPlayAI() {
return false;
}
// some AI code could be added (certain colored mana needs analyze
// method maybe)
@Override
public boolean canPlay() {
if (AllZoneUtil.isCardInPlay("Stabilizer")) {
return false;
}
return super.canPlay();
}
@Override
public void resolve() {
final CardList cards = sourceCard.getController().getCardsIn(ZoneType.Library);
final CardList sameType = new CardList();
for (int i = 0; i < cards.size(); i++) {
if (cards.get(i).isType(type)) {
sameType.add(cards.get(i));
}
}
if (sameType.size() == 0) {
sourceCard.getController().discard(sourceCard, this);
return;
}
final Object o = GuiUtils.chooseOneOrNone("Select a card", sameType.toArray());
if (o != null) {
// ability.setTargetCard((Card)o);
sourceCard.getController().discard(sourceCard, this);
final Card c1 = (Card) o;
Singletons.getModel().getGameAction().moveToHand(c1);
}
sourceCard.getController().shuffle();
}
};
if (type.contains("Basic")) {
description = "Basic land";
} else {
description = type;
} }
sb.append(" Discard<1/CARDNAME> | ActivationZone$ Hand | PrecostDesc$ ").append(desc).append("cycling ");
sb.append("| Origin$ Library | Destination$ Hand |");
sb.append("ChangeType$ ").append(type);
sb.append(" | SpellDescription$ Search your library for a ").append(desc).append(" card, reveal it,");
sb.append(" and put it into your hand. Then shuffle your library.");
AbilityFactory af = new AbilityFactory();
SpellAbility cycle = af.getAbility(sb.toString(), sourceCard);
cycle.setIsCycling(true); cycle.setIsCycling(true);
final StringBuilder sbDesc = new StringBuilder();
sbDesc.append(description).append("cycling (").append(abCost.toString());
sbDesc.append(" Search your library for a ").append(description);
sbDesc.append(" card, reveal it, and put it into your hand. Then shuffle your library.)");
cycle.setDescription(sbDesc.toString());
final StringBuilder sbStack = new StringBuilder();
sbStack.append(sourceCard).append(" ").append(description);
sbStack.append("cycling: Search your library for a ").append(description).append(" card.)");
cycle.setStackDescription(sbStack.toString());
cycle.getRestrictions().setZone(ZoneType.Hand);
return cycle; return cycle;
} // abilityTypecycle() } // abilityTypecycle()

View File

@@ -83,9 +83,8 @@ public abstract class AbilityActivated extends SpellAbility implements java.io.S
} }
final Card c = this.getSourceCard(); final Card c = this.getSourceCard();
if (c.isFaceDown() && this.isIntrinsic()) { // Intrinsic abilities can't if (c.isFaceDown() && this.isIntrinsic()) {
// be // Intrinsic abilities can't be activated by face down cards
// activated by face down cards
return false; return false;
} }
@@ -104,6 +103,10 @@ public abstract class AbilityActivated extends SpellAbility implements java.io.S
return false; return false;
} }
if (this.isCycling() && AllZoneUtil.isCardInPlay("Stabilizer")) {
return false;
}
if (!(this.getRestrictions().canPlay(c, this))) { if (!(this.getRestrictions().canPlay(c, this))) {
return false; return false;
} }