copy-pasters must die!

(moved after mulligan actions to MatchController (temporary))
This commit is contained in:
Maxmtg
2013-04-03 05:14:35 +00:00
parent 4481fb72bd
commit 9f83c38d75
4 changed files with 72 additions and 133 deletions

View File

@@ -20,20 +20,13 @@ package forge.control.input;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Iterables;
import forge.Card;
import forge.CardPredicates;
import forge.FThreads;
import forge.card.ability.AbilityFactory;
import forge.card.spellability.SpellAbility;
import forge.game.GameAction;
import forge.game.GameState;
import forge.game.GameType;
import forge.game.MatchController;
import forge.game.ai.ComputerUtil;
import forge.game.player.AIPlayer;
import forge.game.player.HumanPlayer;
import forge.game.player.Player;
import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
@@ -114,76 +107,21 @@ public class InputMulligan extends InputBase {
}
}
// Human Leylines & Chancellors
ButtonUtil.reset();
final GameAction ga = game.getAction();
for (Player p : game.getPlayers()) {
final List<Card> openingHand = new ArrayList<Card>(p.getCardsIn(ZoneType.Hand));
for (final Card c : openingHand) {
if (p.isHuman()) {
for (String kw : c.getKeyword()) {
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = AbilityFactory.getAbility(c.getSVar(effName), c);
if (GuiDialog.confirm(c, "Use " + c +"'s ability?")) {
// If we ever let the AI memorize cards in the players
// hand, this would be a place to do so.
game.getActionPlay().playSpellAbilityNoStack((HumanPlayer)p, effect);
}
}
}
if (c.getName().startsWith("Leyline of")) {
if (GuiDialog.confirm(c, "Use " + c + "'s ability?")) {
ga.moveToPlay(c);
}
}
} else { // Computer Leylines & Chancellors
if (!c.getName().startsWith("Leyline of")) {
for (String kw : c.getKeyword()) {
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = AbilityFactory.getAbility(c.getSVar(effName), c);
// Is there a better way for the AI to decide this?
if (effect.doTrigger(false, (AIPlayer)p)) {
GuiDialog.message("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ").");
ComputerUtil.playNoStack((AIPlayer)p, effect, game);
}
}
}
}
if (c.getName().startsWith("Leyline of")
&& !(c.getName().startsWith("Leyline of Singularity")
&& (Iterables.any(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity"))))) {
ga.moveToPlay(c);
//ga.checkStateEffects();
}
}
}
}
ga.checkStateEffects();
Player next = game.getPhaseHandler().getPlayerTurn();
if(game.getType() == GameType.Planechase)
{
next.initPlane();
}
//Set Field shown to current player.
VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(next);
SDisplayUtil.showTab(nextField);
game.setMulliganned(true);
FThreads.invokeInNewThread( new Runnable() {
@Override
public void run() {
match.getInput().clearInput();
match.afterMulligans();
}
});
}

View File

