use of mage.game.permanent.PermanentCard in project mage by magefree.
the class GameImpl method loadCards.
@Override
public void loadCards(Set<Card> cards, UUID ownerId) {
for (Card card : cards) {
if (card instanceof PermanentCard) {
card = ((PermanentCard) card).getCard();
}
// init each card by parts... if you add new type here then getInitAbilities must be
// implemented too (it allows to split abilities between card and parts)
// main card
card.setOwnerId(ownerId);
addCardToState(card);
// parts
if (card instanceof SplitCard) {
// left
Card leftCard = ((SplitCard) card).getLeftHalfCard();
leftCard.setOwnerId(ownerId);
addCardToState(leftCard);
// right
Card rightCard = ((SplitCard) card).getRightHalfCard();
rightCard.setOwnerId(ownerId);
addCardToState(rightCard);
} else if (card instanceof ModalDoubleFacesCard) {
// left
Card leftCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
leftCard.setOwnerId(ownerId);
addCardToState(leftCard);
// right
Card rightCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
rightCard.setOwnerId(ownerId);
addCardToState(rightCard);
} else if (card instanceof AdventureCard) {
Card spellCard = ((AdventureCard) card).getSpellCard();
spellCard.setOwnerId(ownerId);
addCardToState(spellCard);
}
}
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class CardUtil method putCardOntoBattlefieldWithEffects.
/**
* Put card to battlefield without resolve (for cheats and tests only)
*
* @param source must be non null (if you need it empty then use fakeSourceAbility)
* @param game
* @param newCard
* @param player
*/
public static void putCardOntoBattlefieldWithEffects(Ability source, Game game, Card newCard, Player player) {
// same logic as ZonesHandler->maybeRemoveFromSourceZone
// workaround to put real permanent from one side (example: you call mdf card by cheats)
Card permCard = getDefaultCardSideForBattlefield(game, newCard);
// prepare card and permanent
permCard.setZone(Zone.BATTLEFIELD, game);
permCard.setOwnerId(player.getId());
PermanentCard permanent;
if (permCard instanceof MeldCard) {
permanent = new PermanentMeld(permCard, player.getId(), game);
} else {
permanent = new PermanentCard(permCard, player.getId(), game);
}
// put onto battlefield with possible counters
game.getPermanentsEntering().put(permanent.getId(), permanent);
permCard.checkForCountersToAdd(permanent, source, game);
permanent.entersBattlefield(source, game, Zone.OUTSIDE, false);
game.addPermanent(permanent, game.getState().getNextPermanentOrderNumber());
game.getPermanentsEntering().remove(permanent.getId());
// workaround for special tapped status from test framework's command (addCard)
if (permCard instanceof PermanentCard && ((PermanentCard) permCard).isTapped()) {
permanent.setTapped(true);
}
// remove sickness
permanent.removeSummoningSickness();
// init effects on static abilities (init continuous effects; warning, game state contains copy)
for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
Optional<Ability> ability = game.getState().getContinuousEffects().getLayeredEffectAbilities(effect).stream().findFirst();
if (ability.isPresent() && permanent.getId().equals(ability.get().getSourceId())) {
effect.init(ability.get(), game, player.getId());
}
}
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class EerieInterludeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (sourceObject != null && controller != null) {
Set<Card> toExile = new HashSet<>();
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Permanent targetCreature = game.getPermanent(targetId);
if (targetCreature != null) {
toExile.add(targetCreature);
}
}
UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
controller.moveCardsToExile(toExile, source, game, true, exileId, sourceObject.getIdName());
Cards cardsToReturn = new CardsImpl();
for (Card exiled : toExile) {
if (exiled instanceof PermanentMeld) {
MeldCard meldCard = (MeldCard) ((PermanentCard) exiled).getCard();
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();
if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter()) {
cardsToReturn.add(topCard);
}
if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter()) {
cardsToReturn.add(bottomCard);
}
} else if (exiled.getZoneChangeCounter(game) == game.getState().getZoneChangeCounter(exiled.getId()) - 1) {
cardsToReturn.add(exiled);
}
}
Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
effect.setTargetPointer(new FixedTargets(cardsToReturn, game));
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
return false;
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class NephaliaAcademyEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.DISCARD_CARD) {
// only save card info if it's an opponent effect
Card card = game.getCard(event.getTargetId());
if (card != null) {
boolean isAnOpponentEffect = false;
MageObject object = game.getObject(event.getSourceId());
if (object instanceof PermanentCard) {
isAnOpponentEffect = game.getOpponents(source.getControllerId()).contains(((PermanentCard) object).getControllerId());
} else if (object instanceof Spell) {
isAnOpponentEffect = game.getOpponents(source.getControllerId()).contains(((Spell) object).getControllerId());
} else if (object instanceof Card) {
isAnOpponentEffect = game.getOpponents(source.getControllerId()).contains(((Card) object).getOwnerId());
}
if (isAnOpponentEffect) {
cardId = card.getId();
zoneChangeCounter = game.getState().getZoneChangeCounter(cardId);
}
}
return false;
}
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(event.getTargetId());
if (controller != null && card != null) {
cardId = null;
zoneChangeCounter = 0;
if (controller.chooseUse(outcome, "Put " + card.getIdName() + " on top of your library instead?", source, game)) {
Cards cardsToLibrary = new CardsImpl(card);
// reveal the card then put it on top of your library
controller.revealCards(card.getName(), cardsToLibrary, game);
controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
return true;
}
}
}
return false;
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class DermotaxiCopyApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
if (sourcePermanent == null) {
return false;
}
Card card = game.getCard(sourcePermanent.getImprinted().get(0));
if (card == null) {
return false;
}
Permanent newBluePrint = new PermanentCard(card, source.getControllerId(), game);
newBluePrint.assignNewId();
DermotaxiCopyApplier applier = new DermotaxiCopyApplier();
applier.apply(game, newBluePrint, source, sourcePermanent.getId());
CopyEffect copyEffect = new CopyEffect(Duration.EndOfTurn, newBluePrint, sourcePermanent.getId());
copyEffect.newId();
copyEffect.setApplier(applier);
game.addEffect(copyEffect, source);
return true;
}
Aggregations