Search in sources :

Example 56 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FroghemothEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<Card> cardsToExile = new HashSet<>();
    int numCounters = 0;
    int lifeGain = 0;
    for (UUID cardId : getTargetPointer().getTargets(game, source)) {
        Card card = game.getCard(cardId);
        if (card != null && game.getState().getZone(cardId) == Zone.GRAVEYARD && cardsToExile.add(card)) {
            if (card.isCreature(game)) {
                numCounters++;
            } else {
                lifeGain++;
            }
        }
    }
    if (!cardsToExile.isEmpty()) {
        controller.moveCards(cardsToExile, Zone.EXILED, source, game);
        if (numCounters > 0) {
            Permanent permanent = source.getSourcePermanentIfItStillExists(game);
            if (permanent != null) {
                permanent.addCounters(CounterType.P1P1.createInstance(numCounters), source.getControllerId(), source, game);
            }
        }
        if (lifeGain > 0) {
            controller.gainLife(lifeGain, game, source);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 57 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FrontierSiegeFightEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent triggeredCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    Permanent target = game.getPermanent(source.getFirstTarget());
    if (triggeredCreature != null && target != null && triggeredCreature.isCreature(game) && target.isCreature(game)) {
        triggeredCreature.fight(target, source, game);
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 58 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FrontierWarmongerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Set<UUID> opponents = game.getOpponents(this.getControllerId());
    Predicate<UUID> predicate = uuid -> opponents.contains(game.getCombat().getDefendingPlayerId(uuid, game));
    if (game.getCombat().getAttackers().stream().noneMatch(predicate)) {
        return false;
    }
    List<Permanent> permanents = game.getCombat().getAttackers().stream().filter(predicate).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
    this.getEffects().setTargetPointer(new FixedTargets(permanents, game));
    return true;
}
Also used : Zone(mage.constants.Zone) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) List(java.util.List) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FixedTargets(mage.target.targetpointer.FixedTargets) MenaceAbility(mage.abilities.keyword.MenaceAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) UUID(java.util.UUID)

Example 59 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FrayingSanityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // In the case that the enchantment is blinked
    Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (enchantment == null) {
        // It was not blinked, use the standard method
        enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
    }
    if (enchantment == null) {
        return false;
    }
    Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
    if (enchantedPlayer != null) {
        CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
        if (watcher != null) {
            xAmount = watcher.getAmountCardsPutToGraveyard(enchantedPlayer.getId());
        }
        enchantedPlayer.millCards(xAmount, source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) CardsPutIntoGraveyardWatcher(mage.watchers.common.CardsPutIntoGraveyardWatcher)

Example 60 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class FreneticEfreetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    boolean flip = controller.flipCoin(source, game, true);
    if (permanent == null) {
        return false;
    }
    if (flip) {
        return permanent.phaseOut(game);
    } else {
        permanent.sacrifice(source, game);
        return true;
    }
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Aggregations

Permanent (mage.game.permanent.Permanent)3269 Player (mage.players.Player)1706 UUID (java.util.UUID)665 TargetPermanent (mage.target.TargetPermanent)571 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)541 FixedTarget (mage.target.targetpointer.FixedTarget)496 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)467 FilterPermanent (mage.filter.FilterPermanent)466 Card (mage.cards.Card)425 MageObject (mage.MageObject)246 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)226 Target (mage.target.Target)225 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)217 ContinuousEffect (mage.abilities.effects.ContinuousEffect)207 Effect (mage.abilities.effects.Effect)183 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)179 Test (org.junit.Test)179 OneShotEffect (mage.abilities.effects.OneShotEffect)175 FilterCard (mage.filter.FilterCard)158 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)153