Search in sources :

Example 51 with MageObject

use of mage.MageObject in project mage by magefree.

the class RevealHandSourceControllerCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Player controller = game.getPlayer(controllerId);
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        controller.revealCards(sourceObject.getName(), controller.getHand(), game);
        paid = true;
    }
    return paid;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject)

Example 52 with MageObject

use of mage.MageObject in project mage by magefree.

the class ReturnToHandSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    MageObject mageObject;
    if (returnFromNextZone && game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) {
        mageObject = game.getObject(source.getSourceId());
    } else {
        mageObject = source.getSourceObjectIfItStillExists(game);
    }
    if (mageObject == null) {
        return true;
    }
    switch(game.getState().getZone(mageObject.getId())) {
        case BATTLEFIELD:
            Permanent permanent = game.getPermanent(source.getSourceId());
            if (permanent != null && permanent.isPhasedIn()) {
                return controller.moveCards(permanent, Zone.HAND, source, game);
            }
            break;
        case GRAVEYARD:
            Card card = (Card) mageObject;
            return !fromBattlefieldOnly && controller.moveCards(card, Zone.HAND, source, game);
        case STACK:
            Spell spell = game.getSpell(source.getSourceId());
            return !fromBattlefieldOnly && spell != null && controller.moveCards(spell.getMainCard(), Zone.HAND, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 53 with MageObject

use of mage.MageObject in project mage by magefree.

the class ReturnToHandTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> copyIds = new ArrayList<>();
    Set<Card> cards = new LinkedHashSet<>();
    if (multitargetHandling) {
        for (Target target : source.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                MageObject mageObject = game.getObject(targetId);
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    } else {
        for (UUID targetId : targetPointer.getTargets(game, source)) {
            MageObject mageObject = game.getObject(targetId);
            if (mageObject != null) {
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    }
    for (UUID copyId : copyIds) {
        game.getStack().remove(game.getSpell(copyId), game);
    }
    return controller.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 54 with MageObject

use of mage.MageObject in project mage by magefree.

the class PreventAllDamageByAllObjectsEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
        return false;
    }
    DamageEvent damageEvent = (DamageEvent) event;
    if (!damageEvent.isCombatDamage() && onlyCombat) {
        return false;
    }
    if (filter == null) {
        return true;
    }
    MageObject damageSource = game.getObject(damageEvent.getSourceId());
    if (damageSource == null) {
        return false;
    }
    if (filter instanceof FilterInPlay) {
        return ((FilterInPlay) filter).match(damageSource, source.getSourceId(), source.getControllerId(), game);
    }
    return filter.match(damageSource, game);
}
Also used : FilterInPlay(mage.filter.FilterInPlay) MageObject(mage.MageObject) DamageEvent(mage.game.events.DamageEvent)

Example 55 with MageObject

use of mage.MageObject in project mage by magefree.

the class OpponentsCantCastChosenUntilNextTurnEffect method getInfoMessage.

@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
    MageObject mageObject = game.getObject(source.getSourceId());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (mageObject != null && cardName != null) {
        return "You can't cast a card named " + cardName + " (" + mageObject.getIdName() + ").";
    }
    return null;
}
Also used : MageObject(mage.MageObject)

Aggregations

MageObject (mage.MageObject)738 Player (mage.players.Player)554 Permanent (mage.game.permanent.Permanent)239 UUID (java.util.UUID)224 Card (mage.cards.Card)210 FilterCard (mage.filter.FilterCard)113 CardsImpl (mage.cards.CardsImpl)106 TargetCard (mage.target.TargetCard)91 Cards (mage.cards.Cards)73 Spell (mage.game.stack.Spell)68 FixedTarget (mage.target.targetpointer.FixedTarget)66 HashSet (java.util.HashSet)56 Ability (mage.abilities.Ability)52 ContinuousEffect (mage.abilities.effects.ContinuousEffect)51 TargetPermanent (mage.target.TargetPermanent)48 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)48 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)46 Target (mage.target.Target)44 Effect (mage.abilities.effects.Effect)42 OneShotEffect (mage.abilities.effects.OneShotEffect)41