Search in sources :

Example 11 with TargetPermanent

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

the class ResoluteStrikeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (player == null || permanent == null || !permanent.hasSubtype(SubType.WARRIOR, game) || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0 || !player.chooseUse(outcome, "Attach an equipment you control?", source, game)) {
        return false;
    }
    TargetPermanent targetPermanent = new TargetPermanent(0, 1, filter, true);
    player.choose(outcome, targetPermanent, source.getSourceId(), game);
    return permanent.addAttachment(targetPermanent.getFirstTarget(), source, game);
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 12 with TargetPermanent

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

the class SabaccGameEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        if (targetPermanent != null) {
            Player opponent = game.getPlayer(targetPermanent.getControllerId());
            if (opponent != null) {
                FilterPermanent filter = new FilterPermanent("permanent controlled by " + controller.getName());
                filter.add(new ControllerIdPredicate(controller.getId()));
                TargetPermanent target = new TargetPermanent(1, 1, filter, true);
                Permanent chosenPermanent = null;
                if (target.chooseTarget(outcome, opponent.getId(), source, game)) {
                    chosenPermanent = game.getPermanent(target.getFirstTarget());
                }
                boolean flipWin = controller.flipCoin(source, game, true);
                if (flipWin) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, controller.getId());
                    effect.setTargetPointer(new FixedTarget(targetPermanent, game));
                    game.addEffect(effect, source);
                } else if (chosenPermanent != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
                    effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
                    game.addEffect(effect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 13 with TargetPermanent

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

the class RustmouthOgreTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
    if (damageEvent.isCombatDamage() && event.getSourceId().equals(this.getSourceId())) {
        FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact that player controls");
        filter.add(new ControllerIdPredicate(event.getPlayerId()));
        filter.setMessage("artifact controlled by " + game.getPlayer(event.getTargetId()).getLogName());
        this.getTargets().clear();
        this.addTarget(new TargetPermanent(filter));
        return true;
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) TargetPermanent(mage.target.TargetPermanent)

Example 14 with TargetPermanent

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

the class SigardasVanguardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetCreaturesWithDifferentPowers();
    player.choose(outcome, target, source.getSourceId(), game);
    if (target.getTargets().isEmpty()) {
        return false;
    }
    game.addEffect(new GainAbilityTargetEffect(DoubleStrikeAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(new FixedTargets(new CardsImpl(target.getTargets()), game)), source);
    return true;
}
Also used : Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetPermanent(mage.target.TargetPermanent) TargetCreaturesWithDifferentPowers(mage.target.common.TargetCreaturesWithDifferentPowers) CardsImpl(mage.cards.CardsImpl)

Example 15 with TargetPermanent

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

the class SlaughterTheStrongEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                boolean selectionDone = false;
                Set<UUID> selectedCreatures = new HashSet<>();
                while (player.canRespond() && selectionDone == false) {
                    int powerSum = 0;
                    for (UUID creatureId : selectedCreatures) {
                        Permanent creature = game.getPermanent(creatureId);
                        if (creature != null) {
                            powerSum += creature.getPower().getValue();
                        }
                    }
                    FilterControlledCreaturePermanent currentFilter = new FilterControlledCreaturePermanent("any number of creatures you control with total power 4 or less (already selected total power " + powerSum + ")");
                    Set<PermanentIdPredicate> alreadySelectedCreatures = new HashSet<>();
                    if (!selectedCreatures.isEmpty()) {
                        for (UUID creatureId : selectedCreatures) {
                            alreadySelectedCreatures.add(new PermanentIdPredicate(creatureId));
                        }
                        currentFilter.add(Predicates.or(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum), Predicates.or(alreadySelectedCreatures)));
                    } else {
                        currentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum));
                    }
                    // human can de-select targets, but AI must choose only one time
                    Target target;
                    if (player.isComputer()) {
                        // AI settings
                        FilterControlledCreaturePermanent strictFilter = currentFilter.copy();
                        selectedCreatures.stream().forEach(id -> {
                            strictFilter.add(Predicates.not(new PermanentIdPredicate(id)));
                        });
                        target = new TargetPermanent(0, 1, strictFilter, true);
                    } else {
                        // Human settings
                        target = new TargetPermanent(0, 1, currentFilter, true);
                    }
                    player.chooseTarget(Outcome.BoostCreature, target, source, game);
                    if (target.getFirstTarget() != null) {
                        if (selectedCreatures.contains(target.getFirstTarget())) {
                            selectedCreatures.remove(target.getFirstTarget());
                        } else {
                            selectedCreatures.add(target.getFirstTarget());
                        }
                    } else {
                        if (player.isComputer()) {
                            // AI stops
                            selectionDone = true;
                        } else {
                            // Human can continue
                            String selected = "Selected: ";
                            for (UUID creatureId : selectedCreatures) {
                                Permanent creature = game.getPermanent(creatureId);
                                if (creature != null) {
                                    selected += creature.getLogName() + " ";
                                }
                            }
                            selectionDone = player.chooseUse(Outcome.Detriment, "Creature selection", selected, "End the selection", "Continue the selection", source, game);
                        }
                    }
                }
                for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                    if (!selectedCreatures.contains(creature.getId())) {
                        creature.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Target(mage.target.Target) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

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