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.CardSetInfo;
import mage.constants.*;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game;
@ -112,21 +113,13 @@ class OathOfTeferiLoyaltyEffect extends ContinuousEffectImpl {
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.setLoyaltyUsePerTurn(Math.max(2, controller.getLoyaltyUsePerTurn()));
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(
StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER,
source.getControllerId(), source, game
)) {
permanent.incrementLoyaltyActivationsAvailable(2);
}
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;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.common.BeginningOfEndStepTriggeredAbility;
@ -16,30 +12,36 @@ import mage.abilities.effects.common.LoseLifeSourceControllerEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.StackObject;
import mage.players.Player;
import mage.watchers.Watcher;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class TheChainVeil extends CardImpl {
public TheChainVeil(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{4}");
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
addSuperType(SuperType.LEGENDARY);
// 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(
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.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
new TheChainVeilIncreaseLoyaltyUseEffect(),
new ManaCostsImpl<>("{4}"));
Ability ability = new SimpleActivatedAbility(
new TheChainVeilIncreaseLoyaltyUseEffect(), new ManaCostsImpl<>("{4}")
);
ability.addCost(new TapSourceCost());
this.addAbility(ability);
@ -65,7 +67,9 @@ class ActivatedLoyaltyAbilityWatcher extends Watcher {
@Override
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());
if (stackObject != null
&& stackObject.getStackAbility() != null
@ -73,7 +77,6 @@ class ActivatedLoyaltyAbilityWatcher extends Watcher {
playerIds.add(stackObject.getControllerId());
}
}
}
@Override
public void reset() {
@ -103,9 +106,11 @@ class TheChainVeilIncreaseLoyaltyUseEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.setLoyaltyUsePerTurn(controller.getLoyaltyUsePerTurn() + 1);
for (Permanent permanent : game.getBattlefield().getActivePermanents(
StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER,
source.getControllerId(), source, game
)) {
permanent.incrementLoyaltyActivationsAvailable();
}
return true;
}
@ -122,26 +127,16 @@ class TheChainVeilIncreaseLoyaltyUseEffect extends ContinuousEffectImpl {
}
enum TheChainVeilCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
ActivatedLoyaltyAbilityWatcher watcher = game.getState().getWatcher(ActivatedLoyaltyAbilityWatcher.class);
if (watcher != null) {
if (!watcher.activatedLoyaltyAbility(source.getControllerId())) {
return true;
}
}
return false;
return watcher != null && !watcher.activatedLoyaltyAbility(source.getControllerId());
}
@Override
public String toString() {
return "if you didn't activate a loyalty ability of a planeswalker this turn";
}
}

View file

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

View file

@ -3352,16 +3352,6 @@ public class TestPlayer implements Player {
computerPlayer.setLandsPerTurn(landsPerTurn);
}
@Override
public int getLoyaltyUsePerTurn() {
return computerPlayer.getLoyaltyUsePerTurn();
}
@Override
public void setLoyaltyUsePerTurn(int loyaltyUsePerTurn) {
computerPlayer.setLoyaltyUsePerTurn(loyaltyUsePerTurn);
}
@Override
public int 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
public int getMaxHandSize() {
return 0;

View file

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

View file

@ -467,8 +467,15 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public void incrementLoyaltyActivationsAvailable() {
this.incrementLoyaltyActivationsAvailable(Integer.MAX_VALUE);
}
@Override
public void incrementLoyaltyActivationsAvailable(int max) {
if (this.loyaltyActivationsAvailable < max) {
this.loyaltyActivationsAvailable++;
}
}
@Override
public void addLoyaltyUsed() {
@ -479,7 +486,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
public boolean canLoyaltyBeUsed(Game game) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
return Math.max(controller.getLoyaltyUsePerTurn(), loyaltyActivationsAvailable) > timesLoyaltyUsed;
return loyaltyActivationsAvailable > timesLoyaltyUsed;
}
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.
* E.g. Angel of Jubilation sets it to `nonSpellnonActivatedAbilities`,
* and Karn's Sylex sets it to `onlyManaAbilities`.
*
*
* <p>
* <p>
* Default is PayLifeCostLevel.allAbilities.
*/
enum PayLifeCostLevel {
@ -215,10 +215,6 @@ public interface Player extends MageItem, Copyable<Player> {
void setLandsPerTurn(int landsPerTurn);
int getLoyaltyUsePerTurn();
void setLoyaltyUsePerTurn(int loyaltyUsePerTurn);
int getMaxHandSize();
void setMaxHandSize(int maxHandSize);

View file

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