removed Action interface

CommandList replaced with a plain list (though should better have used a stack, since the commandlist was adding items at index 0)
Phase - removed duplicate wrapper UntilYourNextTurn to same data as until(player)
removed imports, 
ColorChanger - used List instead of ArrayList
This commit is contained in:
Maxmtg
2013-04-22 07:02:46 +00:00
parent ce428b0c1b
commit bc5f5aac51
15 changed files with 62 additions and 301 deletions

View File

@@ -1,18 +0,0 @@
package forge;
/**
* <p>
* Command interface, just like Guava Function but return type is void.
* </p>
*
* @author Forge
* @version $Id: Command.java 12297 2011-11-28 19:56:47Z jendave $
*/
public interface Action<T> {
/**
* <p>
* execute.
* </p>
*/
void perform(T argument);
}

View File

@@ -1586,7 +1586,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return new CardColor(this);
}
final ArrayList<CardColor> globalChanges = getOwner() == null ? new ArrayList<CardColor>() : getOwner().getGame().getColorChanger().getColorChanges();
final List<CardColor> globalChanges = getOwner() == null ? new ArrayList<CardColor>() : getOwner().getGame().getColorChanger().getColorChanges();
CardColor colors = this.determineColor(globalChanges);
colors.fixColorless();
return colors;
@@ -1623,7 +1623,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* an ArrayList<CardColor>
* @return a CardColor
*/
final CardColor determineColor(final ArrayList<CardColor> globalChanges) {
final CardColor determineColor(final List<CardColor> globalChanges) {
final CardColor colors = new CardColor(this);
int i = this.getCharacteristics().getCardColor().size() - 1;
int j = -1;

View File

@@ -18,6 +18,7 @@
package forge;
import java.util.ArrayList;
import java.util.List;
import forge.card.mana.ManaCostBeingPaid;
@@ -26,7 +27,7 @@ import forge.card.mana.ManaCostBeingPaid;
*
*/
public class ColorChanger {
private final ArrayList<CardColor> globalColorChanges = new ArrayList<CardColor>();
private final List<CardColor> globalColorChanges = new ArrayList<CardColor>();
/**
* <p>
@@ -104,7 +105,7 @@ public class ColorChanger {
*
* @return a {@link java.util.ArrayList} object.
*/
public final ArrayList<CardColor> getColorChanges() {
public final List<CardColor> getColorChanges() {
return this.globalColorChanges;
}
}

View File

@@ -1,139 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge;
import java.util.ArrayList;
import java.util.Iterator;
/**
* <p>
* CommandList class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class CommandList implements Command, Iterable<Command> {
/** Constant <code>serialVersionUID=-1532687201812613302L</code>. */
private static final long serialVersionUID = -1532687201812613302L;
private final ArrayList<Command> a = new ArrayList<Command>();
/**
* Create a new CommandList.
*/
public CommandList() {
// nothing to do
}
/**
* Create a new CommandList that contains a command c.
*
* @param c
* a Command
*/
public CommandList(final Command c) {
this.a.add(c);
}
/**
* <p>
* iterator.
* </p>
*
* @return a {@link java.util.Iterator} object.
*/
@Override
public final Iterator<Command> iterator() {
return this.a.iterator();
}
// bug fix, when token is pumped up like with Giant Growth
// and Sorceress Queen targets token, the effects need to be done
// in this order, weird I know, DO NOT CHANGE THIS
/**
* <p>
* add.
* </p>
*
* @param c
* a {@link forge.Command} object.
*/
public final void add(final Command c) {
this.a.add(0, c);
}
/**
* <p>
* get.
* </p>
*
* @param i
* a int.
* @return a {@link forge.Command} object.
*/
public final Command get(final int i) {
return this.a.get(i);
}
/**
* <p>
* remove.
* </p>
*
* @param i
* a int.
* @return a {@link forge.Command} object.
*/
public final Command remove(final int i) {
return this.a.remove(i);
}
/**
* <p>
* size.
* </p>
*
* @return a int.
*/
public final int size() {
return this.a.size();
}
/**
* <p>
* clear.
* </p>
*/
public final void clear() {
this.a.clear();
}
/**
* <p>
* execute.
* </p>
*/
@Override
public final void run() {
for (int i = 0; i < this.size(); i++) {
this.get(i).run();
}
}
}

View File

@@ -272,7 +272,7 @@ public class AnimateEffect extends AnimateEffectBase {
} else if (sa.hasParam("UntilControllerNextUntap")) {
Singletons.getModel().getGame().getUntap().addUntil(c.getController(), unanimate);
} else if (sa.hasParam("UntilYourNextTurn")) {
Singletons.getModel().getGame().getCleanup().addUntilYourNextTurn(host.getController(), unanimate);
Singletons.getModel().getGame().getCleanup().addUntil(host.getController(), unanimate);
} else {
Singletons.getModel().getGame().getEndOfTurn().addUntil(unanimate);
}

View File

@@ -203,7 +203,7 @@ public class CloneEffect extends SpellAbilityEffect {
if (duration.equals("UntilEndOfTurn")) {
Singletons.getModel().getGame().getEndOfTurn().addUntil(unclone);
} else if (duration.equals("UntilYourNextTurn")) {
Singletons.getModel().getGame().getCleanup().addUntilYourNextTurn(host.getController(), unclone);
Singletons.getModel().getGame().getCleanup().addUntil(host.getController(), unclone);
}
}

View File

@@ -212,7 +212,7 @@ public class EffectEffect extends SpellAbilityEffect {
hostCard.addLeavesPlayCommand(endEffect);
}
else if (duration.equals("UntilYourNextTurn")) {
Singletons.getModel().getGame().getCleanup().addUntilYourNextTurn(controller, endEffect);
Singletons.getModel().getGame().getCleanup().addUntil(controller, endEffect);
}
}

View File

@@ -64,7 +64,7 @@ public class PumpEffect extends SpellAbilityEffect {
sa.getSourceCard().addLeavesPlayCommand(untilEOT);
sa.getSourceCard().addChangeControllerCommand(untilEOT);
} else if (sa.hasParam("UntilYourNextTurn")) {
Singletons.getModel().getGame().getCleanup().addUntilYourNextTurn(sa.getActivatingPlayer(), untilEOT);
Singletons.getModel().getGame().getCleanup().addUntil(sa.getActivatingPlayer(), untilEOT);
} else if (sa.hasParam("UntilUntaps")) {
sa.getSourceCard().addUntapCommand(untilEOT);
} else {

View File

@@ -46,13 +46,11 @@ import forge.control.input.InputSelectCards;
import forge.control.input.InputSelectCardsFromList;
import forge.game.ai.ComputerUtilCard;
import forge.game.ai.ComputerUtilCombat;
import forge.game.event.TokenCreatedEvent;
import forge.game.player.Player;
import forge.game.zone.PlayerZone;
import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
import forge.gui.GuiChoose;
import forge.item.CardToken;
import forge.util.Aggregates;
/**

View File

@@ -170,7 +170,7 @@ public class EndOfTurn extends Phase {
game.getStack().addSimultaneousStackEntry(change);
}
this.execute(this.getAt());
this.execute(this.at);
} // executeAt()

View File

@@ -17,11 +17,13 @@
*/
package forge.game.phase;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.google.common.collect.Lists;
import forge.Command;
import forge.CommandList;
import forge.Singletons;
import forge.game.GameState;
import forge.game.player.Player;
@@ -38,66 +40,76 @@ public abstract class Phase implements java.io.Serializable {
private static final long serialVersionUID = 4665309652476851977L;
/** The at. */
private final CommandList at = new CommandList();
protected final GameState game;
public Phase(final GameState game0) {
game = game0;
}
/** The at. */
protected final List<Command> at = new ArrayList<Command>();
/**
* Gets the at.
*
* @return the at
* <p>
* Add a hardcoded trigger that will execute "at <phase>".
* </p>
*
* @param c
* a {@link forge.Command} object.
*/
public CommandList getAt() {
return at;
public final void addAt(final Command c) {
this.at.add(0, c);
}
/**
* Gets the until.
*
* @return the until
* <p>
* Executes any hardcoded triggers that happen "at <phase>".
* </p>
*/
public CommandList getUntil() {
return until;
}
/**
* Gets the until map.
*
* @return the until map
*/
public HashMap<Player, CommandList> getUntilMap() {
return untilMap;
public void executeAt() {
this.execute(this.at);
}
/** The until. */
private final CommandList until = new CommandList();
private final List<Command> until = new ArrayList<Command>();
/**
* <p>
* Add a Command that will terminate an effect with "until <phase>".
* </p>
*
* @param c
* a {@link forge.Command} object.
*/
public final void addUntil(final Command c) {
this.until.add(0, c);
}
/**
* <p>
* Executes the termination of effects that apply "until <phase>".
* </p>
*/
public final void executeUntil() {
this.execute(this.until);
}
/** The until map. */
private final HashMap<Player, CommandList> untilMap = new HashMap<Player, CommandList>();
private final HashMap<Player, List<Command>> untilMap = new HashMap<Player, List<Command>>();
/**
* <p>
* Add a Command that will terminate an effect with "until <Player's> next <phase>".
* </p>
*
* @param p
* a {@link forge.game.player.Player} object
* @param c
* a {@link forge.Command} object.
* Use cleanup phase to terminate an effect with "until <Player's> next turn"
*/
public final void addUntil(Player p, final Command c) {
if (null == p) {
p = Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn();
p = game.getPhaseHandler().getPlayerTurn();
}
if (this.untilMap.containsKey(p)) {
this.untilMap.get(p).add(c);
this.untilMap.get(p).add(0, c);
} else {
this.untilMap.put(p, new CommandList(c));
this.untilMap.put(p, Lists.newArrayList(c));
}
}
@@ -115,84 +127,6 @@ public abstract class Phase implements java.io.Serializable {
}
}
/**
* <p>
* Add a Command that will terminate an effect with "until <Player's> next turn".
* </p>
*
* @param p
* a {@link forge.game.player.Player} object
* @param command
* a {@link forge.Command} object.
*/
public final void addUntilYourNextTurn(Player p, final Command command) {
if (null == p) {
p = Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn();
}
if (this.untilMap.containsKey(p)) {
this.untilMap.get(p).add(command);
} else {
this.untilMap.put(p, new CommandList(command));
}
}
/**
* <p>
* Executes the termination of effects that apply "until <Player's> next turn".
* </p>
*
* @param pNext
* the next active player
*/
public final void executeUntilTurn(final Player pNext) {
if (this.untilMap.containsKey(pNext)) {
this.execute(this.untilMap.get(pNext));
}
}
/**
* <p>
* Add a hardcoded trigger that will execute "at <phase>".
* </p>
*
* @param c
* a {@link forge.Command} object.
*/
public final void addAt(final Command c) {
this.at.add(c);
}
/**
* <p>
* Add a Command that will terminate an effect with "until <phase>".
* </p>
*
* @param c
* a {@link forge.Command} object.
*/
public final void addUntil(final Command c) {
this.until.add(c);
}
/**
* <p>
* Executes any hardcoded triggers that happen "at <phase>".
* </p>
*/
public void executeAt() {
this.execute(this.at);
}
/**
* <p>
* Executes the termination of effects that apply "until <phase>".
* </p>
*/
public final void executeUntil() {
this.execute(this.until);
}
/**
* <p>
* execute.
@@ -201,7 +135,7 @@ public abstract class Phase implements java.io.Serializable {
* @param c
* a {@link forge.CommandList} object.
*/
protected void execute(final CommandList c) {
protected void execute(final List<Command> c) {
final int length = c.size();
for (int i = 0; i < length; i++) {
@@ -209,15 +143,4 @@ public abstract class Phase implements java.io.Serializable {
}
}
/**
* <p>
* reset.
* </p>
*/
public void reset() {
at.clear();
until.clear();
untilMap.clear();
}
} //end class Phase

View File

@@ -383,7 +383,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
player.getController().autoPassCancel(); // autopass won't wrap to next turn
}
this.getPlayerTurn().removeKeyword("Skip all combat phases of this turn.");
game.getCleanup().executeUntilTurn(this.getNextTurn());
game.getCleanup().executeUntil(this.getNextTurn());
break;
default:

View File

@@ -63,7 +63,7 @@ public class Untap extends Phase {
*/
@Override
public void executeAt() {
this.execute(this.getAt());
this.execute(this.at);
final Player turn = game.getPhaseHandler().getPlayerTurn();
Untap.doPhasing(turn);

View File

@@ -1,7 +1,5 @@
package forge.gui.home;
import org.apache.commons.lang.StringUtils;
import forge.Command;
import forge.Singletons;
import forge.control.FControl;