use of mage.constants.Zone in project mage by magefree.
the class FactOrFictionEffect 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;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
controller.revealCards(sourceObject.getName(), cards, game);
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (!opponents.isEmpty()) {
Player opponent = game.getPlayer(opponents.iterator().next());
if (opponents.size() > 1) {
Target targetOpponent = new TargetOpponent(true);
if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
opponent = game.getPlayer(targetOpponent.getFirstTarget());
game.informPlayers(controller.getLogName() + " chose " + opponent.getLogName() + " to separate the revealed cards");
}
}
TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
if (opponent.choose(Outcome.Neutral, cards, target, game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = cards.get(targetId, game);
if (card != null) {
pile1.add(card);
cards.remove(card);
}
}
}
List<Card> pile2 = new ArrayList<>();
pile2.addAll(cards.getCards(game));
boolean choice = controller.choosePile(outcome, "Choose a pile to put into your hand.", pile1, pile2, game);
Zone pile1Zone = Zone.GRAVEYARD;
Zone pile2Zone = Zone.HAND;
if (choice) {
pile1Zone = Zone.HAND;
pile2Zone = Zone.GRAVEYARD;
}
StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
int i = 0;
for (Card card : pile1) {
i++;
sb.append(card.getName());
if (i < pile1.size()) {
sb.append(", ");
}
}
cards.clear();
cards.addAll(pile1);
controller.moveCards(cards, pile1Zone, source, game);
game.informPlayers(sb.toString());
sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
i = 0;
for (Card card : pile2) {
i++;
sb.append(' ').append(card.getName());
if (i < pile2.size()) {
sb.append(", ");
}
}
cards.clear();
cards.addAll(pile2);
controller.moveCards(cards, pile2Zone, source, game);
game.informPlayers(sb.toString());
}
return true;
}
use of mage.constants.Zone in project mage by magefree.
the class RunedCrownEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = null;
Zone zone = null;
if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for a Rune card?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
target.setNotTarget(true);
if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.GRAVEYARD;
}
}
}
if (card == null && controller.chooseUse(Outcome.Neutral, "Search your hand for a Rune card?", source, game)) {
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.HAND;
}
}
}
if (card == null) {
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.LIBRARY;
}
}
controller.shuffleLibrary(source, game);
}
// aura card found - attach it
if (card == null) {
return true;
}
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null) {
game.getState().setValue("attachTo:" + card.getId(), permanent);
}
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
if (permanent != null) {
return permanent.addAttachment(card.getId(), source, game);
}
return true;
}
use of mage.constants.Zone in project mage by magefree.
the class RevealAndShuffleIntoLibrarySourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
Player controller = game.getPlayer(source.getControllerId());
if (sourceObject != null && controller != null) {
Player owner = null;
Cards cards = new CardsImpl();
Permanent permanent = null;
if (sourceObject instanceof Spell) {
sourceObject = ((Spell) sourceObject).getCard();
}
if (sourceObject instanceof Permanent) {
permanent = (Permanent) sourceObject;
owner = game.getPlayer(permanent.getOwnerId());
if (sourceObject instanceof PermanentCard) {
cards.add(permanent);
}
} else if (sourceObject instanceof Card) {
owner = game.getPlayer(((Card) sourceObject).getOwnerId());
cards.add((Card) sourceObject);
}
if (owner != null) {
Zone fromZone = game.getState().getZone(sourceObject.getId());
if (!cards.isEmpty()) {
controller.revealCards(sourceObject.getName(), cards, game);
}
if (permanent != null) {
controller.moveCardToLibraryWithInfo(permanent, source, game, fromZone, true, true);
} else {
controller.moveCardToLibraryWithInfo((Card) sourceObject, source, game, fromZone, true, true);
}
if (!cards.isEmpty()) {
controller.shuffleLibrary(source, game);
}
}
return true;
}
return false;
}
use of mage.constants.Zone in project mage by magefree.
the class KickerAbility method getActivationKey.
/**
* Return activation zcc key for searching spell's settings in source object
*
* @param source
* @param game
* @return
*/
public static String getActivationKey(Ability source, Game game) {
// Kicker activates in STACK zone so all zcc must be from "stack moment"
// Use cases:
// * resolving spell have same zcc (example: check kicker status in sorcery/instant);
// * copied spell have same zcc as source spell (see Spell.copySpell and zcc sync);
// * creature/token from resolved spell have +1 zcc after moved to battlefield (example: check kicker status in ETB triggers/effects);
// find object info from the source ability (it can be a permanent or a spell on stack, on the moment of trigger/resolve)
MageObject sourceObject = source.getSourceObject(game);
Zone sourceObjectZone = game.getState().getZone(sourceObject.getId());
int zcc = CardUtil.getActualSourceObjectZoneChangeCounter(game, source);
// * spells and copied spells resolves on STACK (zcc not changes)
if (sourceObjectZone != Zone.STACK) {
--zcc;
}
return zcc + "";
}
use of mage.constants.Zone in project mage by magefree.
the class HauntEffect method isInUseableZone.
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
boolean fromOK = true;
Permanent sourcePermanent = (Permanent) game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD);
if (creatureHaunt && sourcePermanent == null) {
// check it was previously on battlefield
fromOK = false;
}
if (!this.hasSourceObjectAbility(game, sourcePermanent, event)) {
return false;
}
// check now it is in graveyard
Zone after = game.getState().getZone(sourceId);
return fromOK && after != null && Zone.GRAVEYARD.match(after);
}
Aggregations