Search in sources :

Example 76 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class WithdrawEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Effect effect = new ReturnToHandTargetEffect();
    effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
    effect.apply(game, source);
    Permanent secondCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (secondCreature != null) {
        Player creatureController = game.getPlayer(secondCreature.getControllerId());
        if (creatureController != null) {
            Cost cost = ManaUtil.createManaCost(1, false);
            if (creatureController.chooseUse(Outcome.Benefit, "Pay {1}? (Otherwise " + secondCreature.getName() + " will be returned to its owner's hand)", source, game)) {
                cost.pay(source, game, source, creatureController.getId(), false);
            }
            if (!cost.isPaid()) {
                creatureController.moveCards(secondCreature, Zone.HAND, source, game);
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) Cost(mage.abilities.costs.Cost)

Example 77 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class SimulatedPlayer2 method optimizeOptions.

protected List<Ability> optimizeOptions(Game game, List<Ability> options, Ability ability) {
    if (options.isEmpty()) {
        return options;
    }
    // determine if all effects are bad or good
    Iterator<Ability> iterator = options.iterator();
    boolean bad = true;
    boolean good = true;
    // TODO: add custom outcome from ability?
    for (Effect effect : ability.getEffects()) {
        if (effect.getOutcome().isGood()) {
            bad = false;
        } else {
            good = false;
        }
    }
    if (bad) {
        // remove its own creatures, player itself for bad effects with one target
        while (iterator.hasNext()) {
            Ability ability1 = iterator.next();
            if (ability1.getTargets().size() == 1 && ability1.getTargets().get(0).getTargets().size() == 1) {
                Permanent permanent = game.getPermanent(ability1.getFirstTarget());
                if (permanent != null && !game.getOpponents(playerId).contains(permanent.getControllerId())) {
                    iterator.remove();
                    continue;
                }
                if (ability1.getFirstTarget().equals(playerId)) {
                    iterator.remove();
                }
            }
        }
    }
    if (good) {
        // remove opponent creatures and opponent for only good effects with one target
        while (iterator.hasNext()) {
            Ability ability1 = iterator.next();
            if (ability1.getTargets().size() == 1 && ability1.getTargets().get(0).getTargets().size() == 1) {
                Permanent permanent = game.getPermanent(ability1.getFirstTarget());
                if (permanent != null && game.getOpponents(playerId).contains(permanent.getControllerId())) {
                    iterator.remove();
                    continue;
                }
                if (game.getOpponents(playerId).contains(ability1.getFirstTarget())) {
                    iterator.remove();
                }
            }
        }
    }
    return options;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) Effect(mage.abilities.effects.Effect)

Example 78 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class BloodSeekerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
        EntersTheBattlefieldEvent zEvent = (EntersTheBattlefieldEvent) event;
        Card card = zEvent.getTarget();
        if (card != null && card.isCreature(game)) {
            for (Effect effect : this.getEffects()) {
                effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) LoseLifeTargetEffect(mage.abilities.effects.common.LoseLifeTargetEffect) Effect(mage.abilities.effects.Effect) Card(mage.cards.Card)

Example 79 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class BlightningEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayerOrPlaneswalkerController(source.getFirstTarget());
    if (player == null) {
        return false;
    }
    Effect effect = new DiscardTargetEffect(2);
    effect.setTargetPointer(new FixedTarget(player.getId(), game));
    return effect.apply(game, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) DiscardTargetEffect(mage.abilities.effects.common.discard.DiscardTargetEffect) DiscardTargetEffect(mage.abilities.effects.common.discard.DiscardTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect)

Example 80 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class ClockworkBeetleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        Effect effect = new RemoveCounterTargetEffect(CounterType.P1P1.createInstance());
        effect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
        game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(effect), source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) RemoveCounterTargetEffect(mage.abilities.effects.common.counter.RemoveCounterTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Effect(mage.abilities.effects.Effect) RemoveCounterTargetEffect(mage.abilities.effects.common.counter.RemoveCounterTargetEffect) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)

Aggregations

Effect (mage.abilities.effects.Effect)328 OneShotEffect (mage.abilities.effects.OneShotEffect)254 FixedTarget (mage.target.targetpointer.FixedTarget)224 Permanent (mage.game.permanent.Permanent)180 Player (mage.players.Player)167 UUID (java.util.UUID)75 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)60 Card (mage.cards.Card)57 MageObject (mage.MageObject)41 ContinuousEffect (mage.abilities.effects.ContinuousEffect)40 TargetPermanent (mage.target.TargetPermanent)39 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)38 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 FilterPermanent (mage.filter.FilterPermanent)29 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)28 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)27 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)25 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)24 AttachEffect (mage.abilities.effects.common.AttachEffect)23 Target (mage.target.Target)22