Search in sources :

Example 31 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class HeavenlyBlademasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (sourcePermanent == null || player == null) {
        return false;
    }
    Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    target.getTargets().stream().map(attachmentId -> game.getPermanent(attachmentId)).filter(attachment -> attachment != null).forEachOrdered((attachment) -> {
        if (!sourcePermanent.cantBeAttachedBy(attachment, source, game, true)) {
            if (attachment.getAttachedTo() != sourcePermanent.getId()) {
                if (attachment.getAttachedTo() != null) {
                    Permanent fromPermanent = game.getPermanent(attachment.getAttachedTo());
                    if (fromPermanent != null) {
                        fromPermanent.removeAttachment(attachment.getId(), source, game);
                    }
                }
            }
            sourcePermanent.addAttachment(attachment.getId(), source, game);
            game.informPlayers(attachment.getLogName() + " was attached to " + sourcePermanent.getLogName());
        }
    });
    return true;
}
Also used : Target(mage.target.Target) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) AuraAttachedCount(mage.abilities.dynamicvalue.common.AuraAttachedCount) Predicates(mage.filter.predicate.Predicates) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) DynamicValue(mage.abilities.dynamicvalue.DynamicValue) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) StaticFilters(mage.filter.StaticFilters) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) DoubleStrikeAbility(mage.abilities.keyword.DoubleStrikeAbility) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect) AdditiveDynamicValue(mage.abilities.dynamicvalue.AdditiveDynamicValue) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) EquipmentAttachedCount(mage.abilities.dynamicvalue.common.EquipmentAttachedCount) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 32 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class MetamorphicAlterationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent enchantment = game.getPermanent(source.getSourceId());
    Permanent copied = (Permanent) game.getState().getValue(source.getSourceId().toString() + ChooseACreature.INFO_KEY);
    if (enchantment == null || copied == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
    if (permanent == null) {
        return false;
    }
    permanent.setName(copied.getName());
    permanent.getManaCost().clear();
    permanent.getManaCost().addAll(copied.getManaCost());
    permanent.setExpansionSetCode(copied.getExpansionSetCode());
    permanent.getSuperType().clear();
    for (SuperType t : copied.getSuperType()) {
        permanent.addSuperType(t);
    }
    permanent.removeAllCardTypes(game);
    for (CardType cardType : copied.getCardType(game)) {
        permanent.addCardType(game, cardType);
    }
    permanent.removeAllSubTypes(game);
    permanent.copySubTypesFrom(game, copied);
    permanent.getColor(game).setColor(copied.getColor(game));
    permanent.removeAllAbilities(source.getSourceId(), game);
    for (Ability ability : copied.getAbilities()) {
        permanent.addAbility(ability, source.getSourceId(), game);
    }
    permanent.getPower().setValue(copied.getPower().getBaseValueModified());
    permanent.getToughness().setValue(copied.getToughness().getBaseValueModified());
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) AsEntersBattlefieldAbility(mage.abilities.common.AsEntersBattlefieldAbility) EnchantAbility(mage.abilities.keyword.EnchantAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 33 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class PatchworkCrawlerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
    if (permanent == null || exileZone == null || exileZone.isEmpty()) {
        return false;
    }
    for (Card card : exileZone.getCards(StaticFilters.FILTER_CARD_CREATURE, game)) {
        for (Ability ability : card.getAbilities(game)) {
            if (ability instanceof ActivatedAbility) {
                permanent.addAbility(ability, source.getSourceId(), game);
            }
        }
    }
    return true;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ActivatedAbility(mage.abilities.ActivatedAbility) ExileZone(mage.game.ExileZone) Card(mage.cards.Card)

Example 34 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class PastInFlamesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.getGraveyard().stream().filter((cardId) -> (affectedObjectList.contains(new MageObjectReference(cardId, game)))).forEachOrdered((cardId) -> {
        Card card = game.getCard(cardId);
        if (card != null) {
            FlashbackAbility ability = new FlashbackAbility(card, card.getManaCost());
            ability.setSourceId(cardId);
            ability.setControllerId(card.getOwnerId());
            game.getState().addOtherAbility(card, ability);
        }
    });
    return true;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) FlashbackAbility(mage.abilities.keyword.FlashbackAbility) MageObjectReference(mage.MageObjectReference) UUID(java.util.UUID) Card(mage.cards.Card) mage.constants(mage.constants) Player(mage.players.Player) Ability(mage.abilities.Ability) FlashbackAbility(mage.abilities.keyword.FlashbackAbility) Player(mage.players.Player) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 35 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class PrimalEmpathyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int highestPower = game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(0);
    boolean flag = game.getBattlefield().getAllActivePermanents(source.getControllerId()).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).anyMatch(i -> i >= highestPower);
    if (flag) {
        return player.drawCards(1, source, game) > 0;
    }
    Target target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
Also used : Target(mage.target.Target) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) TargetController(mage.constants.TargetController) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MageInt(mage.MageInt) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

Ability (mage.abilities.Ability)359 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)134 UUID (java.util.UUID)126 Game (mage.game.Game)123 OneShotEffect (mage.abilities.effects.OneShotEffect)98 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)87 CardSetInfo (mage.cards.CardSetInfo)87 CardImpl (mage.cards.CardImpl)85 CardType (mage.constants.CardType)78 Outcome (mage.constants.Outcome)76 Card (mage.cards.Card)72 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)64 MageObject (mage.MageObject)57 MageInt (mage.MageInt)47 SpellAbility (mage.abilities.SpellAbility)43 Objects (java.util.Objects)38 Zone (mage.constants.Zone)38 mage.constants (mage.constants)37 FilterCard (mage.filter.FilterCard)35