Search in sources :

Example 41 with Ability

use of mage.abilities.Ability 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 42 with Ability

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

the class TakenoSamuraiGeneralEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (this.affectedObjectsSet) {
        for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
            // filter may not be used again, because object can have changed filter relevant attributes but still geets boost
            Permanent permanent = it.next().getPermanent(game);
            if (permanent != null) {
                for (Ability ability : permanent.getAbilities()) {
                    if (ability instanceof BushidoAbility) {
                        int value = ((BushidoAbility) ability).getValue(source, game, this);
                        permanent.addPower(value);
                        permanent.addToughness(value);
                    }
                }
            } else {
                // no longer on the battlefield, remove reference to object
                it.remove();
            }
        }
    } else {
        for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
            if (!perm.getId().equals(source.getSourceId())) {
                for (Ability ability : perm.getAbilities()) {
                    if (ability instanceof BushidoAbility) {
                        int value = ((BushidoAbility) ability).getValue(source, game, this);
                        perm.addPower(value);
                        perm.addToughness(value);
                    }
                }
            }
        }
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BushidoAbility(mage.abilities.keyword.BushidoAbility) Ability(mage.abilities.Ability) BushidoAbility(mage.abilities.keyword.BushidoAbility) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Example 43 with Ability

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

the class VesuvanDoppelgangerCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    final Permanent sourcePermanent = permanent;
    if (controller != null && sourcePermanent != null) {
        Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
        target.setRequired(true);
        if (source instanceof SimpleStaticAbility) {
            target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
            target.setRequired(false);
            target.setNotTarget(true);
        }
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            controller.choose(Outcome.Copy, target, source.getSourceId(), game);
            Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
            if (copyFromPermanent != null) {
                game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {

                    @Override
                    public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
                        blueprint.getColor().setColor(sourcePermanent.getColor(game));
                        blueprint.getAbilities().add(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new VesuvanDoppelgangerCopyEffect(), TargetController.YOU, true, false, rule2));
                        return true;
                    }
                });
                return true;
            }
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) MageObject(mage.MageObject) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Game(mage.game.Game) CopyApplier(mage.util.functions.CopyApplier) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 44 with Ability

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

the class ViashinoBeyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    TargetOpponent targetDefender = new TargetOpponent();
    if (controller != null) {
        game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game).stream().filter((permanent) -> (filter.match(permanent, source.getSourceId(), source.getControllerId(), game))).forEachOrdered((permanent) -> {
            if (game.getOpponents(controller.getId()).size() > 1) {
                controller.choose(outcome.Benefit, targetDefender, source.getSourceId(), game);
            } else {
                targetDefender.add(game.getOpponents(controller.getId()).iterator().next(), game);
            }
            if (permanent.canAttack(targetDefender.getFirstTarget(), game)) {
                controller.declareAttacker(permanent.getId(), targetDefender.getFirstTarget(), game, false);
            }
        });
    }
    return false;
}
Also used : TargetOpponent(mage.target.common.TargetOpponent) AttacksTriggeredAbility(mage.abilities.common.AttacksTriggeredAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) TargetController(mage.constants.TargetController) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent)

Example 45 with Ability

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

the class WordOfCommandTestFlashEffect method checkPlayability.

private boolean checkPlayability(Card card, Player targetPlayer, Game game, Ability source) {
    // check for card playability
    boolean canPlay = false;
    if (card.isLand(game)) {
        // we can't use getPlayableObjects(game) in here because it disallows playing lands outside the main step // TODO: replace to getPlayable() checks with disable step condition?
        if (targetPlayer.canPlayLand() && game.getActivePlayerId().equals(targetPlayer.getId())) {
            for (Ability ability : card.getAbilities(game)) {
                if (ability instanceof PlayLandAbility) {
                    if (!game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability, targetPlayer.getId()), ability, game, true)) {
                        canPlay = true;
                    }
                }
            }
        }
    } else {
        // Word of Command allows the chosen card to be played "as if it had flash" so we need to invoke such effect to bypass the check
        AsThoughEffectImpl effect2 = new WordOfCommandTestFlashEffect();
        game.addEffect(effect2, source);
        if (targetPlayer.getPlayableObjects(game, Zone.HAND).containsObject(card.getId())) {
            canPlay = true;
        }
        for (AsThoughEffect eff : game.getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.CAST_AS_INSTANT, game)) {
            if (eff instanceof WordOfCommandTestFlashEffect) {
                eff.discard();
                break;
            }
        }
    }
    return canPlay;
}
Also used : PlayLandAbility(mage.abilities.PlayLandAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) PlayLandAbility(mage.abilities.PlayLandAbility) AsThoughEffect(mage.abilities.effects.AsThoughEffect) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl)

Aggregations

Ability (mage.abilities.Ability)359 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)134 UUID (java.util.UUID)126 Game (mage.game.Game)123 OneShotEffect (mage.abilities.effects.OneShotEffect)98 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)87 CardSetInfo (mage.cards.CardSetInfo)87 CardImpl (mage.cards.CardImpl)85 CardType (mage.constants.CardType)78 Outcome (mage.constants.Outcome)76 Card (mage.cards.Card)72 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)64 MageObject (mage.MageObject)57 MageInt (mage.MageInt)47 SpellAbility (mage.abilities.SpellAbility)43 Objects (java.util.Objects)38 Zone (mage.constants.Zone)38 mage.constants (mage.constants)37 FilterCard (mage.filter.FilterCard)35