Reveal and choose card from opponent's hand.

This commit is contained in:
marcins78@gmail.com
2011-09-06 15:35:07 +00:00
parent 17630e04d7
commit 9282ec9a4e
6 changed files with 141 additions and 69 deletions

View File

@@ -0,0 +1,45 @@
package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.filters.Filter;
import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.decisions.ArbitraryCardsSelectionDecision;
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
import java.util.LinkedList;
import java.util.List;
public abstract class RevealAndChooseCardsFromOpponentHandEffect extends UnrespondableEffect {
private String _playerId;
private String _opponentId;
private Filter _selectionFilter;
private int _minChosen;
private int _maxChosen;
protected RevealAndChooseCardsFromOpponentHandEffect(String playerId, String opponentId, Filter selectionFilter, int minChosen, int maxChosen) {
_playerId = playerId;
_opponentId = opponentId;
_selectionFilter = selectionFilter;
_minChosen = minChosen;
_maxChosen = maxChosen;
}
@Override
public void playEffect(LotroGame game) {
List<PhysicalCard> opponentHand = new LinkedList<PhysicalCard>(game.getGameState().getHand(_opponentId));
List<PhysicalCard> selectable = Filters.filter(opponentHand, game.getGameState(), game.getModifiersQuerying(), _selectionFilter);
game.getUserFeedback().sendAwaitingDecision(_playerId,
new ArbitraryCardsSelectionDecision(1, "Opponent's hand", opponentHand, selectable, Math.min(_minChosen, selectable.size()), Math.min(_maxChosen, selectable.size())) {
@Override
public void decisionMade(String result) throws DecisionResultInvalidException {
List<PhysicalCard> selectedCards = getSelectedCardsByResponse(result);
cardsSelected(selectedCards);
}
});
}
protected abstract void cardsSelected(List<PhysicalCard> selectedCards);
}

View File

