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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations