use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class DawnOfTheDeadEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && card != null) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent creature = game.getPermanent(card.getId());
if (creature != null) {
// gains haste
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
// Exile at begin of next end step
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(creature, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class DauntlessBodyguardGainAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent == null) {
return false;
}
MageObjectReference mor = (MageObjectReference) game.getState().getValue(sourcePermanent.getId() + "_chosenCreature");
if (mor == null) {
return false;
}
Permanent chosenPermanent = mor.getPermanent(game);
if (chosenPermanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
game.addEffect(effect, source);
}
return true;
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class GideonBlackbladeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (player == null || permanent == null) {
return false;
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose an ability to give to " + permanent.getLogName());
choice.setChoices(choices);
if (!player.choose(outcome, choice, game)) {
return false;
}
Ability ability = null;
switch(choice.getChoice()) {
case "Vigilance":
ability = VigilanceAbility.getInstance();
break;
case "Lifelink":
ability = LifelinkAbility.getInstance();
break;
case "Indestructible":
ability = IndestructibleAbility.getInstance();
break;
}
if (ability != null) {
game.addEffect(new GainAbilityTargetEffect(ability, Duration.EndOfTurn), source);
}
return true;
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class GhoulsNightOutTypeChangingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID controllerId = source.getControllerId();
Player controller = game.getPlayer(controllerId);
if (controller != null) {
Set<Card> cardsToBattlefield = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
boolean creatureInGraveyard = false;
for (UUID cardId : player.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
creatureInGraveyard = true;
break;
}
}
if (creatureInGraveyard) {
FilterCreatureCard filter = new FilterCreatureCard("creature card in " + player.getName() + "'s graveyard");
TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
target.setNotTarget(true);
controller.chooseTarget(controllerId.equals(playerId) ? Outcome.Benefit : Outcome.Detriment, player.getGraveyard(), target, source, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cardsToBattlefield.add(card);
}
}
}
}
if (!cardsToBattlefield.isEmpty()) {
controller.moveCards(cardsToBattlefield, Zone.BATTLEFIELD, source, game);
cardsToBattlefield.removeIf(card -> game.getState().getZone(card.getId()) != Zone.BATTLEFIELD);
if (!cardsToBattlefield.isEmpty()) {
game.addEffect(new GhoulsNightOutTypeChangingEffect().setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
game.addEffect(new GainAbilityTargetEffect(new DecayedAbility(), Duration.Custom).setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
return true;
}
}
}
return false;
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class GruesomeEncoreReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
return true;
}
return false;
}
Aggregations