Search in sources :

Example 31 with Permanent

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

the class ChimericCoilsEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    switch(layer) {
        case TypeChangingEffects_4:
            if (!permanent.isArtifact(game)) {
                permanent.addCardType(game, CardType.ARTIFACT);
            }
            if (!permanent.isCreature(game)) {
                permanent.addCardType(game, CardType.CREATURE);
            }
            permanent.removeAllCreatureTypes(game);
            permanent.addSubType(game, SubType.CONSTRUCT);
            break;
        case PTChangingEffects_7:
            if (sublayer == SubLayer.SetPT_7b) {
                int xValue = source.getManaCostsToPay().getX();
                permanent.getPower().setValue(xValue);
                permanent.getToughness().setValue(xValue);
            }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent)

Example 32 with Permanent

use of mage.game.permanent.Permanent 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 33 with Permanent

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

the class CradleOfVitalityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    int lifeGained = 0;
    if (this.getValue("gainedLife") != null) {
        lifeGained = (Integer) this.getValue("gainedLife");
    }
    return permanent != null && lifeGained > 0 && permanent.addCounters(CounterType.P1P1.createInstance(lifeGained), source.getControllerId(), source, game);
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 34 with Permanent

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

the class CounterbalanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
        if (spell != null) {
            Card topcard = controller.getLibrary().getFromTop(game);
            if (topcard != null) {
                CardsImpl cards = new CardsImpl();
                cards.add(topcard);
                controller.revealCards(sourcePermanent.getName(), cards, game);
                if (topcard.getManaValue() == spell.getManaValue()) {
                    return game.getStack().counter(spell.getId(), source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Spell(mage.game.stack.Spell) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 35 with Permanent

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

the class CosmicHorrorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent cosmicHorror = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && cosmicHorror != null) {
        StringBuilder sb = new StringBuilder(cost.getText()).append('?');
        if (!sb.toString().toLowerCase(Locale.ENGLISH).startsWith("exile ") && !sb.toString().toLowerCase(Locale.ENGLISH).startsWith("return ")) {
            sb.insert(0, "Pay ");
        }
        if (controller.chooseUse(Outcome.Benefit, sb.toString(), source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                return true;
            }
        }
        if (cosmicHorror.destroy(source, game, false)) {
            controller.damage(7, source.getSourceId(), source, game);
            return true;
        }
    }
    return false;
}
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