Search in sources :

Example 1 with LoyaltyAbility

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

the class PayVariableLoyaltyCost method getMaxValue.

@Override
public int getMaxValue(Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return 0;
    }
    int maxValue = permanent.getCounters(game).getCount(CounterType.LOYALTY.getName());
    // apply cost modification
    if (source instanceof LoyaltyAbility) {
        LoyaltyAbility copiedAbility = ((LoyaltyAbility) source).copy();
        permanent.adjustCosts(copiedAbility, game);
        game.getContinuousEffects().costModification(copiedAbility, game);
        for (Cost cost : copiedAbility.getCosts()) {
            if (cost instanceof PayVariableLoyaltyCost) {
                maxValue += ((PayVariableLoyaltyCost) cost).getCostModification();
            }
        }
    }
    return Math.max(0, maxValue);
}
Also used : Permanent(mage.game.permanent.Permanent) LoyaltyAbility(mage.abilities.LoyaltyAbility) Cost(mage.abilities.costs.Cost)

Example 2 with LoyaltyAbility

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

the class CostModificationTest method test_PlaneswalkerLoyalty_CostModification_Single.

@Test
public void test_PlaneswalkerLoyalty_CostModification_Single() {
    // Carth the Lion
    // Planeswalkers' loyalty abilities you activate cost an additional {+1} to activate.
    addCard(Zone.BATTLEFIELD, playerA, "Carth the Lion", 1);
    // 
    // Vivien Reid
    // 5 Loyalty
    // +1, -3, -8 Abilities
    addCard(Zone.BATTLEFIELD, playerA, "Vivien Reid", 1);
    // 
    // Huatli, Warrior Poet
    // 3 Loyalty
    // Testing X Ability
    // −X: Huatli, Warrior Poet deals X damage divided as you choose among any number of target creatures. Creatures dealt damage this way can’t block this turn.
    addCard(Zone.BATTLEFIELD, playerA, "Huatli, Warrior Poet", 1);
    // 
    // 2 toughness creatures for Huatli to kill
    addCard(Zone.BATTLEFIELD, playerB, "Grizzly Bears", 1);
    addCard(Zone.BATTLEFIELD, playerB, "Ghitu Lavarunner", 1);
    // Vivien: make cost +2 instead +1 (total 7 counters)
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: Look at the top four");
    setChoice(playerA, false);
    checkPermanentCounters("Vivien Reid counter check", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Vivien Reid", CounterType.LOYALTY, 7);
    // loyalty cost modification doesn't affect card rule's text, so it still shown an old cost value for a user
    // Vivien: make cost -7 instead -8
    activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "-8: You get an emblem");
    // Huatli: check x cost changes
    runCode("check x cost", 3, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
        Permanent huatli = game.getBattlefield().getAllActivePermanents().stream().filter(p -> p.getName().equals("Huatli, Warrior Poet")).findFirst().orElse(null);
        Assert.assertNotNull("must have huatli on battlefield", huatli);
        LoyaltyAbility ability = (LoyaltyAbility) huatli.getAbilities(game).stream().filter(a -> a.getRule().startsWith("-X: ")).findFirst().orElse(null);
        Assert.assertNotNull("must have loyalty ability", ability);
        // counters: 3
        // cost modification: +1
        // max possible X to pay: 3 + 1 = 4
        PayVariableLoyaltyCost cost = (PayVariableLoyaltyCost) ability.getCosts().get(0);
        Assert.assertEquals("must have max possible X as 4", 4, cost.getMaxValue(ability, game));
    });
    // Huatli: make x cost -3 instead -4
    activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "-X: {this} deals X damage divided as you choose");
    setChoice(playerA, "X=4");
    addTargetAmount(playerA, "Grizzly Bears", 2);
    addTargetAmount(playerA, "Ghitu Lavarunner", 2);
    setStrictChooseMode(true);
    setStopAt(3, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
    assertGraveyardCount(playerA, "Vivien Reid", 1);
    assertGraveyardCount(playerA, "Huatli, Warrior Poet", 1);
    assertGraveyardCount(playerB, "Grizzly Bears", 1);
    assertGraveyardCount(playerB, "Ghitu Lavarunner", 1);
}
Also used : LoyaltyAbility(mage.abilities.LoyaltyAbility) CardTestPlayerBase(org.mage.test.serverside.base.CardTestPlayerBase) Zone(mage.constants.Zone) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) Permanent(mage.game.permanent.Permanent) PhaseStep(mage.constants.PhaseStep) Test(org.junit.Test) Assert(org.junit.Assert) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) LoyaltyAbility(mage.abilities.LoyaltyAbility) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) Test(org.junit.Test)

