use of mage.cards.Card in project mage by magefree.
the class ReturnCreatureFromGraveyardToBattlefieldAndGainHasteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = game.getCard(source.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
return true;
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class ReturnToBattlefieldUnderYourControlTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cardsToBattlefield = new CardsImpl();
if (returnFromExileZoneOnly) {
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
UUID mainCardId = CardUtil.getMainCardId(game, targetId);
if (game.getExile().containsId(mainCardId, game)) {
cardsToBattlefield.add(mainCardId);
} else {
Card card = game.getCard(targetId);
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();
if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
cardsToBattlefield.add(topCard);
}
if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
cardsToBattlefield.add(bottomCard);
}
}
}
}
} else {
cardsToBattlefield.addAll(getTargetPointer().getTargets(game, source));
}
for (Card card : cardsToBattlefield.getCards(game)) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, false, null)) {
if (attacking) {
game.getCombat().addAttackingCreature(card.getId(), game);
}
}
}
return true;
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class ReturnToHandSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
MageObject mageObject;
if (returnFromNextZone && game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) {
mageObject = game.getObject(source.getSourceId());
} else {
mageObject = source.getSourceObjectIfItStillExists(game);
}
if (mageObject == null) {
return true;
}
switch(game.getState().getZone(mageObject.getId())) {
case BATTLEFIELD:
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.isPhasedIn()) {
return controller.moveCards(permanent, Zone.HAND, source, game);
}
break;
case GRAVEYARD:
Card card = (Card) mageObject;
return !fromBattlefieldOnly && controller.moveCards(card, Zone.HAND, source, game);
case STACK:
Spell spell = game.getSpell(source.getSourceId());
return !fromBattlefieldOnly && spell != null && controller.moveCards(spell.getMainCard(), Zone.HAND, source, game);
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class ReturnToHandTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<UUID> copyIds = new ArrayList<>();
Set<Card> cards = new LinkedHashSet<>();
if (multitargetHandling) {
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
MageObject mageObject = game.getObject(targetId);
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
} else {
for (UUID targetId : targetPointer.getTargets(game, source)) {
MageObject mageObject = game.getObject(targetId);
if (mageObject != null) {
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
}
for (UUID copyId : copyIds) {
game.getStack().remove(game.getSpell(copyId), game);
}
return controller.moveCards(cards, Zone.HAND, source, game);
}
use of mage.cards.Card in project mage by magefree.
the class ReturnToBattlefieldUnderOwnerControlTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cardsToBattlefield = new CardsImpl();
if (returnFromExileZoneOnly) {
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
if (game.getExile().containsId(targetId, game)) {
cardsToBattlefield.add(targetId);
} else {
Card card = game.getCard(targetId);
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();
if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
cardsToBattlefield.add(topCard);
}
if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
cardsToBattlefield.add(bottomCard);
}
}
}
}
} else {
cardsToBattlefield.addAll(getTargetPointer().getTargets(game, source));
}
if (!cardsToBattlefield.isEmpty()) {
controller.moveCards(cardsToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, tapped, false, true, null);
}
return true;
}
return false;
}
Aggregations