use of mage.target.targetpointer.TargetPointer in project mage by magefree.
the class BesmirchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (game.getPermanent(source.getFirstTarget()) != null) {
TargetPointer target = new FixedTarget(source.getFirstTarget(), game);
// gain control
game.addEffect(new GainControlTargetEffect(Duration.EndOfTurn).setTargetPointer(target), source);
// haste
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(target), source);
// goad
game.addEffect(new GoadTargetEffect().setTargetPointer(target), source);
// untap
new UntapTargetEffect().setTargetPointer(target).apply(game, source);
return true;
}
return false;
}
use of mage.target.targetpointer.TargetPointer 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.TargetPointer in project mage by magefree.
the class StackAbilityView method updateTargets.
private void updateTargets(Game game, StackAbility ability) {
List<String> names = new ArrayList<>();
for (UUID modeId : ability.getModes().getSelectedModes()) {
Mode mode = ability.getModes().get(modeId);
if (!mode.getTargets().isEmpty()) {
addTargets(mode.getTargets(), mode.getEffects(), ability, game);
} else {
List<UUID> targetList = new ArrayList<>();
for (Effect effect : mode.getEffects()) {
TargetPointer targetPointer = effect.getTargetPointer();
if (targetPointer instanceof FixedTarget) {
targetList.add(((FixedTarget) targetPointer).getTarget());
}
}
if (!targetList.isEmpty()) {
overrideTargets(targetList);
for (UUID uuid : targetList) {
MageObject mageObject = game.getObject(uuid);
if (mageObject != null) {
if ((mageObject instanceof Card) && ((Card) mageObject).isFaceDown(game)) {
continue;
}
String newName = GameLog.getColoredObjectIdNameForTooltip(mageObject);
if (!names.contains(newName)) {
names.add(newName);
}
}
}
}
}
}
if (!names.isEmpty()) {
getRules().add("<i>Related objects: " + names + "</i>");
}
// show for modal ability, which mode was choosen
if (ability.isModal()) {
Modes modes = ability.getModes();
for (UUID modeId : modes.getSelectedModes()) {
Mode mode = modes.get(modeId);
this.rules.add("<span color='green'><i>Chosen mode: " + mode.getEffects().getText(mode) + "</i></span>");
}
}
if (HintUtils.ABILITY_HINTS_ENABLE) {
List<String> abilityHints = new ArrayList<>();
for (Hint hint : ability.getHints()) {
abilityHints.add(hint.getText(game, ability));
}
// total hints
if (!abilityHints.isEmpty()) {
rules.add(HintUtils.HINT_START_MARK);
HintUtils.appendHints(rules, abilityHints);
}
}
}
Aggregations