use of mage.target.Target in project mage by magefree.
the class TragicArroganceffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Permanent> choosenPermanent = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterArtifactPermanent filterArtifactPermanent = new FilterArtifactPermanent("an artifact of " + player.getName());
filterArtifactPermanent.add(new ControllerIdPredicate(playerId));
Target target1 = new TargetArtifactPermanent(1, 1, filterArtifactPermanent, true);
FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent("a creature of " + player.getName());
filterCreaturePermanent.add(new ControllerIdPredicate(playerId));
Target target2 = new TargetPermanent(1, 1, filterCreaturePermanent, true);
FilterEnchantmentPermanent filterEnchantmentPermanent = new FilterEnchantmentPermanent("an enchantment of " + player.getName());
filterEnchantmentPermanent.add(new ControllerIdPredicate(playerId));
Target target3 = new TargetPermanent(1, 1, filterEnchantmentPermanent, true);
FilterPlaneswalkerPermanent filterPlaneswalkerPermanent = new FilterPlaneswalkerPermanent("a planeswalker of " + player.getName());
filterPlaneswalkerPermanent.add(new ControllerIdPredicate(playerId));
Target target4 = new TargetPermanent(1, 1, filterPlaneswalkerPermanent, true);
if (target1.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target1, source, game);
Permanent artifact = game.getPermanent(target1.getFirstTarget());
if (artifact != null) {
choosenPermanent.add(artifact);
}
target1.clearChosen();
}
if (target2.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target2, source, game);
Permanent creature = game.getPermanent(target2.getFirstTarget());
if (creature != null) {
choosenPermanent.add(creature);
}
target2.clearChosen();
}
if (target3.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target3, source, game);
Permanent enchantment = game.getPermanent(target3.getFirstTarget());
if (enchantment != null) {
choosenPermanent.add(enchantment);
}
target3.clearChosen();
}
if (target4.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target4, source, game);
Permanent planeswalker = game.getPermanent(target4.getFirstTarget());
if (planeswalker != null) {
choosenPermanent.add(planeswalker);
}
target4.clearChosen();
}
}
}
// Then each player sacrifices all other nonland permanents they control
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENTS_NON_LAND, playerId, game)) {
if (!choosenPermanent.contains(permanent)) {
permanent.sacrifice(source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class VaevictisAsmadiTheDireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Player> playersToFlip = new ArrayList<>();
for (Target target : source.getTargets()) {
for (UUID permId : target.getTargets()) {
Permanent permanent = game.getPermanent(permId);
if (permanent == null || !permanent.sacrifice(source, game)) {
continue;
}
Player player = game.getPlayer(permanent.getControllerId());
if (player != null) {
playersToFlip.add(player);
}
}
}
for (Player player : playersToFlip) {
if (player == null) {
return false;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
continue;
}
player.revealCards(source, new CardsImpl(card), game);
if (card.isPermanent(game)) {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return true;
}
use of mage.target.Target 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.target.Target in project mage by magefree.
the class SourceTargetsPermanentCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
if (sourceSpell == null) {
return false;
}
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
while (targets.hasNext()) {
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
return true;
}
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class ReturnToHandTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<UUID> copyIds = new ArrayList<>();
Set<Card> cards = new LinkedHashSet<>();
if (multitargetHandling) {
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
MageObject mageObject = game.getObject(targetId);
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
} else {
for (UUID targetId : targetPointer.getTargets(game, source)) {
MageObject mageObject = game.getObject(targetId);
if (mageObject != null) {
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
}
for (UUID copyId : copyIds) {
game.getStack().remove(game.getSpell(copyId), game);
}
return controller.moveCards(cards, Zone.HAND, source, game);
}
Aggregations