use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class PeerPressureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Choice choice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (controller != null && controller.choose(Outcome.GainControl, choice, game)) {
String chosenType = choice.getChoice();
game.informPlayers(controller.getLogName() + " has chosen " + chosenType);
UUID playerWithMost = null;
int maxControlled = 0;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
FilterPermanent filter = new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType);
filter.add(new ControllerIdPredicate(playerId));
int controlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
if (controlled > maxControlled) {
maxControlled = controlled;
playerWithMost = playerId;
} else if (controlled == maxControlled) {
// Do nothing in case of tie
playerWithMost = null;
}
}
if (playerWithMost != null && playerWithMost.equals(controller.getId())) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType), controller.getId(), source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class PsychicBattleEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject != null) {
if (!stackObject.isTargetChanged() && !stackObject.getName().equals("Psychic Battle")) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
// resets the targetChanged flag
stackObject.setTargetChanged(false);
return true;
}
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class PsychicIntrusionSpendAnyManaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (opponent != null && sourceObject != null) {
opponent.revealCards(sourceObject.getName(), opponent.getHand(), game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int cardsGraveyard = opponent.getGraveyard().count(filter, game);
int cardsHand = opponent.getHand().count(filter, game);
boolean fromHand = false;
if (cardsGraveyard > 0 && cardsHand > 0) {
if (controller.chooseUse(Outcome.Detriment, "Exile card from opponents Hand?", source, game)) {
fromHand = true;
}
} else {
if (cardsHand > 0) {
fromHand = true;
}
}
Card card = null;
if (cardsHand > 0 && fromHand) {
TargetCard target = new TargetCard(Zone.HAND, filter);
if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
card = opponent.getHand().get(target.getFirstTarget(), game);
}
}
if (cardsGraveyard > 0 && !fromHand) {
TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
if (controller.choose(Outcome.Benefit, opponent.getGraveyard(), target, game)) {
card = opponent.getGraveyard().get(target.getFirstTarget(), game);
}
}
if (card != null) {
// move card to exile
UUID exileId = CardUtil.getCardExileZoneId(game, source);
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, fromHand ? Zone.HAND : Zone.GRAVEYARD, true);
// allow to cast the card
ContinuousEffect effect = new PsychicIntrusionCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
// and you may spend mana as though it were mana of any color to cast it
effect = new PsychicIntrusionSpendAnyManaEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
}
return true;
}
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class PsychicPurgeTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (getSourceId().equals(event.getTargetId())) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject != null) {
if (game.getOpponents(this.getControllerId()).contains(stackObject.getControllerId())) {
Effect effect = this.getEffects().get(0);
effect.setTargetPointer(new FixedTarget(stackObject.getControllerId()));
return true;
}
}
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class PuppeteerCliqueEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card == null) {
return false;
}
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
return false;
}
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return false;
}
ContinuousEffect hasteEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
hasteEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(hasteEffect, source);
ExileTargetEffect exileEffect = new ExileTargetEffect("exile " + permanent.getLogName());
exileEffect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect, TargetController.YOU);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
Aggregations