- Fixed possible NPE's in findParentsTargetedCard.

- Converted Insurrection to script.
This commit is contained in:
Sloth
2012-03-03 11:16:22 +00:00
parent f93090ebd6
commit 0fb0f92f70
6 changed files with 39 additions and 74 deletions

View File

@@ -1,8 +1,9 @@
Name:Insurrection
ManaCost:5 R R R
Types:Sorcery
Text:Untap all creatures and gain control of them until end of turn. They gain haste until end of turn.
SVar:PlayMain1:TRUE
Text:no text
A:SP$ UntapAll | Cost$ 5 R R R | ValidCards$ Creature | SubAbility$ DBGainControl | SpellDescription$ Untap all creatures and gain control of them until end of turn. They gain haste until end of turn.
SVar:DBGainControl:DB$ GainControl | AllValid$ Creature | NewController$ You | AddKWs$ Haste | LoseControl$ EOT
SVar:Rarity:Rare
SVar:Picture:http://www.wizards.com/global/images/magic/general/insurrection.jpg
SetInfo:ONS|Rare|http://magiccards.info/scans/en/on/213.jpg

View File

@@ -1788,7 +1788,7 @@ public class AbilityFactory {
else if (defined.equals("Targeted")) {
final SpellAbility parent = AbilityFactory.findParentsTargetedCard(sa);
if (parent != null) {
if (parent.getTarget() != null) {
if (parent.getTarget() != null && parent.getTarget().getTargetCards() != null) {
cards.addAll(parent.getTarget().getTargetCards());
}
}
@@ -2194,11 +2194,13 @@ public class AbilityFactory {
SpellAbility parent = sa;
do {
if (!(parent instanceof AbilitySub)) {
if (!(parent instanceof AbilitySub) || ((AbilitySub) parent).getParent() == null) {
return parent;
}
parent = ((AbilitySub) parent).getParent();
} while ((parent.getTarget() == null) || (parent.getTarget().getTargetCards().size() == 0));
} while (parent.getTarget() == null
|| parent.getTarget().getTargetCards() == null
|| parent.getTarget().getTargetCards().size() == 0);
return parent;
}

View File

@@ -950,10 +950,9 @@ public final class AbilityFactoryCombat {
boolean chance = false;
CardList list = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield).getType("Creature");
list = list.getTargetableCards(sa);
if (abTgt != null) {
CardList list = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield).getType("Creature");
list = list.getTargetableCards(sa);
list = list.getValidCards(abTgt.getValidTgts(), source.getController(), source);
list = list.filter(new CardListFilter() {
@Override
@@ -970,15 +969,15 @@ public final class AbilityFactoryCombat {
return true;
}
});
if (!list.isEmpty()) {
final Card blocker = CardFactoryUtil.getBestCreatureAI(list);
if (blocker == null) {
return false;
}
abTgt.addTarget(CardFactoryUtil.getBestCreatureAI(list));
chance = true; // TODO change this to true, once the human input
// takes mustblocks into account
if (list.isEmpty()) {
return false;
}
final Card blocker = CardFactoryUtil.getBestCreatureAI(list);
if (blocker == null) {
return false;
}
abTgt.addTarget(blocker);
chance = true;
} else {
return false;
}

View File

@@ -521,7 +521,18 @@ public class AbilityFactoryGainControl {
*/
private boolean gainControlDrawbackAI(final SpellAbility sa) {
if ((sa.getTarget() == null) || !sa.getTarget().doesTarget()) {
// all is good
if (this.params.containsKey("AllValid")) {
CardList tgtCards = AllZoneUtil.getCardsIn(Constant.Zone.Battlefield)
.getController(AllZone.getHumanPlayer());
tgtCards = AbilityFactory.filterListByType(tgtCards, this.params.get("AllValid"), sa);
if (tgtCards.isEmpty()) {
return false;
}
}
if ((this.lose != null) && this.lose.contains("EOT")
&& AllZone.getPhaseHandler().isAfter(Constant.Phase.COMBAT_DECLARE_ATTACKERS)) {
return false;
}
} else {
return this.gainControlTgtAI(sa);
}

View File

@@ -192,7 +192,7 @@ public class AbilityFactoryPermanentState {
sb.append("up to ").append(params.get("Amount")).append(" ");
sb.append(params.get("UntapType")).append("s");
} else {
ArrayList<Card> tgtCards;
ArrayList<Card> tgtCards = new ArrayList<Card>();
final Target tgt = sa.getTarget();
if (tgt != null) {
tgtCards = tgt.getTargetCards();
@@ -1325,9 +1325,11 @@ public class AbilityFactoryPermanentState {
* @return a boolean.
*/
private static boolean untapAllCanPlayAI(final AbilityFactory af, final SpellAbility sa) {
/*
* All cards using this currently have SVar:RemAIDeck:True
*/
// check SubAbilities DoTrigger?
final AbilitySub abSub = sa.getSubAbility();
if (abSub != null && abSub.chkAIDrawback()) {
return true;
}
return false;
}

View File

@@ -176,12 +176,12 @@ public class CardFactorySorceries {
} // *************** END ************ END **************************
// *************** START *********** START **************************
else if (cardName.equals("Insurrection")) {
/*else if (cardName.equals("Insurrection")) {
/*
* Untap all creatures and gain control of them until end of turn.
* They gain haste until end of turn.
*/
final ArrayList<PlayerZone> orig = new ArrayList<PlayerZone>();
/*final ArrayList<PlayerZone> orig = new ArrayList<PlayerZone>();
final PlayerZone[] newZone = new PlayerZone[1];
final ArrayList<Player> controllerEOT = new ArrayList<Player>();
final ArrayList<Card> targets = new ArrayList<Card>();
@@ -245,7 +245,7 @@ public class CardFactorySorceries {
}; // SpellAbility
card.addSpellAbility(spell);
card.setSVar("PlayMain1", "TRUE");
} // *************** END ************ END **************************
}*/ // *************** END ************ END **************************
// *************** START *********** START **************************
else if (cardName.equals("Brilliant Ultimatum")) {
@@ -1136,56 +1136,6 @@ public class CardFactorySorceries {
spell.setBeforePayMana(input);
} // *************** END ************ END **************************
/*************** START *********** START **************************
else if (cardName.equals("Recall")) {
/*
* Discard X cards, then return a card from your graveyard to your
* hand for each card discarded this way. Exile Recall.
*
final Cost cost = new Cost(card.getManaCost(), cardName, false);
final SpellAbility spell = new Spell(card, cost, null) {
private static final long serialVersionUID = -3935814273439962834L;
@Override
public boolean canPlayAI() {
// for compy to play this wisely, it should check hand, and if there
// are no spells that canPlayAI(), then use recall. maybe.
return false;
}
@Override
public void resolve() {
int numCards = card.getXManaCostPaid();
final Player player = card.getController();
final int maxCards = player.getCardsIn(Zone.Hand).size();
if (numCards != 0) {
numCards = Math.min(numCards, maxCards);
if (player.isHuman()) {
AllZone.getInputControl()
.setInput(CardFactoryUtil.inputDiscardRecall(numCards, card, this));
}
}
/*
* else { //computer
* card.getControler().discardRandom(numCards);
* Singletons.getModel().getGameAction().exile(card); CardList grave =
* AllZoneUtil.getPlayerGraveyard(card.getController());
* for(int i = 1; i <= numCards; i ++) { Card t1 =
* CardFactoryUtil.AI_getBestCreature(grave); if(null != t1)
* { t1 = grave.get(0); grave.remove(t1);
* Singletons.getModel().getGameAction().moveToHand(t1); } } }
*
} // resolve()
}; // SpellAbility
final StringBuilder sb = new StringBuilder();
sb.append(card).append(" - discard X cards and return X cards to your hand.");
spell.setStackDescription(sb.toString());
card.addSpellAbility(spell);
} // *************** END ************ END **************************
*/
// *************** START *********** START **************************
else if (cardName.equals("Windfall")) {
final SpellAbility spell = new Spell(card) {