Skip to content

Commit 640cde0

Browse files
Akse1otHanmac
andauthored
Update HumanCostDecision.java (#10468)
* Update HumanCostDecision.java Adds a UI filter to HumanCostDecision that prevents incompatible cards from being selected when paying the exile cost if the +withSharedCardType condition is met. * Use sharesCardTypeWith in HumanCostDecision * Update HumanCostDecision.java * Update HumanCostDecision.java Format --------- Co-authored-by: Hans Mackowiak <hanmac@gmx.de>
1 parent ad51d74 commit 640cde0

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

forge-gui/src/main/java/forge/player/HumanCostDecision.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,54 @@ private PaymentDecision exileFromMiscZone(final CostExile cost, final int nNeede
468468
return null;
469469
}
470470

471-
final List<ZoneType> origin = Lists.newArrayList(cost.from);
472-
final String required = sharedType ? " (must share a card type)" : "";
471+
if (!sharedType) {
472+
final List<ZoneType> origin = Lists.newArrayList(cost.from);
473+
final List<Card> chosen = controller.chooseCardsForZoneChange(
474+
ZoneType.Exile,
475+
origin,
476+
ability,
477+
typeList,
478+
mandatory ? nNeeded : 0,
479+
nNeeded,
480+
null,
481+
cost.toString(nNeeded),
482+
null
483+
);
484+
485+
if (chosen.size() < nNeeded) {
486+
return null;
487+
}
488+
return PaymentDecision.card(chosen);
489+
}
490+
491+
if (typeList.size() < nNeeded) {
492+
return null;
493+
}
473494

474-
final List<Card> chosen = controller.chooseCardsForZoneChange(ZoneType.Exile, origin, ability, typeList,
475-
mandatory ? nNeeded : 0, nNeeded, null, cost.toString(nNeeded) + required,
476-
null);
495+
final InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, mandatory ? nNeeded : 0, nNeeded, typeList, ability) {
496+
private static final long serialVersionUID = 1L;
477497

478-
if (chosen.size() < nNeeded) {
498+
@Override
499+
protected boolean onCardSelected(final Card c, final List<Card> otherCardsToSelect, final ITriggerEvent triggerEvent) {
500+
final Card firstSelected = Iterables.getFirst(this.selected, null);
501+
if (firstSelected != null && !firstSelected.sharesCardTypeWith(c)) {
502+
return false;
503+
}
504+
return super.onCardSelected(c, otherCardsToSelect, triggerEvent);
505+
}
506+
};
507+
508+
inp.setMessage(cost.toString(nNeeded) + " (must share a card type)");
509+
inp.setCancelAllowed(!mandatory);
510+
inp.showAndWait();
511+
512+
if (inp.hasCancelled()) {
479513
return null;
480514
}
481-
if (sharedType) {
482-
if (!chosen.get(1).sharesCardTypeWith(chosen.get(0))) return null;
515+
516+
final CardCollection chosen = new CardCollection(inp.getSelected());
517+
if (chosen.size() < nNeeded) {
518+
return null;
483519
}
484520

485521
return PaymentDecision.card(chosen);

0 commit comments

Comments
 (0)