use of mage.MageObject in project mage by magefree.
the class MycoidShepherdTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject lastKnown = game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
if (lastKnown == null) {
return false;
}
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
Permanent permanent = zEvent.getTarget();
if (permanent == null) {
return false;
}
if (super.getSourceId().equals(event.getTargetId()) || permanent.getPower().getValue() > 4 && permanent.isControlledBy(controllerId)) {
Zone after = game.getState().getZone(event.getTargetId());
return after != null && Zone.GRAVEYARD.match(after);
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class ManaCanBeSpentAsAnyColorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ObjectColor colorless = new ObjectColor();
// permaments
for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
perm.getColor(game).setColor(colorless);
}
List<Card> affectedCards = new ArrayList<>();
// spells
for (MageObject object : game.getStack()) {
if (object instanceof Spell) {
game.getState().getCreateMageObjectAttribute(object, game).getColor().setColor(colorless);
Card card = ((Spell) object).getCard();
affectedCards.add(card);
}
}
// exile
affectedCards.addAll(game.getExile().getAllCardsByRange(game, controller.getId()));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
// command
affectedCards.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY));
// hand
affectedCards.addAll(player.getHand().getCards(game));
// library
affectedCards.addAll(player.getLibrary().getCards(game));
// graveyard
affectedCards.addAll(player.getGraveyard().getCards(game));
}
// apply colors to all cards
affectedCards.forEach(card -> {
game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
// mdf cards
if (card instanceof ModalDoubleFacesCard) {
ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
}
// split cards
if (card instanceof SplitCard) {
SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
}
// double faces cards
if (card.getSecondCardFace() != null) {
game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
}
});
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class NissaNaturesArtisanEffect 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) {
return false;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 2));
if (!cards.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), cards, game);
Set<Card> toBattlefield = new LinkedHashSet<>();
for (Card card : cards.getCards(new FilterLandCard(), source.getSourceId(), source.getControllerId(), game)) {
cards.remove(card);
toBattlefield.add(card);
}
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
controller.moveCards(cards, Zone.HAND, source, game);
}
return true;
}
use of mage.MageObject in project mage by magefree.
the class NovaPentacleEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// check source
MageObject object = game.getObject(event.getSourceId());
if (object == null) {
game.informPlayers("Couldn't find source of damage");
return false;
}
if (!object.getId().equals(damageSource.getFirstTarget()) && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(damageSource.getFirstTarget()))) {
return false;
}
this.redirectTarget = source.getTargets().get(0);
// check player
Player player = game.getPlayer(event.getTargetId());
if (player != null) {
return player.getId().equals(source.getControllerId());
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class PeregrinationEffect 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) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards revealed = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
revealed.add(card);
}
controller.revealCards(sourceObject.getIdName(), revealed, game);
if (target.getTargets().size() == 2) {
TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
controller.choose(Outcome.Benefit, revealed, target2, game);
Card card = revealed.get(target2.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
revealed.remove(card);
Set<Card> cards = revealed.getCards(game);
card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.HAND, source, game);
} else if (target.getTargets().size() == 1) {
Set<Card> cards = revealed.getCards(game);
Card card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
Aggregations