use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class TigerTribeHunterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetPermanent target = new TargetPermanent(0, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
int power = Math.max(permanent.getPower().getValue(), 0);
if (!permanent.sacrifice(source, game)) {
return false;
}
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(power), false, "{this} deals damage equal to the sacrificed creature's power to target creature.");
ability.addTarget(new TargetCreaturePermanent());
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class GodsendRuleModifyingEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent equipment = game.getPermanentOrLKIBattlefield((this.getSourceId()));
if (equipment != null && equipment.getAttachedTo() != null) {
Permanent equippedPermanent = game.getPermanentOrLKIBattlefield((equipment.getAttachedTo()));
if (equippedPermanent != null) {
possibleTargets.clear();
String targetName = "";
if (equippedPermanent.isAttacking()) {
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.getAttackers().contains(equippedPermanent.getId())) {
possibleTargets.addAll(group.getBlockers());
}
}
targetName = "a creature blocking attacker ";
} else if (equippedPermanent.getBlocking() > 0) {
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.getBlockers().contains(equippedPermanent.getId())) {
possibleTargets.addAll(group.getAttackers());
}
}
targetName = "a creature blocked by creature ";
}
if (!possibleTargets.isEmpty()) {
this.getTargets().clear();
if (possibleTargets.size() == 1) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(possibleTargets.iterator().next(), game));
} else {
this.getEffects().get(0).setTargetPointer(new FirstTargetPointer());
targetName = targetName + " equipped by " + equipment.getName();
FilterCreaturePermanent filter = new FilterCreaturePermanent(targetName);
List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
for (UUID creatureId : possibleTargets) {
uuidPredicates.add(new PermanentIdPredicate(creatureId));
}
filter.add(Predicates.or(uuidPredicates));
this.getTargets().add(new TargetCreaturePermanent(filter));
}
return true;
}
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class ImpetuousDevilsAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
filter.add(new ControllerIdPredicate(defenderId));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(0, 1, filter, false);
this.addTarget(target);
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class SiegeStrikerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int tappedAmount = 0;
TargetCreaturePermanent target = new TargetCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Tap, source.getControllerId(), source.getSourceId(), game)) {
for (UUID creatureId : target.getTargets()) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
creature.tap(source, game);
tappedAmount++;
}
}
}
if (tappedAmount > 0) {
game.addEffect(new BoostSourceEffect(tappedAmount, tappedAmount, Duration.EndOfTurn), source);
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class ProvokeRequirementEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(sourceId, game);
filter.add(new ControllerIdPredicate(defendingPlayerId));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
return false;
}
Aggregations