Search in sources :

Example 6 with StackObject

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

the class PsychicPurgeTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (getSourceId().equals(event.getTargetId())) {
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        if (stackObject != null) {
            if (game.getOpponents(this.getControllerId()).contains(stackObject.getControllerId())) {
                Effect effect = this.getEffects().get(0);
                effect.setTargetPointer(new FixedTarget(stackObject.getControllerId()));
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) StackObject(mage.game.stack.StackObject) LoseLifeTargetEffect(mage.abilities.effects.common.LoseLifeTargetEffect) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect)

Example 7 with StackObject

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

the class PsychicStrikeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean countered = false;
    StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (game.getStack().counter(source.getFirstTarget(), source, game)) {
        countered = true;
    }
    if (stackObject != null) {
        Player controller = game.getPlayer(stackObject.getControllerId());
        if (controller != null) {
            controller.millCards(2, source, game);
        }
    }
    return countered;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject)

Example 8 with StackObject

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

the class RemKarolusStalwartSlayerReplacementEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    UUID targetId = event.getTargetId();
    if (targetId.equals(source.getSourceId())) {
        return false;
    }
    UUID controllerId = source.getControllerId();
    if (!targetId.equals(controllerId)) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent == null || !permanent.isControlledBy(controllerId)) {
            return false;
        }
    }
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (stackObject == null) {
        stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
    }
    if (stackObject instanceof Spell) {
        return super.applies(event, source, game);
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 9 with StackObject

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

the class ReparationsTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    // spell cast
    UUID stackObjectId = event.getTargetId();
    // spell caster
    UUID casterId = event.getPlayerId();
    StackObject stackObject = game.getStack().getStackObject(stackObjectId);
    if (stackObject != null && game.getOpponents(controllerId).contains(casterId)) {
        Player targetPlayer = game.getPlayer(stackObject.getStackAbility().getFirstTarget());
        Permanent targetPermanent = game.getPermanent(stackObject.getStackAbility().getFirstTarget());
        if (targetPlayer != null && targetPlayer.getId().equals(controllerId)) {
            return true;
        }
        if (targetPermanent != null && targetPermanent.isCreature(game) && targetPermanent.isControlledBy(controllerId)) {
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 10 with StackObject

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

the class TestOfTalentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    MageObject targetObject = game.getObject(stackObject.getSourceId());
    String cardName;
    if (targetObject instanceof Card) {
        cardName = targetObject.getName();
    } else {
        cardName = "";
    }
    UUID searchPlayerId = stackObject.getControllerId();
    Player player = game.getPlayer(searchPlayerId);
    if (player == null) {
        return false;
    }
    int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    game.getStack().counter(source.getFirstTarget(), source, game);
    this.applySearchAndExile(game, source, cardName, searchPlayerId);
    int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    if (previousCount > newCount) {
        player.drawCards(previousCount - newCount, source, game);
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card) Ability(mage.abilities.Ability) TargetSpell(mage.target.TargetSpell) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Objects(java.util.Objects) UUID(java.util.UUID) Card(mage.cards.Card)

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