Search in sources :

Example 81 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CantAttackIfAttackedLastTurnEffect method canAttack.

@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
    AttackedLastTurnWatcher watcher = game.getState().getWatcher(AttackedLastTurnWatcher.class);
    if (watcher != null) {
        Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(attacker.getControllerId());
        MageObjectReference mor = new MageObjectReference(attacker, game);
        return !attackingCreatures.contains(mor);
    }
    return true;
}
Also used : AttackedLastTurnWatcher(mage.watchers.common.AttackedLastTurnWatcher) MageObjectReference(mage.MageObjectReference)

Example 82 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class IdolOfEnduranceWatcher method addPlayable.

static void addPlayable(Ability source, Game game) {
    MageObjectReference mor = new MageObjectReference(source);
    game.getState().getWatcher(IdolOfEnduranceWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
Also used : MageObjectReference(mage.MageObjectReference) HashMap(java.util.HashMap) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Map(java.util.Map) mage.constants(mage.constants) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterCard(mage.filter.FilterCard) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) ExileZone(mage.game.ExileZone) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) GameEvent(mage.game.events.GameEvent) Permanent(mage.game.permanent.Permanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) HashMap(java.util.HashMap) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil)

Example 83 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class LightmineFieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> attackers = game.getCombat().getAttackers();
    int damage = attackers.size();
    Set<MageObjectReference> attackSet = (Set<MageObjectReference>) getValue("Lightmine Field");
    if (!attackers.isEmpty()) {
        for (Iterator<MageObjectReference> it = attackSet.iterator(); it.hasNext(); ) {
            MageObjectReference attacker = it.next();
            Permanent creature = attacker.getPermanent(game);
            if (creature != null) {
                creature.damage(damage, source.getSourceId(), source, game, false, true);
            }
        }
        return true;
    }
    return false;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 84 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class MagmaticChannelerCastFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 2));
    player.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    Card card = null;
    if (cards.isEmpty()) {
        return false;
    } else if (cards.size() == 1) {
        card = cards.getRandom(game);
    } else {
        TargetCard targetCard = new TargetCardInExile(StaticFilters.FILTER_CARD, null);
        player.choose(outcome, cards, targetCard, game);
        card = game.getCard(targetCard.getFirstTarget());
    }
    if (card == null) {
        return false;
    }
    game.addEffect(new MagmaticChannelerCastFromExileEffect(new MageObjectReference(card, game)), source);
    return true;
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) MageObjectReference(mage.MageObjectReference) TargetCard(mage.target.TargetCard)

Example 85 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class MythRealizedSetPTEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null && new MageObjectReference(source.getSourceObject(game), game).refersTo(permanent, game)) {
            int amount = permanent.getCounters(game).getCount(CounterType.LORE);
            permanent.getPower().setValue(amount);
            permanent.getToughness().setValue(amount);
            return true;
        } else {
            discard();
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)250 Permanent (mage.game.permanent.Permanent)147 Player (mage.players.Player)76 UUID (java.util.UUID)47 Card (mage.cards.Card)45 Ability (mage.abilities.Ability)34 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)33 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)26 OneShotEffect (mage.abilities.effects.OneShotEffect)24 FilterPermanent (mage.filter.FilterPermanent)23 Game (mage.game.Game)22 Spell (mage.game.stack.Spell)21 TargetPermanent (mage.target.TargetPermanent)20 CardImpl (mage.cards.CardImpl)18 CardSetInfo (mage.cards.CardSetInfo)18 MageObject (mage.MageObject)17 Effect (mage.abilities.effects.Effect)16 HashSet (java.util.HashSet)15 mage.constants (mage.constants)14 GameEvent (mage.game.events.GameEvent)13