use of mage.abilities.effects.common.combat.CantBlockTargetEffect in project mage by magefree.
the class BorosBattleshaperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature1 = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (creature1 != null) {
if (game.getOpponents(creature1.getControllerId()).contains(game.getActivePlayerId())) {
// Blocks
ContinuousEffectImpl effect = new BlocksIfAbleTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
game.addEffect(effect, source);
effect = new GainAbilityTargetEffect(BlocksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
game.addEffect(effect, source);
} else {
// Attacks
ContinuousEffectImpl effect = new AttacksIfAbleTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
game.addEffect(effect, source);
effect = new GainAbilityTargetEffect(AttacksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
game.addEffect(effect, source);
}
}
Permanent creature2 = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (creature2 != null) {
if (game.getOpponents(creature2.getControllerId()).contains(game.getActivePlayerId())) {
// Blocks
ContinuousEffectImpl effect = new CantBlockTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
game.addEffect(effect, source);
} else {
// Attacks
ContinuousEffectImpl effect = new CantAttackTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
use of mage.abilities.effects.common.combat.CantBlockTargetEffect in project mage by magefree.
the class HuatliWarriorPoetDamageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (source.getTargets().isEmpty()) {
return true;
}
Target multiTarget = source.getTargets().get(0);
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null && permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game, false, true) > 0) {
ContinuousEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
use of mage.abilities.effects.common.combat.CantBlockTargetEffect in project mage by magefree.
the class ChandraPyromasterEffect3 method apply.
@Override
public boolean apply(Game game, Ability source) {
game.damagePlayerOrPlaneswalker(source.getTargets().get(0).getFirstTarget(), 1, source.getSourceId(), source, game, false, true);
Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (creature != null) {
creature.damage(1, source.getSourceId(), source, game, false, true);
ContinuousEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature.getId(), game));
game.addEffect(effect, source);
}
return true;
}
use of mage.abilities.effects.common.combat.CantBlockTargetEffect in project mage by magefree.
the class StandOrFallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// 802.2. As the combat phase starts, the attacking player doesn’t choose an opponent to become the defending player.
// Instead, all the attacking player’s opponents are defending players during the combat phase.
//
// 802.2a Any rule, object, or effect that refers to a “defending player” refers to one specific defending player, not to all of the defending players.
// If an ability of an attacking creature refers to a defending player, or a spell or ability refers to both an attacking creature and a defending player,
// then unless otherwise specified, the defending player it’s referring to is the player that creature was attacking at the time it became an attacking
// creature that combat, or the controller of the planeswalker that creature was attacking at the time it became an attacking creature that combat. If a spell or ability
// could apply to multiple attacking creatures, the appropriate defending player is individually determined for each of those attacking creatures.
// If there are multiple defending players that could be chosen, the controller of the spell or ability chooses one.
//
// https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/756140-stand-or-fall-mechanics
Player player = game.getPlayer(source.getControllerId());
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (!opponents.isEmpty()) {
Player targetPlayer = game.getPlayer(opponents.iterator().next());
if (opponents.size() > 1) {
TargetOpponent targetOpponent = new TargetOpponent(true);
if (player != null && player.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
targetPlayer = game.getPlayer(targetOpponent.getFirstTarget());
game.informPlayers(player.getLogName() + " chose " + targetPlayer.getLogName() + " as the defending player");
}
}
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
creatures.setRequired(false);
if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
List<UUID> targets = creatures.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can block this turn.", pile1, pile2, game);
List<Permanent> chosenPile = choice ? pile2 : pile1;
List<Permanent> otherPile = choice ? pile1 : pile2;
for (Permanent permanent : chosenPile) {
if (permanent != null) {
RestrictionEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
effect.setText("");
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
game.informPlayers("Creatures that can block this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
return true;
}
}
return false;
}
Aggregations