use of mage.abilities.Ability in project mage by magefree.
the class MindleecherLookEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
game.getOpponents(controller.getId()).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
if (cards.isEmpty()) {
return false;
}
controller.moveCards(cards, Zone.EXILED, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
if (cards.isEmpty()) {
return false;
}
cards.getCards(game).stream().forEach(card -> card.setFaceDown(true, game));
for (Card card : cards.getCards(game)) {
game.addEffect(new MindleecherCastFromExileEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
game.addEffect(new MindleecherLookEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
}
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class PakoArcaneRetrieverWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
PakoArcaneRetrieverWatcher watcher = game.getState().getWatcher(PakoArcaneRetrieverWatcher.class);
if (controller == null || watcher == null) {
return false;
}
Cards cards = new CardsImpl();
game.getState().getPlayersInRange(controller.getId(), game).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
controller.moveCards(cards, Zone.EXILED, source, game);
cards.removeIf(cardId -> game.getState().getZone(cardId) != Zone.EXILED);
int counters = cards.count(StaticFilters.FILTER_CARD_NON_CREATURE, game);
if (cards.isEmpty()) {
return true;
}
cards.getCards(game).stream().filter(card -> card.addCounters(CounterType.FETCH.createInstance(), source.getControllerId(), source, game)).filter(card -> !card.isCreature(game)).forEach(card -> watcher.addCard(controller.getId(), card, game));
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null || counters == 0) {
return true;
}
return permanent.addCounters(CounterType.P1P1.createInstance(counters), source.getControllerId(), source, game);
}
use of mage.abilities.Ability in project mage by magefree.
the class QuickSilverElementalBlueManaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
Permanent creature = game.getPermanent(source.getTargets().getFirstTarget());
if (permanent != null && creature != null) {
for (ActivatedAbility ability : creature.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
Ability newAbility = ability.copy();
newAbility.newOriginalId();
game.addEffect(new GainAbilitySourceEffect(newAbility, Duration.EndOfTurn), source);
}
return true;
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class RetetherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<Card, Permanent> auraMap = new HashMap<>();
auraCardsInGraveyard: for (Card aura : controller.getGraveyard().getCards(filterAura, source.getSourceId(), source.getControllerId(), game)) {
if (aura != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature to enchant (" + aura.getLogName() + ')');
filter.add(new CanBeEnchantedByPredicate(aura));
Target target = null;
auraLegalitySearch: for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
if (permanent != null) {
for (Ability ability : aura.getAbilities()) {
if (ability instanceof SpellAbility) {
for (Target abilityTarget : ability.getTargets()) {
if (abilityTarget.possibleTargets(controller.getId(), game).contains(permanent.getId())) {
target = abilityTarget.copy();
break auraLegalitySearch;
}
}
}
}
}
}
}
if (target != null) {
target.getFilter().add(CardType.CREATURE.getPredicate());
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
target.setTargetName("creature to enchant (" + aura.getLogName() + ')');
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, true)) {
auraMap.put(aura, permanent);
game.getState().setValue("attachTo:" + aura.getId(), permanent);
continue auraCardsInGraveyard;
}
}
}
}
game.informPlayers("No valid creature targets for " + aura.getLogName());
}
}
controller.moveCards(auraMap.keySet(), Zone.BATTLEFIELD, source, game);
for (Entry<Card, Permanent> entry : auraMap.entrySet()) {
Card aura = entry.getKey();
Permanent permanent = entry.getValue();
if (aura != null && permanent != null) {
permanent.addAttachment(aura.getId(), source, game);
}
}
return true;
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class SerpentsSoulJarWatcher method addPlayable.
static void addPlayable(Ability source, Game game) {
MageObjectReference mor = new MageObjectReference(source);
game.getState().getWatcher(SerpentsSoulJarWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
Aggregations