Search in sources :

Example 11 with Mode

use of mage.abilities.Mode in project mage by magefree.

the class EmissaryOfGrudgesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    if (controller == null || stackObject == null || !stackObject.isControlledBy(ChooseSecretOpponentEffect.getChosenPlayer(source, game))) {
        return false;
    }
    // find if it targets you or a permanent you control
    boolean targetsYouOrAPermanentYouControl = false;
    for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
        Mode mode = stackObject.getStackAbility().getModes().get(modeId);
        for (Target target : mode.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                if (source.isControlledBy(targetId)) {
                    targetsYouOrAPermanentYouControl = true;
                }
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null && source.isControlledBy(permanent.getControllerId())) {
                    targetsYouOrAPermanentYouControl = true;
                }
            }
        }
    }
    if (targetsYouOrAPermanentYouControl) {
        return stackObject.chooseNewTargets(game, source.getControllerId(), false, false, null);
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) Mode(mage.abilities.Mode) TargetStackObject(mage.target.TargetStackObject) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 12 with Mode

use of mage.abilities.Mode in project mage by magefree.

the class FeatherTheRedeemedEffect method checkSpell.

private boolean checkSpell(Spell spell, Game game) {
    if (spell == null) {
        return false;
    }
    SpellAbility sa = spell.getSpellAbility();
    for (UUID modeId : sa.getModes().getSelectedModes()) {
        Mode mode = sa.getModes().get(modeId);
        for (Target target : mode.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null && permanent.isCreature(game) && permanent.isControlledBy(getControllerId())) {
                    this.getEffects().clear();
                    this.addEffect(new FeatherTheRedeemedEffect(new MageObjectReference(spell, game)));
                    return true;
                }
            }
        }
        for (Effect effect : mode.getEffects()) {
            for (UUID targetId : effect.getTargetPointer().getTargets(game, sa)) {
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null && permanent.isCreature(game) && permanent.isControlledBy(getControllerId())) {
                    this.getEffects().clear();
                    this.addEffect(new FeatherTheRedeemedEffect(new MageObjectReference(spell, game)));
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) Mode(mage.abilities.Mode) SpellAbility(mage.abilities.SpellAbility) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 13 with Mode

use of mage.abilities.Mode in project mage by magefree.

the class GuileSonicSoldierEffect method makeAbility.

private static final ReflexiveTriggeredAbility makeAbility() {
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(4), false);
    ability.addTarget(new TargetAnyTarget());
    Mode mode = new Mode(new GainAbilitySourceEffect(LifelinkAbility.getInstance(), Duration.EndOfTurn).setText("{this} gains lifelink"));
    mode.addEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn).setText("and indestructible until end of turn"));
    ability.withFirstModeFlavorWord("Sonic Boom").addMode(mode.withFlavorWord("Flash Kick"));
    return ability;
}
Also used : GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) Mode(mage.abilities.Mode) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 14 with Mode

use of mage.abilities.Mode in project mage by magefree.

the class MeddleEffect method checkTarget.

private static final boolean checkTarget(Game game, Ability source) {
    StackObject stackObject = game.getState().getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    int numberOfTargets = 0;
    for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
        Mode mode = stackObject.getStackAbility().getModes().get(modeId);
        for (Target target : mode.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                if (numberOfTargets++ > 1) {
                    return false;
                }
                Permanent permanent = game.getPermanent(targetId);
                if (permanent == null || !permanent.isCreature(game)) {
                    return false;
                }
            }
        }
    }
    return numberOfTargets == 1;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) Mode(mage.abilities.Mode) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 15 with Mode

use of mage.abilities.Mode in project mage by magefree.

the class RadiantPerformerEffect method prepareCopiesWithTargets.

@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
    List<MageObjectReferencePredicate> predicates = new ArrayList<>();
    Ability ability = stackObject instanceof Spell ? ((Spell) stackObject).getSpellAbility() : (StackAbility) stackObject;
    UUID targeted = ability == null ? null : ability.getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    return predicates;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) Ability(mage.abilities.Ability) Target(mage.target.Target) java.util(java.util) CopySpellForEachItCouldTargetEffect(mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect) TargetStackObject(mage.target.TargetStackObject) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) CastFromHandSourcePermanentCondition(mage.abilities.condition.common.CastFromHandSourcePermanentCondition) SubType(mage.constants.SubType) Mode(mage.abilities.Mode) Player(mage.players.Player) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) FilterStackObject(mage.filter.FilterStackObject) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CastFromHandWatcher(mage.watchers.common.CastFromHandWatcher) Ability(mage.abilities.Ability) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Aggregations

Mode (mage.abilities.Mode)19 Target (mage.target.Target)16 UUID (java.util.UUID)11 Player (mage.players.Player)10 Spell (mage.game.stack.Spell)8 Ability (mage.abilities.Ability)7 StackObject (mage.game.stack.StackObject)7 Permanent (mage.game.permanent.Permanent)6 Effect (mage.abilities.effects.Effect)5 MageObject (mage.MageObject)4 MageObjectReference (mage.MageObjectReference)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 ArrayList (java.util.ArrayList)3 MageInt (mage.MageInt)3 CardImpl (mage.cards.CardImpl)3 CardSetInfo (mage.cards.CardSetInfo)3 CardType (mage.constants.CardType)3 SubType (mage.constants.SubType)3 java.util (java.util)2 AbilityImpl (mage.abilities.AbilityImpl)2