permanentCard.setZone(Zone.BATTLEFIELD, this); permanentCard.setOwnerId(ownerId); PermanentCard newPermanent = new PermanentCard(permanentCard.getCard(), ownerId, this); getPermanentsEntering().put(newPermanent.getId(), newPermanent); newPermanent.entersBattlefield(newPermanent.getId(), this, Zone.OUTSIDE, false); getBattlefield().addPermanent(newPermanent); getPermanentsEntering().remove(newPermanent.getId()); newPermanent.removeSummoningSickness(); if (permanentCard.isTapped()) { newPermanent.setTapped(true);
private void init(Card card, Game game) { power = card.getPower().copy(); toughness = card.getToughness().copy(); copyFromCard(card, game); // if temporary added abilities to the spell/card exist, you need to add it to the permanent derived from that card Abilities<Ability> otherAbilities = game.getState().getAllOtherAbilities(card.getId()); if (otherAbilities != null) { abilities.addAll(otherAbilities); } /*if (card.getCardType().contains(CardType.PLANESWALKER)) { this.loyalty = new MageInt(card.getLoyalty().getValue()); }*/ if (card instanceof LevelerCard) { maxLevelCounters = ((LevelerCard) card).getMaxLevelCounters(); } if (isTransformable()) { if (game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId()) != null) { game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId(), null); setTransformed(true); TransformAbility.transform(this, getSecondCardFace(), game); } } }
@Override public void adjustTargets(Ability ability, Game game) { if (this.isTransformed() && card.getSecondCardFace() != null) { card.getSecondCardFace().adjustTargets(ability, game); } else { if (this.isCopy()) { // if COPIED card have adjuster then it's must be called instead own -- see OathOfLieges tests // raise null error on wrong copy this.getCopyFrom().adjustTargets(ability, game); } else { card.adjustTargets(ability, game); } } }
@Override public int getConvertedManaCost() { if (isTransformed()) { // 711.4b While a double-faced permanent's back face is up, it has only the characteristics of its back face. // However, its converted mana cost is calculated using the mana cost of its front face. This is a change from previous rules. // If a permanent is copying the back face of a double-faced card (even if the card representing that copy // is itself a double-faced card), the converted mana cost of that permanent is 0. return getCard().getConvertedManaCost(); } if (faceDown) { // game not neccessary return getManaCost().convertedManaCost(); } return super.getConvertedManaCost(); }
@Override public void loadCards(Set<Card> cards, UUID ownerId) { for (Card card : cards) { if (card instanceof PermanentCard) { card = ((PermanentCard) card).getCard(); } card.setOwnerId(ownerId); gameCards.put(card.getId(), card); state.addCard(card); if (card.isSplitCard()) { Card leftCard = ((SplitCard) card).getLeftHalfCard(); leftCard.setOwnerId(ownerId); gameCards.put(leftCard.getId(), leftCard); state.addCard(leftCard); Card rightCard = ((SplitCard) card).getRightHalfCard(); rightCard.setOwnerId(ownerId); gameCards.put(rightCard.getId(), rightCard); state.addCard(rightCard); } } }
target.setCopySourceCard(((PermanentToken) source).getToken().getCopySourceCard()); } else if (source instanceof PermanentCard) { if (((PermanentCard) source).isMorphed() || ((PermanentCard) source).isManifested()) { MorphAbility.setPermanentToFaceDownCreature(target); return target; } else { if (((PermanentCard) source).isTransformed() && source.getSecondCardFace() != null) { sourceObj = ((PermanentCard) source).getSecondCardFace(); } else { sourceObj = ((PermanentCard) source).getCard();
if (targetCard != null || targetPermanent != null || targetPlayer != null) { card.removeFromZone(game, fromZone, sourceId); PermanentCard permanent = new PermanentCard(card, (controllingPlayer == null ? card.getOwnerId() : controllingPlayer.getId()), game); ZoneChangeEvent zoneChangeEvent = new ZoneChangeEvent(permanent, controllerId, fromZone, Zone.BATTLEFIELD); permanent.updateZoneChangeCounter(game, zoneChangeEvent); game.getBattlefield().addPermanent(permanent); card.setZone(Zone.BATTLEFIELD, game); if (permanent.entersBattlefield(event.getSourceId(), game, fromZone, true)) { if (targetCard != null) { permanent.attachTo(targetCard.getId(), game); } else if (targetPermanent != null) { targetPermanent.addAttachment(permanent.getId(), game); } else if (targetPlayer != null) { targetPlayer.addAttachment(permanent.getId(), game);
if (object instanceof PermanentCard) { PermanentCard permanent = (PermanentCard) object; if (permanent.isTransformable() && event.getType() == GameEvent.EventType.TRANSFORMED) { exists = permanent.getCard().getAbilities().contains(ability); if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) { return false;
@Override public PermanentCard copy() { return new PermanentCard(this); }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getPlayerId().equals(source.getControllerId())) { MageObject object = game.getObject(event.getSourceId()); if (object instanceof PermanentCard) { if (game.getOpponents(source.getControllerId()).contains(((PermanentCard) object).getControllerId())) { return true; } } if (object instanceof Spell) { if (game.getOpponents(source.getControllerId()).contains(((Spell) object).getControllerId())) { return true; } } if (object instanceof Card) { if (game.getOpponents(source.getControllerId()).contains(((Card) object).getOwnerId())) { return true; } } if (object instanceof StackAbility) { if (game.getOpponents(source.getControllerId()).contains(((StackAbility) object).getControllerId())) { return true; } } } return false; }
@Override public void reset(Game game) { // when the permanent is reset, copy all original values from the card // must copy card each reset so that the original values don't get modified copyFromCard(card, game); power.resetToBaseValue(); toughness.resetToBaseValue(); super.reset(game); }
@Override public boolean apply(Game game, Ability source) { MageObject sourceObject = source.getSourceObjectIfItStillExists(game); // Transform only if it's the same object as the effect was put on the stack if (sourceObject instanceof Permanent) { Permanent sourcePermanent = (Permanent) sourceObject; if (sourcePermanent.canTransform(source, game)) { // check not to transform twice the same side if (sourcePermanent.isTransformed() != fromDayToNight) { if (withoutTrigger) { sourcePermanent.setTransformed(fromDayToNight); } else { sourcePermanent.transform(game); } if (!game.isSimulation()) { if (fromDayToNight) { if (sourcePermanent.getSecondCardFace() != null) { if (sourcePermanent instanceof PermanentCard) { game.informPlayers(((PermanentCard) sourcePermanent).getCard().getLogName() + " transforms into " + sourcePermanent.getSecondCardFace().getLogName()); } } } else { game.informPlayers(sourcePermanent.getSecondCardFace().getLogName() + " transforms into " + sourcePermanent.getLogName()); } } } } } return true; }
@Override public void init(Ability source, Game game) { super.init(source, game); if (!(copyFromObject instanceof Permanent) && (copyFromObject instanceof Card)) { this.copyFromObject = new PermanentCard((Card) copyFromObject, source.getControllerId(), game); } Permanent permanent = game.getPermanent(copyToObjectId); if (permanent != null) { affectedObjectList.add(new MageObjectReference(permanent, game)); } else if (source.getAbilityType() == AbilityType.STATIC) { // for replacement effects that let a permanent enter the battlefield as a copy of another permanent we need to apply that copy // before the permanent is added to the battlefield permanent = game.getPermanentEntering(copyToObjectId); if (permanent != null) { copyToPermanent(permanent, game, source); // set reference to the permanent later on the battlefield so we have to add already one (if no token) to the zone change counter int ZCCDiff = 1; if (permanent instanceof PermanentToken) { ZCCDiff = 0; } affectedObjectList.add(new MageObjectReference(permanent.getId(), game.getState().getZoneChangeCounter(copyToObjectId) + ZCCDiff, game)); } } }
@Override public boolean applies(GameEvent event, Ability source, Game game) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && permanent.isControlledBy(source.getControllerId())) { MageObject object = game.getObject(event.getSourceId()); if (object instanceof PermanentCard) { if (game.getOpponents(source.getControllerId()).contains(((PermanentCard)object).getControllerId())) { return true; } } if (object instanceof Spell) { if (game.getOpponents(source.getControllerId()).contains(((Spell)object).getControllerId())) { return true; } } } return false; }
Card card = game.getCard(stackObject.getSourceId()); if (card == null && (object instanceof PermanentCard)) { card = ((PermanentCard) object).getCard();
permanent = new PermanentCard(card, event.getPlayerId(), game);
MageObject object = game.getObject(event.getSourceId()); if (object instanceof PermanentCard) { isAnOpponentEffect = game.getOpponents(source.getControllerId()).contains(((PermanentCard) object).getControllerId());
for (Card exiled : toExile) { if (exiled instanceof PermanentMeld) { MeldCard meldCard = (MeldCard) ((PermanentCard) exiled).getCard(); Card topCard = meldCard.getTopHalfCard(); Card bottomCard = meldCard.getBottomHalfCard();
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent lazavTheMultifarious = game.getPermanent(source.getSourceId()); Permanent newBluePrint = null; if (controller != null && lazavTheMultifarious != null) { Card copyFromCard = game.getCard(source.getFirstTarget()); if (copyFromCard != null) { newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game); newBluePrint.assignNewId(); ApplyToPermanent applier = new LazavTheMultifariousApplier(); applier.apply(game, newBluePrint, source, lazavTheMultifarious.getId()); CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, lazavTheMultifarious.getId()); copyEffect.newId(); copyEffect.setApplier(applier); Ability newAbility = source.copy(); copyEffect.init(newAbility, game); game.addEffect(copyEffect, newAbility); } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); if (permanent != null) { if (permanent.canTransform(source, game)) { // check not to transform twice the same side if (withoutTrigger) { permanent.setTransformed(!permanent.isTransformed()); } else { permanent.transform(game); } if (!game.isSimulation()) { if (permanent.isTransformed()) { if (permanent.getSecondCardFace() != null) { if (permanent instanceof PermanentCard) { game.informPlayers(((PermanentCard) permanent).getCard().getLogName() + " transforms into " + permanent.getSecondCardFace().getLogName()); } } } else { game.informPlayers(permanent.getSecondCardFace().getLogName() + " transforms into " + permanent.getLogName()); } } } return true; } return false; }