use of mage.target.TargetPermanent in project mage by magefree.
the class PrimalAdversaryToken method apply.
@Override
public boolean apply(Game game, Ability source) {
Integer timesPaid = (Integer) getValue("timesPaid");
if (timesPaid == null || timesPaid <= 0) {
return false;
}
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(timesPaid)), false, staticText);
ability.addEffect(new BecomesCreatureTargetEffect(new PrimalAdversaryToken(), false, true, Duration.Custom));
ability.addTarget(new TargetPermanent(0, timesPaid, StaticFilters.FILTER_CONTROLLED_PERMANENT_LANDS));
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class RaidingPartyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null) {
Set<UUID> plainsToSave = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
int tappedCount = 0;
Target untappedCreatureTarget = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
if (player.choose(Outcome.Benefit, untappedCreatureTarget, source.getSourceId(), game)) {
tappedCount = untappedCreatureTarget.getTargets().size();
for (UUID creatureId : untappedCreatureTarget.getTargets()) {
Permanent creature = game.getPermanentOrLKIBattlefield(creatureId);
if (creature != null) {
creature.tap(source, game);
}
}
}
if (tappedCount > 0) {
Target plainsToSaveTarget = new TargetPermanent(0, tappedCount * 2, filter2, true);
if (player.choose(Outcome.Benefit, plainsToSaveTarget, source.getSourceId(), game)) {
for (UUID plainsId : plainsToSaveTarget.getTargets()) {
plainsToSave.add(plainsId);
Permanent plains = game.getPermanent(plainsId);
if (plains != null) {
game.informPlayers(player.getLogName() + " chose " + plains.getLogName() + " to not be destroyed by " + sourcePermanent.getLogName());
}
}
}
}
}
}
for (Permanent plains : game.getBattlefield().getActivePermanents(filter2, source.getControllerId(), source.getSourceId(), game)) {
if (!plainsToSave.contains(plains.getId())) {
plains.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class SavingGraceReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent) event;
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
Permanent creature = game.getPermanent(sourcePermanent.getAttachedTo());
if (creature == null) {
return false;
}
// Name of old target
Permanent targetPermanent = game.getPermanent(event.getTargetId());
StringBuilder message = new StringBuilder();
message.append(creature.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
creature.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class ScarabOfTheUnseenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
if (controller != null && targetPermanent != null) {
if (!targetPermanent.getAttachments().isEmpty()) {
List<UUID> attachments = new ArrayList<>();
attachments.addAll(targetPermanent.getAttachments());
for (UUID attachedId : attachments) {
Permanent attachedPerm = game.getPermanent(attachedId);
if (attachedPerm != null && filter.match(attachedPerm, game)) {
controller.moveCards(attachedPerm, Zone.HAND, source, game);
}
}
}
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class ShowOfDominanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int highestPower = Integer.MIN_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (highestPower < permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = permanent;
} else if (highestPower == permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = null;
}
}
if (highestPower != Integer.MIN_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
effect.setTargetPointer(target);
effect.apply(game, source);
ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
continuousEffect.setTargetPointer(target);
game.addEffect(continuousEffect, source);
return true;
}
}
return true;
}
return false;
}
Aggregations