mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
reveal cost payment will really reveal cards to players.
This commit is contained in:
@@ -91,19 +91,27 @@ public abstract class CostPartWithList extends CostPart {
|
||||
}
|
||||
|
||||
public final boolean executePayment(SpellAbility ability, Card targetCard) {
|
||||
addToList(targetCard);
|
||||
this.list.add(targetCard);
|
||||
doPayment(ability, targetCard);
|
||||
return true;
|
||||
}
|
||||
|
||||
// always returns true, made this to inline with return
|
||||
public final boolean executePayment(SpellAbility ability, Collection<Card> targetCards) {
|
||||
if(canPayListAtOnce()) { // This is used by reveal. Without it when opponent would reveal hand, you'll get N message boxes.
|
||||
this.list.addAll(targetCards);
|
||||
doListPayment(ability, targetCards);
|
||||
return true;
|
||||
}
|
||||
for(Card c: targetCards)
|
||||
executePayment(ability, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void doPayment(SpellAbility ability, Card targetCard);
|
||||
// Overload these two only together, set to true and perform payment on list
|
||||
protected boolean canPayListAtOnce() { return false; }
|
||||
protected void doListPayment(SpellAbility ability, Collection<Card> targetCards) { };
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
|
||||
@@ -18,20 +18,22 @@
|
||||
package forge.card.cost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.InputPayment;
|
||||
import forge.control.input.InputSelectCards;
|
||||
import forge.control.input.InputSelectCardsFromList;
|
||||
import forge.game.GameState;
|
||||
import forge.game.player.AIPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.view.ButtonUtil;
|
||||
|
||||
/**
|
||||
* The Class CostReveal.
|
||||
@@ -39,87 +41,6 @@ import forge.view.ButtonUtil;
|
||||
public class CostReveal extends CostPartWithList {
|
||||
// Reveal<Num/Type/TypeDescription>
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public static final class InputPayReveal extends InputPayCostBase {
|
||||
private final CostReveal part;
|
||||
private final String discType;
|
||||
private final List<Card> handList;
|
||||
private final SpellAbility sa;
|
||||
private final int nNeeded;
|
||||
private static final long serialVersionUID = -329993322080934435L;
|
||||
private int nReveal = 0;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param part
|
||||
* @param discType
|
||||
* @param handList
|
||||
* @param sa
|
||||
* @param payment
|
||||
* @param nNeeded
|
||||
*/
|
||||
public InputPayReveal(CostReveal part, String discType, List<Card> handList, SpellAbility sa, int nNeeded) {
|
||||
this.part = part;
|
||||
this.discType = discType;
|
||||
this.handList = handList;
|
||||
this.sa = sa;
|
||||
this.nNeeded = nNeeded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage() {
|
||||
if (nNeeded == 0) {
|
||||
this.done();
|
||||
}
|
||||
|
||||
/*if (handList.size() + this.nReveal < nNeeded) {
|
||||
this.stop();
|
||||
}*/
|
||||
final StringBuilder type = new StringBuilder("");
|
||||
if (!discType.equals("Card")) {
|
||||
type.append(" ").append(discType);
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("Select a ");
|
||||
sb.append(part.getDescriptiveType());
|
||||
sb.append(" to reveal.");
|
||||
if (nNeeded > 1) {
|
||||
sb.append(" You have ");
|
||||
sb.append(nNeeded - this.nReveal);
|
||||
sb.append(" remaining.");
|
||||
}
|
||||
showMessage(sb.toString());
|
||||
ButtonUtil.enableOnlyCancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectCard(final Card card) {
|
||||
Zone zone = Singletons.getModel().getGame().getZoneOf(card);
|
||||
if (zone.is(ZoneType.Hand) && handList.contains(card)) {
|
||||
// send in List<Card> for Typing
|
||||
handList.remove(card);
|
||||
part.executePayment(sa, card);
|
||||
this.nReveal++;
|
||||
|
||||
// in case no more cards in hand
|
||||
if (this.nReveal == nNeeded) {
|
||||
this.done();
|
||||
} else if (sa.getActivatingPlayer().getZone(ZoneType.Hand).size() == 0) {
|
||||
// really
|
||||
// shouldn't
|
||||
// happen
|
||||
this.cancel();
|
||||
} else {
|
||||
this.showMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new cost reveal.
|
||||
*
|
||||
@@ -239,10 +160,13 @@ public class CostReveal extends CostPartWithList {
|
||||
}
|
||||
}
|
||||
if ( num == 0 ) return true;
|
||||
|
||||
InputPayment inp = new InputPayReveal(this, this.getType(), handList, ability, num);
|
||||
InputSelectCards inp = new InputSelectCardsFromList(num, num, handList);
|
||||
inp.setMessage("Select %d more " + getDescriptiveType() + " card(s) to reveal.");
|
||||
FThreads.setInputAndWait(inp);
|
||||
return inp.isPaid();
|
||||
if ( inp.hasCancelled() )
|
||||
return false;
|
||||
|
||||
return executePayment(ability, inp.getSelected());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,9 +208,16 @@ public class CostReveal extends CostPartWithList {
|
||||
*/
|
||||
@Override
|
||||
protected void doPayment(SpellAbility ability, Card targetCard) {
|
||||
// write code to actually reveal card
|
||||
ability.getActivatingPlayer().getGame().getAction().reveal(Lists.newArrayList(targetCard), ability.getActivatingPlayer());
|
||||
}
|
||||
|
||||
|
||||
@Override protected boolean canPayListAtOnce() { return true; }
|
||||
@Override
|
||||
protected void doListPayment(SpellAbility ability, Collection<Card> targetCards) {
|
||||
ability.getActivatingPlayer().getGame().getAction().reveal(targetCards, ability.getActivatingPlayer());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.cost.CostPartWithList#getHashForList()
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package forge.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -1394,6 +1395,18 @@ public class GameAction {
|
||||
return true;
|
||||
} // sacrificeDestroy()
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param targetCard
|
||||
* @param activatingPlayer
|
||||
*/
|
||||
public void reveal(Collection<Card> cards, Player cardOwner) {
|
||||
for(Player p : game.getPlayers()) {
|
||||
if ( cardOwner == p) continue;
|
||||
p.getController().reveal(cardOwner + " reveals card", cards, ZoneType.Hand, cardOwner);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* playCardWithoutManaCost.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge.game.player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -105,7 +106,7 @@ public abstract class PlayerController {
|
||||
public abstract List<Card> orderAttackers(Card blocker, List<Card> attackers);
|
||||
|
||||
/** Shows the card to this player*/
|
||||
public abstract void reveal(String string, List<Card> cards, ZoneType zone, Player owner);
|
||||
public abstract void reveal(String string, Collection<Card> cards, ZoneType zone, Player owner);
|
||||
public abstract ImmutablePair<List<Card>, List<Card>> arrangeForScry(List<Card> topN);
|
||||
public abstract boolean willPutCardOnTop(Card c);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.game.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -184,7 +185,7 @@ public class PlayerControllerAi extends PlayerController {
|
||||
* @see forge.game.player.PlayerController#reveal(java.lang.String, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public void reveal(String string, List<Card> cards, ZoneType zone, Player owner) {
|
||||
public void reveal(String string, Collection<Card> cards, ZoneType zone, Player owner) {
|
||||
// We don't know how to reveal cards to AI
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.game.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -278,7 +279,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
* @see forge.game.player.PlayerController#reveal(java.lang.String, java.util.List, forge.game.zone.ZoneType, forge.game.player.Player)
|
||||
*/
|
||||
@Override
|
||||
public void reveal(String string, List<Card> cards, ZoneType zone, Player owner) {
|
||||
public void reveal(String string, Collection<Card> cards, ZoneType zone, Player owner) {
|
||||
String message = string;
|
||||
if ( StringUtils.isBlank(message) )
|
||||
message = String.format("Looking at %s's %s", owner, zone);
|
||||
|
||||
Reference in New Issue
Block a user