From 4182ad7395a491b2a500df9e76da241f02eaac5a Mon Sep 17 00:00:00 2001 From: Hanmac Date: Sun, 14 Jul 2019 05:59:04 +0200 Subject: [PATCH] DigEffect: remove AndOrValid --- .../java/forge/ai/PlayerControllerAi.java | 14 -- .../forge/game/ability/effects/DigEffect.java | 28 +--- .../forge/game/player/PlayerController.java | 1 - .../util/PlayerControllerForTests.java | 6 - .../match/input/InputSelectFromTwoLists.java | 152 ------------------ .../forge/player/PlayerControllerHuman.java | 35 ---- 6 files changed, 6 insertions(+), 230 deletions(-) delete mode 100644 forge-gui/src/main/java/forge/match/input/InputSelectFromTwoLists.java diff --git a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java index 342c53d260d..2d427ef70e1 100644 --- a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java +++ b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java @@ -181,20 +181,6 @@ public class PlayerControllerAi extends PlayerController { return selecteds; } - @Override - public List chooseFromTwoListsForEffect(FCollectionView optionList1, FCollectionView optionList2, - boolean optional, DelayedReveal delayedReveal, SpellAbility sa, String title, Player targetedPlayer) { - if (delayedReveal != null) { - reveal(delayedReveal.getCards(), delayedReveal.getZone(), delayedReveal.getOwner(), delayedReveal.getMessagePrefix()); - } - T selected1 = chooseSingleEntityForEffect(optionList1, null, sa, title, optional, targetedPlayer); - T selected2 = chooseSingleEntityForEffect(optionList2, null, sa, title, optional || selected1!=null, targetedPlayer); - List selecteds = new ArrayList(); - if ( selected1 != null ) { selecteds.add(selected1); } - if ( selected2 != null ) { selecteds.add(selected2); } - return selecteds; - } - @Override public SpellAbility chooseSingleSpellForEffect(java.util.List spells, SpellAbility sa, String title, Map params) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/DigEffect.java b/forge-game/src/main/java/forge/game/ability/effects/DigEffect.java index 49f66a4fd69..7d8a8d4cab4 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/DigEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/DigEffect.java @@ -66,8 +66,6 @@ public class DigEffect extends SpellAbilityEffect { int destZone1ChangeNum = 1; final boolean mitosis = sa.hasParam("Mitosis"); String changeValid = sa.hasParam("ChangeValid") ? sa.getParam("ChangeValid") : ""; - //andOrValid is for cards with "creature card and/or a land card" - String andOrValid = sa.hasParam("AndOrValid") ? sa.getParam("AndOrValid") : ""; final boolean anyNumber = sa.hasParam("AnyNumber"); final int libraryPosition2 = sa.hasParam("LibraryPosition2") ? Integer.parseInt(sa.getParam("LibraryPosition2")) : -1; @@ -173,28 +171,18 @@ public class DigEffect extends SpellAbilityEffect { if (!noMove) { CardCollection movedCards; - CardCollection andOrCards; for (final Card c : top) { rest.add(c); } CardCollection valid; if (mitosis) { valid = sharesNameWithCardOnBattlefield(game, top); - andOrCards = new CardCollection(); } else if (!changeValid.isEmpty()) { if (changeValid.contains("ChosenType")) { changeValid = changeValid.replace("ChosenType", host.getChosenType()); } valid = CardLists.getValidCards(top, changeValid.split(","), host.getController(), host, sa); - if (!andOrValid.equals("")) { - andOrCards = CardLists.getValidCards(top, andOrValid.split(","), host.getController(), host, sa); - andOrCards.removeAll((Collection)valid); - valid.addAll(andOrCards); //pfps need to add andOr cards to valid to have set of all valid cards set up - } - else { - andOrCards = new CardCollection(); - } } else { // If all the cards are valid choices, no need for a separate reveal dialog to the chooser. pfps?? @@ -202,7 +190,6 @@ public class DigEffect extends SpellAbilityEffect { delayedReveal = null; } valid = top; - andOrCards = new CardCollection(); } if (forceRevealToController) { @@ -282,16 +269,13 @@ public class DigEffect extends SpellAbilityEffect { chooser.getController().tempShowCards(top); } List chosen = new ArrayList(); - if (!andOrValid.equals("")) { - valid.removeAll(andOrCards); //pfps remove andOr cards to get two two choices set up correctly - chosen = chooser.getController().chooseFromTwoListsForEffect(valid, andOrCards, optional, delayedReveal, sa, prompt, p); - } else { - int max = anyNumber ? valid.size() : Math.min(valid.size(),destZone1ChangeNum); - int min = (anyNumber || optional) ? 0 : max; - if ( max > 0 ) { // if max is 0 don't make a choice - chosen = chooser.getController().chooseEntitiesForEffect(valid, min, max, delayedReveal, sa, prompt, p); - } + + int max = anyNumber ? valid.size() : Math.min(valid.size(),destZone1ChangeNum); + int min = (anyNumber || optional) ? 0 : max; + if ( max > 0 ) { // if max is 0 don't make a choice + chosen = chooser.getController().chooseEntitiesForEffect(valid, min, max, delayedReveal, sa, prompt, p); } + chooser.getController().endTempShowCards(); movedCards.addAll(chosen); } diff --git a/forge-game/src/main/java/forge/game/player/PlayerController.java b/forge-game/src/main/java/forge/game/player/PlayerController.java index 2d1ad450468..96f146e564f 100644 --- a/forge-game/src/main/java/forge/game/player/PlayerController.java +++ b/forge-game/src/main/java/forge/game/player/PlayerController.java @@ -115,7 +115,6 @@ public abstract class PlayerController { Map params); public abstract List chooseEntitiesForEffect(FCollectionView optionList, int min, int max, DelayedReveal delayedReveal, SpellAbility sa, String title, Player relatedPlayer); - public abstract List chooseFromTwoListsForEffect(FCollectionView optionList1, FCollectionView optionList2, boolean optional, DelayedReveal delayedReveal, SpellAbility sa, String title, Player relatedPlayer); public abstract boolean confirmAction(SpellAbility sa, PlayerActionConfirmMode mode, String message); public abstract boolean confirmBidAction(SpellAbility sa, PlayerActionConfirmMode bidlife, String string, int bid, Player winner); diff --git a/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java b/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java index e05f79393e2..f8a0f1eff77 100644 --- a/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java +++ b/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java @@ -180,12 +180,6 @@ public class PlayerControllerForTests extends PlayerController { return null; } - @Override - public List chooseFromTwoListsForEffect(FCollectionView optionList1, FCollectionView optionList2, boolean optional, DelayedReveal delayedReveal, SpellAbility sa, String title, Player targetedPlayer) { - // this isn't used - return null; - } - @Override public boolean confirmAction(SpellAbility sa, PlayerActionConfirmMode mode, String message) { return true; diff --git a/forge-gui/src/main/java/forge/match/input/InputSelectFromTwoLists.java b/forge-gui/src/main/java/forge/match/input/InputSelectFromTwoLists.java deleted file mode 100644 index 90c6b717240..00000000000 --- a/forge-gui/src/main/java/forge/match/input/InputSelectFromTwoLists.java +++ /dev/null @@ -1,152 +0,0 @@ -package forge.match.input; - -import java.util.Collection; -import java.util.List; -import java.util.ArrayList; - -import forge.game.GameEntity; -import forge.game.card.Card; -import forge.game.card.CardView; - -import forge.game.player.Player; -import forge.game.spellability.SpellAbility; -import forge.player.PlayerControllerHuman; -import forge.util.collect.FCollection; -import forge.util.collect.FCollectionView; -import forge.util.ITriggerEvent; -import forge.player.PlayerZoneUpdate; -import forge.player.PlayerZoneUpdates; -import forge.game.zone.Zone; -import forge.FThreads; - -public class InputSelectFromTwoLists extends InputSelectManyBase { - private final FCollectionView valid1, valid2; - private final FCollection validBoth; - private FCollectionView validChoices; - - protected final FCollection selected = new FCollection(); - protected final PlayerZoneUpdates zonesToUpdate = new PlayerZoneUpdates(); - protected Iterable zonesShown; // want to hide these zones when input done - - public InputSelectFromTwoLists(final PlayerControllerHuman controller, final boolean optional, - final FCollectionView list1, final FCollectionView list2, final SpellAbility sa0) { - super(controller, optional?0:1, 2, sa0); - valid1 = list1; - valid2 = list2; - validBoth = new FCollection(valid1); - for ( T v : valid2 ) { validBoth.add(v); } - validChoices = validBoth; - setSelectables(); - - for (final GameEntity c : validChoices) { - final Zone cz = (c instanceof Card) ? ((Card) c).getZone() : null ; - if ( cz != null ) { - zonesToUpdate.add(new PlayerZoneUpdate(cz.getPlayer().getView(),cz.getZoneType())); - } - } - FThreads.invokeInEdtNowOrLater(new Runnable() { - @Override public void run() { - controller.getGui().updateZones(zonesToUpdate); - zonesShown = controller.getGui().tempShowZones(controller.getPlayer().getView(),zonesToUpdate); - } - }); - } - - private void setSelectables() { - ArrayList vCards = new ArrayList(); - getController().getGui().clearSelectables(); - for ( T c : validChoices ) { - if ( c instanceof Card ) { - vCards.add(((Card)c).getView()) ; - } - } - getController().getGui().setSelectables(vCards); - } - - private void setValid() { - boolean selected1 = false, selected2 = false; - for ( T s : selected ) { - if ( valid1.contains(s) ) { selected1 = true; } - if ( valid2.contains(s) ) { selected2 = true; } - } - validChoices = selected1 ? ( selected2 ? FCollection.getEmpty() : valid2 ) : ( selected2 ? valid1 : validBoth ); - setSelectables(); - FThreads.invokeInEdtNowOrLater(new Runnable() { - @Override public void run() { - getController().getGui().updateZones(zonesToUpdate); - } - }); - } - - @Override - protected boolean onCardSelected(final Card c, final List otherCardsToSelect, final ITriggerEvent triggerEvent) { - if (!selectEntity(c)) { - return false; - } - refresh(); - return true; - } - - @Override - public String getActivateAction(final Card card) { - if (validChoices.contains(card)) { - if (selected.contains(card)) { - return "unselect card"; - } - return "select card"; - } - return null; - } - - @Override - protected void onPlayerSelected(final Player p, final ITriggerEvent triggerEvent) { - if (!selectEntity(p)) { - return; - } - refresh(); - } - - @Override - public final Collection getSelected() { - return selected; - } - - @SuppressWarnings("unchecked") - protected boolean selectEntity(final GameEntity c) { - if (!validChoices.contains(c) && !selected.contains(c)) { - return false; - } - - final boolean entityWasSelected = selected.contains(c); - if (entityWasSelected) { - selected.remove(c); - } - else { - selected.add((T)c); - } - setValid(); - onSelectStateChanged(c, !entityWasSelected); - - return true; - } - - // might re-define later - @Override - protected boolean hasEnoughTargets() { return selected.size() >= min; } - @Override - protected boolean hasAllTargets() { return selected.size() >= max; } - - @Override - protected String getMessage() { - return max == Integer.MAX_VALUE - ? String.format(message, selected.size()) - : String.format(message, max - selected.size()); - } - - @Override - protected void onStop() { - getController().getGui().hideZones(getController().getPlayer().getView(),zonesShown); - getController().getGui().clearSelectables(); - super.onStop(); - } -} diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java index 788a1fffafb..efaf8a53e5a 100644 --- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java @@ -511,41 +511,6 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont return results; } - @Override - public List chooseFromTwoListsForEffect(final FCollectionView optionList1, final FCollectionView optionList2, - boolean optional, final DelayedReveal delayedReveal, final SpellAbility sa, final String title, final Player targetedPlayer) { - // Human is supposed to read the message and understand from it what to choose - // useful details for debugging problems with the mass select logic - Sentry.getContext().addExtra("Card", sa.getCardView().toString()); - Sentry.getContext().addExtra("SpellAbility", sa.toString()); - - if (delayedReveal != null) { - tempShow(delayedReveal.getCards()); - } - - tempShow(optionList1); - tempShow(optionList2); - - if (useSelectCardsInput(optionList1) && useSelectCardsInput(optionList2)) { - final InputSelectFromTwoLists input = new InputSelectFromTwoLists(this, optional, optionList1, optionList2, sa); - input.setCancelAllowed(optional); - input.setMessage(MessageUtil.formatMessage(title, player, targetedPlayer)); - input.showAndWait(); - endTempShowCards(); - return (List) input.getSelected(); - } - - final GameEntityView result1 = getGui().chooseSingleEntityForEffect(title, GameEntityView.getEntityCollection(optionList1), null, optional); - final GameEntityView result2 = getGui().chooseSingleEntityForEffect(title, GameEntityView.getEntityCollection(optionList2), null, (result1==null)?optional:true); - endTempShowCards(); - List results = new ArrayList<>(); - GameEntity entity1 = convertToEntity(result1); - if (entity1!=null) { results.add((T) entity1); } - GameEntity entity2 = convertToEntity(result2); - if (entity2!=null) { results.add((T) entity2); } - return results; - } - @Override public int chooseNumber(final SpellAbility sa, final String title, final int min, final int max) { if (min >= max) {