use of mage.constants.CardType in project mage by magefree.
the class MartyrsBondEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> perms = new ArrayList<>();
if (source != null) {
Permanent saccedPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && saccedPermanent != null) {
FilterControlledPermanent filter = new FilterControlledPermanent();
String message = "permanent with type (";
boolean firstType = true;
List<CardType.CardTypePredicate> cardTypes = new ArrayList<>();
for (CardType type : saccedPermanent.getCardType(game)) {
cardTypes.add(type.getPredicate());
if (firstType) {
message += type;
firstType = false;
} else {
message += " or " + type;
}
}
message += ") to sacrifice";
filter.add(Predicates.or(cardTypes));
filter.setMessage(message);
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && !playerId.equals(controller.getId())) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), playerId, game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
perms.add(target.getFirstTarget());
}
}
}
boolean saccedPermaents = false;
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
saccedPermaents = true;
}
}
return saccedPermaents;
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class MuldrothaTheGravetideWatcher method applies.
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (source.isControlledBy(affectedControllerId) && // only from your graveyard
source.isControlledBy(game.getOwnerId(objectId)) && // only during your turns (e.g. prevent flash creatures)
affectedControllerId.equals(game.getActivePlayerId()) && Zone.GRAVEYARD.equals(game.getState().getZone(objectId))) {
MuldrothaTheGravetideWatcher watcher = game.getState().getWatcher(MuldrothaTheGravetideWatcher.class);
MageObject mageObject = game.getObject(objectId);
if (mageObject != null && watcher != null) {
for (CardType cardType : mageObject.getCardType(game)) {
if (cardType.isPermanentType()) {
MageObjectReference mor = new MageObjectReference(source.getSourceObject(game), game);
if (!watcher.permanentTypePlayedFromGraveyard(mor, cardType)) {
return true;
}
}
}
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class SelectionBox method updateCounts.
private void updateCounts() {
deckNameAndCountLabel.setText(role.getName() + " - " + allCards.size());
creatureCountLabel.setText(String.valueOf(creatureCounter.get()));
landCountLabel.setText(String.valueOf(landCounter.get()));
for (CardType cardType : selectByTypeButtons.keySet()) {
AbstractButton button = selectByTypeButtons.get(cardType);
String text = cardType.toString();
int numCards = getCount(cardType);
if (cardType == CardType.CONSPIRACY) {
continue;
}
if (numCards > 0) {
button.setForeground(Color.BLACK);
text = text + " - " + numCards;
} else {
button.setForeground(new Color(100, 100, 100));
}
button.setText(text);
}
}
use of mage.constants.CardType in project mage by magefree.
the class SelectionBox method reselectBy.
public void reselectBy() {
// Deselect everything
deselectAll();
boolean useText = false;
String searchStr = "";
if (searchByTextField.getText().length() >= 3) {
useText = true;
searchStr = searchByTextField.getText().toLowerCase(Locale.ENGLISH);
}
for (CardType cardType : selectByTypeButtons.keySet()) {
AbstractButton button = selectByTypeButtons.get(cardType);
if (button != null) {
if (button.isSelected()) {
// Special case - "Multiples" (CONSPIRACY type)
if (cardType == CardType.CONSPIRACY) {
Map<String, CardView> cardNames = new HashMap<>();
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
if (cardNames.get(card.getName()) == null) {
cardNames.put(card.getName(), card);
} else {
card.setSelected(true);
cardViews.get(card.getId()).update(card);
CardView origCard = cardNames.get(card.getName());
origCard.setSelected(true);
cardViews.get(origCard.getId()).update(origCard);
}
}
}
}
continue;
}
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
boolean s = card.isSelected() || card.getCardTypes().contains(cardType);
card.setSelected(s);
cardViews.get(card.getId()).update(card);
}
}
}
}
}
}
if (useText) {
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
boolean s = card.isSelected();
// Name
if (!s) {
s = card.getName().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
// Sub & Super Types
if (!s) {
for (SuperType str : card.getSuperTypes()) {
s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
for (SubType str : card.getSubTypes()) {
s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
}
// Rarity
if (!s) {
Rarity r = card.getRarity();
if (r != null) {
s |= r.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
}
// Type line
if (!s) {
String t = "";
for (CardType type : card.getCardTypes()) {
t += ' ' + type.toString();
}
s |= t.toLowerCase(Locale.ENGLISH).contains(searchStr);
}
// Casting cost
if (!s) {
s |= card.getManaCostStr().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
// Rules
if (!s) {
for (String str : card.getRules()) {
s |= str.toLowerCase(Locale.ENGLISH).contains(searchStr);
}
}
card.setSelected(s);
cardViews.get(card.getId()).update(card);
}
}
}
}
// And finally rerender
layoutGrid();
repaintGrid();
}
use of mage.constants.CardType in project mage by magefree.
the class CardInfoWindowDialog 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();
}
}
Aggregations