mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
- Some more cleanup related to PlayerZone.remove and moveTo
This commit is contained in:
@@ -180,7 +180,7 @@ public class AIPlayer extends Player{
|
||||
protected void doScry(final CardList topN, final int N) {
|
||||
int num = N;
|
||||
for(int i = 0; i < num; i++) {
|
||||
boolean b = false;
|
||||
boolean bottom = false;
|
||||
if(topN.get(i).getType().contains("Basic")) {
|
||||
CardList bl = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
|
||||
bl = bl.filter(new CardListFilter() {
|
||||
@@ -191,8 +191,7 @@ public class AIPlayer extends Player{
|
||||
}
|
||||
});
|
||||
|
||||
if(bl.size() > 5) // if control more than 5 Basic land, probably don't need more
|
||||
b = true;
|
||||
bottom = bl.size() > 5; // if control more than 5 Basic land, probably don't need more
|
||||
} else if(topN.get(i).getType().contains("Creature")) {
|
||||
CardList cl = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
|
||||
cl = cl.filter(new CardListFilter() {
|
||||
@@ -203,20 +202,21 @@ public class AIPlayer extends Player{
|
||||
}
|
||||
});
|
||||
|
||||
if(cl.size() > 5) // if control more than 5 Creatures, probably don't need more
|
||||
b = true;
|
||||
bottom = cl.size() > 5; // if control more than 5 Creatures, probably don't need more
|
||||
}
|
||||
if(b == true) {
|
||||
AllZone.Computer_Library.add(topN.get(i));
|
||||
topN.remove(i);
|
||||
if(bottom) {
|
||||
Card c = topN.get(i);
|
||||
AllZone.GameAction.moveToBottomOfLibrary(c);
|
||||
topN.remove(c);
|
||||
}
|
||||
}
|
||||
num = topN.size();
|
||||
if(num > 0) for(int i = 0; i < num; i++) // put the rest on top in random order
|
||||
for(int i = 0; i < num; i++) // put the rest on top in random order
|
||||
{
|
||||
Random rndm = new Random();
|
||||
int r = rndm.nextInt(topN.size());
|
||||
AllZone.Computer_Library.add(topN.get(r), 0);
|
||||
Card c = topN.get(r);
|
||||
AllZone.GameAction.moveToLibrary(c);
|
||||
topN.remove(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5713,8 +5713,12 @@ public class CardFactory implements NewConstants {
|
||||
PlayerZone library = AllZone.getZone(Constant.Zone.Library, card.getController());
|
||||
|
||||
if(library.size() != 0) {
|
||||
Card c = library.get(0);
|
||||
library.remove(0);
|
||||
Card c = library.get(0);
|
||||
library.remove(c);
|
||||
|
||||
// TODO: Necro really exiles face down, but for now we'll just do it this way
|
||||
// c.setIsFaceDown(true);
|
||||
// AllZone.GameAction.exile(c);
|
||||
necroCards.add(c); //add card to necro so that it goes into hand at end of turn
|
||||
AllZone.EndOfTurn.addAt(necro);
|
||||
}
|
||||
|
||||
@@ -1432,28 +1432,24 @@ public class CardFactory_Instants {
|
||||
CardList top = new CardList();
|
||||
PlayerZone library = AllZone.getZone(Constant.Zone.Library, card.getController());
|
||||
|
||||
Card c;
|
||||
int j = 4;
|
||||
if(library.size() < 4) j = library.size();
|
||||
for(int i = 0; i < j; i++) {
|
||||
c = library.get(0);
|
||||
library.remove(0);
|
||||
top.add(c);
|
||||
top.add(library.get(0));
|
||||
}
|
||||
|
||||
if(top.size() >= 1) {
|
||||
if(top.size() > 0) {
|
||||
//let user get choice
|
||||
Card chosen = AllZone.Display.getChoice("Choose a card to put into your hand",
|
||||
top.toArray());
|
||||
top.remove(chosen);
|
||||
|
||||
//put card in hand
|
||||
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController());
|
||||
hand.add(chosen);
|
||||
AllZone.GameAction.moveToHand(chosen);
|
||||
|
||||
//add cards to bottom of library
|
||||
for(int i = 0; i < top.size(); i++)
|
||||
library.add(top.get(i));
|
||||
AllZone.GameAction.moveToBottomOfLibrary(top.get(i));
|
||||
}
|
||||
}//resolve()
|
||||
};//SpellAbility
|
||||
|
||||
@@ -2818,19 +2818,20 @@ public class CardFactory_Sorceries {
|
||||
|
||||
for(int i = 0; i < 5 && i < limit; i++) {
|
||||
top.add(AllZone.Computer_Library.get(0));
|
||||
AllZone.Computer_Library.remove(0);
|
||||
}
|
||||
|
||||
//put creature card in hand, if there is one
|
||||
CardList creature = top.getType("Creature");
|
||||
if(creature.size() != 0) {
|
||||
AllZone.Computer_Hand.add(creature.get(0));
|
||||
top.remove(creature.get(0));
|
||||
if(creature.size() > 0) {
|
||||
Card best = CardFactoryUtil.AI_getBestCreature(creature);
|
||||
top.remove(best);
|
||||
AllZone.GameAction.moveToHand(best);
|
||||
}
|
||||
|
||||
//put cards on bottom of library
|
||||
for(int i = 0; i < top.size(); i++)
|
||||
AllZone.Computer_Library.add(top.get(i));
|
||||
AllZone.GameAction.moveToBottomOfLibrary(top.get(i));
|
||||
|
||||
}//computerResolve()
|
||||
|
||||
public void humanResolve() {
|
||||
@@ -2844,15 +2845,14 @@ public class CardFactory_Sorceries {
|
||||
//optional, select a creature
|
||||
Object o = AllZone.Display.getChoiceOptional("Select a creature", list.toArray());
|
||||
if(o != null && ((Card) o).isCreature()) {
|
||||
AllZone.GameAction.moveTo(hand, (Card) o);
|
||||
list.remove((Card) o);
|
||||
AllZone.GameAction.moveToHand((Card) o);
|
||||
}
|
||||
|
||||
//put remaining cards on the bottom of the library
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
library.remove(list.get(i));
|
||||
library.add(list.get(i));
|
||||
}
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
AllZone.GameAction.moveToBottomOfLibrary(list.get(i));
|
||||
|
||||
}//resolve()
|
||||
};
|
||||
card.clearSpellAbility();
|
||||
|
||||
@@ -192,14 +192,13 @@ public class GameAction {
|
||||
return moveTo(play, c);
|
||||
}
|
||||
|
||||
public void moveToBottomOfLibrary(Card c) {
|
||||
int pos = AllZoneUtil.getPlayerCardsInLibrary(c.getOwner()).size();
|
||||
moveToLibrary(c, pos);
|
||||
}
|
||||
|
||||
public void moveToTopOfLibrary(Card c) {
|
||||
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, 0);
|
||||
moveToLibrary(c, 0);
|
||||
}
|
||||
|
||||
public void moveToLibrary(Card c) {
|
||||
@@ -215,20 +214,7 @@ public class GameAction {
|
||||
|
||||
library.add(c, libPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* moves a card from whichever Zone it's in to the bottom of its owner's library
|
||||
*
|
||||
* @param c the card to move
|
||||
*/
|
||||
public void moveToBottomOfLibrary(Card c) {
|
||||
PlayerZone p = AllZone.getZone(c);
|
||||
PlayerZone lib = AllZone.getZone(Constant.Zone.Library, c.getOwner());
|
||||
if( p != null ) p.remove(c);
|
||||
if(!c.isToken()) lib.add(c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean AI_discardNumType(int numDiscard, String[] uTypes, SpellAbility sa) {
|
||||
CardList hand = new CardList();
|
||||
hand.addAll(AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer).getCards());
|
||||
|
||||
@@ -102,23 +102,23 @@ public class HumanPlayer extends Player{
|
||||
protected void doScry(final CardList topN, final int N) {
|
||||
int num = N;
|
||||
for(int i = 0; i < num; i++) {
|
||||
Object o;
|
||||
o = AllZone.Display.getChoiceOptional("Put on bottom of library.",topN.toArray());
|
||||
Object o = AllZone.Display.getChoiceOptional("Put on bottom of library.",topN.toArray());
|
||||
if(o != null) {
|
||||
Card c = (Card) o;
|
||||
topN.remove(c);
|
||||
AllZone.Human_Library.add(c);
|
||||
} else // no card chosen for the bottom
|
||||
break;
|
||||
AllZone.GameAction.moveToBottomOfLibrary(c);
|
||||
}
|
||||
else // no card chosen for the bottom
|
||||
break;
|
||||
}
|
||||
num = topN.size();
|
||||
if(num > 0) for(int i = 0; i < num; i++) {
|
||||
for(int i = 0; i < num; i++) {
|
||||
Object o;
|
||||
o = AllZone.Display.getChoice("Put on top of library.", topN.toArray());
|
||||
if(o != null) {
|
||||
Card c = (Card) o;
|
||||
topN.remove(c);
|
||||
AllZone.Human_Library.add(c, 0);
|
||||
AllZone.GameAction.moveToLibrary(c);
|
||||
}
|
||||
// no else - a card must have been chosen
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ public class MagicStack extends MyObservable {
|
||||
continue;
|
||||
}
|
||||
Card revealed = AllZone.Human_Library.get(0);
|
||||
AllZone.Human_Library.remove(0);
|
||||
|
||||
revealMsg.append(revealed.getName());
|
||||
if(!revealed.isType("Creature"))
|
||||
{
|
||||
@@ -522,7 +522,6 @@ public class MagicStack extends MyObservable {
|
||||
continue;
|
||||
}
|
||||
Card revealed = AllZone.Computer_Library.get(0);
|
||||
AllZone.Computer_Library.remove(0);
|
||||
revealMsg.append(revealed.getName());
|
||||
if(!revealed.isType("Creature"))
|
||||
{
|
||||
|
||||
@@ -530,20 +530,20 @@ public abstract class Player extends MyObservable{
|
||||
|
||||
public void drawCards(int n) {
|
||||
PlayerZone library = AllZone.getZone(Constant.Zone.Library, this);
|
||||
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, this);
|
||||
|
||||
for(int i = 0; i < n; i++) {
|
||||
// todo: any draw replacements would go here, not just Dredge
|
||||
if(getDredge().size() == 0 || !dredge()) {
|
||||
doDraw(library, hand);
|
||||
doDraw(library);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doDraw(PlayerZone library, PlayerZone hand) {
|
||||
private void doDraw(PlayerZone library) {
|
||||
if(library.size() != 0) {
|
||||
Card c = library.get(0);
|
||||
library.remove(0);
|
||||
hand.add(c);
|
||||
AllZone.GameAction.moveToHand(c);
|
||||
|
||||
setLastDrawnCard(c);
|
||||
c.setDrawnThisTurn(true);
|
||||
numDrawnThisTurn++;
|
||||
@@ -740,7 +740,6 @@ public abstract class Player extends MyObservable{
|
||||
numScry = Math.min(numScry, library.size());
|
||||
for(int i = 0; i < numScry; i++) {
|
||||
topN.add(library.get(0));
|
||||
library.remove(0);
|
||||
}
|
||||
doScry(topN, topN.size());
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ interface IPlayerZone
|
||||
|
||||
public Card get(int index);
|
||||
public void remove(Object o);
|
||||
public void remove(int index);
|
||||
|
||||
public void setCards(Card c[]);
|
||||
public Card[] getCards();
|
||||
|
||||
Reference in New Issue
Block a user