Search in sources :

Example 1 with FightTargetSourceEffect

use of mage.abilities.effects.common.FightTargetSourceEffect in project mage by magefree.

the class HansErikssonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    player.revealCards(source, new CardsImpl(card), game);
    if (!card.isCreature(game)) {
        return player.moveCards(card, Zone.HAND, source, game);
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return true;
    }
    UUID defendingPlayerId = getTargetPointer().getFirst(game, source);
    UUID defenderId;
    if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), defendingPlayerId, game) < 1) {
        defenderId = defendingPlayerId;
    } else {
        FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker("defending player or a planeswalker they control");
        filter.getPlayerFilter().add(new PlayerIdPredicate(defendingPlayerId));
        filter.getPermanentFilter().add(new ControllerIdPredicate(defendingPlayerId));
        TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        defenderId = target.getFirstTarget();
    }
    if (defenderId != null) {
        game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
    }
    Effect fightEffect = new FightTargetSourceEffect();
    fightEffect.setTargetPointer(new FixedTarget(permanent, game));
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(fightEffect, false, "When you put a creature card onto the battlefield this way, it fights {this}");
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect) FilterPlayerOrPlaneswalker(mage.filter.common.FilterPlayerOrPlaneswalker) Card(mage.cards.Card) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) TargetPlayerOrPlaneswalker(mage.target.common.TargetPlayerOrPlaneswalker)

Example 2 with FightTargetSourceEffect

use of mage.abilities.effects.common.FightTargetSourceEffect in project mage by magefree.

the class MythosOfIllunaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId());
    if (condition.apply(game, source)) {
        Ability ability = new ConditionalInterveningIfTriggeredAbility(new EntersBattlefieldTriggeredAbility(new FightTargetSourceEffect()), MythosOfIllunaCondition.instance, "When this permanent enters the battlefield, " + "if it's a creature, it fights up to one target creature you don't control.");
        ability.addTarget(new TargetPermanent(0, 1, StaticFilters.FILTER_CREATURE_YOU_DONT_CONTROL, false));
        effect.addAdditionalAbilities(ability);
    }
    return effect.apply(game, source);
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)

Example 3 with FightTargetSourceEffect

use of mage.abilities.effects.common.FightTargetSourceEffect in project mage by magefree.

the class SkophosMazeWardenTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (stackObject == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(stackObject.getSourceId());
    if (permanent == null || !permanent.isControlledBy(getControllerId()) || !permanent.isLand(game) || !permanent.getName().equals("Labyrinth of Skophos")) {
        return false;
    }
    Permanent creature = game.getPermanent(event.getTargetId());
    if (creature == null || !creature.isCreature(game) || creature.getId().equals(getSourceId())) {
        return false;
    }
    this.getEffects().clear();
    this.addEffect(new FightTargetSourceEffect().setTargetPointer(new FixedTarget(creature, game)));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect)

Example 4 with FightTargetSourceEffect

use of mage.abilities.effects.common.FightTargetSourceEffect in project mage by magefree.

the class CherishedHatchlingTriggeredAbility method getEffectToAdd.

private static Effect getEffectToAdd() {
    Ability abilityToAdd = new EntersBattlefieldTriggeredAbility(new FightTargetSourceEffect().setText("you may have it fight another target creature"), true);
    abilityToAdd.addTarget(new TargetCreaturePermanent(filter));
    Effect effect = new GainAbilityTargetEffect(abilityToAdd, Duration.EndOfTurn, "it gains \"When this creature enters the battlefield, you may have it fight another target creature.\"", true);
    return effect;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) CastAsThoughItHadFlashAllEffect(mage.abilities.effects.common.continuous.CastAsThoughItHadFlashAllEffect) Effect(mage.abilities.effects.Effect) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect)

Aggregations

FightTargetSourceEffect (mage.abilities.effects.common.FightTargetSourceEffect)4 Permanent (mage.game.permanent.Permanent)3 Ability (mage.abilities.Ability)2 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)2 Effect (mage.abilities.effects.Effect)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 UUID (java.util.UUID)1 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1 DiesSourceTriggeredAbility (mage.abilities.common.DiesSourceTriggeredAbility)1 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)1 ConditionalInterveningIfTriggeredAbility (mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 CreateDelayedTriggeredAbilityEffect (mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect)1 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)1 CastAsThoughItHadFlashAllEffect (mage.abilities.effects.common.continuous.CastAsThoughItHadFlashAllEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 Card (mage.cards.Card)1 CardsImpl (mage.cards.CardsImpl)1 FilterPlayerOrPlaneswalker (mage.filter.common.FilterPlayerOrPlaneswalker)1 PlayerIdPredicate (mage.filter.predicate.other.PlayerIdPredicate)1