*If, for some reason, a ChangeZone ability is passed zero targets (if, say, a Faceless Devourer enters play without targeting anything) there will no longer be an NPE. Fixes the Faceless creatures, Oblivion Ring,Journey to Nowhere etc.

This commit is contained in:
jendave
2011-08-06 16:34:34 +00:00
parent 27d4596c0c
commit 06823e0007

View File

@@ -827,50 +827,53 @@ public class AbilityFactory_ChangeZone {
tgtCards.add(c);
}
}
Card targetCard = null;
if(tgtCards.size() != 0)
{
Card targetCard = tgtCards.get(0);
for(Card tgtC : tgtCards){
PlayerZone originZone = AllZone.getZone(tgtC);
// if Target isn't in the expected Zone, continue
if (!originZone.is(origin))
continue;
if (tgt != null && origin.equals("Battlefield")){
// check targeting
if (!CardFactoryUtil.canTarget(sa.getSourceCard(), tgtC))
continue;
}
targetCard = tgtCards.get(0);
for(Card tgtC : tgtCards){
PlayerZone originZone = AllZone.getZone(tgtC);
// if Target isn't in the expected Zone, continue
if (!originZone.is(origin))
continue;
if (tgt != null && origin.equals("Battlefield")){
// check targeting
if (!CardFactoryUtil.canTarget(sa.getSourceCard(), tgtC))
continue;
}
Player pl = player;
if (!destination.equals("Battlefield"))
pl = tgtC.getOwner();
Player pl = player;
if (!destination.equals("Battlefield"))
pl = tgtC.getOwner();
if (destination.equals("Library")){
// library position is zero indexed
int libraryPosition = params.containsKey("LibraryPosition") ? Integer.parseInt(params.get("LibraryPosition")) : 0;
if (destination.equals("Library")){
// library position is zero indexed
int libraryPosition = params.containsKey("LibraryPosition") ? Integer.parseInt(params.get("LibraryPosition")) : 0;
AllZone.GameAction.moveToLibrary(tgtC, libraryPosition);
AllZone.GameAction.moveToLibrary(tgtC, libraryPosition);
if (params.containsKey("Shuffle")) // for things like Gaea's Blessing
player.shuffle();
}
else{
if (destination.equals("Battlefield")){
if (params.containsKey("Tapped"))
tgtC.tap();
if (params.containsKey("GainControl"))
tgtC.setController(sa.getActivatingPlayer());
if (params.containsKey("Shuffle")) // for things like Gaea's Blessing
player.shuffle();
}
else{
if (destination.equals("Battlefield")){
if (params.containsKey("Tapped"))
tgtC.tap();
if (params.containsKey("GainControl"))
tgtC.setController(sa.getActivatingPlayer());
AllZone.GameAction.moveTo(AllZone.getZone(destination, tgtC.getOwner()),tgtC);
}
else
{
AllZone.GameAction.moveTo(AllZone.getZone(destination, pl), tgtC);
}
}
AllZone.GameAction.moveTo(AllZone.getZone(destination, tgtC.getOwner()),tgtC);
}
else
{
AllZone.GameAction.moveTo(AllZone.getZone(destination, pl), tgtC);
}
}
}
}
if (af.hasSubAbility()){
Ability_Sub abSub = sa.getSubAbility();