Search in sources :

Example 81 with StackObject

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

the class MaskwoodNexusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // in graveyard
    for (UUID cardId : controller.getGraveyard()) {
        Card card = game.getCard(cardId);
        if (card != null && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // on Hand
    for (UUID cardId : controller.getHand()) {
        Card card = game.getCard(cardId);
        if (card != null && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // in Exile
    for (Card card : game.getState().getExile().getAllCards(game)) {
        if (card.isCreature(game) && card.isOwnedBy(controller.getId())) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // in Library (e.g. for Mystical Teachings)
    for (Card card : controller.getLibrary().getCards(game)) {
        if (card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // commander in command zone
    for (CommandObject commandObject : game.getState().getCommand()) {
        if (!(commandObject instanceof Commander)) {
            continue;
        }
        Card card = game.getCard(((Commander) commandObject).getId());
        if (card != null && card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // creature spells you control
    for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
        StackObject stackObject = iterator.next();
        if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId()) && stackObject.isCreature(game)) {
            Card card = ((Spell) stackObject).getCard();
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // creatures you control
    List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game);
    for (Permanent creature : creatures) {
        if (creature != null) {
            creature.setIsAllCreatureTypes(game, true);
        }
    }
    return true;
}
Also used : CommandObject(mage.game.command.CommandObject) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Commander(mage.game.command.Commander) StackObject(mage.game.stack.StackObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 82 with StackObject

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

the class MeddleEffect method checkTarget.

private static final boolean checkTarget(Game game, Ability source) {
    StackObject stackObject = game.getState().getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    int numberOfTargets = 0;
    for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
        Mode mode = stackObject.getStackAbility().getModes().get(modeId);
        for (Target target : mode.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                if (numberOfTargets++ > 1) {
                    return false;
                }
                Permanent permanent = game.getPermanent(targetId);
                if (permanent == null || !permanent.isCreature(game)) {
                    return false;
                }
            }
        }
    }
    return numberOfTargets == 1;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) Mode(mage.abilities.Mode) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 83 with StackObject

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

the class RadiateEffect method prepareCopiesWithTargets.

@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
    List<MageObjectReferencePredicate> predicates = new ArrayList<>();
    UUID targeted = ((Spell) stackObject).getSpellAbilities().stream().map(AbilityImpl::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    return predicates;
}
Also used : Target(mage.target.Target) StaticFilters(mage.filter.StaticFilters) java.util(java.util) CopySpellForEachItCouldTargetEffect(mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect) TargetAddress(mage.util.TargetAddress) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) FilterInstantOrSorcerySpell(mage.filter.common.FilterInstantOrSorcerySpell) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) FilterSpell(mage.filter.FilterSpell) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) ObjectSourcePlayerPredicate(mage.filter.predicate.ObjectSourcePlayerPredicate) Ability(mage.abilities.Ability) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetSpell(mage.target.TargetSpell) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) FilterInstantOrSorcerySpell(mage.filter.common.FilterInstantOrSorcerySpell) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) MageObjectReference(mage.MageObjectReference)

Example 84 with StackObject

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

the class RadiantPerformerEffect method prepareCopiesWithTargets.

@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
    List<MageObjectReferencePredicate> predicates = new ArrayList<>();
    Ability ability = stackObject instanceof Spell ? ((Spell) stackObject).getSpellAbility() : (StackAbility) stackObject;
    UUID targeted = ability == null ? null : ability.getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    return predicates;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) Ability(mage.abilities.Ability) Target(mage.target.Target) java.util(java.util) CopySpellForEachItCouldTargetEffect(mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect) TargetStackObject(mage.target.TargetStackObject) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) CastFromHandSourcePermanentCondition(mage.abilities.condition.common.CastFromHandSourcePermanentCondition) SubType(mage.constants.SubType) Mode(mage.abilities.Mode) Player(mage.players.Player) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) FilterStackObject(mage.filter.FilterStackObject) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CastFromHandWatcher(mage.watchers.common.CastFromHandWatcher) Ability(mage.abilities.Ability) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 85 with StackObject

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

the class SearingBlazeTarget 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);
    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