use of mage.MageObject in project mage by magefree.
the class FaithsShieldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
if (FatefulHourCondition.instance.apply(game, source)) {
ChoiceColor choice = new ChoiceColor();
if (!controller.choose(Outcome.Protect, choice, game)) {
return false;
}
if (choice.getColor() != null) {
game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
FilterCard filter = new FilterCard();
filter.add(new ColorPredicate(choice.getColor()));
filter.setMessage(choice.getChoice());
Ability ability = new ProtectionAbility(filter);
game.addEffect(new GainAbilityControlledEffect(ability, Duration.EndOfTurn), source);
game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
return true;
}
} else {
game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source);
return true;
}
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class GrenzoHavocRaiserEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player damagedPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (damagedPlayer != null) {
MageObject sourceObject = game.getObject(source.getSourceId());
UUID exileId = CardUtil.getCardExileZoneId(game, source);
Card card = damagedPlayer.getLibrary().getFromTop(game);
if (card != null && sourceObject != null) {
// move card to exile
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, Zone.LIBRARY, true);
// Add effects only if the card has a spellAbility (e.g. not for lands).
if (card.getSpellAbility() != null) {
// allow to cast the card
// and you may spend mana as though it were mana of any color to cast it
CardUtil.makeCardPlayable(game, source, card, Duration.EndOfTurn, true);
}
}
return true;
}
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class GrenzosRuffiansEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID damagedOpponent = this.getTargetPointer().getFirst(game, source);
int amount = (Integer) getValue("damage");
MageObject object = game.getObject(source.getSourceId());
if (object != null && amount > 0 && damagedOpponent != null) {
for (UUID playerId : game.getOpponents(source.getControllerId())) {
if (!Objects.equals(playerId, damagedOpponent)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
int dealtDamage = opponent.damage(amount, source.getSourceId(), source, game);
game.informPlayers(object.getLogName() + " deals " + dealtDamage + " damage to " + opponent.getLogName());
}
}
}
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class GrimReminderWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_NON_LAND);
if (controller.searchLibrary(target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
Cards cardsToReveal = new CardsImpl(card);
controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
String cardName = card.getName();
GrimReminderWatcher watcher = game.getState().getWatcher(GrimReminderWatcher.class);
if (watcher != null) {
for (UUID playerId : watcher.getPlayersCastSpell(cardName)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.loseLife(6, game, source, false);
}
}
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class HellishRebukeTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject mageObject = source.getSourceObject(game);
game.addEffect(new GainAbilityAllEffect(new HellishRebukeTriggeredAbility(source, game), Duration.EndOfTurn, StaticFilters.FILTER_OPPONENTS_PERMANENT), source);
return true;
}
Aggregations