update remaining confirm action for human decision

- to show relevant card and fix message title (removing "\n").
This commit is contained in:
Anthony Calosa
2022-07-31 19:02:34 +08:00
parent 37354d3aa7
commit 44997b55cd
2 changed files with 153 additions and 216 deletions

View File

@@ -87,7 +87,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
} }
if (discardType.equals("Hand")) { if (discardType.equals("Hand")) {
if (!mandatory && !confirmAction(Localizer.getInstance().getMessage("lblDoYouWantDiscardYourHand"))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblDoYouWantDiscardYourHand"), ability)*/) { if (!mandatory && !confirmAction(Localizer.getInstance().getMessage("lblDoYouWantDiscardYourHand"))) {
return null; return null;
} }
if (hand.size() > 1 && ability.getActivatingPlayer() != null) { if (hand.size() > 1 && ability.getActivatingPlayer() != null) {
@@ -131,16 +131,13 @@ public class HumanCostDecision extends CostDecisionMakerBase {
final String type = TextUtil.fastReplace(discardType, "+WithSameName", ""); final String type = TextUtil.fastReplace(discardType, "+WithSameName", "");
hand = CardLists.getValidCards(hand, type.split(";"), player, source, ability); hand = CardLists.getValidCards(hand, type.split(";"), player, source, ability);
final CardCollectionView landList2 = hand; final CardCollectionView landList2 = hand;
hand = CardLists.filter(hand, new Predicate<Card>() { hand = CardLists.filter(hand, c1 -> {
@Override for (final Card card : landList2) {
public boolean apply(final Card c) { if (!card.equals(c1) && card.getName().equals(c1.getName())) {
for (final Card card : landList2) { return true;
if (!card.equals(c) && card.getName().equals(c.getName())) {
return true;
}
} }
return false;
} }
return false;
}); });
if (c == 0) { if (c == 0) {
return PaymentDecision.card(new CardCollection()); return PaymentDecision.card(new CardCollection());
@@ -182,7 +179,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
public PaymentDecision visit(final CostDamage cost) { public PaymentDecision visit(final CostDamage cost) {
int c = cost.getAbilityAmount(ability); int c = cost.getAbilityAmount(ability);
if (confirmAction(Localizer.getInstance().getMessage("lblDoYouWantCardDealNDamageToYou", CardTranslation.getTranslatedName(source.getName()), String.valueOf(c)))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblDoYouWantCardDealNDamageToYou", CardTranslation.getTranslatedName(source.getName()), String.valueOf(c)), ability)*/) { if (confirmAction(Localizer.getInstance().getMessage("lblDoYouWantCardDealNDamageToYou", CardTranslation.getTranslatedName(source.getName()), String.valueOf(c)))) {
return PaymentDecision.number(c); return PaymentDecision.number(c);
} }
return null; return null;
@@ -209,7 +206,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
message = Localizer.getInstance().getMessage("lblDrawNCardsConfirm", String.valueOf(c)); message = Localizer.getInstance().getMessage("lblDrawNCardsConfirm", String.valueOf(c));
} }
if (!confirmAction(message)/*controller.confirmPayment(cost, message, ability)*/) { if (!confirmAction(message)) {
return null; return null;
} }
@@ -244,7 +241,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
} }
if (cost.payCostFromSource()) { if (cost.payCostFromSource()) {
return source.getZone() == player.getZone(cost.from) && confirmAction(Localizer.getInstance().getMessage("lblExileConfirm", CardTranslation.getTranslatedName(source.getName())))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblExileConfirm", CardTranslation.getTranslatedName(source.getName())), ability)*/ ? PaymentDecision.card(source) : null; return source.getZone() == player.getZone(cost.from) && confirmAction(Localizer.getInstance().getMessage("lblExileConfirm", CardTranslation.getTranslatedName(source.getName()))) ? PaymentDecision.card(source) : null;
} }
if (type.equals("All")) { if (type.equals("All")) {
@@ -373,7 +370,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
private PaymentDecision exileFromTop(final CostExile cost, final SpellAbility sa, final Player player, final int nNeeded) { private PaymentDecision exileFromTop(final CostExile cost, final SpellAbility sa, final Player player, final int nNeeded) {
final CardCollectionView list = player.getCardsIn(ZoneType.Library, nNeeded); final CardCollectionView list = player.getCardsIn(ZoneType.Library, nNeeded);
if (list.size() > nNeeded || !confirmAction(Localizer.getInstance().getMessage("lblExileNCardFromYourTopLibraryConfirm"))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblExileNCardFromYourTopLibraryConfirm"), ability)*/) { if (list.size() > nNeeded || !confirmAction(Localizer.getInstance().getMessage("lblExileNCardFromYourTopLibraryConfirm"))) {
return null; return null;
} }
return PaymentDecision.card(list); return PaymentDecision.card(list);
@@ -439,7 +436,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (cost.payCostFromSource()) { if (cost.payCostFromSource()) {
if (source.getController() == ability.getActivatingPlayer() && source.isInPlay()) { if (source.getController() == ability.getActivatingPlayer() && source.isInPlay()) {
return confirmAction(Localizer.getInstance().getMessage("lblExertCardConfirm", CardTranslation.getTranslatedName(source.getName())))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblExertCardConfirm", CardTranslation.getTranslatedName(source.getName())), ability)*/ ? PaymentDecision.card(source) : null; return confirmAction(Localizer.getInstance().getMessage("lblExertCardConfirm", CardTranslation.getTranslatedName(source.getName()))) ? PaymentDecision.card(source) : null;
} }
return null; return null;
} }
@@ -467,7 +464,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
public PaymentDecision visit(final CostFlipCoin cost) { public PaymentDecision visit(final CostFlipCoin cost) {
Integer c = cost.getAbilityAmount(ability); Integer c = cost.getAbilityAmount(ability);
if (!confirmAction(Localizer.getInstance().getMessage("lblDoYouWantFlipNCoinAction", String.valueOf(c)))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblDoYouWantFlipNCoinAction", String.valueOf(c)), ability)*/) { if (!confirmAction(Localizer.getInstance().getMessage("lblDoYouWantFlipNCoinAction", String.valueOf(c)))) {
return null; return null;
} }
@@ -478,7 +475,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
public PaymentDecision visit(final CostRollDice cost) { public PaymentDecision visit(final CostRollDice cost) {
int c = cost.getAbilityAmount(ability); int c = cost.getAbilityAmount(ability);
if (!confirmAction(Localizer.getInstance().getMessage("lblDoYouWantRollNDiceAction", String.valueOf(c), "d" + cost.getType()))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblDoYouWantRollNDiceAction", String.valueOf(c), "d" + cost.getType()), ability)*/) { if (!confirmAction(Localizer.getInstance().getMessage("lblDoYouWantRollNDiceAction", String.valueOf(c), "d" + cost.getType()))) {
return null; return null;
} }
@@ -536,7 +533,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
message = Localizer.getInstance().getMessage("lblMillNCardsFromYourLibraryConfirm", String.valueOf(c)); message = Localizer.getInstance().getMessage("lblMillNCardsFromYourLibraryConfirm", String.valueOf(c));
} }
if (!confirmAction(message)/*controller.confirmPayment(cost, message, ability)*/) { if (!confirmAction(message)) {
return null; return null;
} }
return PaymentDecision.number(c); return PaymentDecision.number(c);
@@ -558,7 +555,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
} }
// for costs declared mandatory, this is only reachable with a valid amount // for costs declared mandatory, this is only reachable with a valid amount
if (player.canPayLife(c, isEffect(), ability) && confirmAction(message)/*controller.confirmPayment(cost, message, ability)*/) { if (player.canPayLife(c, isEffect(), ability) && confirmAction(message)) {
//force mandatory if paylife is paid.. todo add check if all can be paid //force mandatory if paylife is paid.. todo add check if all can be paid
mandatory = true; mandatory = true;
return PaymentDecision.number(c); return PaymentDecision.number(c);
@@ -571,7 +568,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
Integer c = cost.getAbilityAmount(ability); Integer c = cost.getAbilityAmount(ability);
if (player.canPayEnergy(c) && if (player.canPayEnergy(c) &&
confirmAction(Localizer.getInstance().getMessage("lblPayEnergyConfirm", cost.toString(), String.valueOf(player.getCounters(CounterEnumType.ENERGY)), "{E}"))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblPayEnergyConfirm", cost.toString(), String.valueOf(player.getCounters(CounterEnumType.ENERGY)), "{E}"), ability)*/) { confirmAction(Localizer.getInstance().getMessage("lblPayEnergyConfirm", cost.toString(), String.valueOf(player.getCounters(CounterEnumType.ENERGY)), "{E}"))) {
return PaymentDecision.number(c); return PaymentDecision.number(c);
} }
return null; return null;
@@ -591,7 +588,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
player.getCardsIn(cost.getFrom()), cost.getType().split(";"), player, source, ability); player.getCardsIn(cost.getFrom()), cost.getType().split(";"), player, source, ability);
if (cost.payCostFromSource()) { if (cost.payCostFromSource()) {
return source.getZone() == player.getZone(cost.from) && confirmAction(Localizer.getInstance().getMessage("lblPutCardToLibraryConfirm", CardTranslation.getTranslatedName(source.getName())))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblPutCardToLibraryConfirm", CardTranslation.getTranslatedName(source.getName())), ability)*/ ? PaymentDecision.card(source) : null; return source.getZone() == player.getZone(cost.from) && confirmAction(Localizer.getInstance().getMessage("lblPutCardToLibraryConfirm", CardTranslation.getTranslatedName(source.getName()))) ? PaymentDecision.card(source) : null;
} }
if (cost.from == ZoneType.Hand) { if (cost.from == ZoneType.Hand) {
@@ -671,7 +668,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (cost.payCostFromSource()) { if (cost.payCostFromSource()) {
// UnlessCost so player might not want to pay (Fabricate) // UnlessCost so player might not want to pay (Fabricate)
if (ability.hasParam("UnlessCost") && !confirmAction(Localizer.getInstance().getMessage("lblPutNTypeCounterOnTarget", String.valueOf(c), cost.getCounter().getName(), ability.getHostCard().getName()))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblPutNTypeCounterOnTarget", String.valueOf(c), cost.getCounter().getName(), ability.getHostCard().getName()), ability)*/) { if (ability.hasParam("UnlessCost") && !confirmAction(Localizer.getInstance().getMessage("lblPutNTypeCounterOnTarget", String.valueOf(c), cost.getCounter().getName(), ability.getHostCard().getName()))) {
return null; return null;
} }
cost.setLastPaidAmount(c); cost.setLastPaidAmount(c);
@@ -701,7 +698,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
final Card card = ability.getHostCard(); final Card card = ability.getHostCard();
if (card.getController() == player && card.isInPlay()) { if (card.getController() == player && card.isInPlay()) {
final CardView view = CardView.get(card); final CardView view = CardView.get(card);
return confirmAction(Localizer.getInstance().getMessage("lblReturnCardToHandConfirm", CardTranslation.getTranslatedName(view.getName())))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblReturnCardToHandConfirm", CardTranslation.getTranslatedName(view.getName())), ability)*/ ? PaymentDecision.card(card) : null; return confirmAction(Localizer.getInstance().getMessage("lblReturnCardToHandConfirm", CardTranslation.getTranslatedName(view.getName()))) ? PaymentDecision.card(card) : null;
} }
} else { } else {
final CardCollectionView validCards = CardLists.getValidCards(ability.getActivatingPlayer().getCardsIn(ZoneType.Battlefield), final CardCollectionView validCards = CardLists.getValidCards(ability.getActivatingPlayer().getCardsIn(ZoneType.Battlefield),
@@ -732,16 +729,13 @@ public class HumanCostDecision extends CostDecisionMakerBase {
final Integer num = cost.getAbilityAmount(ability); final Integer num = cost.getAbilityAmount(ability);
CardCollectionView hand = player.getCardsIn(cost.getRevealFrom()); CardCollectionView hand = player.getCardsIn(cost.getRevealFrom());
final CardCollectionView hand2 = hand; final CardCollectionView hand2 = hand;
hand = CardLists.filter(hand, new Predicate<Card>() { hand = CardLists.filter(hand, c -> {
@Override for (final Card card : hand2) {
public boolean apply(final Card c) { if (!card.equals(c) && card.sharesColorWith(c)) {
for (final Card card : hand2) { return true;
if (!card.equals(c) && card.sharesColorWith(c)) {
return true;
}
} }
return false;
} }
return false;
}); });
if (num == 0) { if (num == 0) {
return PaymentDecision.number(0); return PaymentDecision.number(0);
@@ -944,7 +938,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (maxCounters < cntRemoved) { if (maxCounters < cntRemoved) {
return null; return null;
} }
if (!confirmAction(Localizer.getInstance().getMessage("lblRemoveNTargetCounterFromCardPayCostConfirm", amount, cost.counter.getName().toLowerCase(), CardTranslation.getTranslatedName(source.getName())))/*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblRemoveNTargetCounterFromCardPayCostConfirm", amount, cost.counter.getName().toLowerCase(), CardTranslation.getTranslatedName(source.getName())), ability)*/) { if (!confirmAction(Localizer.getInstance().getMessage("lblRemoveNTargetCounterFromCardPayCostConfirm", amount, cost.counter.getName().toLowerCase(), CardTranslation.getTranslatedName(source.getName())))) {
return null; return null;
} }
} }
@@ -1000,7 +994,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (cost.payCostFromSource()) { if (cost.payCostFromSource()) {
if (source.getController() == ability.getActivatingPlayer() && source.isInPlay()) { if (source.getController() == ability.getActivatingPlayer() && source.isInPlay()) {
return mandatory || confirmAction(Localizer.getInstance().getMessage("lblSacrificeCardConfirm", CardTranslation.getTranslatedName(source.getName()))) /*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblSacrificeCardConfirm", CardTranslation.getTranslatedName(source.getName())), ability)*/ ? PaymentDecision.card(source) : null; return mandatory || confirmAction(Localizer.getInstance().getMessage("lblSacrificeCardConfirm", CardTranslation.getTranslatedName(source.getName()))) ? PaymentDecision.card(source) : null;
} }
return null; return null;
} }
@@ -1008,7 +1002,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (type.equals("OriginalHost")) { if (type.equals("OriginalHost")) {
Card host = ability.getOriginalHost(); Card host = ability.getOriginalHost();
if (host.getController() == ability.getActivatingPlayer() && host.isInPlay()) { if (host.getController() == ability.getActivatingPlayer() && host.isInPlay()) {
return confirmAction(Localizer.getInstance().getMessage("lblSacrificeCardConfirm", CardTranslation.getTranslatedName(host.getName()))) /*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblSacrificeCardConfirm", CardTranslation.getTranslatedName(host.getName())), ability)*/ ? PaymentDecision.card(host) : null; return confirmAction(Localizer.getInstance().getMessage("lblSacrificeCardConfirm", CardTranslation.getTranslatedName(host.getName()))) ? PaymentDecision.card(host) : null;
} }
return null; return null;
} }
@@ -1081,16 +1075,13 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (sameType) { if (sameType) {
final CardCollection list2 = typeList; final CardCollection list2 = typeList;
typeList = CardLists.filter(typeList, new Predicate<Card>() { typeList = CardLists.filter(typeList, c12 -> {
@Override for (final Card card : list2) {
public boolean apply(final Card c) { if (!card.equals(c12) && card.sharesCreatureTypeWith(c12)) {
for (final Card card : list2) { return true;
if (!card.equals(c) && card.sharesCreatureTypeWith(c)) {
return true;
}
} }
return false;
} }
return false;
}); });
final CardCollection tapped = new CardCollection(); final CardCollection tapped = new CardCollection();
@@ -1104,12 +1095,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
} }
final Card first = inp.getFirstSelected(); final Card first = inp.getFirstSelected();
tapped.add(first); tapped.add(first);
typeList = CardLists.filter(typeList, new Predicate<Card>() { typeList = CardLists.filter(typeList, c1 -> c1.sharesCreatureTypeWith(first));
@Override
public boolean apply(final Card c) {
return c.sharesCreatureTypeWith(first);
}
});
typeList.remove(first); typeList.remove(first);
c--; c--;
} }
@@ -1171,7 +1157,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
@Override @Override
public PaymentDecision visit(final CostUnattach cost) { public PaymentDecision visit(final CostUnattach cost) {
final Card cardToUnattach = cost.findCardToUnattach(source, player, ability); final Card cardToUnattach = cost.findCardToUnattach(source, player, ability);
if (cardToUnattach != null && confirmAction(Localizer.getInstance().getMessage("lblUnattachCardConfirm", CardTranslation.getTranslatedName(cardToUnattach.getName()))) /*controller.confirmPayment(cost, Localizer.getInstance().getMessage("lblUnattachCardConfirm", CardTranslation.getTranslatedName(cardToUnattach.getName())), ability)*/) { if (cardToUnattach != null && confirmAction(Localizer.getInstance().getMessage("lblUnattachCardConfirm", CardTranslation.getTranslatedName(cardToUnattach.getName())))) {
return PaymentDecision.card(cardToUnattach); return PaymentDecision.card(cardToUnattach);
} }
return null; return null;
@@ -1188,6 +1174,6 @@ public class HumanCostDecision extends CostDecisionMakerBase {
cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getImprintedCards().get(0).getCurrentState().getImageKey())); cardView = CardView.getCardForUi(ImageUtil.getPaperCardFromImageKey(cardView.getImprintedCards().get(0).getCurrentState().getImageKey()));
else if (ability.getTargets() != null && ability.getTargets().isTargetingAnyCard() && ability.getTargets().size() == 1) else if (ability.getTargets() != null && ability.getTargets().isTargetingAnyCard() && ability.getTargets().size() == 1)
cardView = CardView.get(ability.getTargetCard()); cardView = CardView.get(ability.getTargetCard());
return controller.getGui().confirm(cardView, message); return controller.getGui().confirm(cardView, message.replaceAll("\n", " "));
} }
} }

View File

@@ -810,10 +810,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
buildQuestion.append("\n").append(localizer.getMessage("lblTriggeredby")).append(": ").append(tos.get(AbilityKey.Card)); buildQuestion.append("\n").append(localizer.getMessage("lblTriggeredby")).append(": ").append(tos.get(AbilityKey.Card));
} }
} }
return this.getGui().confirm(wrapper.getView().getHostCard(), buildQuestion.toString().replaceAll("\n", " "));
final InputConfirm inp = new InputConfirm(this, buildQuestion.toString(), wrapper);
inp.showAndWait();
return inp.getResult();
} }
@Override @Override
@@ -1344,11 +1341,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
// create sorted list from map from least to most frequent // create sorted list from map from least to most frequent
List<Entry<String, Integer>> sortedList = Lists.newArrayList(typesInDeck.entrySet()); List<Entry<String, Integer>> sortedList = Lists.newArrayList(typesInDeck.entrySet());
Collections.sort(sortedList, new Comparator<Entry<String, Integer>>() { Collections.sort(sortedList, (o1, o2) -> o1.getValue().compareTo(o2.getValue()));
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
}
});
// loop through sorted list and move each type to the front of the // loop through sorted list and move each type to the front of the
// validTypes collection // validTypes collection
@@ -1377,9 +1370,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override @Override
public boolean confirmReplacementEffect(final ReplacementEffect replacementEffect, final SpellAbility effectSA, public boolean confirmReplacementEffect(final ReplacementEffect replacementEffect, final SpellAbility effectSA,
GameEntity affected, final String question) { GameEntity affected, final String question) {
final InputConfirm inp = new InputConfirm(this, question, effectSA); return this.getGui().confirm(effectSA.getView().getHostCard(), question.replaceAll("\n", " "));
inp.showAndWait();
return inp.getResult();
} }
@Override @Override
@@ -1781,9 +1772,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override @Override
public boolean confirmPayment(final CostPart costPart, final String question, SpellAbility sa) { public boolean confirmPayment(final CostPart costPart, final String question, SpellAbility sa) {
final InputConfirm inp = new InputConfirm(this, question, sa); return this.getGui().confirm(sa.getView().getHostCard(), question.replaceAll("\n", " "));
inp.showAndWait();
return inp.getResult();
} }
@Override @Override
@@ -2229,11 +2218,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
} }
inp.selectButtonOK(); inp.selectButtonOK();
} else { } else {
FThreads.invokeInEdtNowOrLater(new Runnable() { FThreads.invokeInEdtNowOrLater(() -> {
@Override // getGui().message("Cannot pass priority at this time.");
public final void run() {
// getGui().message("Cannot pass priority at this time.");
}
}); });
} }
} }
@@ -2352,12 +2338,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final Map<String, String> produced = Maps.newHashMap(); final Map<String, String> produced = Maps.newHashMap();
produced.put("Produced", "W W W W W W W U U U U U U U B B B B B B B G G G G G G G R R R R R R R 7"); produced.put("Produced", "W W W W W W W U U U U U U U B B B B B B B G G G G G G G R R R R R R R 7");
final AbilityManaPart abMana = new AbilityManaPart(dummy, produced); final AbilityManaPart abMana = new AbilityManaPart(dummy, produced);
getGame().getAction().invoke(new Runnable() { getGame().getAction().invoke(() -> abMana.produceMana(null));
@Override
public void run() {
abMana.produceMana(null);
}
});
} }
@Override @Override
@@ -2470,12 +2451,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
return; return;
} }
getGame().getAction().invoke(new Runnable() { getGame().getAction().invoke(() -> getGame().getAction().moveToHand(card, null));
@Override
public void run() {
getGame().getAction().moveToHand(card, null);
}
});
} }
/* /*
@@ -2510,12 +2486,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final Card card = gameCacheCounters.get(cv); final Card card = gameCacheCounters.get(cv);
final ImmutableList<CounterType> counters = subtract ? ImmutableList.copyOf(card.getCounters().keySet()) final ImmutableList<CounterType> counters = subtract ? ImmutableList.copyOf(card.getCounters().keySet())
: ImmutableList.copyOf(Collections2.transform(CounterEnumType.values, new Function<CounterEnumType, CounterType>() { : ImmutableList.copyOf(Collections2.transform(CounterEnumType.values, input -> CounterType.get(input)));
@Override
public CounterType apply(CounterEnumType input) {
return CounterType.get(input);
}
}));
final CounterType counter = getGui().oneOrNone(localizer.getMessage("lblWhichTypeofCounter"), counters); final CounterType counter = getGui().oneOrNone(localizer.getMessage("lblWhichTypeofCounter"), counters);
if (counter == null) { if (counter == null) {
@@ -2541,20 +2512,17 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/ */
@Override @Override
public void tapPermanents() { public void tapPermanents() {
getGame().getAction().invoke(new Runnable() { getGame().getAction().invoke(() -> {
@Override final CardCollectionView untapped = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield),
public void run() { Predicates.not(CardPredicates.Presets.TAPPED));
final CardCollectionView untapped = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield), final InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0,
Predicates.not(CardPredicates.Presets.TAPPED)); Integer.MAX_VALUE, untapped);
final InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0, inp.setCancelAllowed(true);
Integer.MAX_VALUE, untapped); inp.setMessage(localizer.getMessage("lblChoosePermanentstoTap"));
inp.setCancelAllowed(true); inp.showAndWait();
inp.setMessage(localizer.getMessage("lblChoosePermanentstoTap")); if (!inp.hasCancelled()) {
inp.showAndWait(); for (final Card c : inp.getSelected()) {
if (!inp.hasCancelled()) { c.tap(true);
for (final Card c : inp.getSelected()) {
c.tap(true);
}
} }
} }
}); });
@@ -2567,20 +2535,17 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
*/ */
@Override @Override
public void untapPermanents() { public void untapPermanents() {
getGame().getAction().invoke(new Runnable() { getGame().getAction().invoke(() -> {
@Override final CardCollectionView tapped = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield),
public void run() { CardPredicates.Presets.TAPPED);
final CardCollectionView tapped = CardLists.filter(getGame().getCardsIn(ZoneType.Battlefield), final InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0,
CardPredicates.Presets.TAPPED); Integer.MAX_VALUE, tapped);
final InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0, inp.setCancelAllowed(true);
Integer.MAX_VALUE, tapped); inp.setMessage(localizer.getMessage("lblChoosePermanentstoUntap"));
inp.setCancelAllowed(true); inp.showAndWait();
inp.setMessage(localizer.getMessage("lblChoosePermanentstoUntap")); if (!inp.hasCancelled()) {
inp.showAndWait(); for (final Card c : inp.getSelected()) {
if (!inp.hasCancelled()) { c.untap(true);
for (final Card c : inp.getSelected()) {
c.untap(true);
}
} }
} }
}); });
@@ -2759,91 +2724,88 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
forgeCard.setTimestamp(getGame().getNextTimestamp()); forgeCard.setTimestamp(getGame().getNextTimestamp());
PaperCard finalC = c; PaperCard finalC = c;
getGame().getAction().invoke(new Runnable() { getGame().getAction().invoke(() -> {
@Override if (targetZone == ZoneType.Battlefield) {
public void run() { if (!forgeCard.getName().equals(f.getName())) {
if (targetZone == ZoneType.Battlefield) { forgeCard.changeToState(CardStateName.Flipped);
if (!forgeCard.getName().equals(f.getName())) { forgeCard.changeToState(CardStateName.Transformed);
forgeCard.changeToState(CardStateName.Flipped); forgeCard.changeToState(CardStateName.Modal);
forgeCard.changeToState(CardStateName.Transformed);
forgeCard.changeToState(CardStateName.Modal);
}
if (noTriggers) {
if (forgeCard.isPermanent() && !forgeCard.isAura()) {
if (forgeCard.isCreature()) {
if (!repeatLast) {
if (forgeCard.hasKeyword(Keyword.HASTE)) {
lastSummoningSickness = true;
} else {
lastSummoningSickness = getGui().confirm(forgeCard.getView(),
localizer.getMessage("lblCardShouldBeSummoningSicknessConfirm", CardTranslation.getTranslatedName(forgeCard.getName())));
}
}
}
getGame().getAction().moveTo(targetZone, forgeCard, null, AbilityKey.newMap());
if (forgeCard.isCreature()) {
forgeCard.setSickness(lastSummoningSickness);
}
} else {
getGui().message(localizer.getMessage("lblChosenCardNotPermanentorCantExistIndependentlyontheBattleground"), localizer.getMessage("lblError"));
return;
}
} else {
if (finalC.getRules().getType().isLand()) {
// this is needed to ensure land abilities fire
getGame().getAction().moveToHand(forgeCard, null);
getGame().getAction().moveToPlay(forgeCard, null, null);
// ensure triggered abilities fire
getGame().getTriggerHandler().runWaitingTriggers();
} else {
final FCollectionView<SpellAbility> choices = forgeCard.getBasicSpells();
if (choices.isEmpty()) {
return; // when would it happen?
}
final SpellAbility sa;
if (choices.size() == 1) {
sa = choices.iterator().next();
} else {
sa = repeatLast ? lastAddedSA : getGui().oneOrNone(localizer.getMessage("lblChoose"), (FCollection<SpellAbility>) choices);
}
if (sa == null) {
return; // happens if cancelled
}
lastAddedSA = sa;
// this is really needed (for rollbacks at least)
getGame().getAction().moveToHand(forgeCard, null);
// Human player is choosing targets for an ability
// controlled by chosen player.
sa.setActivatingPlayer(p);
sa.setSVar("IsCastFromPlayEffect", "True");
HumanPlay.playSaWithoutPayingManaCost(PlayerControllerHuman.this, getGame(), sa, true);
}
// playSa could fire some triggers
getGame().getStack().addAllTriggeredAbilitiesToStack();
}
} else if (targetZone == ZoneType.Library) {
if (!repeatLast) {
lastTopOfTheLibrary = getGui().confirm(forgeCard.getView(), localizer.getMessage("lblCardShouldBeAddedToLibraryTopOrBottom", CardTranslation.getTranslatedName(forgeCard.getName())),
true, Arrays.asList(localizer.getMessage("lblTop"), localizer.getMessage("lblBottom")));
}
if (lastTopOfTheLibrary) {
getGame().getAction().moveToLibrary(forgeCard, null);
} else {
getGame().getAction().moveToBottomOfLibrary(forgeCard, null);
}
} else {
getGame().getAction().moveTo(targetZone, forgeCard, null, AbilityKey.newMap());
} }
lastAdded = f; if (noTriggers) {
lastAddedZone = targetZone; if (forgeCard.isPermanent() && !forgeCard.isAura()) {
lastAddedPlayer = p; if (forgeCard.isCreature()) {
lastTrigs = noTriggers; if (!repeatLast) {
if (forgeCard.hasKeyword(Keyword.HASTE)) {
lastSummoningSickness = true;
} else {
lastSummoningSickness = getGui().confirm(forgeCard.getView(),
localizer.getMessage("lblCardShouldBeSummoningSicknessConfirm", CardTranslation.getTranslatedName(forgeCard.getName())));
}
}
}
getGame().getAction().moveTo(targetZone, forgeCard, null, AbilityKey.newMap());
if (forgeCard.isCreature()) {
forgeCard.setSickness(lastSummoningSickness);
}
} else {
getGui().message(localizer.getMessage("lblChosenCardNotPermanentorCantExistIndependentlyontheBattleground"), localizer.getMessage("lblError"));
return;
}
} else {
if (finalC.getRules().getType().isLand()) {
// this is needed to ensure land abilities fire
getGame().getAction().moveToHand(forgeCard, null);
getGame().getAction().moveToPlay(forgeCard, null, null);
// ensure triggered abilities fire
getGame().getTriggerHandler().runWaitingTriggers();
} else {
final FCollectionView<SpellAbility> choices1 = forgeCard.getBasicSpells();
if (choices1.isEmpty()) {
return; // when would it happen?
}
final SpellAbility sa;
if (choices1.size() == 1) {
sa = choices1.iterator().next();
} else {
sa = repeatLast ? lastAddedSA : getGui().oneOrNone(localizer.getMessage("lblChoose"), (FCollection<SpellAbility>) choices1);
}
if (sa == null) {
return; // happens if cancelled
}
lastAddedSA = sa;
// this is really needed (for rollbacks at least)
getGame().getAction().moveToHand(forgeCard, null);
// Human player is choosing targets for an ability
// controlled by chosen player.
sa.setActivatingPlayer(p);
sa.setSVar("IsCastFromPlayEffect", "True");
HumanPlay.playSaWithoutPayingManaCost(PlayerControllerHuman.this, getGame(), sa, true);
}
// playSa could fire some triggers
getGame().getStack().addAllTriggeredAbilitiesToStack();
}
} else if (targetZone == ZoneType.Library) {
if (!repeatLast) {
lastTopOfTheLibrary = getGui().confirm(forgeCard.getView(), localizer.getMessage("lblCardShouldBeAddedToLibraryTopOrBottom", CardTranslation.getTranslatedName(forgeCard.getName())),
true, Arrays.asList(localizer.getMessage("lblTop"), localizer.getMessage("lblBottom")));
}
if (lastTopOfTheLibrary) {
getGame().getAction().moveToLibrary(forgeCard, null);
} else {
getGame().getAction().moveToBottomOfLibrary(forgeCard, null);
}
} else {
getGame().getAction().moveTo(targetZone, forgeCard, null, AbilityKey.newMap());
} }
lastAdded = f;
lastAddedZone = targetZone;
lastAddedPlayer = p;
lastTrigs = noTriggers;
}); });
} }
@@ -2986,12 +2948,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
System.out.println("Rigging planar dice roll: " + res.toString()); System.out.println("Rigging planar dice roll: " + res.toString());
getGame().getAction().invoke(new Runnable() { getGame().getAction().invoke(() -> PlanarDice.roll(player, res));
@Override
public void run() {
PlanarDice.roll(player, res);
}
});
} }
/* /*
@@ -3022,24 +2979,18 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final Card forgeCard = Card.fromPaperCard(c, p); final Card forgeCard = Card.fromPaperCard(c, p);
forgeCard.setOwner(p); forgeCard.setOwner(p);
getGame().getAction().invoke(new Runnable() { getGame().getAction().invoke(() -> {
@Override getGame().getAction().changeZone(null, p.getZone(ZoneType.PlanarDeck), forgeCard, 0, null);
public void run() { PlanarDice.roll(p, PlanarDice.Planeswalk);
getGame().getAction().changeZone(null, p.getZone(ZoneType.PlanarDeck), forgeCard, 0, null);
PlanarDice.roll(p, PlanarDice.Planeswalk);
}
}); });
} }
public void askAI() { public void askAI() {
PlayerControllerAi ai = new PlayerControllerAi(player.getGame(), player, player.getOriginalLobbyPlayer()); PlayerControllerAi ai = new PlayerControllerAi(player.getGame(), player, player.getOriginalLobbyPlayer());
player.runWithController(new Runnable() { player.runWithController(() -> {
@Override List<SpellAbility> sas = ai.chooseSpellAbilityToPlay();
public void run() { SpellAbility chosen = sas == null ? null : sas.get(0);
List<SpellAbility> sas = ai.chooseSpellAbilityToPlay(); getGui().message(chosen == null ? "AI doesn't want to play anything right now" : chosen.getHostCard().toString(), "AI Play Suggestion");
SpellAbility chosen = sas == null ? null : sas.get(0);
getGui().message(chosen == null ? "AI doesn't want to play anything right now" : chosen.getHostCard().toString(), "AI Play Suggestion");
}
}, ai); }, ai);
} }
} }