Search in sources :

Example 1 with Outcome

use of mage.constants.Outcome in project mage by magefree.

the class CelestialJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    Map<Integer, List<Permanent>> powerMap = permanents.stream().collect(Collectors.toMap(permanent -> permanent.getPower().getValue(), permanent -> Arrays.asList(permanent), (a1, a2) -> {
        a1.addAll(a2);
        return a1;
    }));
    Set<UUID> toKeep = new HashSet<>();
    for (Map.Entry<Integer, List<Permanent>> entry : powerMap.entrySet()) {
        if (entry.getValue().size() == 1) {
            toKeep.add(entry.getValue().get(0).getId());
            continue;
        }
        FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save");
        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey()));
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        toKeep.add(target.getFirstTarget());
    }
    for (Permanent permanent : permanents) {
        if (!toKeep.contains(permanent.getId())) {
            permanent.destroy(source, game);
        }
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 2 with Outcome

use of mage.constants.Outcome in project mage by magefree.

the class PrimalEmpathyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int highestPower = game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(0);
    boolean flag = game.getBattlefield().getAllActivePermanents(source.getControllerId()).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).anyMatch(i -> i >= highestPower);
    if (flag) {
        return player.drawCards(1, source, game) > 0;
    }
    Target target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
Also used : Target(mage.target.Target) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) TargetController(mage.constants.TargetController) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MageInt(mage.MageInt) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 3 with Outcome

use of mage.constants.Outcome in project mage by magefree.

the class SparkFiendUpkeepEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int roll = controller.rollDice(outcome, source, game, 6, 2, 0).stream().mapToInt(x -> x).sum();
        MageObject mageObject = game.getObject(source.getSourceId());
        if (mageObject instanceof Permanent) {
            Permanent sourcePermanent = (Permanent) mageObject;
            if (roll == 2 || roll == 3 || roll == 12) {
                // sacrifice
                sourcePermanent.sacrifice(source, game);
            } else if (roll == 7 || roll == 11) {
                // don't roll again
                game.getState().setValue("SparkFiend" + source.getSourceId().toString(), 0);
                // might apply if this ability was copied
                sourcePermanent.addInfo("roll counter", CardUtil.addToolTipMarkTags(""), game);
            } else {
                // note that total
                game.getState().setValue("SparkFiend" + source.getSourceId().toString(), roll);
                sourcePermanent.addInfo("roll counter", CardUtil.addToolTipMarkTags("Noted roll: " + roll), game);
            }
        }
        return true;
    }
    return false;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) TargetController(mage.constants.TargetController) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) MageObject(mage.MageObject) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 4 with Outcome

use of mage.constants.Outcome in project mage by magefree.

the class CopyPermanentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId());
    if (sourcePermanent == null) {
        sourcePermanent = game.getObject(source.getSourceId());
    }
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    Permanent copyFromPermanent = null;
    if (useTargetOfAbility) {
        copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    } else {
        Target target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            controller.choose(Outcome.Copy, target, source.getSourceId(), game);
            copyFromPermanent = game.getPermanent(target.getFirstTarget());
        }
    }
    if (copyFromPermanent == null) {
        return true;
    }
    bluePrintPermanent = game.copyPermanent(duration, copyFromPermanent, sourcePermanent.getId(), source, applier);
    if (bluePrintPermanent == null) {
        return false;
    }
    // if object is a copy of an aura, it needs to attach again for new target
    if (!bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
        return true;
    }
    // copied from mage.cards.c.CopyEnchantment.java
    // permanent can be attached (Estrid's Mask) or enchant (Utopia Sprawl)
    // TODO: fix Animate Dead -- it's can't be copied (can't retarget)
    Outcome auraOutcome = Outcome.BoostCreature;
    Target auraTarget = null;
    // attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
    for (Ability ability : bluePrintPermanent.getAbilities()) {
        if (!(ability instanceof SpellAbility)) {
            continue;
        }
        auraOutcome = ability.getEffects().getOutcome(ability);
        for (Effect effect : ability.getEffects()) {
            if (!(effect instanceof AttachEffect)) {
                continue;
            }
            if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
                auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
            }
        }
    }
    // enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
    if (auraTarget == null) {
        for (Ability ability : bluePrintPermanent.getAbilities()) {
            if (!(ability instanceof EnchantAbility)) {
                continue;
            }
            auraOutcome = ability.getEffects().getOutcome(ability);
            if (ability.getTargets().size() > 0) {
                // Animate Dead don't have targets
                auraTarget = ability.getTargets().get(0);
            }
        }
    }
    /* if this is a copy of a copy, the copy's target has been
         * copied and needs to be cleared
         */
    if (auraTarget == null) {
        return true;
    }
    // clear selected target
    if (auraTarget.getFirstTarget() != null) {
        auraTarget.remove(auraTarget.getFirstTarget());
    }
    // select new target
    auraTarget.setNotTarget(true);
    if (!controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
        return true;
    }
    UUID targetId = auraTarget.getFirstTarget();
    Permanent targetPermanent = game.getPermanent(targetId);
    Player targetPlayer = game.getPlayer(targetId);
    if (targetPermanent != null) {
        targetPermanent.addAttachment(sourcePermanent.getId(), source, game);
    } else if (targetPlayer != null) {
        targetPlayer.addAttachment(sourcePermanent.getId(), source, game);
    } else {
        return false;
    }
    return true;
}
Also used : EnchantAbility(mage.abilities.keyword.EnchantAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Outcome(mage.constants.Outcome) MageObject(mage.MageObject) SpellAbility(mage.abilities.SpellAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) EnchantAbility(mage.abilities.keyword.EnchantAbility) UUID(java.util.UUID)

Example 5 with Outcome

use of mage.constants.Outcome in project mage by magefree.

the class BucknardsEverfullPurseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    new TreasureToken().putOntoBattlefield(player.rollDice(outcome, source, game, 4), game, source, source.getControllerId());
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (permanent == null) {
        return true;
    }
    UUID playerToRightId = game.getState().getPlayersInRange(source.getControllerId(), game).stream().reduce((u1, u2) -> u2).orElse(null);
    if (playerToRightId == null) {
        return false;
    }
    game.addEffect(new GainControlTargetEffect(Duration.Custom, true, playerToRightId).setTargetPointer(new FixedTarget(permanent, game)), source);
    return true;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Duration(mage.constants.Duration) Game(mage.game.Game) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TreasureToken(mage.game.permanent.token.TreasureToken) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TreasureToken(mage.game.permanent.token.TreasureToken) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Aggregations

Outcome (mage.constants.Outcome)20 Player (mage.players.Player)19 Ability (mage.abilities.Ability)16 OneShotEffect (mage.abilities.effects.OneShotEffect)16 CardType (mage.constants.CardType)14 Game (mage.game.Game)14 UUID (java.util.UUID)13 CardImpl (mage.cards.CardImpl)13 CardSetInfo (mage.cards.CardSetInfo)13 Permanent (mage.game.permanent.Permanent)12 FilterPermanent (mage.filter.FilterPermanent)6 Target (mage.target.Target)6 Collectors (java.util.stream.Collectors)5 MageInt (mage.MageInt)5 MageObject (mage.MageObject)5 SubType (mage.constants.SubType)5 SpellAbility (mage.abilities.SpellAbility)4 Zone (mage.constants.Zone)4 CounterType (mage.counters.CounterType)4 TargetPermanent (mage.target.TargetPermanent)4