use of mage.constants.CardType in project mage by magefree.
the class CreepingDreadEffect method apply.
/*
* When a spell or ability instructs each player to discard a card,
starting with the player whose turn it is and proceeding in turn order,
each player selects a card from their hand without revealing it,
sets it aside, and then all of those cards are revealed and discarded at once.
https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=409851
*/
@Override
public boolean apply(Game game, Ability source) {
// controller discards a card - store info on card type
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<CardType> typesChosen = new HashSet<>();
Map<Player, Card> cardsChosen = new HashMap<>();
if (!controller.getHand().isEmpty()) {
TargetCard controllerTarget = new TargetCard(Zone.HAND, new FilterCard());
if (controller.choose(Outcome.Discard, controller.getHand(), controllerTarget, game)) {
Card card = controller.getHand().get(controllerTarget.getFirstTarget(), game);
if (card != null) {
typesChosen = new HashSet<>(card.getCardType(game));
cardsChosen.put(controller, card);
}
}
}
Set<Player> opponentsAffected = new HashSet<>();
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player opponent = game.getPlayer(playerId);
// opponent discards a card - if it is same card type as controller, add to opponentsAffected
if (opponent != null && !opponent.getHand().isEmpty()) {
TargetCard target = new TargetCard(Zone.HAND, new FilterCard());
if (opponent.choose(Outcome.Discard, opponent.getHand(), target, game)) {
Card card = opponent.getHand().get(target.getFirstTarget(), game);
if (card != null) {
if (!typesChosen.isEmpty()) {
for (CardType cType : typesChosen) {
for (CardType oType : card.getCardType(game)) {
if (cType == oType) {
opponentsAffected.add(opponent);
break;
}
}
}
}
cardsChosen.put(opponent, card);
}
}
}
}
// everyone discards the card at the same time
if (!cardsChosen.isEmpty()) {
for (Map.Entry<Player, Card> entry : cardsChosen.entrySet()) {
Player player = entry.getKey();
Card cardChosen = entry.getValue();
if (player != null) {
player.discard(cardChosen, false, source, game);
}
}
}
// each opponent who discarded a card of the same type loses 3 life
if (!opponentsAffected.isEmpty()) {
for (Player opponent : opponentsAffected) {
opponent.loseLife(3, game, source, false);
}
}
return true;
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class PlayerPanelExt method qtyCardTypes.
private int qtyCardTypes(mage.view.CardsView cardsView) {
Set<String> cardTypesPresent = new LinkedHashSet<String>() {
};
for (CardView card : cardsView.values()) {
Set<CardType> cardTypes = EnumSet.noneOf(CardType.class);
cardTypes.addAll(card.getCardTypes());
for (CardType cardType : cardTypes) {
cardTypesPresent.add(cardType.toString());
}
}
if (cardTypesPresent.isEmpty()) {
return 0;
} else {
return cardTypesPresent.size();
}
}
use of mage.constants.CardType in project mage by magefree.
the class DaringThiefSecondTarget method possibleTargets.
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
// get all cardtypes from opponents permanents
Set<CardType> cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
for (CardType type : permanent.getCardType(game)) {
if (cardTypes.contains(type)) {
possibleTargets.add(permanent.getId());
break;
}
}
}
}
}
return possibleTargets;
}
use of mage.constants.CardType in project mage by magefree.
the class DaringThiefSecondTarget method getOpponentPermanentCardTypes.
private EnumSet<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) {
Player controller = game.getPlayer(sourceControllerId);
EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class);
if (controller != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId, game)) {
if (controller.hasOpponent(permanent.getControllerId(), game)) {
cardTypes.addAll(permanent.getCardType(game));
}
}
}
return cardTypes;
}
Aggregations