use of mage.MageObject in project mage by magefree.
the class MindBombEffect 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) {
return false;
}
Map<UUID, Cards> cardsToDiscard = new HashMap<>();
// choose
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Cards cards = new CardsImpl();
Target target = new TargetDiscard(0, 3, new FilterCard(), playerId);
player.chooseTarget(Outcome.Discard, target, source, game);
cards.addAll(target.getTargets());
cardsToDiscard.put(playerId, cards);
}
// discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cards cardsPlayer = cardsToDiscard.get(playerId);
cardsToDiscard.put(playerId, player.discard(cardsPlayer, false, source, game));
}
}
// damage
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Cards cardsPlayer = cardsToDiscard.get(playerId);
if (cardsPlayer != null) {
player.damage(3 - cardsPlayer.size(), source.getSourceId(), source, game);
}
}
return true;
}
use of mage.MageObject in project mage by magefree.
the class MundaAmbushLeaderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Cards allCards = new CardsImpl();
allCards.addAll(controller.getLibrary().getTopCards(game, 4));
controller.lookAtCards(sourceObject.getIdName(), allCards, game);
if (!allCards.isEmpty()) {
Cards cardsToReveal = new CardsImpl();
TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
controller.chooseTarget(outcome, allCards, target, source, game);
cardsToReveal.addAll(target.getTargets());
if (!cardsToReveal.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), cardsToReveal, game, true);
allCards.removeAll(cardsToReveal);
}
controller.putCardsOnTopOfLibrary(cardsToReveal, game, source, true);
}
if (!allCards.isEmpty()) {
controller.putCardsOnBottomOfLibrary(allCards, game, source, true);
}
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class MultiformWonder2Effect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
String message = "Should " + sourceObject.getLogName() + " get -2/+2 instead of +2/-2?";
if (controller.chooseUse(Outcome.Neutral, message, source, game)) {
this.power *= -1;
this.toughness *= -1;
}
}
}
use of mage.MageObject in project mage by magefree.
the class NovijenHeartOfProgressEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
if (permanent.getTurnsOnBattlefield() == 0) {
permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts a +1/+1 counter on " + permanent.getLogName());
}
}
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class OathOfMagesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player firstPlayer = game.getPlayer(game.getActivePlayerId());
Player secondPlayer = game.getPlayer(source.getFirstTarget());
if (sourceObject == null || firstPlayer == null) {
return false;
}
if (firstPlayer.chooseUse(Outcome.Benefit, "Deal one damage to " + secondPlayer.getLogName() + "?", source, game)) {
secondPlayer.damage(1, source.getSourceId(), source, game);
}
return true;
}
Aggregations