Example 3 with LoyaltyAbility

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

the class RevelInSilenceEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
        return false;
    }
    switch(event.getType()) {
        case CAST_SPELL:
            return true;
        case ACTIVATE_ABILITY:
            Ability ability = game.getAbility(event.getTargetId(), event.getSourceId()).orElse(null);
            if (!(ability instanceof LoyaltyAbility)) {
                return false;
            }
            Permanent permanent = game.getPermanent(event.getSourceId());
            return permanent != null && permanent.isPlaneswalker(game);
    }
    return false;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) StackAbility(mage.game.stack.StackAbility) LoyaltyAbility(mage.abilities.LoyaltyAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) LoyaltyAbility(mage.abilities.LoyaltyAbility)

Example 4 with LoyaltyAbility

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

the class PayLoyaltyCost method canPay.

@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
    Permanent planeswalker = game.getPermanent(source.getSourceId());
    if (planeswalker == null) {
        return false;
    }
    int loyaltyCost = amount;
    // apply cost modification
    if (ability instanceof LoyaltyAbility) {
        LoyaltyAbility copiedAbility = ((LoyaltyAbility) ability).copy();
        planeswalker.adjustCosts(copiedAbility, game);
        game.getContinuousEffects().costModification(copiedAbility, game);
        loyaltyCost = 0;
        for (Cost cost : copiedAbility.getCosts()) {
            if (cost instanceof PayLoyaltyCost) {
                loyaltyCost += ((PayLoyaltyCost) cost).getAmount();
            }
        }
    }
    return planeswalker.getCounters(game).getCount(CounterType.LOYALTY) + loyaltyCost >= 0 && planeswalker.canLoyaltyBeUsed(game);
}
Also used : Permanent(mage.game.permanent.Permanent) LoyaltyAbility(mage.abilities.LoyaltyAbility) Cost(mage.abilities.costs.Cost)

Example 5 with LoyaltyAbility

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

the class RepeatedReverberationEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getPlayerId().equals(this.getControllerId())) {
        return false;
    }
    // activated ability
    if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
        StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
        if (stackAbility != null && stackAbility.getStackAbility() instanceof LoyaltyAbility) {
            this.getEffects().clear();
            this.addEffect(new RepeatedReverberationEffect().setTargetPointer(new FixedTarget(event.getTargetId(), game)));
            return true;
        }
    }
    // spell
    if (event.getType() == GameEvent.EventType.SPELL_CAST) {
        Spell spell = game.getStack().getSpell(event.getTargetId());
        if (spell != null && spell.isInstantOrSorcery(game)) {
            this.getEffects().clear();
            this.addEffect(new CopyTargetSpellEffect(true).setTargetPointer(new FixedTarget(event.getTargetId(), game)));
            this.addEffect(new CopyTargetSpellEffect(true).setTargetPointer(new FixedTarget(event.getTargetId(), game)));
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) LoyaltyAbility(mage.abilities.LoyaltyAbility) CopyTargetSpellEffect(mage.abilities.effects.common.CopyTargetSpellEffect) StackAbility(mage.game.stack.StackAbility) Spell(mage.game.stack.Spell)

Aggregations

LoyaltyAbility (mage.abilities.LoyaltyAbility)6 Permanent (mage.game.permanent.Permanent)5 StackAbility (mage.game.stack.StackAbility)3 Cost (mage.abilities.costs.Cost)2 Ability (mage.abilities.Ability)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 PayVariableLoyaltyCost (mage.abilities.costs.common.PayVariableLoyaltyCost)1 CopyTargetSpellEffect (mage.abilities.effects.common.CopyTargetSpellEffect)1 PhaseStep (mage.constants.PhaseStep)1 Zone (mage.constants.Zone)1 CounterType (mage.counters.CounterType)1 Spell (mage.game.stack.Spell)1 FixedTarget (mage.target.targetpointer.FixedTarget)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1 CardTestPlayerBase (org.mage.test.serverside.base.CardTestPlayerBase)1