From c52a94bbfc6d69daae2bde64df369d1002d4ae34 Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Wed, 30 Jun 2021 00:45:03 +0200 Subject: [PATCH] Refactor for facedown --- .../main/java/forge/ai/ability/PlayAi.java | 8 ++++- .../game/ability/effects/AttachEffect.java | 3 +- .../game/ability/effects/PlayEffect.java | 31 ++++++++++--------- .../res/cardsfolder/k/kasmina_enigma_sage.txt | 2 +- .../forge/player/PlayerControllerHuman.java | 16 +++------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ability/PlayAi.java b/forge-ai/src/main/java/forge/ai/ability/PlayAi.java index cfd1c82ce58..1d92c736965 100644 --- a/forge-ai/src/main/java/forge/ai/ability/PlayAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/PlayAi.java @@ -28,6 +28,7 @@ import forge.game.card.CardPredicates; import forge.game.cost.Cost; import forge.game.keyword.Keyword; import forge.game.player.Player; +import forge.game.player.PlayerActionConfirmMode; import forge.game.spellability.Spell; import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbilityPredicates; @@ -158,6 +159,11 @@ public class PlayAi extends SpellAbilityAi { return true; } + @Override + public boolean confirmAction(Player ai, SpellAbility sa, PlayerActionConfirmMode mode, String message) { + return true; + } + /* (non-Javadoc) * @see forge.card.ability.SpellAbilityAi#chooseSingleCard(forge.game.player.Player, forge.card.spellability.SpellAbility, java.util.List, boolean) */ @@ -192,7 +198,7 @@ public class PlayAi extends SpellAbilityAi { spell = (Spell) spell.copyWithDefinedCost(abCost); } - if (AiPlayDecision.WillPlay == ((PlayerControllerAi)ai.getController()).getAi().canPlayFromEffectAI(spell, !isOptional, true)) { + if (AiPlayDecision.WillPlay == ((PlayerControllerAi)ai.getController()).getAi().canPlayFromEffectAI(spell, !(isOptional || sa.hasParam("Optional")), true)) { // Before accepting, see if the spell has a valid number of targets (it should at this point). // Proceeding past this point if the spell is not correctly targeted will result // in "Failed to add to stack" error and the card disappearing from the game completely. diff --git a/forge-game/src/main/java/forge/game/ability/effects/AttachEffect.java b/forge-game/src/main/java/forge/game/ability/effects/AttachEffect.java index 0746c83624a..c5f78d3e8d9 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/AttachEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/AttachEffect.java @@ -90,7 +90,7 @@ public class AttachEffect extends SpellAbilityEffect { // If Cast Targets will be checked on the Stack for (final Card attachment : attachments) { String message = Localizer.getInstance().getMessage("lblDoYouWantAttachSourceToTarget", CardTranslation.getTranslatedName(attachment.getName()), attachToName); - if ( sa.hasParam("Optional") && !p.getController().confirmAction(sa, null, message) ) + if (sa.hasParam("Optional") && !p.getController().confirmAction(sa, null, message)) continue; handleAttachment(attachment, attachTo, sa); } @@ -118,7 +118,6 @@ public class AttachEffect extends SpellAbilityEffect { * the o */ public static void handleAttachment(final Card card, final Object o, final SpellAbility sa) { - if (card == null) { return; } if (o instanceof Card) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/PlayEffect.java b/forge-game/src/main/java/forge/game/ability/effects/PlayEffect.java index 9ee2a195470..5ba073cc8ae 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/PlayEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/PlayEffect.java @@ -183,18 +183,11 @@ public class PlayEffect extends SpellAbilityEffect { activator.addController(controlledByTimeStamp, controlledByPlayer); } + boolean singleOption = tgtCards.size() == 1 && amount == 1 && optional; + while (!tgtCards.isEmpty() && amount > 0) { activator.getController().tempShowCards(showCards); - Card tgtCard = null; - if (tgtCards.size() == 1 && amount == 1 && optional) { - tgtCard = tgtCards.get(0); - if (!controller.getController().confirmAction(sa, null, Localizer.getInstance().getMessage("lblDoYouWantPlayCard", CardTranslation.getTranslatedName(tgtCard.getName())))) { - break; - } - } else { - tgtCard = controller.getController().chooseSingleEntityForEffect(tgtCards, sa, Localizer.getInstance().getMessage("lblSelectCardToPlay"), optional, null); - } - + Card tgtCard = controller.getController().chooseSingleEntityForEffect(tgtCards, sa, Localizer.getInstance().getMessage("lblSelectCardToPlay"), !singleOption, null); activator.getController().endTempShowCards(); if (tgtCard == null) { break; @@ -210,12 +203,16 @@ public class PlayEffect extends SpellAbilityEffect { game.getAction().revealTo(tgtCard, activator); } - if (!sa.hasParam("AllowRepeats")) { - tgtCards.remove(tgtCard); + if (singleOption && !controller.getController().confirmAction(sa, null, Localizer.getInstance().getMessage("lblDoYouWantPlayCard", CardTranslation.getTranslatedName(tgtCard.getName())))) { + if (wasFaceDown) { + tgtCard.turnFaceDownNoUpdate(); + tgtCard.updateStateForView(); + } + break; } - if (wasFaceDown) { - tgtCard.updateStateForView(); + if (!sa.hasParam("AllowRepeats")) { + tgtCards.remove(tgtCard); } final Card original = tgtCard; @@ -272,6 +269,10 @@ public class PlayEffect extends SpellAbilityEffect { } // in case player canceled from choice dialog if (tgtSA == null) { + if (wasFaceDown) { + tgtCard.turnFaceDownNoUpdate(); + tgtCard.updateStateForView(); + } continue; } @@ -329,7 +330,7 @@ public class PlayEffect extends SpellAbilityEffect { source.addRemembered(tgtSA.getHostCard()); } - //Forgot only of playing was successful + //Forgot only if playing was successful if (sa.hasParam("ForgetRemembered")) { source.clearRemembered(); } diff --git a/forge-gui/res/cardsfolder/k/kasmina_enigma_sage.txt b/forge-gui/res/cardsfolder/k/kasmina_enigma_sage.txt index 17c60b9b9ec..2ef507224ec 100644 --- a/forge-gui/res/cardsfolder/k/kasmina_enigma_sage.txt +++ b/forge-gui/res/cardsfolder/k/kasmina_enigma_sage.txt @@ -8,7 +8,7 @@ A:AB$ Token | Cost$ SubCounter | Planeswalker$ True | TokenScript$ gu SVar:DBPutCounter:DB$ PutCounter | Defined$ Remembered | CounterType$ P1P1 | CounterNum$ X | SubAbility$ DBCleanup SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True SVar:X:Count$xPaid -A:AB$ ChangeZone | Cost$ SubCounter<8/LOYALTY> | Planeswalker$ True | Ultimate$ True | Origin$ Library | Destination$ Exile | ChangeType$ Instant.SharesColorWith Card.Self,Sorcery.SharesColorWith Card.Self | ChangeNum$ 1 | SubAbility$ DBPlay | RememberChanged$ True | SpellDescription$ Search your library for an instant or sorcery card that shares a color with this planeswalker, exile that card, then shuffle. You may cast that card without paying its mana cost. +A:AB$ ChangeZone | Cost$ SubCounter<8/LOYALTY> | Planeswalker$ True | Ultimate$ True | Origin$ Library | Destination$ Exile | ChangeType$ Instant.SharesColorWith,Sorcery.SharesColorWith | ChangeNum$ 1 | SubAbility$ DBPlay | RememberChanged$ True | SpellDescription$ Search your library for an instant or sorcery card that shares a color with this planeswalker, exile that card, then shuffle. You may cast that card without paying its mana cost. SVar:DBPlay:DB$ Play | Defined$ Remembered | WithoutManaCost$ True | Optional$ True | SubAbility$ DBCleanup DeckHints:Type$Instant|Sorcery DeckHas:Ability$Token & Ability$Counters diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java index b4c8bb118f0..652ecb0547c 100644 --- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java @@ -601,8 +601,6 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont tempShow(delayedReveal.getCards()); } - GameEntityViewMap gameCacheChoose = GameEntityView.getMap(optionList); - if (useSelectCardsInput(optionList)) { final InputSelectEntitiesFromList input = new InputSelectEntitiesFromList<>(this, isOptional ? 0 : 1, 1, optionList, sa); @@ -613,6 +611,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont return Iterables.getFirst(input.getSelected(), null); } + GameEntityViewMap gameCacheChoose = GameEntityView.getMap(optionList); final GameEntityView result = getGui().chooseSingleEntityForEffect(title, gameCacheChoose.getTrackableKeys(), delayedReveal, isOptional); endTempShowCards(); @@ -626,8 +625,6 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont @Override public List chooseEntitiesForEffect(final FCollectionView optionList, final int min, final int max, final DelayedReveal delayedReveal, final SpellAbility sa, final String title, final Player targetedPlayer, Map params) { - - // useful details for debugging problems with the mass select logic Sentry.getContext().addExtra("Card", sa.getCardView().toString()); Sentry.getContext().addExtra("SpellAbility", sa.toString()); @@ -655,6 +652,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont endTempShowCards(); return (List) input.getSelected(); } + GameEntityViewMap gameCacheEntity = GameEntityView.getMap(optionList); final List views = getGui().chooseEntitiesForEffect(title, gameCacheEntity.getTrackableKeys(), min, max, delayedReveal); endTempShowCards(); @@ -700,8 +698,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont Map spellViewCache = SpellAbilityView.getMap(spells); Object choice = getGui().one(title, Lists.newArrayList(spellViewCache.keySet())); - // Human is supposed to read the message and understand from it what to - // choose + // Human is supposed to read the message and understand from it what to choose return spellViewCache.get(choice); } @@ -948,8 +945,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont CardCollection toTop = null; tempShowCards(topN); - if ( FModel.getPreferences().getPrefBoolean(FPref.UI_SELECT_FROM_CARD_DISPLAYS) && - (!GuiBase.getInterface().isLibgdxPort()) && (!GuiBase.isNetworkplay())) { //prevent crash for desktop vs mobile port it will crash the netplay since mobile doesnt have manipulatecardlist, send the alternate below + if (FModel.getPreferences().getPrefBoolean(FPref.UI_SELECT_FROM_CARD_DISPLAYS) && + (!GuiBase.getInterface().isLibgdxPort()) && (!GuiBase.isNetworkplay())) { //prevent crash for desktop vs mobile port it will crash the netplay since mobile doesnt have manipulatecardlist, send the alternate below CardCollectionView cardList = player.getCardsIn(ZoneType.Library); ImmutablePair result = arrangeForMove(localizer.getMessage("lblMoveCardstoToporBbottomofLibrary"), cardList, topN, true, true); @@ -1566,8 +1563,6 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont @Override public List chooseSaToActivateFromOpeningHand(final List usableFromOpeningHand) { - - final CardCollection srcCards = new CardCollection(); for (final SpellAbility sa : usableFromOpeningHand) { srcCards.add(sa.getHostCard()); @@ -2557,7 +2552,6 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont */ @Override public void setPlayerLife() { - GameEntityViewMap gameCachePlayer = GameEntityView.getMap(getGame().getPlayers()); final PlayerView pv = getGui().oneOrNone(localizer.getMessage("lblSetLifeforWhichPlayer"), gameCachePlayer.getTrackableKeys());