use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class LucilleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment == null) {
return false;
}
Player player = game.getPlayer(game.getCombat().getDefendingPlayerId(equipment.getAttachedTo(), game));
if (player == null) {
return false;
}
TargetPermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (!target.canChoose(source.getSourceId(), player.getId(), game)) {
return false;
}
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
return permanent.sacrifice(source, game) && new WalkerToken().putOntoBattlefield(1, game, source, source.getControllerId());
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class MeldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Find the two permanents to meld.
UUID sourceId = source.getSourceId();
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature named " + meldWithName);
filter.add(new NamePredicate(meldWithName));
TargetPermanent target = new TargetControlledCreaturePermanent(filter);
Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
if (meldWithList.isEmpty()) {
// possible permanent has left the battlefield meanwhile
return false;
}
UUID meldWithId = null;
if (meldWithList.size() == 1) {
meldWithId = meldWithList.iterator().next();
} else {
if (controller.choose(Outcome.BoostCreature, target, sourceId, game)) {
meldWithId = target.getFirstTarget();
}
}
// Exile the two permanents to meld.
Permanent sourcePermanent = game.getPermanent(sourceId);
Permanent meldWithPermanent = game.getPermanent(meldWithId);
if (sourcePermanent != null && meldWithPermanent != null) {
Set<Card> toExile = new HashSet<>();
toExile.add(sourcePermanent);
toExile.add(meldWithPermanent);
controller.moveCards(toExile, Zone.EXILED, source, game);
// Create the meld card and move it to the battlefield.
Card sourceCard = game.getExile().getCard(sourceId, game);
Card meldWithCard = game.getExile().getCard(meldWithId, game);
if (sourceCard != null && !sourceCard.isCopy() && meldWithCard != null && !meldWithCard.isCopy()) {
meldCard.setOwnerId(controller.getId());
meldCard.setTopHalfCard(meldWithCard, game);
meldCard.setBottomHalfCard(sourceCard, game);
meldCard.setMelded(true, game);
game.addMeldCard(meldCard.getId(), meldCard);
game.getState().addCard(meldCard);
meldCard.setZone(Zone.EXILED, game);
controller.moveCards(meldCard, Zone.BATTLEFIELD, source, game);
}
return true;
}
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class OfferingCostReductionEffect method applies.
@Override
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
if (sourceId.equals(source.getSourceId())) {
Card card = game.getCard(sourceId);
if (card == null || !card.isOwnedBy(source.getControllerId())) {
return false;
}
// because can activate is always called twice, result from first call will be used
Object object = game.getState().getValue("offering_" + card.getId());
if (object != null && object.equals(true)) {
Object alreadyConfirmed = game.getState().getValue("offering_ok_" + card.getId());
game.getState().setValue("offering_" + card.getId(), null);
game.getState().setValue("offering_ok_" + card.getId(), null);
return alreadyConfirmed != null;
} else {
// first call -> remove previous Ids
game.getState().setValue("offering_Id_" + card.getId(), null);
}
if (game.getBattlefield().count(((OfferingAbility) source).getFilter(), source.getSourceId(), source.getControllerId(), game) > 0) {
if (game.inCheckPlayableState()) {
return true;
}
FilterControlledCreaturePermanent filter = ((OfferingAbility) source).getFilter();
Card spellToCast = game.getCard(source.getSourceId());
if (spellToCast == null) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) {
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
player.chooseTarget(Outcome.Sacrifice, target, source, game);
if (!target.isChosen()) {
return false;
}
game.getState().setValue("offering_" + card.getId(), true);
Permanent offer = game.getPermanent(target.getFirstTarget());
if (offer != null) {
UUID activationId = UUID.randomUUID();
OfferingCostReductionEffect effect = new OfferingCostReductionEffect(activationId);
effect.setTargetPointer(new FixedTarget(offer, game));
game.addEffect(effect, source);
game.getState().setValue("offering_ok_" + card.getId(), true);
game.getState().setValue("offering_Id_" + card.getId(), activationId);
game.informPlayers(player.getLogName() + " announces to offer " + offer.getLogName() + " to cast " + // No id name to prevent to offer hand card knowledge after cancel casting
GameLog.getColoredObjectName(spellToCast));
return true;
}
} else {
game.getState().setValue("offering_" + card.getId(), true);
}
}
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class BronzehideLionContinuousEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !(game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD)) {
return false;
}
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
TargetPermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (controller.choose(outcome, target, source.getSourceId(), game) && game.getPermanent(target.getFirstTarget()) != null) {
game.getState().setValue("attachTo:" + source.getSourceId(), target.getFirstTarget());
}
game.addEffect(new BronzehideLionContinuousEffect(game.getState().getZoneChangeCounter(source.getSourceId()) + 1), source);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent aura = game.getPermanent(card.getId());
Permanent creature = game.getPermanent(target.getFirstTarget());
if (aura == null || creature == null) {
return true;
}
creature.addAttachment(aura.getId(), source, game);
return true;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class DoomfallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (targetPlayer.choose(outcome, target, source.getSourceId(), game)) {
targetPlayer.moveCards(game.getPermanent(target.getFirstTarget()), Zone.EXILED, source, game);
}
return true;
}
return false;
}
Aggregations