diff --git a/src/main/java/forge/IPlayerZone.java b/src/main/java/forge/IPlayerZone.java index 5b3a6578cfd..006de0d8f84 100644 --- a/src/main/java/forge/IPlayerZone.java +++ b/src/main/java/forge/IPlayerZone.java @@ -3,130 +3,208 @@ package forge; import java.util.List; /** - *
IPlayerZone interface.
- * + *+ * IPlayerZone interface. + *
+ * * @author Forge * @version $Id$ */ interface IPlayerZone { /** - *setUpdate.
- * - * @param b a boolean. + *+ * setUpdate. + *
+ * + * @param b + * a boolean. */ void setUpdate(boolean b); /** - *getUpdate.
- * + *+ * getUpdate. + *
+ * * @return a boolean. */ boolean getUpdate(); /** - *size.
- * + *+ * size. + *
+ * * @return a int. */ int size(); /** - *add.
- * - * @param o a {@link java.lang.Object} object. + *+ * add. + *
+ * + * @param o + * a {@link java.lang.Object} object. */ void add(Object o); /** - *add.
- * - * @param c a {@link forge.Card} object. - * @param index a int. + *+ * add. + *
+ * + * @param c + * a {@link forge.Card} object. + * @param index + * a int. */ void add(Card c, int index); /** - *get.
- * - * @param index a int. + *+ * get. + *
+ * + * @param index + * a int. * @return a {@link forge.Card} object. */ Card get(int index); /** - *remove.
- * - * @param o a {@link java.lang.Object} object. + *+ * remove. + *
+ * + * @param o + * a {@link java.lang.Object} object. */ void remove(Object o); /** - *setCards.
- * - * @param c an array of {@link forge.Card} objects. + *+ * setCards. + *
+ * + * @param c + * an array of {@link forge.Card} objects. */ void setCards(Card[] c); /** - *getCards.
- * + *+ * getCards. + *
+ * + * @param filter + * the filter * @return an array of {@link forge.Card} objects. */ Card[] getCards(boolean filter); + + /** + * Gets the cards. + * + * @return the cards + */ Card[] getCards(); + + /** + * Gets the cards. + * + * @param n + * the n + * @return the cards + */ Card[] getCards(int n); - + + /** + * Contains. + * + * @param c + * the c + * @return true, if successful + */ boolean contains(Card c); - - /** isEmpty returns true if given zone contains no cards */ + + /** + * isEmpty returns true if given zone contains no cards. + * + * @return true, if is empty + */ boolean isEmpty(); - //removes all cards + // removes all cards /** - *reset.
+ *+ * reset. + *
*/ void reset(); /** - *is.
- * - * @param zone a {@link java.lang.String} object. + *+ * is. + *
+ * + * @param zone + * a {@link java.lang.String} object. * @return a boolean. */ boolean is(Constant.Zone zone); + + /** + * Checks if is. + * + * @param zones + * the zones + * @return true, if successful + */ boolean is(Listis.
- * - * @param zone a {@link java.lang.String} object. - * @param player a {@link forge.Player} object. + *+ * is. + *
+ * + * @param zone + * a {@link java.lang.String} object. + * @param player + * a {@link forge.Player} object. * @return a boolean. */ boolean is(Constant.Zone zone, Player player); /** - *getPlayer.
- * + *+ * getPlayer. + *
+ * * @return a {@link forge.Player} object. */ - Player getPlayer(); //the Player that owns this zone + Player getPlayer(); // the Player that owns this zone /** - *getZoneName.
- * + *+ * getZoneName. + *
+ * * @return a {@link java.lang.String} object. */ - Constant.Zone getZoneType(); //returns the Zone's name like Graveyard + Constant.Zone getZoneType(); // returns the Zone's name like Graveyard /** - *toString.
- * + *+ * toString. + *
+ * * @return a {@link java.lang.String} object. */ String toString(); - - + + /** + * Reset cards added this turn. + */ void resetCardsAddedThisTurn(); } - diff --git a/src/main/java/forge/MagicStack.java b/src/main/java/forge/MagicStack.java index a921e3a4bee..dc249d8f903 100644 --- a/src/main/java/forge/MagicStack.java +++ b/src/main/java/forge/MagicStack.java @@ -26,8 +26,10 @@ import forge.gui.input.Input; import forge.gui.input.Input_PayManaCost_Ability; /** - *MagicStack class.
- * + *+ * MagicStack class. + *
+ * * @author Forge * @version $Id$ */ @@ -40,13 +42,15 @@ public class MagicStack extends MyObservable { private boolean frozen = false; private boolean bResolving = false; private int splitSecondOnStack = 0; - + private CardList thisTurnCast = new CardList(); private CardList lastTurnCast = new CardList(); /** - *isFrozen.
- * + *+ * isFrozen. + *
+ * * @return a boolean. */ public final boolean isFrozen() { @@ -54,16 +58,21 @@ public class MagicStack extends MyObservable { } /** - *Setter for the field frozen.
+ * Setter for the field frozen.
+ *
reset.
+ *+ * reset. + *
*/ public final void reset() { getStack().clear(); @@ -74,8 +83,10 @@ public class MagicStack extends MyObservable { } /** - *isSplitSecondOnStack.
- * + *+ * isSplitSecondOnStack. + *
+ * * @return a boolean. */ public final boolean isSplitSecondOnStack() { @@ -83,9 +94,12 @@ public class MagicStack extends MyObservable { } /** - *incrementSplitSecond.
- * - * @param sp a {@link forge.card.spellability.SpellAbility} object. + *+ * incrementSplitSecond. + *
+ * + * @param sp + * a {@link forge.card.spellability.SpellAbility} object. */ public final void incrementSplitSecond(final SpellAbility sp) { if (sp.getSourceCard().hasKeyword("Split second")) { @@ -94,9 +108,12 @@ public class MagicStack extends MyObservable { } /** - *decrementSplitSecond.
- * - * @param sp a {@link forge.card.spellability.SpellAbility} object. + *+ * decrementSplitSecond. + *
+ * + * @param sp + * a {@link forge.card.spellability.SpellAbility} object. */ public final void decrementSplitSecond(final SpellAbility sp) { if (sp.getSourceCard().hasKeyword("Split second")) { @@ -109,23 +126,27 @@ public class MagicStack extends MyObservable { } /** - *freezeStack.
+ *+ * freezeStack. + *
*/ public final void freezeStack() { frozen = true; } /** - *addAndUnfreeze.
- * - * @param ability a {@link forge.card.spellability.SpellAbility} object. + *+ * addAndUnfreeze. + *
+ * + * @param ability + * a {@link forge.card.spellability.SpellAbility} object. */ public final void addAndUnfreeze(final SpellAbility ability) { ability.getRestrictions().abilityActivated(); if (ability.getRestrictions().getActivationNumberSacrifice() != -1 - && ability.getRestrictions().getNumberTurnActivations() - >= ability.getRestrictions().getActivationNumberSacrifice()) - { + && ability.getRestrictions().getNumberTurnActivations() >= ability.getRestrictions() + .getActivationNumberSacrifice()) { ability.getSourceCard().addExtrinsicKeyword("At the beginning of the end step, sacrifice CARDNAME."); } // triggered abilities should go on the frozen stack @@ -135,7 +156,8 @@ public class MagicStack extends MyObservable { this.add(ability); - // if the ability is a spell, but not a copied spell and its not already on the stack zone, move there + // if the ability is a spell, but not a copied spell and its not already + // on the stack zone, move there if (ability.isSpell()) { Card source = ability.getSourceCard(); if (!source.isCopiedSpell() && !AllZone.getZoneOf(source).is(Constant.Zone.Stack)) { @@ -149,7 +171,9 @@ public class MagicStack extends MyObservable { } /** - *unfreezeStack.
+ *+ * unfreezeStack. + *
*/ public final void unfreezeStack() { frozen = false; @@ -164,18 +188,24 @@ public class MagicStack extends MyObservable { } /** - *clearFrozen.
+ *+ * clearFrozen. + *
*/ public final void clearFrozen() { - // TODO: frozen triggered abilities and undoable costs have nasty consequences + // TODO: frozen triggered abilities and undoable costs have nasty + // consequences frozen = false; getFrozenStack().clear(); } /** - *setResolving.
- * - * @param b a boolean. + *+ * setResolving. + *
+ * + * @param b + * a boolean. */ public final void setResolving(final boolean b) { bResolving = b; @@ -185,8 +215,10 @@ public class MagicStack extends MyObservable { } /** - *getResolving.
- * + *+ * getResolving. + *
+ * * @return a boolean. */ public final boolean getResolving() { @@ -194,33 +226,41 @@ public class MagicStack extends MyObservable { } /** - *add.
- * - * @param sp a {@link forge.card.spellability.SpellAbility} object. - * @param useX a boolean. + *+ * add. + *
+ * + * @param sp + * a {@link forge.card.spellability.SpellAbility} object. + * @param useX + * a boolean. */ public final void add(final SpellAbility sp, final boolean useX) { if (!useX) { this.add(sp); - } - else { + } else { // TODO: make working triggered abilities! if (sp instanceof Ability_Mana || sp instanceof Ability_Triggered) { sp.resolve(); - } - else { + } else { push(sp); - /*if (sp.getTargetCard() != null) - CardFactoryUtil.checkTargetingEffects(sp, sp.getTargetCard());*/ + /* + * if (sp.getTargetCard() != null) + * CardFactoryUtil.checkTargetingEffects(sp, + * sp.getTargetCard()); + */ } } } /** - *getMultiKickerSpellCostChange.
- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. + *+ * getMultiKickerSpellCostChange. + *
+ * + * @param sa + * a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.mana.ManaCost} object. */ public final ManaCost getMultiKickerSpellCostChange(final SpellAbility sa) { @@ -239,11 +279,9 @@ public class MagicStack extends MyObservable { if (mana.toString().length() == 1) { numberManaCost = mana.toString().substring(0, 1); - } - else if (mana.toString().length() == 0) { + } else if (mana.toString().length() == 0) { numberManaCost = "0"; // Should Never Occur - } - else { + } else { numberManaCost = mana.toString().substring(0, 2); } @@ -272,42 +310,46 @@ public class MagicStack extends MyObservable { for (int colorCutIx = 0; colorCutIx < colorCut.length(); colorCutIx++) { if ("WUGRB".contains(colorCut.substring(colorCutIx, colorCutIx + 1)) - && !mana.equals(mana.replaceFirst((colorCut.substring(colorCutIx, colorCutIx + 1)), ""))) - { - mana = mana.replaceFirst(colorCut.substring(colorCutIx, colorCutIx + 1), ""); + && !mana.equals(mana.replaceFirst((colorCut.substring(colorCutIx, colorCutIx + 1)), ""))) { + mana = mana.replaceFirst(colorCut.substring(colorCutIx, colorCutIx + 1), ""); - AllZone.getGameAction().CostCutting_GetMultiMickerManaCostPaid_Colored = - AllZone.getGameAction().CostCutting_GetMultiMickerManaCostPaid_Colored - .replaceFirst(colorCut.substring(colorCutIx, colorCutIx + 1), ""); + AllZone.getGameAction().CostCutting_GetMultiMickerManaCostPaid_Colored = AllZone.getGameAction().CostCutting_GetMultiMickerManaCostPaid_Colored + .replaceFirst(colorCut.substring(colorCutIx, colorCutIx + 1), ""); - mana = mana.trim(); - if (mana.equals("")) { - mana = "0"; - } - manaCost = new ManaCost(mana); + mana = mana.trim(); + if (mana.equals("")) { + mana = "0"; + } + manaCost = new ManaCost(mana); } } return manaCost; } - //TODO: this may be able to use a straight copy of MultiKicker cost change + // TODO: this may be able to use a straight copy of MultiKicker cost change /** - *getReplicateSpellCostChange.
- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. + *+ * getReplicateSpellCostChange. + *
+ * + * @param sa + * a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.mana.ManaCost} object. */ public final ManaCost getReplicateSpellCostChange(final SpellAbility sa) { ManaCost manaCost = new ManaCost(sa.getManaCost()); - //String Mana = manaCost.toString(); + // String Mana = manaCost.toString(); return manaCost; } /** - *add.
+ *+ * add. + *
* - * @param sp a {@link forge.card.spellability.SpellAbility} object. + * @param sp + * a {@link forge.card.spellability.SpellAbility} object. */ public final void add(final SpellAbility sp) { ArrayListsize.
- * + *+ * size. + *
+ * * @return a int. */ public final int size() { @@ -731,9 +790,12 @@ public class MagicStack extends MyObservable { // Push should only be used by add. /** - *push.
- * - * @param sp a {@link forge.card.spellability.SpellAbility} object. + *+ * push. + *
+ * + * @param sp + * a {@link forge.card.spellability.SpellAbility} object. */ private void push(final SpellAbility sp) { if (null == sp.getActivatingPlayer()) { @@ -756,7 +818,9 @@ public class MagicStack extends MyObservable { } /** - *resolveStack.
+ *+ * resolveStack. + *
*/ public final void resolveStack() { // Resolving the Stack @@ -764,15 +828,17 @@ public class MagicStack extends MyObservable { // TODO: change to use forge.view.FView? GuiDisplayUtil.updateGUI(); - this.freezeStack(); // freeze the stack while we're in the middle of resolving + this.freezeStack(); // freeze the stack while we're in the middle of + // resolving setResolving(true); SpellAbility sa = AllZone.getStack().pop(); - AllZone.getPhase().resetPriority(); // ActivePlayer gains priority first after Resolve + AllZone.getPhase().resetPriority(); // ActivePlayer gains priority first + // after Resolve final Card source = sa.getSourceCard(); - if (hasFizzled(sa, source)) { //Fizzle + if (hasFizzled(sa, source)) { // Fizzle // TODO: Spell fizzles, what's the best way to alert player? Log.debug(source.getName() + " ability fizzles."); finishResolving(sa, true); @@ -783,87 +849,82 @@ public class MagicStack extends MyObservable { sa.resolve(); finishResolving(sa, false); } - - if(source.hasStartOfKeyword("Haunt") && !source.isCreature() && AllZone.getZoneOf(source).is(Constant.Zone.Graveyard)) { + + if (source.hasStartOfKeyword("Haunt") && !source.isCreature() + && AllZone.getZoneOf(source).is(Constant.Zone.Graveyard)) { CardList creats = AllZoneUtil.getCreaturesInPlay(); - for(int i=0;i+ * removeCardFromStack. + *
+ * + * @param sa + * a {@link forge.card.spellability.SpellAbility} object. + * @param fizzle + * a boolean. * @since 1.0.15 */ public final void removeCardFromStack(final SpellAbility sa, final boolean fizzle) { Card source = sa.getSourceCard(); - //do nothing + // do nothing if (sa.getSourceCard().isCopiedSpell() || sa.isAbility()) { } // Handle cards that need to be moved differently @@ -874,23 +935,28 @@ public class MagicStack extends MyObservable { sa.setFlashBackAbility(false); } - // If Spell and still on the Stack then let it goto the graveyard or replace its own movement + // If Spell and still on the Stack then let it goto the graveyard or + // replace its own movement else if (!source.isCopiedSpell() && (source.isInstant() || source.isSorcery() || fizzle) - && AllZone.getZoneOf(source).is(Constant.Zone.Stack)) { + && AllZone.getZoneOf(source).is(Constant.Zone.Stack)) { AllZone.getGameAction().moveToGraveyard(source); } } /** - *finishResolving.
- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param fizzle a boolean. + *+ * finishResolving. + *
+ * + * @param sa + * a {@link forge.card.spellability.SpellAbility} object. + * @param fizzle + * a boolean. * @since 1.0.15 */ public final void finishResolving(final SpellAbility sa, final boolean fizzle) { - //remove card from the stack + // remove card from the stack removeCardFromStack(sa, fizzle); // After SA resolves we have to do a handful of things @@ -909,9 +975,9 @@ public class MagicStack extends MyObservable { // TODO: change to use forge.view.FView? GuiDisplayUtil.updateGUI(); - //TODO: this is a huge hack. Why is this necessary? - //hostCard in AF is not the same object that's on the battlefield - //verified by System.identityHashCode(card); + // TODO: this is a huge hack. Why is this necessary? + // hostCard in AF is not the same object that's on the battlefield + // verified by System.identityHashCode(card); Card tmp = sa.getSourceCard(); if (tmp.getClones().size() > 0) { for (Card c : AllZoneUtil.getCardsIn(Zone.Battlefield)) { @@ -924,10 +990,14 @@ public class MagicStack extends MyObservable { } /** - *hasFizzled.
- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. - * @param source a {@link forge.Card} object. + *+ * hasFizzled. + *
+ * + * @param sa + * a {@link forge.card.spellability.SpellAbility} object. + * @param source + * a {@link forge.Card} object. * @return a boolean. */ public final boolean hasFizzled(final SpellAbility sa, final Card source) { @@ -941,18 +1011,19 @@ public class MagicStack extends MyObservable { while (true) { Target tgt = fizzSA.getTarget(); if (tgt != null && tgt.getMinTargets(source, fizzSA) == 0 && tgt.getNumTargeted() == 0) { - // Don't assume fizzled for minTargets == 0 and nothing is targeted - } - else if (firstTarget && (tgt != null || fizzSA.getTargetCard() != null - || fizzSA.getTargetPlayer() != null)) - { - // If there is at least 1 target, fizzle switches because ALL targets need to be invalid + // Don't assume fizzled for minTargets == 0 and nothing is + // targeted + } else if (firstTarget + && (tgt != null || fizzSA.getTargetCard() != null || fizzSA.getTargetPlayer() != null)) { + // If there is at least 1 target, fizzle switches because ALL + // targets need to be invalid fizzle = true; firstTarget = false; } if (tgt != null) { - // With multi-targets, as long as one target is still legal, we'll try to go through as much as possible + // With multi-targets, as long as one target is still legal, + // we'll try to go through as much as possible ArrayList