use of mage.target.targetpointer.FirstTargetPointer in project mage by magefree.
the class ExileTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> toExile = new LinkedHashSet<>();
if (multitargetHandling && targetPointer instanceof FirstTargetPointer && (source.getTargets().size() > 1 || (source.getTargets().size() > 0 && source.getTargets().get(0).getTargets().size() > 1))) {
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && permanent.isPhasedIn()) {
Zone currentZone = game.getState().getZone(permanent.getId());
if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == Zone.BATTLEFIELD)) {
toExile.add(permanent);
}
} else {
Card card = game.getCard(targetId);
if (card != null) {
Zone currentZone = game.getState().getZone(card.getId());
if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == currentZone)) {
toExile.add(card);
}
} else {
StackObject stackObject = game.getStack().getStackObject(targetId);
if (stackObject instanceof Spell) {
toExile.add((Spell) stackObject);
}
}
}
}
}
} else {
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && permanent.isPhasedIn()) {
Zone currentZone = game.getState().getZone(permanent.getId());
if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == Zone.BATTLEFIELD)) {
toExile.add(permanent);
}
} else {
Card card = game.getCard(targetId);
if (card != null) {
Zone currentZone = game.getState().getZone(card.getId());
if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == currentZone)) {
toExile.add(card);
}
} else {
StackObject stackObject = game.getStack().getStackObject(targetId);
if (stackObject instanceof Spell) {
toExile.add((Spell) stackObject);
}
}
}
}
}
if (toSourceExileZone) {
MageObject sourceObject = source.getSourceObject(game);
exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
if (sourceObject != null) {
exileZone = sourceObject.getIdName();
}
}
controller.moveCardsToExile(toExile, source, game, withName, exileId, exileZone);
return true;
}
return false;
}
use of mage.target.targetpointer.FirstTargetPointer in project mage by magefree.
the class ExileTargetForSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
Set<UUID> objectsToMove = new LinkedHashSet<>();
if (this.targetPointer instanceof FirstTargetPointer && source.getTargets().size() > 1) {
for (Target target : source.getTargets()) {
objectsToMove.addAll(target.getTargets());
}
} else {
if (this.targetPointer != null && !this.targetPointer.getTargets(game, source).isEmpty()) {
objectsToMove.addAll(this.targetPointer.getTargets(game, source));
} else {
// issue with Madness keyword #6889
UUID fixedTargetId = null;
for (Effect effect : source.getEffects()) {
TargetPointer targetPointerId = effect.getTargetPointer();
if (targetPointerId instanceof FixedTarget) {
fixedTargetId = (((FixedTarget) targetPointerId).getTarget());
}
}
if (fixedTargetId != null) {
objectsToMove.add(fixedTargetId);
}
}
}
UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
// it can target permanents on battlefield, so use objects first
Set<Card> cardsToMove = objectsToMove.stream().map(game::getObject).filter(Objects::nonNull).map(object -> {
if (object instanceof Card) {
return (Card) object;
} else {
return game.getCard(object.getId());
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
return controller.moveCardsToExile(cardsToMove, source, game, true, exileId, sourceObject.getIdName());
}
use of mage.target.targetpointer.FirstTargetPointer in project mage by magefree.
the class DestroyTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
if (multitargetHandling && source.getTargets().size() > 1 && targetPointer instanceof FirstTargetPointer) {
// Decimate
for (Target target : source.getTargets()) {
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.isPhasedIn() && !permanent.isPhasedOutIndirectly()) {
permanent.destroy(source, game, noRegen);
affectedTargets++;
}
}
}
} else {
for (UUID permanentId : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.isPhasedIn() && !permanent.isPhasedOutIndirectly()) {
permanent.destroy(source, game, noRegen);
affectedTargets++;
}
}
}
return affectedTargets > 0;
}
use of mage.target.targetpointer.FirstTargetPointer 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;
}
Aggregations