use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class WakeToSlaughterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards pickedCards = new CardsImpl(getTargetPointer().getTargets(game, source));
if (player != null && !pickedCards.isEmpty()) {
Card cardToHand;
if (pickedCards.size() == 1) {
cardToHand = pickedCards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(player.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target targetOpponent = new TargetOpponent(true);
player.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
opponent = game.getPlayer(targetOpponent.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.GRAVEYARD, new FilterCard());
target.withChooseHint("Card to go to opponent's hand (other goes to battlefield)");
opponent.chooseTarget(outcome, pickedCards, target, source, game);
cardToHand = game.getCard(target.getFirstTarget());
}
for (Card card : pickedCards.getCards(game)) {
if (card == cardToHand) {
player.moveCards(cardToHand, Zone.HAND, source, game);
} else {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
FixedTarget fixedTarget = new FixedTarget(card, game);
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfGame);
effect.setTargetPointer(fixedTarget);
game.addEffect(effect, source);
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(fixedTarget);
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
pickedCards.clear();
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class WakeThePastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getGraveyard().getCards(StaticFilters.FILTER_CARD_ARTIFACT, game));
if (cards.isEmpty()) {
return false;
}
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.BATTLEFIELD);
if (cards.isEmpty()) {
return true;
}
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(new FixedTargets(cards, game)), source);
return true;
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class InfoEffect method addCardHintToPermanent.
/**
* Add temporary card hint to permanent (visible in rules list)
*
* @param game
* @param source
* @param permanent
* @param cardHint
* @param duration
*/
public static void addCardHintToPermanent(Game game, Ability source, Permanent permanent, Hint cardHint, Duration duration) {
SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect("hint"));
ability.setRuleVisible(false);
ability.addHint(cardHint);
GainAbilityTargetEffect gainEffect = new GainAbilityTargetEffect(ability, duration);
gainEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(gainEffect, source);
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class EncoreSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
Set<MageObjectReference> addedTokens = new HashSet<>();
int opponentCount = OpponentsCount.instance.calculate(game, source, this);
if (opponentCount < 1) {
return false;
}
token.putOntoBattlefield(opponentCount, game, source, source.getControllerId());
Iterator<UUID> it = token.getLastAddedTokenIds().iterator();
while (it.hasNext()) {
for (UUID playerId : game.getOpponents(source.getControllerId())) {
if (game.getPlayer(playerId) == null) {
continue;
}
UUID tokenId = it.next();
MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game);
game.addEffect(new EncoreRequirementEffect(mageObjectReference, playerId), source);
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom).setTargetPointer(new FixedTarget(mageObjectReference)), source);
addedTokens.add(mageObjectReference);
}
}
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new EncoreSacrificeEffect(addedTokens)), source);
return true;
}
use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.
the class CantStayAwayReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card targetCard = game.getCard(source.getFirstTarget());
if (controller == null || targetCard == null || game.getState().getZone(targetCard.getId()) != Zone.GRAVEYARD) {
return false;
}
controller.moveCards(targetCard, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(targetCard.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(new SimpleStaticAbility(new CantStayAwayReplacementEffect()), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
return true;
}
Aggregations