@@ -20,19 +20,11 @@ package forge.control.input;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Iterables;
import forge.Card;
import forge.CardPredicates;
import forge.FThreads;
import forge.card.ability.AbilityFactory;
import forge.card.spellability.SpellAbility;
import forge.game.GameAction;
import forge.game.GameState;
import forge.game.GameType;
import forge.game.MatchController;
import forge.game.ai.ComputerUtil;
import forge.game.player.AIPlayer;
import forge.game.player.Player;
import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
@@ -40,7 +32,6 @@ import forge.gui.GuiDialog;
import forge.gui.framework.SDisplayUtil;
import forge.gui.match.CMatchUI;
import forge.gui.match.nonsingleton.VField;
import forge.gui.match.views.VMessage;
import forge.view.ButtonUtil;
/**
* <p>
@@ -134,74 +125,19 @@ public class InputPartialParisMulligan extends InputBase {
// Human Leylines & Chancellors
ButtonUtil.reset();
final GameAction ga = game.getAction();
for (Player p : game.getPlayers()) {
final List<Card> openingHand = new ArrayList<Card>(p.getCardsIn(ZoneType.Hand));
for (final Card c : openingHand) {
if (p.isHuman()) {
for (String kw : c.getKeyword()) {
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = AbilityFactory.getAbility(c.getSVar(effName), c);
if (GuiDialog.confirm(c, "Use " + c +"'s ability?")) {
// If we ever let the AI memorize cards in the players
// hand, this would be a place to do so.
game.getActionPlay().playSpellAbilityNoStack(p, effect);
}
}
}
if (c.getName().startsWith("Leyline of")) {
if (GuiDialog.confirm(c, "Use " + c + "'s ability?")) {
ga.moveToPlay(c);
}
}
} else { // Computer Leylines & Chancellors
if (!c.getName().startsWith("Leyline of")) {
for (String kw : c.getKeyword()) {
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = AbilityFactory.getAbility(c.getSVar(effName), c);
// Is there a better way for the AI to decide this?
if (effect.doTrigger(false, (AIPlayer)p)) {
GuiDialog.message("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ").");
ComputerUtil.playNoStack((AIPlayer)p, effect, game);
}
}
}
}
if (c.getName().startsWith("Leyline of")
&& !(c.getName().startsWith("Leyline of Singularity")
&& (Iterables.any(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity"))))) {
ga.moveToPlay(c);
//ga.checkStateEffects();
}
}
}
}
ga.checkStateEffects();
Player next = game.getPhaseHandler().getPlayerTurn();
if(game.getType() == GameType.Planechase)
{
next.initPlane();
}
//Set Field shown to current player.
VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(next);
SDisplayUtil.showTab(nextField);
game.setMulliganned(true);
FThreads.invokeInNewThread( new Runnable() {
@Override
public void run() {
match.getInput().clearInput();
match.afterMulligans();
}
});
}

View File

@@ -7,13 +7,20 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Iterables;
import forge.Constant.Preferences;
import forge.Card;
import forge.CardPredicates;
import forge.Singletons;
import forge.card.ability.AbilityFactory;
import forge.card.spellability.SpellAbility;
import forge.control.FControl;
import forge.control.input.InputControl;
import forge.deck.Deck;
import forge.error.BugReporter;
import forge.game.ai.AiProfileUtil;
import forge.game.ai.ComputerUtil;
import forge.game.event.DuelOutcomeEvent;
import forge.game.player.AIPlayer;
import forge.game.player.HumanPlayer;
@@ -22,6 +29,7 @@ import forge.game.player.Player;
import forge.game.player.PlayerStatistics;
import forge.game.player.PlayerType;
import forge.game.zone.ZoneType;
import forge.gui.GuiDialog;
import forge.gui.InputProxy;
import forge.gui.framework.EDocID;
import forge.gui.framework.SDisplayUtil;
@@ -339,4 +347,63 @@ public class MatchController {
public static int getPoisonCountersAmountToLose() {
return 10;
}
private void handleLeylinesAndChancellors() {
for (Player p : currentGame.getPlayers()) {
final List<Card> openingHand = new ArrayList<Card>(p.getCardsIn(ZoneType.Hand));
for (final Card c : openingHand) {
if (p.isHuman()) {
for (String kw : c.getKeyword()) {
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = AbilityFactory.getAbility(c.getSVar(effName), c);
if (GuiDialog.confirm(c, "Use " + c +"'s ability?")) {
// If we ever let the AI memorize cards in the players
// hand, this would be a place to do so.
currentGame.getActionPlay().playSpellAbilityNoStack((HumanPlayer)p, effect);
}
}
}
if (c.getName().startsWith("Leyline of")) {
if (GuiDialog.confirm(c, "Use " + c + "'s ability?")) {
currentGame.getAction().moveToPlay(c);
}
}
} else { // Computer Leylines & Chancellors
if (!c.getName().startsWith("Leyline of")) {
for (String kw : c.getKeyword()) {
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = AbilityFactory.getAbility(c.getSVar(effName), c);
// Is there a better way for the AI to decide this?
if (effect.doTrigger(false, (AIPlayer)p)) {
GuiDialog.message("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ").");
ComputerUtil.playNoStack((AIPlayer)p, effect, currentGame);
}
}
}
}
if (c.getName().startsWith("Leyline of")
&& !(c.getName().startsWith("Leyline of Singularity")
&& (Iterables.any(currentGame.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity"))))) {
currentGame.getAction().moveToPlay(c);
//ga.checkStateEffects();
}
}
}
}
currentGame.getAction().checkStateEffects();
}
public void afterMulligans()
{
handleLeylinesAndChancellors();
currentGame.setMulliganned(true);
getInput().clearInput();
}
}

View File

@@ -8,8 +8,6 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import javax.swing.JDialog;