use of mage.MageObject in project mage by magefree.
the class WallOfStolenIdentityCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = game.getPermanentEntering(source.getSourceId());
}
final Permanent sourcePermanent = permanent;
if (controller == null || sourcePermanent == null) {
return false;
}
Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
target.setRequired(true);
if (source instanceof SimpleStaticAbility) {
target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
target.setRequired(false);
target.setNotTarget(true);
}
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent == null) {
return false;
}
game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
blueprint.addSubType(SubType.WALL);
blueprint.getAbilities().add(DefenderAbility.getInstance());
return true;
}
});
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new TapTargetEffect(), false, "tap the copied creature " + "and it doesn't untap during its controller's untap step for as long as you control {this}");
ability.addEffect(new DontUntapInControllersUntapStepTargetEffect(Duration.WhileControlled));
ability.getEffects().setTargetPointer(new FixedTarget(copyFromPermanent, game));
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.MageObject in project mage by magefree.
the class WandOfDenialEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (controller != null && targetPlayer != null) {
Card card = targetPlayer.getLibrary().getFromTop(game);
if (card != null) {
MageObject sourceObject = game.getObject(source.getSourceId());
controller.lookAtCards(sourceObject != null ? sourceObject.getName() : "", new CardsImpl(card), game);
if (!card.isLand(game) && controller.canPayLifeCost(source) && controller.getLife() >= 2 && controller.chooseUse(Outcome.Neutral, "Pay 2 life to put " + card.getLogName() + " into graveyard?", source, game)) {
controller.loseLife(2, game, source, false);
controller.moveCards(card, Zone.GRAVEYARD, source, game);
}
return true;
}
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class ZursWeirdingReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
boolean paid = false;
Player player = game.getPlayer(event.getTargetId());
MageObject sourceObject = source.getSourceObject(game);
if (player == null || sourceObject == null) {
return false;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
// Reveals it instead
player.revealCards(sourceObject.getIdName() + " next draw of " + player.getName() + " (" + game.getTurnNum() + '|' + game.getPhase().getType() + ')', new CardsImpl(card), game);
// Then any other player may pay 2 life. If a player does, put that card into its owner's graveyard
String message = "Pay 2 life to put " + card.getLogName() + " into " + player.getLogName() + " graveyard?";
for (UUID playerId : game.getState().getPlayersInRange(player.getId(), game)) {
if (playerId.equals(player.getId())) {
continue;
}
Player otherPlayer = game.getPlayer(playerId);
if (otherPlayer == null || !otherPlayer.canPayLifeCost(source) || otherPlayer.getLife() < 2) {
continue;
}
PayLifeCost lifeCost = new PayLifeCost(2);
if (otherPlayer.chooseUse(Outcome.Benefit, message, source, game) && lifeCost.pay(source, game, source, otherPlayer.getId(), true)) {
player.moveCards(card, Zone.GRAVEYARD, source, game);
return true;
}
}
// This is still replacing the draw, so we still return true
player.drawCards(1, source, game, event);
return true;
}
use of mage.MageObject in project mage by magefree.
the class MeldCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceMageObject = source.getSourceObjectIfItStillExists(game);
if (sourceMageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) sourceMageObject;
if (sourcePermanent.isControlledBy(source.getControllerId()) && sourcePermanent.isOwnedBy(source.getControllerId())) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(new NamePredicate(this.meldWithName));
filter.add(new OwnerIdPredicate(source.getControllerId()));
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
}
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class RevealSecretOpponentCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
if (controllerId == null || !controllerId.equals(ChooseSecretOpponentEffect.getSecretOwner(source, game))) {
return false;
}
UUID opponentId = ChooseSecretOpponentEffect.getChosenPlayer(source, game);
if (opponentId == null) {
return paid;
}
// because only once, the value is set to null
ChooseSecretOpponentEffect.setSecretOwner(null, source, game);
Player controller = game.getPlayer(controllerId);
Player opponent = game.getPlayer(opponentId);
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && opponent != null && sourceObject != null) {
if (sourceObject instanceof Permanent) {
((Permanent) sourceObject).addInfo(ChooseSecretOpponentEffect.SECRET_OPPONENT, null, game);
}
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " reveals the secretly chosen opponent " + opponent.getLogName());
}
paid = true;
return paid;
}
Aggregations