rework effects which increase loyalty abilities (closes #9626)

This commit is contained in:
Evan Kranzler 2022-10-10 18:01:58 -04:00
parent 3fd3cb27e2
commit 09797d4cf6
9 changed files with 59 additions and 98 deletions

View file

@ -11,6 +11,7 @@ import mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetE
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.*; import mage.constants.*;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledPermanent; import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.AnotherPredicate; import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game; import mage.game.Game;
@ -112,21 +113,13 @@ class OathOfTeferiLoyaltyEffect extends ContinuousEffectImpl {
} }
@Override @Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); for (Permanent permanent : game.getBattlefield().getActivePermanents(
if (controller != null) { StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER,
controller.setLoyaltyUsePerTurn(Math.max(2, controller.getLoyaltyUsePerTurn())); source.getControllerId(), source, game
)) {
permanent.incrementLoyaltyActivationsAvailable(2);
} }
return true; return true;
} }
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.RulesEffects;
}
} }

View file

@ -1,9 +1,5 @@
package mage.cards.t; package mage.cards.t;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility; import mage.abilities.LoyaltyAbility;
import mage.abilities.common.BeginningOfEndStepTriggeredAbility; import mage.abilities.common.BeginningOfEndStepTriggeredAbility;
@ -16,14 +12,18 @@ import mage.abilities.effects.common.LoseLifeSourceControllerEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.*; import mage.constants.*;
import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.StackObject; import mage.game.stack.StackObject;
import mage.players.Player;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public final class TheChainVeil extends CardImpl { public final class TheChainVeil extends CardImpl {
@ -34,12 +34,14 @@ public final class TheChainVeil extends CardImpl {
// At the beginning of your end step, if you didn't activate a loyalty ability of a planeswalker this turn, you lose 2 life. // At the beginning of your end step, if you didn't activate a loyalty ability of a planeswalker this turn, you lose 2 life.
this.addAbility(new BeginningOfEndStepTriggeredAbility( this.addAbility(new BeginningOfEndStepTriggeredAbility(
Zone.BATTLEFIELD, new LoseLifeSourceControllerEffect(2), TargetController.YOU, TheChainVeilCondition.instance, false), new ActivatedLoyaltyAbilityWatcher()); new LoseLifeSourceControllerEffect(2), TargetController.YOU,
TheChainVeilCondition.instance, false
), new ActivatedLoyaltyAbilityWatcher());
// {4}, {T}: For each planeswalker you control, you may activate one of its loyalty abilities once this turn as though none of its loyalty abilities had been activated this turn. // {4}, {T}: For each planeswalker you control, you may activate one of its loyalty abilities once this turn as though none of its loyalty abilities had been activated this turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, Ability ability = new SimpleActivatedAbility(
new TheChainVeilIncreaseLoyaltyUseEffect(), new TheChainVeilIncreaseLoyaltyUseEffect(), new ManaCostsImpl<>("{4}")
new ManaCostsImpl<>("{4}")); );
ability.addCost(new TapSourceCost()); ability.addCost(new TapSourceCost());
this.addAbility(ability); this.addAbility(ability);
@ -65,7 +67,9 @@ class ActivatedLoyaltyAbilityWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) { if (event.getType() != GameEvent.EventType.ACTIVATED_ABILITY) {
return;
}
StackObject stackObject = game.getStack().getStackObject(event.getTargetId()); StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
if (stackObject != null if (stackObject != null
&& stackObject.getStackAbility() != null && stackObject.getStackAbility() != null
@ -73,7 +77,6 @@ class ActivatedLoyaltyAbilityWatcher extends Watcher {
playerIds.add(stackObject.getControllerId()); playerIds.add(stackObject.getControllerId());
} }
} }
}
@Override @Override
public void reset() { public void reset() {
@ -103,9 +106,11 @@ class TheChainVeilIncreaseLoyaltyUseEffect extends ContinuousEffectImpl {
@Override @Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId()); for (Permanent permanent : game.getBattlefield().getActivePermanents(
if (controller != null) { StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER,
controller.setLoyaltyUsePerTurn(controller.getLoyaltyUsePerTurn() + 1); source.getControllerId(), source, game
)) {
permanent.incrementLoyaltyActivationsAvailable();
} }
return true; return true;
} }
@ -122,26 +127,16 @@ class TheChainVeilIncreaseLoyaltyUseEffect extends ContinuousEffectImpl {
} }
enum TheChainVeilCondition implements Condition { enum TheChainVeilCondition implements Condition {
instance; instance;
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
ActivatedLoyaltyAbilityWatcher watcher = game.getState().getWatcher(ActivatedLoyaltyAbilityWatcher.class); ActivatedLoyaltyAbilityWatcher watcher = game.getState().getWatcher(ActivatedLoyaltyAbilityWatcher.class);
if (watcher != null) { return watcher != null && !watcher.activatedLoyaltyAbility(source.getControllerId());
if (!watcher.activatedLoyaltyAbility(source.getControllerId())) {
return true;
}
}
return false;
} }
@Override @Override
public String toString() { public String toString() {
return "if you didn't activate a loyalty ability of a planeswalker this turn"; return "if you didn't activate a loyalty ability of a planeswalker this turn";
} }
} }