@@ -3,8 +3,8 @@ package com.gempukku.lotro.cards.set1.elven;
import com.gempukku.lotro.cards.AbstractEvent; import com.gempukku.lotro.cards.AbstractEvent;
import com.gempukku.lotro.cards.actions.PlayEventAction; import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.cards.effects.ChooseAndExertCharacterEffect; import com.gempukku.lotro.cards.effects.ChooseAndExertCharacterEffect;
import com.gempukku.lotro.cards.effects.ChooseArbitraryCardsEffect;
import com.gempukku.lotro.cards.effects.ChooseOpponentEffect; import com.gempukku.lotro.cards.effects.ChooseOpponentEffect;
import com.gempukku.lotro.cards.effects.RevealAndChooseCardsFromOpponentHandEffect;
import com.gempukku.lotro.common.*; import com.gempukku.lotro.common.*;
import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard; import com.gempukku.lotro.game.PhysicalCard;
@@ -47,13 +47,11 @@ public class Card1_044 extends AbstractEvent {
new ChooseOpponentEffect(playerId) { new ChooseOpponentEffect(playerId) {
@Override @Override
protected void opponentChosen(String opponentId) { protected void opponentChosen(String opponentId) {
List<? extends PhysicalCard> hand = game.getGameState().getHand(opponentId); action.addEffect(
List<PhysicalCard> isengardMinions = Filters.filter(hand, game.getGameState(), game.getModifiersQuerying(), Filters.culture(Culture.ISENGARD), Filters.type(CardType.MINION)); new RevealAndChooseCardsFromOpponentHandEffect(playerId, opponentId, Filters.and(Filters.culture(Culture.ISENGARD), Filters.type(CardType.MINION)), 1, 1) {
action.addCost(
new ChooseArbitraryCardsEffect(playerId, "Choose ISENGARD minion to discard", isengardMinions, 1, 1) {
@Override @Override
protected void cardsSelected(List<PhysicalCard> card) { protected void cardsSelected(List<PhysicalCard> selectedCards) {
action.addEffect(new DiscardCardFromHandEffect(card.get(0))); action.addEffect(new DiscardCardFromHandEffect(selectedCards.get(0)));
action.addEffect(new DrawCardEffect(playerId)); action.addEffect(new DrawCardEffect(playerId));
action.addEffect(new DrawCardEffect(playerId)); action.addEffect(new DrawCardEffect(playerId));
} }

View File

@@ -3,8 +3,8 @@ package com.gempukku.lotro.cards.set1.site;
import com.gempukku.lotro.cards.AbstractSite; import com.gempukku.lotro.cards.AbstractSite;
import com.gempukku.lotro.cards.PlayConditions; import com.gempukku.lotro.cards.PlayConditions;
import com.gempukku.lotro.cards.effects.ChooseAndExertCharacterEffect; import com.gempukku.lotro.cards.effects.ChooseAndExertCharacterEffect;
import com.gempukku.lotro.cards.effects.ChooseArbitraryCardsEffect;
import com.gempukku.lotro.cards.effects.ChooseOpponentEffect; import com.gempukku.lotro.cards.effects.ChooseOpponentEffect;
import com.gempukku.lotro.cards.effects.RevealAndChooseCardsFromOpponentHandEffect;
import com.gempukku.lotro.common.Keyword; import com.gempukku.lotro.common.Keyword;
import com.gempukku.lotro.common.Phase; import com.gempukku.lotro.common.Phase;
import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.filters.Filters;
@@ -14,7 +14,6 @@ import com.gempukku.lotro.logic.actions.DefaultCostToEffectAction;
import com.gempukku.lotro.logic.timing.Action; import com.gempukku.lotro.logic.timing.Action;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
/** /**
@@ -43,10 +42,10 @@ public class Card1_351 extends AbstractSite {
@Override @Override
protected void opponentChosen(String opponentId) { protected void opponentChosen(String opponentId) {
action.addEffect( action.addEffect(
new ChooseArbitraryCardsEffect(playerId, "Opponent's hand", new LinkedList<PhysicalCard>(game.getGameState().getHand(opponentId)), 0, 0) { new RevealAndChooseCardsFromOpponentHandEffect(playerId, opponentId, Filters.none(), 0, 0) {
@Override @Override
protected void cardsSelected(List<PhysicalCard> selectedCards) { protected void cardsSelected(List<PhysicalCard> selectedCards) {
// TODO - Reveal hand // Do nothing, it's just to reveal
} }
}); });
} }

View File

@@ -79,6 +79,15 @@ public class Filters {
}; };
} }
public static Filter none() {
return new Filter() {
@Override
public boolean accepts(GameState gameState, ModifiersQuerying modifiersQuerying, PhysicalCard physicalCard) {
return false;
}
};
}
public static Filter signet(final Signet signet) { public static Filter signet(final Signet signet) {
return new Filter() { return new Filter() {
@Override @Override

View File

@@ -7,6 +7,7 @@ import java.util.List;
public abstract class ArbitraryCardsSelectionDecision extends AbstractAwaitingDecision { public abstract class ArbitraryCardsSelectionDecision extends AbstractAwaitingDecision {
private List<PhysicalCard> _physicalCards; private List<PhysicalCard> _physicalCards;
private List<PhysicalCard> _selectable;
private int _minimum; private int _minimum;
private int _maximum; private int _maximum;
@@ -15,14 +16,27 @@ public abstract class ArbitraryCardsSelectionDecision extends AbstractAwaitingDe
} }
public ArbitraryCardsSelectionDecision(int id, String text, List<PhysicalCard> physicalCards, int minimum, int maximum) { public ArbitraryCardsSelectionDecision(int id, String text, List<PhysicalCard> physicalCards, int minimum, int maximum) {
this(id, text, physicalCards, physicalCards, minimum, maximum);
}
public ArbitraryCardsSelectionDecision(int id, String text, List<PhysicalCard> physicalCards, List<PhysicalCard> selectable, int minimum, int maximum) {
super(id, text, AwaitingDecisionType.ARBITRARY_CARDS); super(id, text, AwaitingDecisionType.ARBITRARY_CARDS);
_physicalCards = physicalCards; _physicalCards = physicalCards;
_selectable = selectable;
_minimum = minimum; _minimum = minimum;
_maximum = maximum; _maximum = maximum;
setParam("min", String.valueOf(minimum)); setParam("min", String.valueOf(minimum));
setParam("max", String.valueOf(maximum)); setParam("max", String.valueOf(maximum));
setParam("cardId", getCardIds(physicalCards)); setParam("cardId", getCardIds(physicalCards));
setParam("blueprintId", getBlueprintIds(physicalCards)); setParam("blueprintId", getBlueprintIds(physicalCards));
setParam("selectable", getSelectable(physicalCards, selectable));
}
private String[] getSelectable(List<PhysicalCard> physicalCards, List<PhysicalCard> selectable) {
String[] result = new String[physicalCards.size()];
for (int i = 0; i < physicalCards.size(); i++)
result[i] = String.valueOf(selectable.contains(physicalCards.get(i)));
return result;
} }
private String[] getCardIds(List<PhysicalCard> physicalCards) { private String[] getCardIds(List<PhysicalCard> physicalCards) {
@@ -53,7 +67,7 @@ public abstract class ArbitraryCardsSelectionDecision extends AbstractAwaitingDe
try { try {
for (String cardId : cardIds) { for (String cardId : cardIds) {
PhysicalCard card = _physicalCards.get(Integer.parseInt(cardId.substring(4))); PhysicalCard card = _physicalCards.get(Integer.parseInt(cardId.substring(4)));
if (result.contains(card)) if (result.contains(card) || !_selectable.contains(card))
throw new DecisionResultInvalidException(); throw new DecisionResultInvalidException();
result.add(card); result.add(card);
} }
@@ -66,3 +80,4 @@ public abstract class ArbitraryCardsSelectionDecision extends AbstractAwaitingDe
return result; return result;
} }
} }

View File

@@ -128,7 +128,7 @@ var GempLotrGameUI = Class.extend({
if (event.which == 1) { if (event.which == 1) {
if (event.shiftKey) { if (event.shiftKey) {
that.displayCardInfo(selectedCardElem.data("card")); that.displayCardInfo(selectedCardElem.data("card"));
} else if (selectedCardElem.hasClass("selectableCard")) } else if (selectedCardElem.hasClass("selectableCard"))
that.selectionFunction(selectedCardElem.data("card").cardId); that.selectionFunction(selectedCardElem.data("card").cardId);
} }
} }
@@ -153,52 +153,52 @@ var GempLotrGameUI = Class.extend({
initializeDialogs: function() { initializeDialogs: function() {
this.dialogInstance = $("<div></div>") this.dialogInstance = $("<div></div>")
.dialog({ .dialog({
autoOpen: false, autoOpen: false,
closeOnEscape: false, closeOnEscape: false,
resizable: false, resizable: false,
minHeight: 80 minHeight: 80
}); });
this.assignmentDialog = $("<div></div>") this.assignmentDialog = $("<div></div>")
.dialog({ .dialog({
autoOpen: false, autoOpen: false,
closeOnEscape: false, closeOnEscape: false,
title: "Assignments", title: "Assignments",
resizable: true, resizable: true,
minHeight: 240, minHeight: 240,
minWidth: 400, minWidth: 400,
width: 500, width: 500,
height: 200, height: 200,
position: ["right", "bottom"] position: ["right", "bottom"]
}); });
this.skirmishDialog = $("<div></div>") this.skirmishDialog = $("<div></div>")
.dialog({ .dialog({
autoOpen: false, autoOpen: false,
closeOnEscape: false, closeOnEscape: false,
title: "Skirmish", title: "Skirmish",
resizable: true, resizable: true,
minHeight: 240, minHeight: 240,
minWidth: 400, minWidth: 400,
width: 500, width: 500,
height: 200, height: 200,
position: ["right", "top"] position: ["right", "top"]
}); });
$(".ui-dialog-titlebar-close").hide(); $(".ui-dialog-titlebar-close").hide();
this.infoDialog = $("<div></div>") this.infoDialog = $("<div></div>")
.dialog({ .dialog({
autoOpen: false, autoOpen: false,
closeOnEscape: true, closeOnEscape: true,
resizable: false, resizable: false,
title: "Card information", title: "Card information",
minHeight: 80, minHeight: 80,
minWidth: 200, minWidth: 200,
width: 600, width: 600,
height: 300, height: 300,
maxHeight: 300 maxHeight: 300
}); });
}, },
@@ -538,13 +538,13 @@ var GempLotrGameUI = Class.extend({
this.dialogInstance this.dialogInstance
.html(text + "<br /><input id='integerDecision' type='text' value='0'>") .html(text + "<br /><input id='integerDecision' type='text' value='0'>")
.dialog("option", "buttons", .dialog("option", "buttons",
{ {
"OK": function() { "OK": function() {
$(this).dialog("close"); $(this).dialog("close");
that.decisionFunction(id, $("#integerDecision").val()); that.decisionFunction(id, $("#integerDecision").val());
} }
} }
) )
.dialog("option", "width", "400") .dialog("option", "width", "400")
.dialog("option", "height", "auto"); .dialog("option", "height", "auto");
; ;
@@ -578,13 +578,13 @@ var GempLotrGameUI = Class.extend({
this.dialogInstance this.dialogInstance
.html(html) .html(html)
.dialog("option", "buttons", .dialog("option", "buttons",
{ {
"OK": function() { "OK": function() {
$(this).dialog("close"); $(this).dialog("close");
that.decisionFunction(id, $("#multipleChoiceDecision").val()); that.decisionFunction(id, $("#multipleChoiceDecision").val());
} }
} }
) )
.dialog("option", "width", "400") .dialog("option", "width", "400")
.dialog("option", "height", "auto"); .dialog("option", "height", "auto");
@@ -625,11 +625,14 @@ var GempLotrGameUI = Class.extend({
var max = this.getDecisionParameter(decision, "max"); var max = this.getDecisionParameter(decision, "max");
var cardIds = this.getDecisionParameters(decision, "cardId"); var cardIds = this.getDecisionParameters(decision, "cardId");
var blueprintIds = this.getDecisionParameters(decision, "blueprintId"); var blueprintIds = this.getDecisionParameters(decision, "blueprintId");
var selectable = this.getDecisionParameters(decision, "selectable");
var that = this; var that = this;
var selectedCardIds = new Array(); var selectedCardIds = new Array();
var selectableCardIds = new Array();
this.dialogInstance this.dialogInstance
.html("<div id='arbitraryChoice'></div>") .html("<div id='arbitraryChoice'></div>")
.dialog("option", "title", text) .dialog("option", "title", text)
@@ -652,6 +655,9 @@ var GempLotrGameUI = Class.extend({
var cardId = cardIds[i]; var cardId = cardIds[i];
var blueprintId = blueprintIds[i]; var blueprintId = blueprintIds[i];
if (selectable[i] == "true")
selectableCardIds.push(cardId);
var card = new Card(blueprintId, "SPECIAL", cardId, this.selfParticipantId); var card = new Card(blueprintId, "SPECIAL", cardId, this.selfParticipantId);
var cardDiv = this.createCardDiv(card); var cardDiv = this.createCardDiv(card);
@@ -681,7 +687,7 @@ var GempLotrGameUI = Class.extend({
} }
}; };
this.attachSelectionFunctions(cardIds); this.attachSelectionFunctions(selectableCardIds);
this.specialGroup.setBounds(10, 10, 547, 188); this.specialGroup.setBounds(10, 10, 547, 188);
@@ -911,13 +917,13 @@ var GempLotrGameUI = Class.extend({
if (this.shadowAssignGroups[characterId] == null) { if (this.shadowAssignGroups[characterId] == null) {
this.shadowAssignGroups[characterId] = new NormalCardGroup(null, this.assignmentDialog, function (card) { this.shadowAssignGroups[characterId] = new NormalCardGroup(null, this.assignmentDialog, function (card) {
return (card.zone == "SHADOW_CHARACTERS" && card.assign == characterId); return (card.zone == "SHADOW_CHARACTERS" && card.assign == characterId);
} }
); );
this.freePeopleAssignGroups[characterId] = new NormalCardGroup(null, this.assignmentDialog, function (card) { this.freePeopleAssignGroups[characterId] = new NormalCardGroup(null, this.assignmentDialog, function (card) {
return (card.cardId == characterId); return (card.cardId == characterId);
} }
); );
this.moveCardToElement(characterId, this.assignmentDialog); this.moveCardToElement(characterId, this.assignmentDialog);
this.assignDialogResized(); this.assignDialogResized();