diff --git a/src/main/java/forge/EndOfTurn.java b/src/main/java/forge/EndOfTurn.java index 154d21ff6d5..c1cc994a05c 100644 --- a/src/main/java/forge/EndOfTurn.java +++ b/src/main/java/forge/EndOfTurn.java @@ -20,11 +20,11 @@ package forge; import forge.Constant.Zone; import forge.card.spellability.Ability; import forge.card.spellability.SpellAbility; +import forge.gui.GuiUtils; -//handles "until end of turn" and "at end of turn" commands from cards /** *

- * EndOfTurn class. + * Handles "until end of turn" effects and "at end of turn" triggers. *

* * @author Forge @@ -36,11 +36,10 @@ public class EndOfTurn implements java.io.Serializable { private final CommandList at = new CommandList(); private final CommandList until = new CommandList(); - private final CommandList last = new CommandList(); /** *

- * addAt. + * Add a Command that will act as a trigger for "at end of turn". *

* * @param c @@ -52,7 +51,7 @@ public class EndOfTurn implements java.io.Serializable { /** *

- * addUntil. + * Add a Command that will terminate an effect with "until end of turn". *

* * @param c @@ -64,33 +63,23 @@ public class EndOfTurn implements java.io.Serializable { /** *

- * addLast. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void addLast(final Command c) { - this.last.add(c); - } - - /** - *

- * executeAt. + * Handles all the hardcoded events that happen "at end of turn". *

*/ public final void executeAt() { + // TODO - should this freeze the Stack? + // Pyrohemia and Pestilence final CardList all = AllZoneUtil.getCardsIn(Zone.Battlefield); - GameActionUtil.endOfTurnWallOfReverence(); - GameActionUtil.endOfTurnLighthouseChronologist(); + EndOfTurn.endOfTurnWallOfReverence(); + EndOfTurn.endOfTurnLighthouseChronologist(); // reset mustAttackEntity for me AllZone.getPhase().getPlayerTurn().setMustAttackEntity(null); - GameActionUtil.removeAttackedBlockedThisTurn(); + EndOfTurn.removeAttackedBlockedThisTurn(); AllZone.getStaticEffects().rePopulateStateBasedList(); @@ -237,50 +226,16 @@ public class EndOfTurn implements java.io.Serializable { /** *

- * executeUntil. + * Executes the termination of effects that apply "until end of turn". *

*/ public final void executeUntil() { this.execute(this.until); - this.execute(this.last); } /** *

- * sizeAt. - *

- * - * @return a int. - */ - public final int sizeAt() { - return this.at.size(); - } - - /** - *

- * sizeUntil. - *

- * - * @return a int. - */ - public final int sizeUntil() { - return this.until.size(); - } - - /** - *

- * sizeLast. - *

- * - * @return a int. - */ - public final int sizeLast() { - return this.last.size(); - } - - /** - *

- * execute. + * Executes each Command in a CommandList. *

* * @param c @@ -294,4 +249,101 @@ public class EndOfTurn implements java.io.Serializable { } } + private static void endOfTurnWallOfReverence() { + final Player player = AllZone.getPhase().getPlayerTurn(); + final CardList list = player.getCardsIn(Zone.Battlefield, "Wall of Reverence"); + + Ability ability; + for (int i = 0; i < list.size(); i++) { + final Card card = list.get(i); + ability = new Ability(list.get(i), "0") { + @Override + public void resolve() { + CardList creats = AllZoneUtil.getCreaturesInPlay(player); + creats = creats.getTargetableCards(this); + if (creats.size() == 0) { + return; + } + + if (player.isHuman()) { + final Object o = GuiUtils.getChoiceOptional( + "Select target creature for Wall of Reverence life gain", creats.toArray()); + if (o != null) { + final Card c = (Card) o; + final int power = c.getNetAttack(); + player.gainLife(power, card); + } + } else { // computer + CardListUtil.sortAttack(creats); + final Card c = creats.get(0); + if (c != null) { + final int power = c.getNetAttack(); + player.gainLife(power, card); + } + } + } // resolve + }; // ability + + final StringBuilder sb = new StringBuilder(); + sb.append(card).append(" - ").append(player).append(" gains life equal to target creature's power."); + ability.setStackDescription(sb.toString()); + + AllZone.getStack().addSimultaneousStackEntry(ability); + + } + } // endOfTurnWallOfReverence() + + private static void endOfTurnLighthouseChronologist() { + final Player player = AllZone.getPhase().getPlayerTurn(); + final Player opponent = player.getOpponent(); + CardList list = opponent.getCardsIn(Zone.Battlefield); + + list = list.filter(new CardListFilter() { + @Override + public boolean addCard(final Card c) { + return c.getName().equals("Lighthouse Chronologist") && (c.getCounters(Counters.LEVEL) >= 7); + } + }); + + Ability ability; + for (int i = 0; i < list.size(); i++) { + final Card card = list.get(i); + ability = new Ability(list.get(i), "0") { + @Override + public void resolve() { + AllZone.getPhase().addExtraTurn(card.getController()); + } + }; + + final StringBuilder sb = new StringBuilder(); + sb.append(card).append(" - ").append(card.getController()).append(" takes an extra turn."); + ability.setStackDescription(sb.toString()); + + AllZone.getStack().addSimultaneousStackEntry(ability); + + } + } + + private static void removeAttackedBlockedThisTurn() { + // resets the status of attacked/blocked this turn + final Player player = AllZone.getPhase().getPlayerTurn(); + final CardList list = AllZoneUtil.getCreaturesInPlay(player); + + for (int i = 0; i < list.size(); i++) { + final Card c = list.get(i); + if (c.getCreatureAttackedThisCombat()) { + c.setCreatureAttackedThisCombat(false); + } + if (c.getCreatureBlockedThisCombat()) { + c.setCreatureBlockedThisCombat(false); + // do not reset setCreatureAttackedThisTurn(), this appears to + // be combat specific + } + + if (c.getCreatureGotBlockedThisCombat()) { + c.setCreatureGotBlockedThisCombat(false); + } + } + } + } // end class EndOfTurn diff --git a/src/main/java/forge/GameActionUtil.java b/src/main/java/forge/GameActionUtil.java index 4be7262b8e8..4a8af9b9d94 100644 --- a/src/main/java/forge/GameActionUtil.java +++ b/src/main/java/forge/GameActionUtil.java @@ -323,122 +323,6 @@ public final class GameActionUtil { AllZone.getStack().setResolving(bResolving); } - // START ENDOFTURN CARDS - - /** - *

- * endOfTurnWallOfReverence. - *

- */ - public static void endOfTurnWallOfReverence() { - final Player player = AllZone.getPhase().getPlayerTurn(); - final CardList list = player.getCardsIn(Zone.Battlefield, "Wall of Reverence"); - - Ability ability; - for (int i = 0; i < list.size(); i++) { - final Card card = list.get(i); - ability = new Ability(list.get(i), "0") { - @Override - public void resolve() { - CardList creats = AllZoneUtil.getCreaturesInPlay(player); - creats = creats.getTargetableCards(this); - if (creats.size() == 0) { - return; - } - - if (player.isHuman()) { - final Object o = GuiUtils.getChoiceOptional( - "Select target creature for Wall of Reverence life gain", creats.toArray()); - if (o != null) { - final Card c = (Card) o; - final int power = c.getNetAttack(); - player.gainLife(power, card); - } - } else { // computer - CardListUtil.sortAttack(creats); - final Card c = creats.get(0); - if (c != null) { - final int power = c.getNetAttack(); - player.gainLife(power, card); - } - } - } // resolve - }; // ability - - final StringBuilder sb = new StringBuilder(); - sb.append(card).append(" - ").append(player).append(" gains life equal to target creature's power."); - ability.setStackDescription(sb.toString()); - - AllZone.getStack().addSimultaneousStackEntry(ability); - - } - } // endOfTurnWallOfReverence() - - /** - *

- * endOfTurnLighthouseChronologist. - *

- */ - public static void endOfTurnLighthouseChronologist() { - final Player player = AllZone.getPhase().getPlayerTurn(); - final Player opponent = player.getOpponent(); - CardList list = opponent.getCardsIn(Zone.Battlefield); - - list = list.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - return c.getName().equals("Lighthouse Chronologist") && (c.getCounters(Counters.LEVEL) >= 7); - } - }); - - Ability ability; - for (int i = 0; i < list.size(); i++) { - final Card card = list.get(i); - ability = new Ability(list.get(i), "0") { - @Override - public void resolve() { - AllZone.getPhase().addExtraTurn(card.getController()); - } - }; - - final StringBuilder sb = new StringBuilder(); - sb.append(card).append(" - ").append(card.getController()).append(" takes an extra turn."); - ability.setStackDescription(sb.toString()); - - AllZone.getStack().addSimultaneousStackEntry(ability); - - } - } - - // END ENDOFTURN CARDS - - /** - *

- * removeAttackedBlockedThisTurn. - *

- */ - public static void removeAttackedBlockedThisTurn() { - // resets the status of attacked/blocked this turn - final Player player = AllZone.getPhase().getPlayerTurn(); - final CardList list = AllZoneUtil.getCreaturesInPlay(player); - - for (int i = 0; i < list.size(); i++) { - final Card c = list.get(i); - if (c.getCreatureAttackedThisCombat()) { - c.setCreatureAttackedThisCombat(false); - } - if (c.getCreatureBlockedThisCombat()) { - c.setCreatureBlockedThisCombat(false); - // do not reset setCreatureAttackedThisTurn(), this appears to - // be combat specific - } - - if (c.getCreatureGotBlockedThisCombat()) { - c.setCreatureGotBlockedThisCombat(false); - } - } - } - /** *

* showYesNoDialog.