Search in sources :

Example 76 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class DauntlessBodyguardGainAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanent == null) {
        return false;
    }
    MageObjectReference mor = (MageObjectReference) game.getState().getValue(sourcePermanent.getId() + "_chosenCreature");
    if (mor == null) {
        return false;
    }
    Permanent chosenPermanent = mor.getPermanent(game);
    if (chosenPermanent != null) {
        ContinuousEffect effect = new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
        game.addEffect(effect, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) MageObjectReference(mage.MageObjectReference)

Example 77 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GideonJuraEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    creatingPermanent = new MageObjectReference(source.getSourceId(), game);
    // setup startingController to calc isYourTurn calls
    setStartingControllerAndTurnNum(game, source.getFirstTarget(), game.getActivePlayerId());
}
Also used : MageObjectReference(mage.MageObjectReference)

Example 78 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GideonChampionOfJusticeToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    MageObjectReference mor = new MageObjectReference(source.getSourceObject(game), game);
    Cards cards = new CardsImpl();
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, source.getControllerId(), game).stream().filter(Objects::nonNull).filter(permanent -> !mor.refersTo(permanent, game)).forEach(cards::add);
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : IndestructibleAbility(mage.abilities.keyword.IndestructibleAbility) TargetOpponent(mage.target.common.TargetOpponent) TokenImpl(mage.game.permanent.token.TokenImpl) MageObjectReference(mage.MageObjectReference) BecomesCreatureSourceEffect(mage.abilities.effects.common.continuous.BecomesCreatureSourceEffect) Player(mage.players.Player) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) CountersSourceCount(mage.abilities.dynamicvalue.common.CountersSourceCount) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) mage.constants(mage.constants) StaticFilters(mage.filter.StaticFilters) LockedInDynamicValue(mage.abilities.dynamicvalue.LockedInDynamicValue) Cards(mage.cards.Cards) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) LoyaltyAbility(mage.abilities.LoyaltyAbility) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) PreventAllDamageToSourceEffect(mage.abilities.effects.common.PreventAllDamageToSourceEffect) Game(mage.game.Game) PermanentsTargetOpponentControlsCount(mage.abilities.dynamicvalue.common.PermanentsTargetOpponentControlsCount) CardImpl(mage.cards.CardImpl) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) Objects(java.util.Objects) MageObjectReference(mage.MageObjectReference) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 79 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GideonTheOathswornToken method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (game.getCombat().getAttackingPlayerId().equals(getControllerId())) {
        int attackerCount = 0;
        Set<MageObjectReference> attackers = new HashSet();
        for (UUID attackerId : game.getCombat().getAttackers()) {
            Permanent permanent = game.getPermanent(attackerId);
            if (permanent != null && permanent.isCreature(game) && !permanent.hasSubtype(SubType.GIDEON, game)) {
                attackerCount++;
                attackers.add(new MageObjectReference(permanent, game));
            }
        }
        if (attackerCount >= 2) {
            this.getEffects().clear();
            this.addEffect(new GideonTheOathswornEffect(attackers));
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) HashSet(java.util.HashSet)

Example 80 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GideonsSacrificeEffectReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Target target = new TargetPermanent(filter);
    target.setNotTarget(true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    game.addEffect(new GideonsSacrificeEffectReplacementEffect(new MageObjectReference(target.getFirstTarget(), game)), source);
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetPermanent(mage.target.TargetPermanent) 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