mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
ALL_ZONES added to Player, some functions in AllZone now use GameState
This commit is contained in:
@@ -425,19 +425,21 @@ public final class AllZone implements NewConstants {
|
||||
* @return a {@link forge.PlayerZone} object.
|
||||
*/
|
||||
public static PlayerZone getZone(final Card c) {
|
||||
if (AllZoneUtil.isCardInZone(getStackZone(), c)) {
|
||||
return getStackZone();
|
||||
final FGameState gameState = Singletons.getModel().getGameState();
|
||||
if (gameState == null) { return null; }
|
||||
|
||||
if (AllZoneUtil.isCardInZone(gameState.getStackZone(), c)) {
|
||||
return gameState.getStackZone();
|
||||
}
|
||||
|
||||
Player[] players = new Player[]{ AllZone.getHumanPlayer(), AllZone.getComputerPlayer() };
|
||||
Zone[] zones = new Zone[]{ Zone.Battlefield, Zone.Library, Zone.Graveyard, Zone.Hand, Zone.Exile, Zone.Command };
|
||||
for (Player p : players) {
|
||||
for(Zone z : zones) {
|
||||
|
||||
for (Player p : gameState.getPlayers()) {
|
||||
for(Zone z : Player.ALL_ZONES) {
|
||||
PlayerZone pz = p.getZone(z);
|
||||
if ( AllZoneUtil.isCardInZone(pz, c) )
|
||||
return pz;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -445,16 +447,13 @@ public final class AllZone implements NewConstants {
|
||||
* <p>resetZoneMoveTracking.</p>
|
||||
*/
|
||||
public static void resetZoneMoveTracking() {
|
||||
resetZoneMoveTracking(getHumanPlayer());
|
||||
resetZoneMoveTracking(getComputerPlayer());
|
||||
}
|
||||
|
||||
private static void resetZoneMoveTracking(Player player) {
|
||||
player.getZone(Zone.Command).resetCardsAddedThisTurn();
|
||||
player.getZone(Zone.Library).resetCardsAddedThisTurn();
|
||||
player.getZone(Zone.Hand).resetCardsAddedThisTurn();
|
||||
player.getZone(Zone.Battlefield).resetCardsAddedThisTurn();
|
||||
player.getZone(Zone.Graveyard).resetCardsAddedThisTurn();
|
||||
final FGameState gameState = Singletons.getModel().getGameState();
|
||||
if (gameState == null) { return; }
|
||||
for (Player p : gameState.getPlayers()) {
|
||||
for(Zone z : Player.ALL_ZONES) {
|
||||
p.getZone(z).resetCardsAddedThisTurn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,8 +494,11 @@ public final class AllZone implements NewConstants {
|
||||
getDisplay().showCombat("");
|
||||
getDisplay().loadPrefs();
|
||||
|
||||
resetAllZones(getHumanPlayer());
|
||||
resetAllZones(getComputerPlayer());
|
||||
for (Player p : Singletons.getModel().getGameState().getPlayers()) {
|
||||
for(Zone z : Player.ALL_ZONES) {
|
||||
p.getZone(z).reset();
|
||||
}
|
||||
}
|
||||
|
||||
getInputControl().clearInput();
|
||||
|
||||
@@ -510,15 +512,6 @@ public final class AllZone implements NewConstants {
|
||||
getTriggerHandler().clearRegistered();
|
||||
|
||||
}
|
||||
|
||||
private static void resetAllZones(Player player) {
|
||||
player.getZone(Zone.Command).reset();
|
||||
player.getZone(Zone.Library).reset();
|
||||
player.getZone(Zone.Hand).reset();
|
||||
player.getZone(Zone.Battlefield).reset();
|
||||
player.getZone(Zone.Graveyard).reset();
|
||||
player.getZone(Zone.Exile).reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for matchState.
|
||||
|
||||
@@ -70,16 +70,18 @@ public final class AllZoneUtil {
|
||||
*/
|
||||
public static CardList getCardsIn(final Constant.Zone zone) {
|
||||
CardList cards = new CardList();
|
||||
cards.addAll(AllZone.getHumanPlayer().getZone(zone).getCards());
|
||||
cards.addAll(AllZone.getComputerPlayer().getZone(zone).getCards());
|
||||
for (Player p : Singletons.getModel().getGameState().getPlayers()) {
|
||||
cards.addAll(p.getZone(zone).getCards());
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
public static CardList getCardsIn(final List<Constant.Zone> zones) {
|
||||
CardList cards = new CardList();
|
||||
for (Zone z: zones) {
|
||||
cards.addAll(AllZone.getHumanPlayer().getZone(z).getCards());
|
||||
cards.addAll(AllZone.getComputerPlayer().getZone(z).getCards());
|
||||
for (Player p : Singletons.getModel().getGameState().getPlayers()) {
|
||||
cards.addAll(p.getZone(z).getCards());
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
@@ -149,27 +151,7 @@ public final class AllZoneUtil {
|
||||
|
||||
//////// HAND
|
||||
|
||||
/**
|
||||
* answers the question "is a certain, specific card in this player's hand?".
|
||||
*
|
||||
* @param player the player's hand to check
|
||||
* @param card the specific card to look for
|
||||
* @return true if the card is present in this player's hand; false otherwise
|
||||
*/
|
||||
public static boolean isCardInPlayerHand(final Player player, final Card card) {
|
||||
return isCardInZone(player.getZone(Constant.Zone.Hand), card);
|
||||
}
|
||||
|
||||
/**
|
||||
* answers the question "is a specific card in this player's library?".
|
||||
*
|
||||
* @param player the player's library to check
|
||||
* @param card the specific card to look for
|
||||
* @return true if the card is present in this player's library; false otherwise
|
||||
*/
|
||||
public static boolean isCardInPlayerLibrary(final Player player, final Card card) {
|
||||
return isCardInZone(player.getZone(Constant.Zone.Library), card);
|
||||
}
|
||||
|
||||
/**
|
||||
* answers the question "is a specific card in the specified zone?".
|
||||
@@ -183,10 +165,8 @@ public final class AllZoneUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
CardList cl = getCardsInZone(pz);
|
||||
|
||||
for (int i = 0; i < cl.size(); i++) {
|
||||
if (cl.get(i).equals(card)) {
|
||||
for (Card c : pz.getCards()) {
|
||||
if (c.equals(card)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -204,15 +184,6 @@ public final class AllZoneUtil {
|
||||
return getCardsIn(Zone.Exile).contains(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isCardInGrave.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean isCardInGrave(final Card c) {
|
||||
return getCardsIn(Zone.Graveyard).contains(c);
|
||||
}
|
||||
|
||||
///Check if a certain card is in play
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ public abstract class Player extends GameEntity {
|
||||
protected Object mustAttackEntity = null;
|
||||
|
||||
Map<Constant.Zone, PlayerZone> zones = new EnumMap<Constant.Zone, PlayerZone>(Constant.Zone.class);
|
||||
public final static List<Zone> ALL_ZONES = Collections.unmodifiableList(Arrays.asList(Zone.Battlefield, Zone.Library, Zone.Graveyard, Zone.Hand, Zone.Exile, Zone.Command));
|
||||
|
||||
/**
|
||||
* <p>Constructor for Player.</p>
|
||||
@@ -65,19 +66,9 @@ public abstract class Player extends GameEntity {
|
||||
* @param myPoisonCounters a int.
|
||||
*/
|
||||
public Player(String myName, int myLife, int myPoisonCounters) {
|
||||
PlayerZone battlefield = new PlayerZone_ComesIntoPlay(Constant.Zone.Battlefield, this);
|
||||
PlayerZone hand = new DefaultPlayerZone(Constant.Zone.Hand, this);
|
||||
PlayerZone graveyard = new DefaultPlayerZone(Constant.Zone.Graveyard, this);
|
||||
PlayerZone library = new DefaultPlayerZone(Constant.Zone.Library, this);
|
||||
PlayerZone exile = new DefaultPlayerZone(Constant.Zone.Exile, this);
|
||||
PlayerZone command = new DefaultPlayerZone(Constant.Zone.Command, this);
|
||||
|
||||
zones.put(Constant.Zone.Graveyard, graveyard);
|
||||
zones.put(Constant.Zone.Hand, hand);
|
||||
zones.put(Constant.Zone.Library, library);
|
||||
zones.put(Constant.Zone.Battlefield, battlefield);
|
||||
zones.put(Constant.Zone.Exile, exile);
|
||||
zones.put(Constant.Zone.Command, command);
|
||||
for (Zone z : ALL_ZONES) {
|
||||
zones.put(z, new DefaultPlayerZone(z, this));
|
||||
}
|
||||
|
||||
reset();
|
||||
|
||||
|
||||
@@ -73,6 +73,10 @@ public class FGameState {
|
||||
protected final void setComputerPlayer(final Player computerPlayer0) {
|
||||
this.computerPlayer = computerPlayer0;
|
||||
}
|
||||
|
||||
public final Player[] getPlayers() {
|
||||
return new Player[]{ humanPlayer, computerPlayer };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user