use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class TwistedJusticeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
// had, if thats the case this ability should fizzle.
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
controller.drawCards(permanent.getPower().getValue(), source, game);
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class RenounceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int amount = 0;
TargetControlledPermanent toSacrifice = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
if (player.chooseTarget(Outcome.Sacrifice, toSacrifice, source, game)) {
for (UUID uuid : toSacrifice.getTargets()) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
permanent.sacrifice(source, game);
amount++;
}
}
player.gainLife(amount * 2, game, source);
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class WarrenWeirdingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player == null) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
// had, if thats the case this ability should fizzle.
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
if (filterGoblin.match(permanent, game)) {
for (int i = 0; i < 2; i++) {
Token token = new GoblinRogueToken();
Effect effect = new CreateTokenTargetEffect(token);
effect.setTargetPointer(new FixedTarget(player.getId()));
if (effect.apply(game, source)) {
Permanent tokenPermanent = game.getPermanent(token.getLastAddedToken());
if (tokenPermanent != null) {
ContinuousEffect hasteEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
hasteEffect.setTargetPointer(new FixedTarget(tokenPermanent.getId()));
game.addEffect(hasteEffect, source);
}
}
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class WasitoraNekoruQueenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (damagedPlayer != null && controller != null) {
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
if (damagedPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
Permanent objectToBeSacrificed = game.getPermanent(target.getFirstTarget());
if (objectToBeSacrificed != null) {
if (objectToBeSacrificed.sacrifice(source, game)) {
return true;
}
}
}
new CreateTokenEffect(new WasitoraCatDragonToken()).apply(game, source);
return true;
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class MartyrsBondEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> perms = new ArrayList<>();
if (source != null) {
Permanent saccedPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && saccedPermanent != null) {
FilterControlledPermanent filter = new FilterControlledPermanent();
String message = "permanent with type (";
boolean firstType = true;
List<CardType.CardTypePredicate> cardTypes = new ArrayList<>();
for (CardType type : saccedPermanent.getCardType(game)) {
cardTypes.add(type.getPredicate());
if (firstType) {
message += type;
firstType = false;
} else {
message += " or " + type;
}
}
message += ") to sacrifice";
filter.add(Predicates.or(cardTypes));
filter.setMessage(message);
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && !playerId.equals(controller.getId())) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), playerId, game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
perms.add(target.getFirstTarget());
}
}
}
boolean saccedPermaents = false;
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
saccedPermaents = true;
}
}
return saccedPermaents;
}
}
return false;
}
Aggregations