View file

@ -1,24 +1,25 @@
package mage.cards.u; package mage.cards.u;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SagaAbility; import mage.abilities.common.SagaAbility;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect; import mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardsImpl;
import mage.constants.*;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.*;
import mage.filter.StaticFilters;
import mage.filter.common.FilterPlaneswalkerCard; import mage.filter.common.FilterPlaneswalkerCard;
import mage.filter.predicate.mageobject.ManaValuePredicate; import mage.filter.predicate.mageobject.ManaValuePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import java.util.UUID;
/** /**
*
* @author weirddan455 * @author weirddan455
*/ */
public final class UrzaAssemblesTheTitans extends CardImpl { public final class UrzaAssemblesTheTitans extends CardImpl {
@ -110,11 +111,12 @@ class UrzaAssemblesTheTitansLoyaltyEffect extends ContinuousEffectImpl {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); for (Permanent permanent : game.getBattlefield().getActivePermanents(
if (controller == null) { StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER,
return false; source.getControllerId(), source, game
)) {
permanent.incrementLoyaltyActivationsAvailable(2);
} }
controller.setLoyaltyUsePerTurn(Math.max(2, controller.getLoyaltyUsePerTurn()));
return true; return true;
} }
} }

View file

@ -3352,16 +3352,6 @@ public class TestPlayer implements Player {
computerPlayer.setLandsPerTurn(landsPerTurn); computerPlayer.setLandsPerTurn(landsPerTurn);
} }
@Override
public int getLoyaltyUsePerTurn() {
return computerPlayer.getLoyaltyUsePerTurn();
}
@Override
public void setLoyaltyUsePerTurn(int loyaltyUsePerTurn) {
computerPlayer.setLoyaltyUsePerTurn(loyaltyUsePerTurn);
}
@Override @Override
public int getMaxHandSize() { public int getMaxHandSize() {
return computerPlayer.getMaxHandSize(); return computerPlayer.getMaxHandSize();

View file

@ -275,16 +275,6 @@ public class PlayerStub implements Player {
} }
@Override
public int getLoyaltyUsePerTurn() {
return 0;
}
@Override
public void setLoyaltyUsePerTurn(int loyaltyUsePerTurn) {
}
@Override @Override
public int getMaxHandSize() { public int getMaxHandSize() {
return 0; return 0;

View file

@ -216,6 +216,8 @@ public interface Permanent extends Card, Controllable {
void incrementLoyaltyActivationsAvailable(); void incrementLoyaltyActivationsAvailable();
void incrementLoyaltyActivationsAvailable(int max);
void addLoyaltyUsed(); void addLoyaltyUsed();
boolean canLoyaltyBeUsed(Game game); boolean canLoyaltyBeUsed(Game game);

View file

@ -467,8 +467,15 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override @Override
public void incrementLoyaltyActivationsAvailable() { public void incrementLoyaltyActivationsAvailable() {
this.incrementLoyaltyActivationsAvailable(Integer.MAX_VALUE);
}
@Override
public void incrementLoyaltyActivationsAvailable(int max) {
if (this.loyaltyActivationsAvailable < max) {
this.loyaltyActivationsAvailable++; this.loyaltyActivationsAvailable++;
} }
}
@Override @Override
public void addLoyaltyUsed() { public void addLoyaltyUsed() {
@ -479,7 +486,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
public boolean canLoyaltyBeUsed(Game game) { public boolean canLoyaltyBeUsed(Game game) {
Player controller = game.getPlayer(controllerId); Player controller = game.getPlayer(controllerId);
if (controller != null) { if (controller != null) {
return Math.max(controller.getLoyaltyUsePerTurn(), loyaltyActivationsAvailable) > timesLoyaltyUsed; return loyaltyActivationsAvailable > timesLoyaltyUsed;
} }
return false; return false;
} }

View file

@ -52,8 +52,8 @@ public interface Player extends MageItem, Copyable<Player> {
* By default it is set to `allAbilities`, but can be changed by effects. * By default it is set to `allAbilities`, but can be changed by effects.
* E.g. Angel of Jubilation sets it to `nonSpellnonActivatedAbilities`, * E.g. Angel of Jubilation sets it to `nonSpellnonActivatedAbilities`,
* and Karn's Sylex sets it to `onlyManaAbilities`. * and Karn's Sylex sets it to `onlyManaAbilities`.
* * <p>
* * <p>
* Default is PayLifeCostLevel.allAbilities. * Default is PayLifeCostLevel.allAbilities.
*/ */
enum PayLifeCostLevel { enum PayLifeCostLevel {
@ -215,10 +215,6 @@ public interface Player extends MageItem, Copyable<Player> {
void setLandsPerTurn(int landsPerTurn); void setLandsPerTurn(int landsPerTurn);
int getLoyaltyUsePerTurn();
void setLoyaltyUsePerTurn(int loyaltyUsePerTurn);
int getMaxHandSize(); int getMaxHandSize();
void setMaxHandSize(int maxHandSize); void setMaxHandSize(int maxHandSize);

View file

@ -94,7 +94,6 @@ public abstract class PlayerImpl implements Player, Serializable {
protected Counters counters; protected Counters counters;
protected int landsPlayed; protected int landsPlayed;
protected int landsPerTurn = 1; protected int landsPerTurn = 1;
protected int loyaltyUsePerTurn = 1;
protected int maxHandSize = 7; protected int maxHandSize = 7;
protected int maxAttackedBy = Integer.MAX_VALUE; protected int maxAttackedBy = Integer.MAX_VALUE;
protected ManaPool manaPool; protected ManaPool manaPool;
@ -225,7 +224,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.landsPlayed = player.landsPlayed; this.landsPlayed = player.landsPlayed;
this.landsPerTurn = player.landsPerTurn; this.landsPerTurn = player.landsPerTurn;
this.loyaltyUsePerTurn = player.loyaltyUsePerTurn;
this.maxHandSize = player.maxHandSize; this.maxHandSize = player.maxHandSize;
this.maxAttackedBy = player.maxAttackedBy; this.maxAttackedBy = player.maxAttackedBy;
this.manaPool = player.manaPool.copy(); this.manaPool = player.manaPool.copy();
@ -326,7 +324,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.landsPlayed = player.getLandsPlayed(); this.landsPlayed = player.getLandsPlayed();
this.landsPerTurn = player.getLandsPerTurn(); this.landsPerTurn = player.getLandsPerTurn();
this.loyaltyUsePerTurn = player.getLoyaltyUsePerTurn();
this.maxHandSize = player.getMaxHandSize(); this.maxHandSize = player.getMaxHandSize();
this.maxAttackedBy = player.getMaxAttackedBy(); this.maxAttackedBy = player.getMaxAttackedBy();
this.manaPool = player.getManaPool().copy(); this.manaPool = player.getManaPool().copy();
@ -464,7 +461,6 @@ public abstract class PlayerImpl implements Player, Serializable {
public void reset() { public void reset() {
this.abilities.clear(); this.abilities.clear();
this.landsPerTurn = 1; this.landsPerTurn = 1;
this.loyaltyUsePerTurn = 1;
this.maxHandSize = 7; this.maxHandSize = 7;
this.maxAttackedBy = Integer.MAX_VALUE; this.maxAttackedBy = Integer.MAX_VALUE;
this.canGainLife = true; this.canGainLife = true;
@ -2317,16 +2313,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.landsPerTurn = landsPerTurn; this.landsPerTurn = landsPerTurn;
} }
@Override
public int getLoyaltyUsePerTurn() {
return this.loyaltyUsePerTurn;
}
@Override
public void setLoyaltyUsePerTurn(int loyaltyUsePerTurn) {
this.loyaltyUsePerTurn = loyaltyUsePerTurn;
}
@Override @Override
public int getMaxHandSize() { public int getMaxHandSize() {
return maxHandSize; return maxHandSize;