use of mage.target.TargetPermanent in project mage by magefree.
the class EmptyTheLaboratoryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int toSacrifice = Math.min(source.getManaCostsToPay().getX(), game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game));
if (toSacrifice < 1) {
return false;
}
TargetPermanent target = new TargetPermanent(toSacrifice, filter);
target.setNotTarget(true);
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
int sacrificed = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.sacrifice(source, game)) {
sacrificed++;
}
}
Cards toReveal = new CardsImpl();
int zombies = 0;
for (Card card : player.getLibrary().getCards(game)) {
toReveal.add(card);
if (card.isCreature(game) && card.hasSubtype(SubType.ZOMBIE, game)) {
zombies++;
}
if (zombies >= sacrificed) {
break;
}
}
player.revealCards(source, toReveal, game);
player.moveCards(toReveal.getCards(filter2, game), Zone.BATTLEFIELD, source, game);
toReveal.retainZone(Zone.LIBRARY, game);
player.putCardsOnBottomOfLibrary(toReveal, game, source, false);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class FelineSovereignTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
Permanent p = game.getPermanent(event.getSourceId());
if (damageEvent.isCombatDamage() && p != null && p.isControlledBy(this.getControllerId()) && filter.match(p, getSourceId(), getControllerId(), game) && !damagedPlayerIds.contains(event.getPlayerId())) {
damagedPlayerIds.add(event.getPlayerId());
this.getTargets().clear();
FilterArtifactOrEnchantmentPermanent filter = new FilterArtifactOrEnchantmentPermanent();
filter.add(new ControllerIdPredicate(event.getPlayerId()));
this.addTarget(new TargetPermanent(0, 1, filter, false));
return true;
}
}
if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_PRIORITY || (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(getSourceId()))) {
damagedPlayerIds.clear();
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class FeedThePackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Target target = new TargetPermanent(filter);
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null && permanent.sacrifice(source, game)) {
int toughness = permanent.getToughness().getValue();
WolfToken token = new WolfToken();
token.putOntoBattlefield(toughness, game, source, source.getControllerId());
return true;
}
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class GideonsSacrificeEffectReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
game.addEffect(new GideonsSacrificeEffectReplacementEffect(new MageObjectReference(target.getFirstTarget(), game)), source);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class GideonsSacrificeEffectReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent) event;
Permanent permanent = mor.getPermanent(game);
if (permanent == null) {
return false;
}
// Name of old target
Permanent targetPermanent = game.getPermanent(event.getTargetId());
StringBuilder message = new StringBuilder();
message.append(permanent.getName()).append(": gets ");
message.append(damageEvent.getAmount()).append(" damage redirected from ");
if (targetPermanent != null) {
message.append(targetPermanent.getName());
} else {
Player targetPlayer = game.getPlayer(event.getTargetId());
if (targetPlayer != null) {
message.append(targetPlayer.getLogName());
} else {
message.append("unknown");
}
}
game.informPlayers(message.toString());
// Redirect damage
permanent.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
Aggregations