From 09797d4cf6adef8ae791fafabeb0d772d9661fbe Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 10 Oct 2022 18:01:58 -0400 Subject: [PATCH] rework effects which increase loyalty abilities (closes #9626) --- Mage.Sets/src/mage/cards/o/OathOfTeferi.java | 21 +++---- Mage.Sets/src/mage/cards/t/TheChainVeil.java | 59 +++++++++---------- .../mage/cards/u/UrzaAssemblesTheTitans.java | 20 ++++--- .../java/org/mage/test/player/TestPlayer.java | 10 ---- .../java/org/mage/test/stub/PlayerStub.java | 10 ---- .../java/mage/game/permanent/Permanent.java | 2 + .../mage/game/permanent/PermanentImpl.java | 11 +++- Mage/src/main/java/mage/players/Player.java | 10 +--- .../main/java/mage/players/PlayerImpl.java | 14 ----- 9 files changed, 59 insertions(+), 98 deletions(-) diff --git a/Mage.Sets/src/mage/cards/o/OathOfTeferi.java b/Mage.Sets/src/mage/cards/o/OathOfTeferi.java index 3919a67b1e..6c090f76dc 100644 --- a/Mage.Sets/src/mage/cards/o/OathOfTeferi.java +++ b/Mage.Sets/src/mage/cards/o/OathOfTeferi.java @@ -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; - } } diff --git a/Mage.Sets/src/mage/cards/t/TheChainVeil.java b/Mage.Sets/src/mage/cards/t/TheChainVeil.java index 01ffec7138..30c758c53a 100644 --- a/Mage.Sets/src/mage/cards/t/TheChainVeil.java +++ b/Mage.Sets/src/mage/cards/t/TheChainVeil.java @@ -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,13 +67,14 @@ class ActivatedLoyaltyAbilityWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) { - StackObject stackObject = game.getStack().getStackObject(event.getTargetId()); - if (stackObject != null - && stackObject.getStackAbility() != null - && stackObject.getStackAbility() instanceof LoyaltyAbility) { - playerIds.add(stackObject.getControllerId()); - } + if (event.getType() != GameEvent.EventType.ACTIVATED_ABILITY) { + return; + } + StackObject stackObject = game.getStack().getStackObject(event.getTargetId()); + if (stackObject != null + && stackObject.getStackAbility() != null + && stackObject.getStackAbility() instanceof LoyaltyAbility) { + playerIds.add(stackObject.getControllerId()); } } @@ -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"; } - } diff --git a/Mage.Sets/src/mage/cards/u/UrzaAssemblesTheTitans.java b/Mage.Sets/src/mage/cards/u/UrzaAssemblesTheTitans.java index dd9d622478..ed937ffaeb 100644 --- a/Mage.Sets/src/mage/cards/u/UrzaAssemblesTheTitans.java +++ b/Mage.Sets/src/mage/cards/u/UrzaAssemblesTheTitans.java @@ -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; } } diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index ed12d94b48..df6f9a66a0 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -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(); diff --git a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java index fc24ddd487..05b735cf0b 100644 --- a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java +++ b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java @@ -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; diff --git a/Mage/src/main/java/mage/game/permanent/Permanent.java b/Mage/src/main/java/mage/game/permanent/Permanent.java index 14bb7bb007..89fcdc248c 100644 --- a/Mage/src/main/java/mage/game/permanent/Permanent.java +++ b/Mage/src/main/java/mage/game/permanent/Permanent.java @@ -216,6 +216,8 @@ public interface Permanent extends Card, Controllable { void incrementLoyaltyActivationsAvailable(); + void incrementLoyaltyActivationsAvailable(int max); + void addLoyaltyUsed(); boolean canLoyaltyBeUsed(Game game); diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 2f505bf0aa..00861bf1c6 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -467,7 +467,14 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { @Override public void incrementLoyaltyActivationsAvailable() { - this.loyaltyActivationsAvailable++; + this.incrementLoyaltyActivationsAvailable(Integer.MAX_VALUE); + } + + @Override + public void incrementLoyaltyActivationsAvailable(int max) { + if (this.loyaltyActivationsAvailable < max) { + this.loyaltyActivationsAvailable++; + } } @Override @@ -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; } diff --git a/Mage/src/main/java/mage/players/Player.java b/Mage/src/main/java/mage/players/Player.java index ee66cb4b58..e89d1fd037 100644 --- a/Mage/src/main/java/mage/players/Player.java +++ b/Mage/src/main/java/mage/players/Player.java @@ -51,9 +51,9 @@ public interface Player extends MageItem, Copyable { * Enum used to indicate what each player is allowed to spend life on. * 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`. - * - * + * and Karn's Sylex sets it to `onlyManaAbilities`. + *

+ *

* Default is PayLifeCostLevel.allAbilities. */ enum PayLifeCostLevel { @@ -215,10 +215,6 @@ public interface Player extends MageItem, Copyable { void setLandsPerTurn(int landsPerTurn); - int getLoyaltyUsePerTurn(); - - void setLoyaltyUsePerTurn(int loyaltyUsePerTurn); - int getMaxHandSize(); void setMaxHandSize(int maxHandSize); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 627217e477..627a6458e0 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -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;