use of mage.cards.Card in project mage by magefree.
the class BondOfRevivalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = game.getCard(source.getFirstTarget());
if (player == null || card == null) {
return false;
}
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.UntilYourNextTurn);
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game) + 1));
if (player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
game.addEffect(effect, source);
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class CheckForTrapsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || opponent == null) {
return false;
}
opponent.revealCards(source, opponent.getHand(), game);
TargetCard target = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_NON_LAND);
target.setNotTarget(true);
boolean opponentLoseLife = false;
if (controller.choose(outcome, opponent.getHand(), target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
if (card.isInstant(game) || card.hasAbility(FlashAbility.getInstance(), game)) {
opponentLoseLife = true;
}
}
}
if (opponentLoseLife) {
opponent.loseLife(1, game, source, false);
} else {
controller.loseLife(1, game, source, false);
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class ChecksAndBalancesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null) {
if (player.getHand().isEmpty()) {
game.informPlayers(player.getLogName() + " doesn't have a card in hand to discard to counter " + spell.getLogName() + ", effect aborted.");
return true;
}
}
}
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null) {
if (!player.chooseUse(outcome, "Discard a card to counter " + spell.getLogName() + '?', source, game)) {
game.informPlayers(player.getLogName() + " refuses to discard a card to counter " + spell.getLogName());
return true;
} else {
game.informPlayers(player.getLogName() + " agrees to discard a card to counter " + spell.getLogName());
}
}
}
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null && !player.getHand().isEmpty()) {
TargetCardInHand target = new TargetCardInHand();
if (player.choose(Outcome.Discard, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
player.discard(card, false, source, game);
}
}
}
game.getStack().counter(spell.getId(), source, game);
return true;
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class CounterbalanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
Card topcard = controller.getLibrary().getFromTop(game);
if (topcard != null) {
CardsImpl cards = new CardsImpl();
cards.add(topcard);
controller.revealCards(sourcePermanent.getName(), cards, game);
if (topcard.getManaValue() == spell.getManaValue()) {
return game.getStack().counter(spell.getId(), source, game);
}
}
return true;
}
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class CounterlashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (stackObject != null && controller != null) {
game.getStack().counter(source.getFirstTarget(), source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
FilterCard filter = new FilterCard();
List<Predicate<MageObject>> types = new ArrayList<>();
for (CardType type : stackObject.getCardType(game)) {
if (type != CardType.LAND) {
types.add(type.getPredicate());
}
}
filter.add(Predicates.or(types));
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
return false;
}
Aggregations