Search in sources :

Example 16 with Permanent

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

the class BattleForBretagardTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    Set<String> names = this.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).map(MageObject::getName).collect(Collectors.toSet());
    names.removeIf(Objects::isNull);
    names.removeIf(String::isEmpty);
    possibleTargets.removeIf(uuid -> {
        Permanent permanent = game.getPermanent(uuid);
        return permanent == null || names.contains(permanent.getName());
    });
    return possibleTargets;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Objects(java.util.Objects) UUID(java.util.UUID)

Example 17 with Permanent

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

the class BattleForBretagardTarget method canTarget.

@Override
public boolean canTarget(UUID playerId, UUID id, Ability ability, Game game) {
    if (!super.canTarget(playerId, id, ability, game)) {
        return false;
    }
    Set<String> names = this.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).map(MageObject::getName).collect(Collectors.toSet());
    names.removeIf(Objects::isNull);
    names.removeIf(String::isEmpty);
    Permanent permanent = game.getPermanent(id);
    return permanent != null && !names.contains(permanent.getName());
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Objects(java.util.Objects)

Example 18 with Permanent

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

the class BarrinsSpiteEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Permanent> permanents = source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
    if (permanents.isEmpty()) {
        return false;
    }
    if (permanents.size() == 1) {
        permanents.get(0).sacrifice(source, game);
        return true;
    }
    if (permanents.size() > 2) {
        throw new IllegalStateException("Too many permanents in list, shouldn't be possible");
    }
    Player player = game.getPlayer(permanents.get(0).getControllerId());
    Player controller = game.getPlayer(source.getControllerId());
    if (player == null || controller == null) {
        return false;
    }
    Permanent perm1 = permanents.get(0);
    Permanent perm2 = permanents.get(1);
    if (player.chooseUse(outcome, "Choose which permanent to sacrifice", "The other will be returned to your hand", perm1.getIdName(), perm2.getIdName(), source, game)) {
        perm1.sacrifice(source, game);
        controller.moveCards(perm2, Zone.HAND, source, game);
        return true;
    }
    perm2.sacrifice(source, game);
    controller.moveCards(perm1, Zone.HAND, source, game);
    return true;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 19 with Permanent

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

the class BeamsplitterMageApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    FilterPermanent filter = new FilterControlledCreaturePermanent("a creature you control that can be targeted by " + spell.getName());
    filter.add(AnotherPredicate.instance);
    filter.add(new BeamsplitterMagePredicate(spell));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    spell.createCopyOnStack(game, source, player.getId(), false, 1, new BeamsplitterMageApplier(permanent, game));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Spell(mage.game.stack.Spell)

Example 20 with Permanent

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

the class BazaarTraderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    Permanent permanent = targetPermanentReference.getPermanent(game);
    if (player != null && permanent != null) {
        return permanent.changeControllerId(player.getId(), game, source);
    } else {
        discard();
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent)

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