Search in sources :

Example 41 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class ShadowgrangeArchfiendEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Permanent> toSacrifice = new ArrayList<>();
    // Iterate through each opponent
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        if (!controller.hasOpponent(playerId, game)) {
            continue;
        }
        Player opponent = game.getPlayer(playerId);
        if (opponent == null) {
            continue;
        }
        int greatestPower = Integer.MIN_VALUE;
        int numberOfCreatures = 0;
        Permanent creatureToSacrifice = null;
        // Iterature through each creature
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
            if (permanent.getPower().getValue() > greatestPower) {
                greatestPower = permanent.getPower().getValue();
                numberOfCreatures = 1;
                creatureToSacrifice = permanent;
            } else if (permanent.getPower().getValue() == greatestPower) {
                numberOfCreatures++;
            }
        }
        // If multiple creatures are tied for having the greatest power
        if (numberOfCreatures > 1) {
            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)) {
                creatureToSacrifice = game.getPermanent(target.getFirstTarget());
            }
        }
        if (creatureToSacrifice != null) {
            toSacrifice.add(creatureToSacrifice);
        }
    }
    int greatestPowerAmongAllCreaturesSacked = Integer.MIN_VALUE;
    int powerOfCurrentCreature;
    // Sack the creatures and save the greaterest power amoung those which were sacked
    for (Permanent permanent : toSacrifice) {
        powerOfCurrentCreature = permanent.getPower().getValue();
        // Try to sack it
        if (permanent.sacrifice(source, game)) {
            if (powerOfCurrentCreature > greatestPowerAmongAllCreaturesSacked) {
                greatestPowerAmongAllCreaturesSacked = powerOfCurrentCreature;
            }
        }
    }
    // Gain life equal to the power of greatest creature sacked, if it is positive
    if (greatestPowerAmongAllCreaturesSacked > 0) {
        new GainLifeEffect(greatestPowerAmongAllCreaturesSacked).apply(game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) 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) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect)

Example 42 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class SunkenHopeReturnToHandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
        while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.chooseTarget(Outcome.ReturnToHand, target, source, game);
        }
        for (UUID targetId : target.getTargets()) {
            Permanent permanent = game.getPermanent(targetId);
            if (permanent != null) {
                result |= player.moveCards(permanent, Zone.HAND, source, game);
            }
        }
    }
    return result;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID)

Example 43 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class VampirismBoostEnchantedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    int count = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) - 1;
    if (count > 0) {
        Permanent enchantment = game.getPermanent(source.getSourceId());
        if (enchantment != null && enchantment.getAttachedTo() != null) {
            Permanent creature = game.getPermanent(enchantment.getAttachedTo());
            if (creature != null) {
                creature.addPower(count);
                creature.addToughness(count);
                return true;
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 44 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class EmergeAbility method getMinimumCostToActivate.

@Override
public ManaOptions getMinimumCostToActivate(UUID playerId, Game game) {
    int maxCMC = 0;
    for (Permanent creature : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), playerId, this.getSourceId(), game)) {
        int cmc = creature.getManaValue();
        if (cmc > maxCMC) {
            maxCMC = cmc;
        }
    }
    ManaOptions manaOptions = super.getMinimumCostToActivate(playerId, game);
    for (Mana mana : manaOptions) {
        if (mana.getGeneric() > maxCMC) {
            mana.setGeneric(mana.getGeneric() - maxCMC);
        } else {
            mana.setGeneric(0);
        }
    }
    return manaOptions;
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) Mana(mage.Mana) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 45 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class ConvokeEffect method getManaOptions.

@Override
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
    ManaOptions options = new ManaOptions();
    FilterControlledCreaturePermanent filterBasic = new FilterControlledCreaturePermanent();
    // each creature can give {1} or color mana
    game.getBattlefield().getActivePermanents(filterBasic, source.getControllerId(), source.getSourceId(), game).stream().filter(permanent -> !permanent.isTapped()).forEach(permanent -> {
        ManaOptions permMana = new ManaOptions();
        permMana.add(Mana.GenericMana(1));
        for (ObjectColor color : permanent.getColor(game).getColors()) {
            if (color.isBlack())
                permMana.add(Mana.BlackMana(1));
            if (color.isBlue())
                permMana.add(Mana.BlueMana(1));
            if (color.isGreen())
                permMana.add(Mana.GreenMana(1));
            if (color.isRed())
                permMana.add(Mana.RedMana(1));
            if (color.isWhite())
                permMana.add(Mana.WhiteMana(1));
        }
        options.addMana(permMana);
    });
    options.removeDuplicated();
    return options;
}
Also used : Target(mage.target.Target) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Zone(mage.constants.Zone) SpecialAction(mage.abilities.SpecialAction) TappedPredicate(mage.filter.predicate.permanent.TappedPredicate) Predicates(mage.filter.predicate.Predicates) Player(mage.players.Player) ArrayList(java.util.ArrayList) ManaOptions(mage.abilities.mana.ManaOptions) ValueHint(mage.abilities.hint.ValueHint) AbilityType(mage.constants.AbilityType) ManaPool(mage.players.ManaPool) ManaCost(mage.abilities.costs.mana.ManaCost) Locale(java.util.Locale) ManaType(mage.constants.ManaType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Spell(mage.game.stack.Spell) ObjectColor(mage.ObjectColor) ChoiceColor(mage.choices.ChoiceColor) Choice(mage.choices.Choice) ActivationManaAbilityStep(mage.abilities.costs.mana.ActivationManaAbilityStep) AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Game(mage.game.Game) List(java.util.List) GameEvent(mage.game.events.GameEvent) Permanent(mage.game.permanent.Permanent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Mana(mage.Mana) Ability(mage.abilities.Ability) ManaOptions(mage.abilities.mana.ManaOptions) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ObjectColor(mage.ObjectColor)

Aggregations

FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)75 Permanent (mage.game.permanent.Permanent)62 Player (mage.players.Player)60 UUID (java.util.UUID)29 Target (mage.target.Target)27 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)21 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)16 ArrayList (java.util.ArrayList)13 Card (mage.cards.Card)11 TargetPermanent (mage.target.TargetPermanent)11 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 FixedTarget (mage.target.targetpointer.FixedTarget)9 MageObject (mage.MageObject)7 OneShotEffect (mage.abilities.effects.OneShotEffect)7 Effect (mage.abilities.effects.Effect)6 Ability (mage.abilities.Ability)5 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)5 FilterPermanent (mage.filter.FilterPermanent)5 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)5 Spell (mage.game.stack.Spell)5