Search in sources :

Example 61 with MageObject

use of mage.MageObject in project mage by magefree.

the class BingoCount method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        if (spell.getManaValue() > 9) {
            return true;
        }
        MageObject mageObject = game.getObject(source.getSourceId());
        if (mageObject != null) {
            // Map<number, amount of counters>
            Map<Integer, Integer> chipCounters = new HashMap<>();
            if (game.getState().getValue(mageObject.getId() + "_chip") != null) {
                chipCounters.putAll((Map<Integer, Integer>) game.getState().getValue(mageObject.getId() + "_chip"));
            }
            chipCounters.putIfAbsent(spell.getManaValue(), 0);
            chipCounters.put(spell.getManaValue(), chipCounters.get(spell.getManaValue()) + 1);
            game.getState().setValue(mageObject.getId() + "_chip", chipCounters);
            if (mageObject instanceof Permanent) {
                StringBuilder sb = new StringBuilder();
                int i = 0;
                for (Map.Entry<Integer, Integer> entry : chipCounters.entrySet()) {
                    i++;
                    sb.append(entry.getKey());
                    if (i < chipCounters.size()) {
                        sb.append(", ");
                    }
                }
                ((Permanent) mageObject).addInfo("chip counters", CardUtil.addToolTipMarkTags("Chip counters at: " + sb), game);
                new AddCountersSourceEffect(CounterType.CHIP.createInstance()).apply(game, source);
            }
            return true;
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Permanent(mage.game.permanent.Permanent) HashMap(java.util.HashMap) MageObject(mage.MageObject) HashMap(java.util.HashMap) Map(java.util.Map) Spell(mage.game.stack.Spell) FilterSpell(mage.filter.FilterSpell)

Example 62 with MageObject

use of mage.MageObject in project mage by magefree.

the class BreyasApprenticeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
    game.addEffect(new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.UntilEndOfYourNextTurn).setTargetPointer(new FixedTarget(card, game)), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) MageObject(mage.MageObject) Card(mage.cards.Card)

Example 63 with MageObject

use of mage.MageObject in project mage by magefree.

the class CemeteryProtectorTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetCardInGraveyard target = new TargetCardInGraveyard();
        target.setNotTarget(true);
        controller.choose(outcome, target, source.getSourceId(), game);
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
            MageObject sourceObject = source.getSourceObject(game);
            String exileName = sourceObject == null ? null : sourceObject.getIdName();
            return controller.moveCardsToExile(card, source, game, true, exileId, exileName);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) MageObject(mage.MageObject) UUID(java.util.UUID) Card(mage.cards.Card)

Example 64 with MageObject

use of mage.MageObject in project mage by magefree.

the class CerebralEruptionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player != null && sourceObject != null && player.getLibrary().hasCards()) {
        Card card = player.getLibrary().getFromTop(game);
        Cards cards = new CardsImpl(card);
        player.revealCards(sourceObject.getIdName(), cards, game);
        game.getState().setValue(source.getSourceId().toString(), card);
        int damage = card.getManaValue();
        player.damage(damage, source.getSourceId(), source, game);
        for (Permanent perm : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, player.getId(), game)) {
            perm.damage(damage, source.getSourceId(), source, game, false, true);
        }
        if (card.isLand(game)) {
            Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
            if (spellCard != null) {
                player.moveCards(spellCard, Zone.HAND, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 65 with MageObject

use of mage.MageObject in project mage by magefree.

the class CephalidShrineEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Spell spell = game.getStack().getSpell(event.getTargetId());
    MageObject mageObject = game.getObject(sourceId);
    if (spell != null && mageObject != null) {
        game.getState().setValue("cephalidShrine" + mageObject, spell);
        return true;
    }
    return false;
}
Also used : MageObject(mage.MageObject) Spell(mage.game.stack.Spell)

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