Search in sources :

Example 81 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class ArmedAndArmoredEquipEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterControlledPermanent dwarfFilter = new FilterControlledPermanent(SubType.DWARF);
    List<Permanent> dwarves = game.getBattlefield().getAllActivePermanents(dwarfFilter, controller.getId(), game);
    FilterControlledPermanent equipmentFilter = new FilterControlledPermanent(SubType.EQUIPMENT);
    List<Permanent> equipment = game.getBattlefield().getAllActivePermanents(equipmentFilter, controller.getId(), game);
    if (!dwarves.isEmpty() && !equipment.isEmpty()) {
        TargetPermanent target = new TargetPermanent(0, 1, dwarfFilter, true);
        target.withChooseHint("dwarf to be equipped");
        controller.choose(outcome, target, source.getId(), game);
        Permanent dwarf = game.getPermanent(target.getFirstTarget());
        if (dwarf != null) {
            target = new TargetPermanent(0, Integer.MAX_VALUE, equipmentFilter, true);
            target.withChooseHint("equip to " + dwarf.getLogName());
            controller.choose(outcome, target, source.getId(), game);
            for (UUID targetId : target.getTargets()) {
                dwarf.addAttachment(targetId, source, game);
                game.informPlayers(game.getPermanent(targetId).getLogName() + " was attached to " + dwarf.getLogName());
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

Example 82 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class ArmoredSkyhunterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
    TargetCardInLibrary targetCard = new TargetCardInLibrary(0, 1, filter);
    player.choose(outcome, cards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.LIBRARY);
    Permanent equipment = game.getPermanent(card.getId());
    if (equipment == null || !equipment.hasSubtype(SubType.EQUIPMENT, game)) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    TargetPermanent targetPermanent = new TargetControlledCreaturePermanent(0, 1);
    targetCard.setNotTarget(true);
    player.choose(outcome, targetPermanent, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
    if (permanent != null) {
        permanent.addAttachment(equipment.getId(), source, game);
    }
    return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 83 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class ConfiscationCoupEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        new GetEnergyCountersControllerEffect(4).apply(game, source);
        Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (targetPermanent != null) {
            Cost cost = new PayEnergyCost(targetPermanent.getManaCost().manaValue());
            if (cost.canPay(source, source, source.getControllerId(), game)) {
                int manaValue = targetPermanent.getManaCost().manaValue();
                StringBuilder energy = new StringBuilder(manaValue);
                for (int i = 0; i < manaValue; i++) {
                    energy.append("{E}");
                }
                if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) {
                    if (cost.pay(source, game, source, source.getControllerId(), true)) {
                        ContinuousEffect controllEffect = new GainControlTargetEffect(Duration.Custom);
                        controllEffect.setTargetPointer(new FixedTarget(targetPermanent, game));
                        game.addEffect(controllEffect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) GetEnergyCountersControllerEffect(mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 84 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class DeadlyBrewEffect 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<>();
    Permanent yours = null;
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (!target.canChoose(source.getSourceId(), playerId, game)) {
            continue;
        }
        player.choose(outcome, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent == null) {
            continue;
        }
        if (permanent.isControlledBy(source.getControllerId())) {
            yours = permanent;
        } else {
            toSacrifice.add(permanent);
        }
    }
    for (Permanent permanent : toSacrifice) {
        if (permanent == null) {
            continue;
        }
        permanent.sacrifice(source, game);
    }
    Cards yourGrave = new CardsImpl(controller.getGraveyard());
    yourGrave.removeIf(uuid -> !game.getCard(uuid).isPermanent(game));
    if (yours == null || !yours.sacrifice(source, game)) {
        return true;
    }
    TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(0, 1, StaticFilters.FILTER_CARD_PERMANENT, true);
    controller.choose(outcome, yourGrave, target, game);
    Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
    if (card != null) {
        controller.moveCards(card, Zone.HAND, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterCreatureOrPlaneswalkerPermanent(mage.filter.common.FilterCreatureOrPlaneswalkerPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID)

Example 85 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class DropOfHoneyStateTriggeredAbility 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) {
        int leastPower = Integer.MAX_VALUE;
        boolean multipleExist = false;
        Permanent permanentToDestroy = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
            if (permanent.getPower().getValue() < leastPower) {
                permanentToDestroy = permanent;
                leastPower = permanent.getPower().getValue();
                multipleExist = false;
            } else {
                if (permanent.getPower().getValue() == leastPower) {
                    multipleExist = true;
                }
            }
        }
        if (multipleExist) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least power");
            filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, leastPower));
            Target target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                if (controller.choose(outcome, target, source.getSourceId(), game)) {
                    permanentToDestroy = game.getPermanent(target.getFirstTarget());
                }
            }
        }
        if (permanentToDestroy != null) {
            game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDestroy.getName());
            return permanentToDestroy.destroy(source, game, true);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) TargetPermanent(mage.target.TargetPermanent)

Aggregations

TargetPermanent (mage.target.TargetPermanent)222 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)167 FilterPermanent (mage.filter.FilterPermanent)108 UUID (java.util.UUID)65 Target (mage.target.Target)58 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)47 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)36 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)32 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)24 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)19 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)19 FixedTarget (mage.target.targetpointer.FixedTarget)19 MageObject (mage.MageObject)18 Ability (mage.abilities.Ability)18 Card (mage.cards.Card)17 ArrayList (java.util.ArrayList)15 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)14 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13