Search in sources :

Example 61 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class KheruSpellsnatcherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (stackObject != null && sourceObject != null && game.getStack().counter(targetPointer.getFirst(game, source), source, game, Zone.EXILED, false, ZoneDetail.NONE)) {
        if (!stackObject.isCopy()) {
            MageObject card = game.getObject(stackObject.getSourceId());
            if (card instanceof Card) {
                return PlayFromNotOwnHandZoneTargetEffect.exileAndPlayFromExile(game, source, (Card) card, TargetController.YOU, Duration.Custom, true, false, true);
            }
        }
    }
    return false;
}
Also used : MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card)

Example 62 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class KeeperOfTheDeadEffect method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    Set<UUID> possibleTargets = new HashSet<>();
    MageObject object = game.getObject(sourceId);
    for (StackObject item : game.getState().getStack()) {
        if (item.getId().equals(sourceId)) {
            object = item;
        }
        if (item.getSourceId().equals(sourceId)) {
            object = item;
        }
    }
    if (object instanceof StackObject) {
        UUID playerId = ((StackObject) object).getStackAbility().getFirstTarget();
        for (UUID targetId : availablePossibleTargets) {
            Permanent permanent = game.getPermanent(targetId);
            if (permanent != null && StaticFilters.FILTER_PERMANENT_CREATURE_NON_BLACK.match(permanent, game) && permanent.isControlledBy(playerId)) {
                possibleTargets.add(targetId);
            }
        }
    }
    return possibleTargets;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 63 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class OupheVandalsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId = source.getFirstTarget();
    StackObject stackObject = game.getStack().getStackObject(targetId);
    if (targetId != null && game.getStack().counter(targetId, source, game)) {
        UUID permanentId = stackObject.getSourceId();
        if (permanentId != null) {
            Permanent usedPermanent = game.getPermanent(permanentId);
            if (usedPermanent != null) {
                usedPermanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterStackObject(mage.filter.FilterStackObject) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 64 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class PsychicBattleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null) {
        Map<Player, Integer> manacostMap = new HashMap<>();
        for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.getLibrary().hasCards()) {
                Card card = player.getLibrary().getFromTop(game);
                player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', new CardsImpl(card), game);
                manacostMap.put(player, card.getManaValue());
            }
        }
        Player highestCostPlayer = null;
        int maxValue = Collections.max(manacostMap.values());
        boolean tie = false;
        for (Map.Entry<Player, Integer> entry : manacostMap.entrySet()) {
            if (entry.getValue() == maxValue) {
                if (highestCostPlayer != null) {
                    // the result is tied, so nobody changes the targets
                    tie = true;
                    break;
                } else {
                    highestCostPlayer = entry.getKey();
                }
            }
        }
        if (highestCostPlayer != null && !tie) {
            StackObject stackObject = game.getStack().getStackObject(this.getTargetPointer().getFirst(game, source));
            if (stackObject != null) {
                // this makes the new target "invisible" for the Psychic Battle ability
                stackObject.setTargetChanged(true);
                stackObject.chooseNewTargets(game, highestCostPlayer.getId(), false, false, null);
            }
            return true;
        }
        return tie;
    }
    return false;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) CardsImpl(mage.cards.CardsImpl)

Example 65 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class RavagerOfTheFellsTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    Set<UUID> possibleTargets = new HashSet<>();
    MageObject object = game.getObject(sourceId);
    for (StackObject item : game.getState().getStack()) {
        if (item.getId().equals(sourceId)) {
            object = item;
        }
        if (item.getSourceId().equals(sourceId)) {
            object = item;
        }
    }
    if (object instanceof StackObject) {
        UUID playerId = ((StackObject) object).getStackAbility().getFirstTarget();
        Player player = game.getPlayerOrPlaneswalkerController(playerId);
        if (player != null) {
            for (UUID targetId : availablePossibleTargets) {
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null && permanent.isControlledBy(player.getId())) {
                    possibleTargets.add(targetId);
                }
            }
        }
    }
    return possibleTargets;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

StackObject (mage.game.stack.StackObject)130 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)57 Spell (mage.game.stack.Spell)41 MageObject (mage.MageObject)37 UUID (java.util.UUID)36 Card (mage.cards.Card)29 Target (mage.target.Target)17 TargetPermanent (mage.target.TargetPermanent)15 FilterCard (mage.filter.FilterCard)14 Ability (mage.abilities.Ability)13 FilterPermanent (mage.filter.FilterPermanent)13 StackAbility (mage.game.stack.StackAbility)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)11 HashSet (java.util.HashSet)10 Effect (mage.abilities.effects.Effect)9 Game (mage.game.Game)9 MageObjectReference (mage.MageObjectReference)8 Cost (mage.abilities.costs.Cost)8