Search in sources :

Example 81 with Player

use of mage.players.Player in project mage by magefree.

the class FrightfulDelusionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    Cost cost = ManaUtil.createManaCost(1, false);
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        if (player != null) {
            cost.clearPaid();
            game.getPlayer(spell.getControllerId()).discard(1, false, false, source, game);
            if (!cost.pay(source, game, source, spell.getControllerId(), false, null)) {
                return game.getStack().counter(source.getFirstTarget(), source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) Cost(mage.abilities.costs.Cost)

Example 82 with Player

use of mage.players.Player 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 83 with Player

use of mage.players.Player 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 84 with Player

use of mage.players.Player 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)

Example 85 with Player

use of mage.players.Player in project mage by magefree.

the class FreeRangeChickenWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Integer> results = controller.rollDice(outcome, source, game, 6, 2, 0);
        int firstRoll = results.get(0);
        int secondRoll = results.get(1);
        if (firstRoll == secondRoll) {
            game.addEffect(new BoostSourceEffect(firstRoll, firstRoll, Duration.EndOfTurn), source);
        }
        FreeRangeChickenWatcher watcher = game.getState().getWatcher(FreeRangeChickenWatcher.class);
        if (watcher != null) {
            int totalRoll = firstRoll + secondRoll;
            Permanent sourcePermanent = game.getPermanent(source.getSourceId());
            if (sourcePermanent != null) {
                if (watcher.rolledThisTurn(sourcePermanent.getId(), totalRoll)) {
                    sourcePermanent.sacrifice(source, game);
                } else {
                    watcher.addRoll(sourcePermanent.getId(), totalRoll);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Aggregations

Player (mage.players.Player)3909 Permanent (mage.game.permanent.Permanent)1705 Card (mage.cards.Card)1099 UUID (java.util.UUID)962 MageObject (mage.MageObject)556 FilterCard (mage.filter.FilterCard)515 CardsImpl (mage.cards.CardsImpl)498 FixedTarget (mage.target.targetpointer.FixedTarget)387 TargetPermanent (mage.target.TargetPermanent)353 Cards (mage.cards.Cards)345 TargetCard (mage.target.TargetCard)328 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)317 TargetPlayer (mage.target.TargetPlayer)312 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)301 FilterPermanent (mage.filter.FilterPermanent)292 Target (mage.target.Target)289 OneShotEffect (mage.abilities.effects.OneShotEffect)230 ContinuousEffect (mage.abilities.effects.ContinuousEffect)227 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)207 Effect (mage.abilities.effects.Effect)170