Search in sources :

Example 31 with Player

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

the class CharmingPrinceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    if (!controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourceObject.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
        return false;
    }
    // create delayed triggered ability
    Effect effect = new ReturnToBattlefieldUnderYourControlTargetEffect();
    effect.setText("Return it to the battlefield under your control at the beginning of the next end step");
    effect.setTargetPointer(new FixedTarget(permanent.getId(), game));
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) ReturnToBattlefieldUnderYourControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ReturnToBattlefieldUnderYourControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlTargetEffect) ScryEffect(mage.abilities.effects.keyword.ScryEffect) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect) Effect(mage.abilities.effects.Effect)

Example 32 with Player

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

the class ChargingCinderhornDamageTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent chargingCinderhoof = game.getPermanent(source.getSourceId());
    if (chargingCinderhoof != null) {
        chargingCinderhoof.addCounters(CounterType.FURY.createInstance(), source.getControllerId(), source, game);
    } else {
        chargingCinderhoof = game.getPermanentOrLKIBattlefield(source.getSourceId());
    }
    if (chargingCinderhoof == null) {
        return false;
    }
    DynamicValue amount = new CountersSourceCount(CounterType.FURY);
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player != null) {
        player.damage(amount.calculate(game, source, this), source.getSourceId(), source, game);
        return true;
    }
    return false;
}
Also used : CountersSourceCount(mage.abilities.dynamicvalue.common.CountersSourceCount) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) DynamicValue(mage.abilities.dynamicvalue.DynamicValue)

Example 33 with Player

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

the class ChaoticBacklashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null) {
        int amount = 2 * game.getBattlefield().countAll(filter, targetPlayer.getId(), game);
        targetPlayer.damage(amount, source.getSourceId(), source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player)

Example 34 with Player

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

the class CracklingDoomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> toSacrifice = new ArrayList<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (controller.hasOpponent(playerId, game)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null) {
                    int greatestPower = Integer.MIN_VALUE;
                    int numberOfCreatures = 0;
                    Permanent permanentToSacrifice = null;
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                        if (permanent.getPower().getValue() > greatestPower) {
                            greatestPower = permanent.getPower().getValue();
                            numberOfCreatures = 1;
                            permanentToSacrifice = permanent;
                        } else if (permanent.getPower().getValue() == greatestPower) {
                            numberOfCreatures++;
                        }
                    }
                    if (numberOfCreatures == 1) {
                        if (permanentToSacrifice != null) {
                            toSacrifice.add(permanentToSacrifice);
                        }
                    } else if (greatestPower != Integer.MIN_VALUE) {
                        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
                        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
                        Target target = new TargetControlledCreaturePermanent(filter);
                        if (opponent.choose(outcome, target, playerId, game)) {
                            Permanent permanent = game.getPermanent(target.getFirstTarget());
                            if (permanent != null) {
                                toSacrifice.add(permanent);
                            }
                        }
                    }
                }
            }
        }
        for (Permanent permanent : toSacrifice) {
            permanent.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 35 with Player

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

the class CouncilsJudgmentVote method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    CouncilsJudgmentVote vote = new CouncilsJudgmentVote(player);
    vote.doVotes(source, game);
    Cards cards = new CardsImpl();
    vote.getMostVoted().stream().forEach(cards::add);
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

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