- Added basic fizzling functionality.

- Added isTargetStillValid which checks the Target class, Auras, and canTarget()
- Added check for TgtZone in Ability_Factory. This will be necessary for targeting cards not on the battlefield.
- Removed unused GameAction.canTarget(player)
This commit is contained in:
jendave
2011-08-06 09:06:33 +00:00
parent 481b596714
commit 5775aaba0e
5 changed files with 86 additions and 38 deletions

View File

@@ -143,6 +143,9 @@ public class AbilityFactory {
abTgt = new Target("TgtV", mapParams.get("TgtPrompt"), mapParams.get("ValidTgts").split(",")); abTgt = new Target("TgtV", mapParams.get("TgtPrompt"), mapParams.get("ValidTgts").split(","));
else else
abTgt = new Target(mapParams.get("Tgt")); abTgt = new Target(mapParams.get("Tgt"));
if (mapParams.containsKey("TgtZone")) // if Targeting something not in play, this Key should be set
abTgt.setZone(mapParams.get("TgtZone"));
} }
hasSubAb = mapParams.containsKey("SubAbility"); hasSubAb = mapParams.containsKey("SubAbility");

View File

@@ -3293,6 +3293,29 @@ public class CardFactoryUtil {
return result; return result;
} }
public static boolean isTargetStillValid(SpellAbility ability, Card target) {
Card source = ability.getSourceCard();
Target tgt = ability.getTarget();
if (tgt != null){
// Reconfirm the Validity of a TgtValid, or if the Creature is still a Creature
if (tgt.canTgtValid() && !target.isValidCard(tgt.getValidTgts(), ability.getActivatingPlayer()))
return false;
else if (tgt.canTgtCreature() && !target.isCreature())
return false;
// Check if the target is in the zone it needs to be in to be targeted
if (!AllZone.getZone(target).is(tgt.getZone()))
return false;
}
// If an Aura's target is removed before it resolves, the Aura fizzles
if (source.isAura() && !AllZone.getZone(target).is(Constant.Zone.Play))
return false;
// Make sure it's still targetable as well
return canTarget(source, target);
}
public static boolean canTarget(SpellAbility ability, Card target) { public static boolean canTarget(SpellAbility ability, Card target) {
return canTarget(ability.getSourceCard(), target); return canTarget(ability.getSourceCard(), target);
} }
@@ -3302,6 +3325,11 @@ public class CardFactoryUtil {
return c.isWhite() || c.isBlue() || c.isBlack() || c.isRed() || c.isGreen(); return c.isWhite() || c.isBlue() || c.isBlack() || c.isRed() || c.isGreen();
} }
public static boolean canTarget(Card spell, String player) {
Card c = player.equals(Constant.Player.Computer) ? AllZone.CardFactory.ComputerNullCard : AllZone.CardFactory.HumanNullCard;
return canTarget(spell, c);
}
public static boolean canTarget(Card spell, Card target) { public static boolean canTarget(Card spell, Card target) {
if(target == null) return true; if(target == null) return true;
//System.out.println("Target:" + target); //System.out.println("Target:" + target);

View File

@@ -3083,10 +3083,6 @@ public class GameAction {
return false; return false;
}//isAttached(Card c) }//isAttached(Card c)
public boolean canTarget(String targetPlayer) {
return true;
}
public void playCard(Card c) { public void playCard(Card c) {
HashMap<String, SpellAbility> map = new HashMap<String, SpellAbility>(); HashMap<String, SpellAbility> map = new HashMap<String, SpellAbility>();
SpellAbility[] abilities = canPlaySpellAbility(c.getSpellAbility()); SpellAbility[] abilities = canPlaySpellAbility(c.getSpellAbility());

View File

@@ -1,6 +1,8 @@
package forge; package forge;
import com.esotericsoftware.minlog.Log;
public class Input_StackNotEmpty extends Input implements java.io.Serializable { public class Input_StackNotEmpty extends Input implements java.io.Serializable {
private static final long serialVersionUID = -3015125043127874730L; private static final long serialVersionUID = -3015125043127874730L;
@@ -22,53 +24,68 @@ public class Input_StackNotEmpty extends Input implements java.io.Serializable {
SpellAbility sa = AllZone.Stack.pop(); SpellAbility sa = AllZone.Stack.pop();
Card c = sa.getSourceCard(); Card c = sa.getSourceCard();
boolean fizzle = false;
final Card crd = c; if (sa.getTargetCard() != null){
if(sa.isBuyBackAbility()) { fizzle = !CardFactoryUtil.isTargetStillValid(sa, sa.getTargetCard());
c.addReplaceMoveToGraveyardCommand(new Command() { }
private static final long serialVersionUID = -2559488318473330418L; else if (sa.getTargetPlayer() != "") {
fizzle = !CardFactoryUtil.canTarget(c, sa.getTargetPlayer());
public void execute() {
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, crd.getController());
AllZone.GameAction.moveTo(hand, crd);
}
});
} }
// To stop Copied Spells from going into the graveyard. if (!fizzle){
if(sa.getSourceCard().isCopiedSpell()) { final Card crd = c;
c.addReplaceMoveToGraveyardCommand(new Command() { if(sa.isBuyBackAbility()) {
private static final long serialVersionUID = -2559488318473330418L; c.addReplaceMoveToGraveyardCommand(new Command() {
public void execute() { private static final long serialVersionUID = -2559488318473330418L;
}
}); public void execute() {
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, crd.getController());
AllZone.GameAction.moveTo(hand, crd);
}
});
}
// To stop Copied Spells from going into the graveyard.
if(sa.getSourceCard().isCopiedSpell()) {
c.addReplaceMoveToGraveyardCommand(new Command() {
private static final long serialVersionUID = -2559488318473330418L;
public void execute() {
}
});
}
sa.resolve();
if(sa.getSourceCard().getKeyword().contains("Draw a card.")
&& !(sa.getSourceCard().getKeyword().contains("Ripple:4") && sa.isAbility()))
AllZone.GameAction.drawCard(sa.getSourceCard().getController());
if(sa.getSourceCard().getKeyword().contains("Proliferate"))
AllZone.GameAction.getProliferateAbility(sa.getSourceCard(), "0").resolve();
for(int i = 0; i < sa.getSourceCard().getKeyword().size(); i++) {
String k = sa.getSourceCard().getKeyword().get(i);
if(k.startsWith("Scry")) {
String kk[] = k.split(" ");
AllZone.GameAction.scry(sa.getSourceCard().getController(), Integer.parseInt(kk[1]));
}
}
} }
sa.resolve(); else{
// Spell fizzles, alert player?
if(sa.getSourceCard().getKeyword().contains("Draw a card.") Log.debug(c.getName() + " ability fizzles.");
&& !(sa.getSourceCard().getKeyword().contains("Ripple:4") && sa.isAbility()))
AllZone.GameAction.drawCard(sa.getSourceCard().getController());
if(sa.getSourceCard().getKeyword().contains("Proliferate"))
AllZone.GameAction.getProliferateAbility(sa.getSourceCard(), "0").resolve();
for(int i = 0; i < sa.getSourceCard().getKeyword().size(); i++) {
String k = sa.getSourceCard().getKeyword().get(i);
if(k.startsWith("Scry")) {
String kk[] = k.split(" ");
AllZone.GameAction.scry(sa.getSourceCard().getController(), Integer.parseInt(kk[1]));
}
} }
AllZone.GameAction.checkStateEffects(); AllZone.GameAction.checkStateEffects();
//special consideration for "Beacon of Unrest" and other "Beacon" cards //special consideration for "Beacon of Unrest" and other "Beacon" cards
if((c.isInstant() || c.isSorcery()) && (!c.getName().startsWith("Beacon")) if((c.isInstant() || c.isSorcery() || (c.isAura() && fizzle)) && (!c.getName().startsWith("Beacon"))
&& (!c.getName().startsWith("Pulse")) && !AllZone.GameAction.isCardRemovedFromGame(c)) //hack to make flashback work && (!c.getName().startsWith("Pulse")) && !AllZone.GameAction.isCardRemovedFromGame(c)) //hack to make flashback work
{ {
if(c.getReplaceMoveToGraveyard().size() == 0) AllZone.GameAction.moveToGraveyard(c); if(c.getReplaceMoveToGraveyard().size() == 0) AllZone.GameAction.moveToGraveyard(c);
else c.replaceMoveToGraveyard(); else c.replaceMoveToGraveyard();
} }
//update all zones, something things arent' updated for some reason //update all zones, something things arent' updated for some reason
AllZone.Human_Hand.updateObservers(); AllZone.Human_Hand.updateObservers();

View File

@@ -18,6 +18,10 @@ public class Target {
public String getVTSelection() { return vtSelection; } public String getVTSelection() { return vtSelection; }
public void setVTSelection(String vtSelStr) { vtSelection = vtSelStr; } public void setVTSelection(String vtSelStr) { vtSelection = vtSelStr; }
private String tgtZone = Constant.Zone.Play;
public void setZone(String tZone) { tgtZone = tZone; }
public String getZone() { return tgtZone; }
private int minTargets = 0; private int minTargets = 0;
public int getMinTargets() { return minTargets; } public int getMinTargets() { return minTargets; }
private int maxTargets = 0; private int maxTargets = 0;