use of mage.target.TargetPermanent in project mage by magefree.
the class HazduhrTheAbbotRedirectDamageEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
if (permanent != null) {
if (filter.match(permanent, permanent.getId(), permanent.getControllerId(), game)) {
if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {
if (event.getTargetId() != null) {
TargetPermanent target = new TargetPermanent();
target.add(source.getSourceId(), game);
redirectTarget = target;
return true;
}
}
}
}
return false;
}
use of mage.target.TargetPermanent 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.TargetPermanent in project mage by magefree.
the class MyrBattlesphereEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent myr = game.getPermanentOrLKIBattlefield(source.getSourceId());
int tappedAmount = 0;
TargetPermanent target = new TargetPermanent(0, 1, filter, true);
while (controller.canRespond()) {
target.clearChosen();
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
Map<String, Serializable> options = new HashMap<>();
options.put("UI.right.btn.text", "Myr tapping complete");
controller.choose(outcome, target, source.getControllerId(), game, options);
if (!target.getTargets().isEmpty()) {
UUID creature = target.getFirstTarget();
if (creature != null) {
game.getPermanent(creature).tap(source, game);
tappedAmount++;
}
} else {
break;
}
} else {
break;
}
}
if (tappedAmount > 0) {
game.informPlayers(controller.getLogName() + " taps " + tappedAmount + " Myrs");
// boost effect
game.addEffect(new BoostSourceEffect(tappedAmount, 0, Duration.EndOfTurn), source);
// damage to defender
return game.damagePlayerOrPlaneswalker(targetPointer.getFirst(game, source), tappedAmount, myr.getId(), source, game, false, true) > 0;
}
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class PurgingScytheEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
int leastToughness = Integer.MAX_VALUE;
boolean multipleExist = false;
Permanent permanentToDamage = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
if (permanent.getToughness().getValue() < leastToughness) {
permanentToDamage = permanent;
leastToughness = permanent.getToughness().getValue();
multipleExist = false;
} else {
if (permanent.getToughness().getValue() == leastToughness) {
multipleExist = true;
}
}
}
if (multipleExist) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least toughness");
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
if (controller.choose(outcome, target, source.getSourceId(), game)) {
permanentToDamage = game.getPermanent(target.getFirstTarget());
}
}
}
if (permanentToDamage != null) {
game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDamage.getName());
return permanentToDamage.damage(2, source.getSourceId(), source, game, false, true) > 0;
}
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class RescuerSphinxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
if (!player.chooseUse(outcome, "Return a nonland permanent you control to your hand?", source, game)) {
return false;
}
Target target = new TargetPermanent(0, 1, filter, true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null || !player.moveCards(permanent, Zone.HAND, source, game)) {
return false;
}
return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
}
Aggregations