use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class AwakenElementalToken method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = null;
for (Target target : source.getTargets()) {
targetId = target.getFirstTarget();
}
if (targetId != null) {
FixedTarget fixedTarget = new FixedTarget(targetId, game);
ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.EndOfGame);
continuousEffect.setTargetPointer(fixedTarget);
game.addEffect(continuousEffect, source);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(3));
effect.setTargetPointer(fixedTarget);
return effect.apply(game, source);
}
return true;
}
use of mage.abilities.effects.ContinuousEffect 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.abilities.effects.ContinuousEffect 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.abilities.effects.ContinuousEffect 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;
}
use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class SabaccGameEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (targetPermanent != null) {
Player opponent = game.getPlayer(targetPermanent.getControllerId());
if (opponent != null) {
FilterPermanent filter = new FilterPermanent("permanent controlled by " + controller.getName());
filter.add(new ControllerIdPredicate(controller.getId()));
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
Permanent chosenPermanent = null;
if (target.chooseTarget(outcome, opponent.getId(), source, game)) {
chosenPermanent = game.getPermanent(target.getFirstTarget());
}
boolean flipWin = controller.flipCoin(source, game, true);
if (flipWin) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, controller.getId());
effect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(effect, source);
} else if (chosenPermanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
return false;
}
Aggregations