Search in sources :

Example 71 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CommanderStormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
    if (spellRef == null) {
        return false;
    }
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
    if (watcher == null) {
        return false;
    }
    int stormCount = game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER, false).stream().mapToInt(watcher::getPlaysCount).sum();
    if (stormCount == 0) {
        return true;
    }
    Spell spell = (Spell) this.getValue("StormSpell");
    if (spell == null) {
        return false;
    }
    game.informPlayers(spell.getLogName() + " will be copied " + stormCount + " time" + (stormCount > 1 ? "s" : ""));
    spell.createCopyOnStack(game, source, source.getControllerId(), true, stormCount);
    return true;
}
Also used : Player(mage.players.Player) CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) MageObjectReference(mage.MageObjectReference) Spell(mage.game.stack.Spell)

Example 72 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CommanderStormEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(getSourceId())) {
        return false;
    }
    StackObject spell = game.getStack().getStackObject(getSourceId());
    if (!(spell instanceof Spell)) {
        return false;
    }
    for (Effect effect : this.getEffects()) {
        effect.setValue("StormSpell", spell);
        effect.setValue("StormSpellRef", new MageObjectReference(spell.getId(), game));
    }
    return true;
}
Also used : StackObject(mage.game.stack.StackObject) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 73 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ExertedThisTurnWatcher method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = game.getPermanent(event.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (creature != null && controller != null) {
        if (exertOnlyOncePerTurn) {
            MageObjectReference creatureReference = new MageObjectReference(creature.getId(), creature.getZoneChangeCounter(game), game);
            ExertedThisTurnWatcher watcher = game.getState().getWatcher(ExertedThisTurnWatcher.class);
            if (watcher != null && watcher.getExertedThisTurnCreatures().contains(creatureReference)) {
                return false;
            }
        }
        if (controller.chooseUse(outcome, "Exert " + creature.getLogName() + '?', "An exerted creature won't untap during your next untap step.", "Yes", "No", source, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(controller.getLogName() + " exerted " + creature.getName());
            }
            game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_EXERTED, creature.getId(), source, source.getControllerId()));
            ContinuousEffect effect = new DontUntapInControllersNextUntapStepTargetEffect("", creature.getControllerId());
            effect.setTargetPointer(new FixedTarget(creature, game));
            game.addEffect(effect, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) DontUntapInControllersNextUntapStepTargetEffect(mage.abilities.effects.common.DontUntapInControllersNextUntapStepTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) MageObjectReference(mage.MageObjectReference)

Example 74 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class EncoreSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getSourceId());
    if (card == null) {
        return false;
    }
    EmptyToken token = new EmptyToken();
    CardUtil.copyTo(token).from(card, game);
    Set<MageObjectReference> addedTokens = new HashSet<>();
    int opponentCount = OpponentsCount.instance.calculate(game, source, this);
    if (opponentCount < 1) {
        return false;
    }
    token.putOntoBattlefield(opponentCount, game, source, source.getControllerId());
    Iterator<UUID> it = token.getLastAddedTokenIds().iterator();
    while (it.hasNext()) {
        for (UUID playerId : game.getOpponents(source.getControllerId())) {
            if (game.getPlayer(playerId) == null) {
                continue;
            }
            UUID tokenId = it.next();
            MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game);
            game.addEffect(new EncoreRequirementEffect(mageObjectReference, playerId), source);
            game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom).setTargetPointer(new FixedTarget(mageObjectReference)), source);
            addedTokens.add(mageObjectReference);
        }
    }
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new EncoreSacrificeEffect(addedTokens)), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Card(mage.cards.Card) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) EmptyToken(mage.game.permanent.token.EmptyToken) HashSet(java.util.HashSet)

Example 75 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CalixDestinysHandReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (source.getTargets().size() > 2) {
        return false;
    }
    source.getTargets();
    Permanent theirPerm = game.getPermanent(source.getTargets().get(0).getFirstTarget());
    Permanent myPerm = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (controller == null || theirPerm == null || myPerm == null) {
        return false;
    }
    MageObjectReference theirMor = new MageObjectReference(theirPerm.getId(), theirPerm.getZoneChangeCounter(game) + 1, game);
    MageObjectReference myMor = new MageObjectReference(myPerm, game);
    UUID exileId = CardUtil.getExileZoneId(myPerm.toString(), game);
    controller.moveCardsToExile(theirPerm, source, game, true, exileId, myPerm.getIdName());
    game.addDelayedTriggeredAbility(new CalixDestinysHandDelayedTriggeredAbility(theirMor, myMor), source);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) 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