Search in sources :

Example 21 with StackObject

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

the class GuileReplacementEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Spell counteredSpell = game.getStack().getSpell(event.getTargetId());
    StackObject counteringObject = game.getStack().getStackObject(event.getSourceId());
    return counteredSpell != null && counteringObject != null && counteringObject.isControlledBy(source.getControllerId());
}
Also used : StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell)

Example 22 with StackObject

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

the class HopeOfGhirapurCombatDamageWatcher method playerGotCombatDamage.

/**
 * Checks if the current object has damaged the player during the current
 * turn.
 *
 * @param objectId
 * @param playerId
 * @return
 */
public boolean playerGotCombatDamage(UUID objectId, UUID playerId, Game game) {
    StackObject stackObject = game.getState().getStack().getStackObject(objectId);
    MageObjectReference mor;
    if (stackObject instanceof StackAbility) {
        // This is neccessary because the source object was sacrificed as cost and the correct zone change counter for target calid check can only be get from stack
        mor = new MageObjectReference(objectId, ((StackAbility) stackObject).getSourceObjectZoneChangeCounter(), game);
    } else {
        mor = new MageObjectReference(objectId, game);
    }
    if (combatDamagedPlayers.containsKey(mor)) {
        return combatDamagedPlayers.get(mor).contains(playerId);
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) MageObjectReference(mage.MageObjectReference) StackAbility(mage.game.stack.StackAbility)

Example 23 with StackObject

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

the class SpellSyphonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        if (player != null && controller != null) {
            int amount = controller.getHand().size();
            if (amount > 0) {
                Cost cost = ManaUtil.createManaCost(amount, false);
                if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
                    game.informPlayers(sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
                    return game.getStack().counter(source.getFirstTarget(), source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Cost(mage.abilities.costs.Cost)

Example 24 with StackObject

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

the class TeferisResponseEffect 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) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) FilterStackObject(mage.filter.FilterStackObject) TargetStackObject(mage.target.TargetStackObject) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 25 with StackObject

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

the class UnpredictableCycloneReplacementEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!event.getPlayerId().equals(source.getControllerId())) {
        return false;
    }
    Player player = game.getPlayer(event.getPlayerId());
    // event.getSourceId() will be null for default draws (non effects)
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (player == null || stackObject == null || stackObject.getStackAbility() == null || !(stackObject.getStackAbility() instanceof CyclingAbility)) {
        return false;
    }
    Card sourceCard = game.getCard(stackObject.getSourceId());
    return sourceCard != null && !sourceCard.isLand(game);
}
Also used : Player(mage.players.Player) CyclingAbility(mage.abilities.keyword.CyclingAbility) StackObject(mage.game.stack.StackObject)

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