Search in sources :

Example 26 with Ability

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

the class ComeuppanceEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    if (preventionData.getPreventedDamage() > 0) {
        MageObject damageDealingObject = game.getObject(event.getSourceId());
        UUID objectControllerId = null;
        if (damageDealingObject instanceof Permanent) {
            if (damageDealingObject.isCreature(game)) {
                ((Permanent) damageDealingObject).damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
            } else {
                objectControllerId = ((Permanent) damageDealingObject).getControllerId();
            }
        } else if (damageDealingObject instanceof Ability) {
            objectControllerId = ((Ability) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Spell) {
            objectControllerId = ((Spell) damageDealingObject).getControllerId();
        }
        if (objectControllerId != null) {
            Player objectController = game.getPlayer(objectControllerId);
            if (objectController != null) {
                objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Ability(mage.abilities.Ability) PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 27 with Ability

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

the class FaithsShieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        if (FatefulHourCondition.instance.apply(game, source)) {
            ChoiceColor choice = new ChoiceColor();
            if (!controller.choose(Outcome.Protect, choice, game)) {
                return false;
            }
            if (choice.getColor() != null) {
                game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
                FilterCard filter = new FilterCard();
                filter.add(new ColorPredicate(choice.getColor()));
                filter.setMessage(choice.getChoice());
                Ability ability = new ProtectionAbility(filter);
                game.addEffect(new GainAbilityControlledEffect(ability, Duration.EndOfTurn), source);
                game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
                return true;
            }
        } else {
            game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) GainProtectionFromColorTargetEffect(mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) MageObject(mage.MageObject) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ChoiceColor(mage.choices.ChoiceColor) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Example 28 with Ability

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

the class GigantoplasmCopyApplier method apply.

@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
    DynamicValue variableMana = ManacostVariableValue.REGULAR;
    Effect effect = new SetPowerToughnessSourceEffect(variableMana, Duration.WhileOnBattlefield, SubLayer.SetPT_7b);
    effect.setText("This creature has base power and toughness X/X");
    Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{X}"));
    blueprint.getAbilities().add(ability);
    return true;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) EntersBattlefieldAbility(mage.abilities.common.EntersBattlefieldAbility) Ability(mage.abilities.Ability) SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) CopyPermanentEffect(mage.abilities.effects.common.CopyPermanentEffect) SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Effect(mage.abilities.effects.Effect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) DynamicValue(mage.abilities.dynamicvalue.DynamicValue)

Example 29 with Ability

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

the class GisaGloriousResurrectorReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Ability exiledWithSource = (Ability) game.getState().getValue("GisaGloriousResurrectorExile" + source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()));
    if (exiledWithSource == null) {
        return false;
    }
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, exiledWithSource));
    if (player == null || exileZone == null || exileZone.isEmpty()) {
        return false;
    }
    Cards cards = new CardsImpl(exileZone.getCards(StaticFilters.FILTER_CARD_CREATURE, game));
    if (cards.isEmpty()) {
        return false;
    }
    player.moveCards(cards, Zone.BATTLEFIELD, source, game);
    cards.retainZone(Zone.BATTLEFIELD, game);
    if (cards.isEmpty()) {
        return false;
    }
    game.addEffect(new GainAbilityTargetEffect(new DecayedAbility(), Duration.Custom).setTargetPointer(new FixedTargets(cards, game)), source);
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) DecayedAbility(mage.abilities.keyword.DecayedAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ExileZone(mage.game.ExileZone) DecayedAbility(mage.abilities.keyword.DecayedAbility) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 30 with Ability

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

the class HeliodsPunishmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourceEnchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourceEnchantment != null && sourceEnchantment.getAttachedTo() != null) {
        Permanent attachedTo = game.getPermanent(sourceEnchantment.getAttachedTo());
        if (attachedTo != null) {
            attachedTo.removeAllAbilities(source.getSourceId(), game);
            HeliodsPunishmentEffect effect = new HeliodsPunishmentEffect(sourceEnchantment.getName());
            Ability ability = new SimpleActivatedAbility(effect, new TapSourceCost());
            effect.setSourceEnchantment(sourceEnchantment.getId());
            attachedTo.addAbility(ability, source.getSourceId(), game);
        }
    }
    return true;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EntersBattlefieldAbility(mage.abilities.common.EntersBattlefieldAbility) EnchantAbility(mage.abilities.keyword.EnchantAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TapSourceCost(mage.abilities.costs.common.TapSourceCost)

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