Search in sources :

Example 11 with GainLifeEffect

use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.

the class OutcomesTest method test_FromAbility_Multi.

@Test
public void test_FromAbility_Multi() {
    Ability abilityGood = new SimpleStaticAbility(new GainLifeEffect(10));
    abilityGood.addEffect(new BoostSourceEffect(10, 10, Duration.EndOfTurn));
    abilityGood.addCustomOutcome(Outcome.Detriment);
    Assert.assertEquals(-1 + -1, abilityGood.getEffects().getOutcomeScore(abilityGood));
    Ability abilityBad = new SimpleStaticAbility(new DamageTargetEffect(10));
    abilityBad.addEffect(new ExileTargetEffect());
    abilityBad.addCustomOutcome(Outcome.Neutral);
    Assert.assertEquals(1 + 1, abilityBad.getEffects().getOutcomeScore(abilityBad));
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) LeavesBattlefieldTriggeredAbility(mage.abilities.common.LeavesBattlefieldTriggeredAbility) Ability(mage.abilities.Ability) BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) Test(org.junit.Test)

Example 12 with GainLifeEffect

use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.

the class SithEvokerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose mode");
        choice.setChoices(choices);
        if (!controller.choose(outcome, choice, game)) {
            return false;
        }
        Card sourceCard = game.getCard(source.getSourceId());
        if (sourceCard != null) {
            for (Object cost : source.getCosts()) {
                if (cost instanceof SacrificeTargetCost) {
                    Permanent p = (Permanent) game.getLastKnownInformation(((SacrificeTargetCost) cost).getPermanents().get(0).getId(), Zone.BATTLEFIELD);
                    if (p != null) {
                        String chosen = choice.getChoice();
                        switch(chosen) {
                            case "Gain life equal to creature's power":
                                new GainLifeEffect(p.getPower().getValue()).apply(game, source);
                                break;
                            default:
                                // "Gain life equal to creature's toughness"
                                new GainLifeEffect(p.getToughness().getValue()).apply(game, source);
                                break;
                        }
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ChoiceImpl(mage.choices.ChoiceImpl) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect) Card(mage.cards.Card)

Example 13 with GainLifeEffect

use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.

the class FlashConscriptionTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedEvent damageEvent = (DamagedEvent) event;
    if (damageEvent.isCombatDamage()) {
        if (event.getSourceId().equals(this.sourceId)) {
            this.getEffects().clear();
            this.getEffects().add(new GainLifeEffect(damageEvent.getAmount()));
            return true;
        }
    }
    return false;
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect)

Example 14 with GainLifeEffect

use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.

the class OrimsPrayerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    boolean applied = false;
    Player controller = game.getPlayer(getControllerId());
    if (controller == null) {
        return false;
    }
    int numberAttackingController = 0;
    for (UUID attackersId : game.getCombat().getAttackers()) {
        Permanent attackingCreature = game.getPermanent(attackersId);
        if (attackingCreature != null && game.getCombat().getDefenderId(attackersId) == this.getControllerId()) {
            numberAttackingController += 1;
            applied = true;
        }
    }
    if (applied && numberAttackingController > 0) {
        this.getEffects().clear();
        this.getEffects().add(new GainLifeEffect(numberAttackingController));
    }
    return applied;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect)

Example 15 with GainLifeEffect

use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.

the class ShadowgrangeArchfiendEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Permanent> toSacrifice = new ArrayList<>();
    // Iterate through each opponent
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        if (!controller.hasOpponent(playerId, game)) {
            continue;
        }
        Player opponent = game.getPlayer(playerId);
        if (opponent == null) {
            continue;
        }
        int greatestPower = Integer.MIN_VALUE;
        int numberOfCreatures = 0;
        Permanent creatureToSacrifice = null;
        // Iterature through each creature
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
            if (permanent.getPower().getValue() > greatestPower) {
                greatestPower = permanent.getPower().getValue();
                numberOfCreatures = 1;
                creatureToSacrifice = permanent;
            } else if (permanent.getPower().getValue() == greatestPower) {
                numberOfCreatures++;
            }
        }
        // If multiple creatures are tied for having the greatest power
        if (numberOfCreatures > 1) {
            FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
            filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
            Target target = new TargetControlledCreaturePermanent(filter);
            if (opponent.choose(outcome, target, playerId, game)) {
                creatureToSacrifice = game.getPermanent(target.getFirstTarget());
            }
        }
        if (creatureToSacrifice != null) {
            toSacrifice.add(creatureToSacrifice);
        }
    }
    int greatestPowerAmongAllCreaturesSacked = Integer.MIN_VALUE;
    int powerOfCurrentCreature;
    // Sack the creatures and save the greaterest power amoung those which were sacked
    for (Permanent permanent : toSacrifice) {
        powerOfCurrentCreature = permanent.getPower().getValue();
        // Try to sack it
        if (permanent.sacrifice(source, game)) {
            if (powerOfCurrentCreature > greatestPowerAmongAllCreaturesSacked) {
                greatestPowerAmongAllCreaturesSacked = powerOfCurrentCreature;
            }
        }
    }
    // Gain life equal to the power of greatest creature sacked, if it is positive
    if (greatestPowerAmongAllCreaturesSacked > 0) {
        new GainLifeEffect(greatestPowerAmongAllCreaturesSacked).apply(game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect)

Aggregations

GainLifeEffect (mage.abilities.effects.common.GainLifeEffect)27 Permanent (mage.game.permanent.Permanent)11 Ability (mage.abilities.Ability)7 LeavesBattlefieldTriggeredAbility (mage.abilities.common.LeavesBattlefieldTriggeredAbility)6 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)6 Player (mage.players.Player)6 Test (org.junit.Test)6 DamagedEvent (mage.game.events.DamagedEvent)5 UUID (java.util.UUID)4 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)4 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)4 BoostSourceEffect (mage.abilities.effects.common.continuous.BoostSourceEffect)4 RevealTargetFromHandCost (mage.abilities.costs.common.RevealTargetFromHandCost)2 Choice (mage.choices.Choice)2 TargetCardInHand (mage.target.common.TargetCardInHand)2 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)2 ArrayList (java.util.ArrayList)1 MageInt (mage.MageInt)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)1