use of mage.MageObject in project mage by magefree.
the class SpoilsOfTheVaultEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (sourceObject == null || controller == null || cardName == null || cardName.isEmpty()) {
return false;
}
Cards cardsToReveal = new CardsImpl();
Cards cardsToExile = new CardsImpl();
for (Card card : controller.getLibrary().getCards(game)) {
if (card != null) {
cardsToReveal.add(card);
if (CardUtil.haveSameNames(card, cardName, game)) {
controller.moveCards(card, Zone.HAND, source, game);
break;
} else {
cardsToExile.add(card);
}
}
}
controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
controller.loseLife(cardsToExile.size(), game, source, false);
return true;
}
use of mage.MageObject in project mage by magefree.
the class SunscourgeChampionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && permanent != null && sourceObject != null) {
controller.gainLife(permanent.getPower().getValue(), game, source);
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class TestOfTalentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
if (stackObject == null) {
return false;
}
MageObject targetObject = game.getObject(stackObject.getSourceId());
String cardName;
if (targetObject instanceof Card) {
cardName = targetObject.getName();
} else {
cardName = "";
}
UUID searchPlayerId = stackObject.getControllerId();
Player player = game.getPlayer(searchPlayerId);
if (player == null) {
return false;
}
int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
game.getStack().counter(source.getFirstTarget(), source, game);
this.applySearchAndExile(game, source, cardName, searchPlayerId);
int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
if (previousCount > newCount) {
player.drawCards(previousCount - newCount, source, game);
}
return true;
}
use of mage.MageObject in project mage by magefree.
the class TrackDownEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject == null || controller == null) {
return false;
}
if (!controller.getLibrary().hasCards()) {
return false;
}
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
CardsImpl cards = new CardsImpl();
cards.add(card);
controller.revealCards(sourceObject.getName(), cards, game);
if (card.isLand(game) || card.isCreature(game)) {
controller.drawCards(1, source, game);
}
return true;
}
use of mage.MageObject in project mage by magefree.
the class ExileAllCardsFromAllGraveyards method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject Valki = game.getObject(source.getSourceId());
Set<Card> cardsToExile = new LinkedHashSet<>();
if (controller != null && Valki != null) {
UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + Valki.getZoneChangeCounter(game), game);
for (UUID opponentId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
opponent.revealCards(source, opponent.getHand(), game);
TargetCard targetToExile = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
targetToExile.withChooseHint("card to exile");
targetToExile.setNotTarget(true);
if (controller.choose(Outcome.Exile, opponent.getHand(), targetToExile, game)) {
Card targetedCardToExile = game.getCard(targetToExile.getFirstTarget());
if (targetedCardToExile != null && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
cardsToExile.add(targetedCardToExile);
}
}
}
}
// exile all cards at one time
controller.moveCardsToExile(cardsToExile, source, game, true, exileId, Valki.getName());
game.addDelayedTriggeredAbility(new ValkiGodOfLiesReturnExiledCardAbility(), source);
return true;
}
return false;
}
Aggregations