Search in sources :

Example 1 with CantBeBlockedSourceEffect

use of mage.abilities.effects.common.combat.CantBeBlockedSourceEffect in project mage by magefree.

the class OgreMarauderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player defender = game.getPlayer(defendingPlayerId);
    if (defender != null && sourceObject != null) {
        Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
        if (cost.canPay(source, source, defendingPlayerId, game) && defender.chooseUse(Outcome.LoseAbility, "Sacrifice a creature to prevent that " + sourceObject.getLogName() + " can't be blocked?", source, game)) {
            if (!cost.pay(source, game, source, defendingPlayerId, false, null)) {
                // cost was not payed - so source can't be blocked
                ContinuousEffect effect = new CantBeBlockedSourceEffect(Duration.EndOfTurn);
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) MageObject(mage.MageObject) CantBeBlockedSourceEffect(mage.abilities.effects.common.combat.CantBeBlockedSourceEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

UUID (java.util.UUID)1 MageObject (mage.MageObject)1 Cost (mage.abilities.costs.Cost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 CantBeBlockedSourceEffect (mage.abilities.effects.common.combat.CantBeBlockedSourceEffect)1 Player (mage.players.Player)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1