- Some Cleanup related to getZone and getCardsInZone

This commit is contained in:
jendave
2011-08-06 15:17:04 +00:00
parent 4db6c5ef34
commit c40670f271
20 changed files with 100 additions and 149 deletions

View File

@@ -140,11 +140,10 @@ public class AIPlayer extends Player{
if(r.nextBoolean()) libPos = "top";
else libPos = "bottom";
}
CardList hand = new CardList();
hand.addAll(AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer).getCards());
CardList hand = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
CardList blIP = new CardList();
blIP.addAll(AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer).getCards());
CardList blIP = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
blIP = blIP.getType("Basic");
if(blIP.size() > 5) {
CardList blIH = hand.getType("Basic");
@@ -183,8 +182,7 @@ public class AIPlayer extends Player{
for(int i = 0; i < num; i++) {
boolean b = false;
if(topN.get(i).getType().contains("Basic")) {
CardList bl = new CardList(
AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer).getCards());
CardList bl = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
bl = bl.filter(new CardListFilter() {
public boolean addCard(Card c) {
if(c.getType().contains("Basic")) return true;
@@ -196,8 +194,7 @@ public class AIPlayer extends Player{
if(bl.size() > 5) // if control more than 5 Basic land, probably don't need more
b = true;
} else if(topN.get(i).getType().contains("Creature")) {
CardList cl = new CardList(
AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer).getCards());
CardList cl = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
cl = cl.filter(new CardListFilter() {
public boolean addCard(Card c) {
if(c.getType().contains("Creature")) return true;

View File

@@ -361,10 +361,10 @@ public class AbilityFactory_ChangeZone {
if (origin.equals("Library") && i < 1) {
player.shuffle();
}
destZone.add(c, libraryPos);
AllZone.GameAction.moveToLibrary(c, libraryPos);
}
else {
destZone.add(c);
AllZone.GameAction.moveTo(destZone, c);
if (destination.equals("Battlefield") && params.containsKey("Tapped"))
c.tap();
}
@@ -456,10 +456,11 @@ public class AbilityFactory_ChangeZone {
origZone.remove(c);
if (destination.equals("Library")){
int libraryPos = params.containsKey("LibraryPosition") ? Integer.parseInt(params.get("LibraryPosition")) : 0;
destZone.add(c, libraryPos);
AllZone.GameAction.moveToLibrary(c, libraryPos);
}
else
destZone.add(c);
AllZone.GameAction.moveTo(destZone, c);
if (destination.equals("Battlefield") && params.containsKey("Tapped"))
c.tap();
}
@@ -808,6 +809,7 @@ public class AbilityFactory_ChangeZone {
for(Card tgtC : tgtCards){
PlayerZone originZone = AllZone.getZone(tgtC);
// if Target isn't in the expected Zone, continue
if (!originZone.is(origin))
continue;
@@ -835,10 +837,8 @@ public class AbilityFactory_ChangeZone {
if (libraryPosition == -1)
libraryPosition = library.size();
Card cardCopy = AllZone.CardFactory.copyCard(tgtC);
library.add(cardCopy, libraryPosition); //move to library
AllZone.GameAction.moveToLibrary(tgtC, libraryPosition);
if (params.containsKey("Shuffle")) // for things like Gaea's Blessing
player.shuffle();
}

View File

@@ -344,7 +344,8 @@ public class AbilityFactory_CounterMagic {
}
else {
//AI decision-making, only draws a card if it doesn't risk discarding it.
if(AllZone.getZone(Constant.Zone.Hand,AllZone.ComputerPlayer).getCards().length + Integer.parseInt(SplitActionParams[0]) < 6) {
if(AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer).size() + Integer.parseInt(SplitActionParams[0]) < 6) {
Target.drawCards(Integer.parseInt(SplitActionParams[0]));
}
}
@@ -419,7 +420,7 @@ public class AbilityFactory_CounterMagic {
//Does nothing now, of course, but sometime in the future the AI may be able to remember cards revealed and prioritize discard spells accordingly.
}
else {
CardList list = new CardList(AllZone.getZone(Constant.Zone.Hand,AllZone.ComputerPlayer).getCards());
CardList list = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
AllZone.Display.getChoiceOptional("Revealed cards",list.toArray());
}
}
@@ -440,7 +441,7 @@ public class AbilityFactory_CounterMagic {
AllZoneUtil.rearrangeTopOfLibrary(Target, Integer.parseInt(SplitActionParams[0]), false);
}
else {
CardList list = new CardList(AllZone.getZone(Constant.Zone.Hand,AllZone.ComputerPlayer).getCards());
CardList list = AllZoneUtil.getCardsInZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
AllZone.Display.getChoiceOptional("Revealed cards",list.toArray());
}
}

View File

@@ -136,8 +136,9 @@ public class AbilityFactory_Counters {
String amountStr = af.getMapParams().get("CounterNum");
Player player = af.isCurse() ? AllZone.HumanPlayer : AllZone.ComputerPlayer;
list = new CardList(AllZone.getZone(Constant.Zone.Battlefield, player).getCards());
list = AllZoneUtil.getPlayerCardsInPlay(player);
list = list.filter(new CardListFilter() {
public boolean addCard(Card c) {
return CardFactoryUtil.canTarget(source, c);
@@ -273,7 +274,7 @@ public class AbilityFactory_Counters {
Player player = af.isCurse() ? AllZone.HumanPlayer : AllZone.ComputerPlayer;
list = new CardList(AllZone.getZone(Constant.Zone.Battlefield, player).getCards());
list = AllZoneUtil.getPlayerCardsInPlay(player);
list = list.filter(new CardListFilter() {
public boolean addCard(Card c) {
return CardFactoryUtil.canTarget(source, c);

View File

@@ -208,8 +208,7 @@ public class AbilityFactory_DealDamage {
if (restDamage == 0) return false;
PlayerZone compHand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
CardList hand = new CardList(compHand.getCards());
CardList hand = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
if(AF.isSpell() && hand.size() > 7) // anti-discard-at-EOT
return true;

View File

@@ -151,8 +151,8 @@ public class AbilityFactory_Destroy {
Target abTgt = sa.getTarget();
final Card source = sa.getSourceCard();
CardList list;
list = new CardList(AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer).getCards());
list = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
list = list.getTargetableCards(source);
if (abTgt != null){
@@ -246,8 +246,8 @@ public class AbilityFactory_Destroy {
if(params.containsKey("ValidCards"))
Valid = params.get("ValidCards");
CardList humanlist = new CardList(AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer).getCards());
CardList computerlist = new CardList(AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer).getCards());
CardList humanlist = AllZoneUtil.getCreaturesInPlay(AllZone.HumanPlayer);
CardList computerlist = AllZoneUtil.getCreaturesInPlay(AllZone.ComputerPlayer);
humanlist = humanlist.getValidCards(Valid.split(","), source.getController(), source);
computerlist = computerlist.getValidCards(Valid.split(","), source.getController(), source);
@@ -339,8 +339,8 @@ public class AbilityFactory_Destroy {
if(params.containsKey("ValidCards"))
Valid = params.get("ValidCards");
CardList list = new CardList(AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer).getCards());
list.addAll(AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer).getCards());
CardList list = AllZoneUtil.getCardsInPlay();
list = list.getValidCards(Valid.split(","), card.getController(), card);

View File

@@ -151,8 +151,7 @@ public class AbilityFactory_Regenerate {
else weight[0] = 0;
// if there are many cards in hand, then maybe it's not such a great idea to waste mana
CardList HandList = new CardList(AllZone.getZone(Constant.Zone.Hand,
AllZone.ComputerPlayer).getCards());
CardList HandList = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
if(HandList.size() >= 4) weight[1] = 25;
else weight[1] = 75;
@@ -164,8 +163,7 @@ public class AbilityFactory_Regenerate {
if(CardUtil.getConvertedManaCost(HandList.getCard(i).getManaCost()) > hCMC) hCMC = CardUtil.getConvertedManaCost(HandList.getCard(
i).getManaCost());
CardList LandList = new CardList(AllZone.getZone(Constant.Zone.Battlefield,
AllZone.ComputerPlayer).getCards());
CardList LandList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
LandList = LandList.getType("Land");
//most regenerate abilities cost 2 or less

View File

@@ -32,8 +32,8 @@ abstract public class Ability_Activated extends SpellAbility implements java.io.
});
if(Pithing.size() != 0) return false;
if(c.isCreature() && AllZone.getZone(c).getZoneName().equals(Constant.Zone.Battlefield)) {
if(c.isCreature() && AllZone.getZone(c).is(Constant.Zone.Battlefield)) {
CardList Silence = AllZoneUtil.getPlayerCardsInPlay(getSourceCard().getController().getOpponent());
Silence = Silence.getName("Linvala, Keeper of Silence");
if (Silence.size() != 0)

View File

@@ -35,8 +35,8 @@ public class EndOfTurn implements java.io.Serializable
if(creature.isEmpty())
{
CardList sacrifice = new CardList();
sacrifice.addAll(all.getName("Pyrohemia").toArray());
sacrifice.addAll(all.getName("Pestilence").toArray());
sacrifice.add(all.getName("Pyrohemia"));
sacrifice.add(all.getName("Pestilence"));
for(int i = 0; i < sacrifice.size(); i++)
AllZone.GameAction.sacrifice(sacrifice.get(i));
@@ -54,17 +54,7 @@ public class EndOfTurn implements java.io.Serializable
AllZone.GameInfo.setPreventCombatDamageThisTurn(false);
AllZone.StaticEffects.rePopulateStateBasedList();
/*
PlayerZone cz = AllZone.getZone(Constant.Zone.Removed_From_Play, AllZone.ComputerPlayer);
PlayerZone hz = AllZone.getZone(Constant.Zone.Removed_From_Play, AllZone.HumanPlayer);
CardList c = new CardList(cz.getCards());
CardList h = new CardList(hz.getCards());
System.out.println("number of cards in compy removed zone: " + c.size());
System.out.println("number of cards in human removed zone: " + h.size());
*/
for(Card c : all) {
if(!c.isFaceDown()
&& c.getKeyword().contains("At the beginning of the end step, sacrifice CARDNAME."))

View File

@@ -32,7 +32,7 @@ public class GameAction {
sa.getRestrictions().resetTurnActivations();
}
}
public Card moveTo(PlayerZone zone, Card c) {
// Remove card from Current Zone, if it has one
String prevZone = "";
@@ -51,6 +51,8 @@ public class GameAction {
moving = addSuspendTriggers(moving);
}
//boolean dontTrigger = p != null && p.is(Constant.Zone.Battlefield) && zone.is(Constant.Zone.Battlefield);
zone.add(moving);
//Run triggers
@@ -59,7 +61,7 @@ public class GameAction {
runParams.put("Origin", prevZone);
runParams.put("Destination", zone.getZoneName());
AllZone.TriggerHandler.runTrigger("ChangesZone", runParams);
return moving;
}
@@ -191,7 +193,17 @@ public class GameAction {
}
public void moveToLibrary(Card c) {
moveToTopOfLibrary(c);
moveToLibrary(c, 0);
}
public void moveToLibrary(Card c, int libPosition){
PlayerZone p = AllZone.getZone(c);
PlayerZone library = AllZone.getZone(Constant.Zone.Library, c.getOwner());
if(p != null) p.remove(c);
if(!c.isToken()) c = AllZone.CardFactory.copyCard(c);
library.add(c, libPosition);
}
/**

View File

@@ -123,25 +123,18 @@ public class GameActionUtil {
// Win / Lose
final Player player = AllZone.Phase.getPlayerTurn();
PlayerZone playZone = AllZone.getZone(Constant.Zone.Battlefield, player);
PlayerZone OpplayZone = AllZone.getZone(Constant.Zone.Battlefield, player.getOpponent());
CardList Platinumlist = new CardList(OpplayZone.getCards());
Platinumlist = Platinumlist.getName("Platinum Angel");
CardList Abyssallist = new CardList(playZone.getCards());
Abyssallist = Abyssallist.getName("Abyssal Persecutor");
if(Platinumlist.size() == 0 && Abyssallist.size() == 0) {
upkeep_Battle_of_Wits();
upkeep_Mortal_Combat();
upkeep_Epic_Struggle();
upkeep_Near_Death_Experience();
upkeep_Test_of_Endurance();
upkeep_Helix_Pinnacle();
upkeep_Barren_Glory();
upkeep_Felidar_Sovereign();
upkeep_Klass();
}
//Win / Lose
// Checks for can't win or can't lose happen in Player.altWinConditionMet()
upkeep_Battle_of_Wits();
upkeep_Mortal_Combat();
upkeep_Epic_Struggle();
upkeep_Near_Death_Experience();
upkeep_Test_of_Endurance();
upkeep_Helix_Pinnacle();
upkeep_Barren_Glory();
upkeep_Felidar_Sovereign();
upkeep_Convalescence();
upkeep_Convalescent_Care();
upkeep_Ancient_Runes();
@@ -10063,33 +10056,6 @@ public class GameActionUtil {
}// for
}// upkeep_Power_Surge()
private static void upkeep_Klass() {
final Player player = AllZone.Phase.getPlayerTurn();
PlayerZone playZone = AllZone.getZone(Constant.Zone.Battlefield, player);
CardList elf = new CardList(playZone.getCards());
elf = elf.getType("Elf");
CardList list = new CardList(playZone.getCards());
list = list.getName("Klaas, Elf Friend");
if(0 < list.size() && 10 <= elf.size()) {
final Card source = list.get(0);
Ability ability = new Ability(source, "0") {
@Override
public void resolve() {
player.getOpponent().setLife(0, source);
}
};// Ability
StringBuilder sb = new StringBuilder();
sb.append("Klaas, Elf Friend - ").append(player).append(" wins the game");
ability.setStackDescription(sb.toString());
AllZone.Stack.add(ability);
}// if
}// upkeep_Klass
private static void upkeep_Felidar_Sovereign() {
final Player player = AllZone.Phase.getPlayerTurn();
PlayerZone playZone = AllZone.getZone(Constant.Zone.Battlefield, player);

View File

@@ -53,7 +53,7 @@ public class Input_Mulligan extends Input {
void end() {
ButtonUtil.reset();
CardList HHandList = new CardList(AllZone.getZone(Constant.Zone.Hand, AllZone.HumanPlayer).getCards());
CardList HHandList = AllZoneUtil.getPlayerHand(AllZone.HumanPlayer);
PlayerZone HPlay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer);
PlayerZone HHand = AllZone.getZone(Constant.Zone.Hand, AllZone.HumanPlayer);
for(int i = 0; i < HHandList.size() ; i++) {
@@ -68,7 +68,7 @@ public class Input_Mulligan extends Input {
}
}
}
CardList CHandList = new CardList(AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer).getCards());
CardList CHandList = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
PlayerZone CPlay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer);
PlayerZone CHand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
for(int i = 0; i < CHandList.size() ; i++) {

View File

@@ -609,8 +609,7 @@ public class MagicStack extends MyObservable {
private static final long serialVersionUID = -2559488318473330418L;
public void execute() {
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, crd.getOwner());
AllZone.GameAction.moveTo(hand, crd);
AllZone.GameAction.moveToHand(crd);
}
});
}

View File

@@ -457,10 +457,8 @@ public class Phase extends MyObservable
public void resetAttackedThisCombat(Player player) {
// resets the status of attacked/blocked this phase
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, player);
CardList list = new CardList();
list.addAll(play.getCards());
CardList list = AllZoneUtil.getPlayerCardsInPlay(player);
list = list.getType("Creature");
for(int i = 0; i < list.size(); i++) {

View File

@@ -28,8 +28,7 @@ public class PhaseUtil {
runParams.put("Player", AllZone.Phase.getPlayerTurn());
AllZone.TriggerHandler.runTrigger("Phase", runParams);
PlayerZone p = AllZone.getZone(Constant.Zone.Battlefield, turn);
Card[] c = p.getCards();
AllZone.Phase.turnReset();
@@ -39,8 +38,9 @@ public class PhaseUtil {
// For tokens a player starts the game with they don't recover from Sum. Sickness on first turn
if (turn.getTurn() > 0){
for(int i = 0; i < c.length; i++)
c[i].setSickness(false);
CardList list = AllZoneUtil.getPlayerCardsInPlay(turn);
for(Card c : list)
c.setSickness(false);
}
turn.incrementTurn();
@@ -63,9 +63,8 @@ public class PhaseUtil {
private static void doUntap()
{
Player player = AllZone.Phase.getPlayerTurn();
PlayerZone p = AllZone.getZone(Constant.Zone.Battlefield, player);
CardList list = new CardList(p.getCards());
CardList list = AllZoneUtil.getPlayerCardsInPlay(player);
for(Card c : list) {
if (c.getBounceAtUntap() && c.getName().contains("Undiscovered Paradise") )
{
@@ -325,9 +324,8 @@ public class PhaseUtil {
return true;
Player turn = AllZone.Phase.getPlayerTurn();
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, turn);
if (turn.getCards(hand).size() == 0 && AllZoneUtil.isCardInPlay("Gibbering Descent", turn))
if (AllZoneUtil.getPlayerHand(turn).size() == 0 && AllZoneUtil.isCardInPlay("Gibbering Descent", turn))
return true;
return false;
@@ -405,13 +403,10 @@ public class PhaseUtil {
if (list.size() == 1){
AllZone.GameAction.checkWheneverKeyword(list.get(0), "Attack - Alone", null);
Player attackingPlayer = AllZone.Combat.getAttackingPlayer();
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, attackingPlayer);
CardList exalted = new CardList(play.getCards());
exalted = exalted.filter(new CardListFilter() {
public boolean addCard(Card c) {
return c.getKeyword().contains("Exalted");
}
});
CardList exalted = AllZoneUtil.getPlayerCardsInPlay(attackingPlayer);
exalted = exalted.getKeyword("Exalted");
if(exalted.size() > 0) CombatUtil.executeExaltedAbility(list.get(0), exalted.size());
// Make sure exalted effects get applied only once per combat
}

View File

@@ -675,8 +675,9 @@ public abstract class Player extends MyObservable{
public void discardRandom(final int num, final SpellAbility sa) {
for(int i = 0; i < num; i++) {
Card[] c = AllZone.getZone(Constant.Zone.Hand, this).getCards();
if(c.length != 0) doDiscard(CardUtil.getRandom(c), sa);
CardList list = AllZoneUtil.getPlayerHand(this);
if(list.size() != 0)
doDiscard(CardUtil.getRandom(list.toArray()), sa);
}
}

View File

@@ -40,23 +40,22 @@ public class SpellAbilityUtil
static public CardList getAvailableMana(Player player)
{
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, player);
CardList all = new CardList(play.getCards());
CardList mana = all.filter(new CardListFilter()
{
public boolean addCard(Card c)
{
if(c.isTapped())
return false;
CardList all = AllZoneUtil.getPlayerCardsInPlay(player);
CardList mana = all.filter(new CardListFilter()
{
public boolean addCard(Card c)
{
if(c.isTapped())
return false;
ArrayList<Ability_Mana> a = c.getManaAbility();
for(Ability_Mana am : a)
return am.isBasic();
return false;
}//addCard()
});//CardListFilter
ArrayList<Ability_Mana> a = c.getManaAbility();
for(Ability_Mana am : a)
return am.isBasic();
return false;
}//addCard()
});//CardListFilter
return mana;
return mana;
}//getUntappedMana
}

View File

@@ -24,6 +24,8 @@ public class SpellAbility_Requirements {
bCasting = true;
if (!ability.getSourceCard().isCopiedSpell()){
Card c = ability.getSourceCard();
// todo(sol): move Spell to Stack here?
fromZone = AllZone.getZone(c);
if (fromZone != null)
fromZone.remove(c);

View File

@@ -171,13 +171,13 @@ public class SpellAbility_Restriction {
if (nCardsInHand != -1){
// Can handle Library of Alexandria, or Hellbent
if (AllZone.getZone(Constant.Zone.Hand, activator).size() != nCardsInHand)
if (AllZoneUtil.getPlayerHand(activator).size() != nCardsInHand)
return false;
}
if (bNeedsThreshold){
// Threshold
if (AllZone.getZone(Constant.Zone.Graveyard, activator).size() < THRESHOLD)
if (AllZoneUtil.getPlayerGraveyard(activator).size() < THRESHOLD)
return false;
}

View File

@@ -89,15 +89,8 @@ public class StaticEffects
public void rePopulateStateBasedList()
{
reset();
PlayerZone playerZone = AllZone.getZone(Constant.Zone.Battlefield,
AllZone.HumanPlayer);
PlayerZone computerZone = AllZone.getZone(Constant.Zone.Battlefield,
AllZone.ComputerPlayer);
CardList cards = new CardList();
cards.addAll(playerZone.getCards());
cards.addAll(computerZone.getCards());
CardList cards = AllZoneUtil.getCardsInPlay();
Log.debug("== Start add state effects ==");
for (int i=0;i<cards.size();i++)