mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
chooseCardsToRevealFromHand - moved function to player controller
RevealEffectBase disbanded
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14008,7 +14008,6 @@ src/main/java/forge/card/ability/effects/RepeatEachEffect.java -text
|
||||
src/main/java/forge/card/ability/effects/RepeatEffect.java -text
|
||||
src/main/java/forge/card/ability/effects/RestartGameEffect.java -text
|
||||
src/main/java/forge/card/ability/effects/RevealEffect.java -text
|
||||
src/main/java/forge/card/ability/effects/RevealEffectBase.java svneol=native#text/plain
|
||||
src/main/java/forge/card/ability/effects/RevealHandEffect.java -text
|
||||
src/main/java/forge/card/ability/effects/RollPlanarDiceEffect.java -text
|
||||
src/main/java/forge/card/ability/effects/SacrificeAllEffect.java -text
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.google.common.collect.Lists;
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.ability.SpellAbilityEffect;
|
||||
import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.Target;
|
||||
@@ -18,7 +19,7 @@ import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
public class DiscardEffect extends RevealEffectBase {
|
||||
public class DiscardEffect extends SpellAbilityEffect {
|
||||
@Override
|
||||
protected String getStackDescription(SpellAbility sa) {
|
||||
final String mode = sa.getParam("Mode");
|
||||
@@ -192,7 +193,7 @@ public class DiscardEffect extends RevealEffectBase {
|
||||
if (sa.hasParam("RevealNumber")) {
|
||||
String amountString = sa.getParam("RevealNumber");
|
||||
int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString) : CardFactoryUtil.xCount(source, source.getSVar(amountString));
|
||||
dPHand = getRevealedList(p, dPHand, amount, false);
|
||||
dPHand = p.getController().chooseCardsToRevealFromHand(amount, amount, dPHand);
|
||||
}
|
||||
final String valid = sa.hasParam("DiscardValid") ? sa.getParam("DiscardValid") : "Card";
|
||||
String[] dValid = valid.split(",");
|
||||
|
||||
@@ -6,67 +6,74 @@ import java.util.List;
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.ability.SpellAbilityEffect;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.Target;
|
||||
import forge.game.Game;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
public class RevealEffect extends RevealEffectBase {
|
||||
public class RevealEffect extends SpellAbilityEffect {
|
||||
|
||||
@Override
|
||||
public void resolve(SpellAbility sa) {
|
||||
final Card host = sa.getSourceCard();
|
||||
final boolean anyNumber = sa.hasParam("AnyNumber");
|
||||
int cnt = sa.hasParam("NumCards") ? AbilityUtils.calculateAmount(host, sa.getParam("NumCards"), sa) : 1;
|
||||
|
||||
|
||||
final Target tgt = sa.getTarget();
|
||||
|
||||
for (final Player p : getTargetPlayers(sa)) {
|
||||
if ((tgt == null) || p.canBeTargetedBy(sa)) {
|
||||
final List<Card> handChoices = p.getCardsIn(ZoneType.Hand);
|
||||
if (handChoices.size() > 0) {
|
||||
final List<Card> revealed = new ArrayList<Card>();
|
||||
if (sa.hasParam("Random")) {
|
||||
if (sa.hasParam("NumCards")) {
|
||||
final int num = AbilityUtils.calculateAmount(host, sa.getParam("NumCards"), sa);
|
||||
final int revealnum = Math.min(handChoices.size(), num);
|
||||
final List<Card> hand = new ArrayList<Card>(handChoices);
|
||||
for (int i = 0; i < revealnum; i++) {
|
||||
final Card random = Aggregates.random(hand);
|
||||
revealed.add(random);
|
||||
hand.remove(random);
|
||||
}
|
||||
} else {
|
||||
revealed.add(Aggregates.random(handChoices));
|
||||
final Game game = p.getGame();
|
||||
if (tgt == null || p.canBeTargetedBy(sa)) {
|
||||
final List<Card> cardsInHand = p.getZone(ZoneType.Hand).getCards();
|
||||
if (cardsInHand.isEmpty())
|
||||
continue;
|
||||
|
||||
final List<Card> revealed = new ArrayList<Card>();
|
||||
if (sa.hasParam("Random")) {
|
||||
if (sa.hasParam("NumCards")) {
|
||||
final int revealnum = Math.min(cardsInHand.size(), cnt);
|
||||
final List<Card> hand = new ArrayList<Card>(cardsInHand);
|
||||
for (int i = 0; i < revealnum; i++) {
|
||||
final Card random = Aggregates.random(hand);
|
||||
revealed.add(random);
|
||||
hand.remove(random);
|
||||
}
|
||||
GuiChoose.oneOrNone("Revealed card(s)", revealed);
|
||||
} else {
|
||||
List<Card> valid = new ArrayList<Card>(handChoices);
|
||||
int max = 1;
|
||||
if (sa.hasParam("RevealValid")) {
|
||||
valid = CardLists.getValidCards(valid, sa.getParam("RevealValid"), p, host);
|
||||
}
|
||||
if (anyNumber) {
|
||||
max = valid.size();
|
||||
}
|
||||
else if (sa.hasParam("NumCards")) {
|
||||
max = Math.min(valid.size(), AbilityUtils.calculateAmount(host, sa.getParam("NumCards"), sa));
|
||||
}
|
||||
//revealed.addAll(getRevealedList(sa.getActivatingPlayer(), valid, max, anyNumber));
|
||||
revealed.addAll(getRevealedList(p, valid, max, anyNumber));
|
||||
//if (sa.getActivatingPlayer().isComputer()) {
|
||||
if (p.isComputer()) {
|
||||
GuiChoose.oneOrNone("Revealed card(s)", revealed);
|
||||
}
|
||||
revealed.add(Aggregates.random(cardsInHand));
|
||||
}
|
||||
|
||||
} else {
|
||||
List<Card> valid = new ArrayList<Card>(cardsInHand);
|
||||
|
||||
if (sa.hasParam("RememberRevealed")) {
|
||||
for (final Card rem : revealed) {
|
||||
host.addRemembered(rem);
|
||||
}
|
||||
if (sa.hasParam("RevealValid")) {
|
||||
valid = CardLists.getValidCards(valid, sa.getParam("RevealValid"), p, host);
|
||||
}
|
||||
|
||||
if (valid.isEmpty())
|
||||
continue;
|
||||
|
||||
if( cnt > valid.size() )
|
||||
cnt = valid.size();
|
||||
|
||||
int min = cnt;
|
||||
if (anyNumber) {
|
||||
cnt = valid.size();
|
||||
min = 0;
|
||||
}
|
||||
|
||||
revealed.addAll(p.getController().chooseCardsToRevealFromHand(min, cnt, valid));
|
||||
}
|
||||
|
||||
game.getAction().reveal(revealed, p);
|
||||
|
||||
if (sa.hasParam("RememberRevealed")) {
|
||||
for (final Card rem : revealed) {
|
||||
host.addRemembered(rem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +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.card.ability.effects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.card.ability.SpellAbilityEffect;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.GuiChoose;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* AbilityFactory_Reveal class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class RevealEffectBase extends SpellAbilityEffect {
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// ************************* Dig *******************************************
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Gets the revealed list.
|
||||
*
|
||||
* @param player the player
|
||||
* @param valid the valid
|
||||
* @param max the max
|
||||
* @param anyNumber a boolean
|
||||
* @return the revealed list
|
||||
*/
|
||||
public static List<Card> getRevealedList(final Player player, final List<Card> valid, final int max, boolean anyNumber) {
|
||||
final List<Card> chosen = new ArrayList<Card>();
|
||||
final int validamount = Math.min(valid.size(), max);
|
||||
|
||||
if (anyNumber && player.isHuman() && validamount > 0) {
|
||||
final List<Card> selection = GuiChoose.order("Choose Which Cards to Reveal", "Revealed", -1, valid, null, null);
|
||||
for (final Object o : selection) {
|
||||
if (o != null && o instanceof Card) {
|
||||
chosen.add((Card) o);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < validamount; i++) {
|
||||
if (player.isHuman()) {
|
||||
final Card o = GuiChoose.one("Choose card(s) to reveal", valid);
|
||||
if (o != null) {
|
||||
chosen.add(o);
|
||||
valid.remove(o);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else { // Computer
|
||||
chosen.add(valid.get(0));
|
||||
valid.remove(valid.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
return chosen;
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public abstract class SpellAbility implements ISpellAbility {
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean canPlayAI() {
|
||||
public /*final*/ boolean canPlayAI() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ public abstract class PlayerController {
|
||||
public abstract void playMiracle(SpellAbility miracle, Card card);
|
||||
public abstract void playMadness(SpellAbility madness);
|
||||
public abstract List<Card> chooseCardsToDelve(int colorLessAmount, List<Card> grave);
|
||||
public abstract List<Card> chooseCardsToRevealFromHand(int min, int max, List<Card> valid);
|
||||
public abstract List<Card> chooseCardsToDiscardUnlessType(int min, List<Card> hand, String param, SpellAbility sa);
|
||||
public abstract Mana chooseManaFromPool(List<Mana> manaChoices);
|
||||
|
||||
|
||||
@@ -287,4 +287,9 @@ public class PlayerControllerAi extends PlayerController {
|
||||
public List<Card> chooseCardsToDiscardToMaximumHandSize(int numDiscard) {
|
||||
return brains.getCardsToDiscard(numDiscard, (String[])null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Card> chooseCardsToRevealFromHand(int min, int max, List<Card> valid) {
|
||||
return max == 0 ? Lists.<Card>newArrayList() : valid.subList(0, max);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,4 +519,16 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
Singletons.getControl().getInputQueue().setInputAndWait(inp);
|
||||
return inp.getSelected();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#chooseCardsToRevealFromHand(int, int, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public List<Card> chooseCardsToRevealFromHand(int min, int max, List<Card> valid) {
|
||||
InputSelectCardsFromList inp = new InputSelectCardsFromList(min, max, valid);
|
||||
inp.setMessage("Choose Which Cards to Reveal");
|
||||
Singletons.getControl().getInputQueue().setInputAndWait(inp);
|
||||
return inp.getSelected();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user