mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 21:02:08 -08:00
Refactor effects which disable the "legend rule" (#9662)
This commit is contained in:
parent
1fece87819
commit
3ed26a2b1f
15 changed files with 243 additions and 211 deletions
|
|
@ -0,0 +1,51 @@
|
|||
package mage.abilities.effects.common.ruleModifying;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class LegendRuleDoesntApplyEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public LegendRuleDoesntApplyEffect() {
|
||||
this(StaticFilters.FILTER_PERMANENTS);
|
||||
this.staticText = "the \"legend rule\" doesn't apply";
|
||||
}
|
||||
|
||||
public LegendRuleDoesntApplyEffect(FilterPermanent filter) {
|
||||
super(Duration.WhileOnBattlefield, Layer.RulesEffects, SubLayer.NA, Outcome.Detriment);
|
||||
staticText = "the \"legend rule\" doesn't apply to " + filter.getMessage();
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
private LegendRuleDoesntApplyEffect(final LegendRuleDoesntApplyEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LegendRuleDoesntApplyEffect copy() {
|
||||
return new LegendRuleDoesntApplyEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(
|
||||
filter, source.getControllerId(), source, game
|
||||
)) {
|
||||
permanent.setLegendRuleApplies(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package mage.filter.predicate.permanent;
|
||||
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum LegendRuleAppliesPredicate implements Predicate<Permanent> {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Permanent input, Game game) {
|
||||
return input.legendRuleApplies();
|
||||
}
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ import mage.filter.StaticFilters;
|
|||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.filter.predicate.permanent.LegendRuleAppliesPredicate;
|
||||
import mage.game.combat.Combat;
|
||||
import mage.game.command.*;
|
||||
import mage.game.command.dungeons.UndercityDungeon;
|
||||
|
|
@ -2478,7 +2479,7 @@ public abstract class GameImpl implements Game {
|
|||
somethingHappened = true;
|
||||
}
|
||||
}
|
||||
if (this.getState().isLegendaryRuleActive() && StaticFilters.FILTER_PERMANENT_LEGENDARY.match(perm, this)) {
|
||||
if (perm.isLegendary() && perm.legendRuleApplies()) {
|
||||
legendary.add(perm);
|
||||
}
|
||||
if (StaticFilters.FILTER_PERMANENT_EQUIPMENT.match(perm, this)) {
|
||||
|
|
@ -2571,22 +2572,24 @@ public abstract class GameImpl implements Game {
|
|||
filterLegendName.add(SuperType.LEGENDARY.getPredicate());
|
||||
filterLegendName.add(new NamePredicate(legend.getName()));
|
||||
filterLegendName.add(new ControllerIdPredicate(legend.getControllerId()));
|
||||
if (getBattlefield().contains(filterLegendName, legend.getControllerId(), null, this, 2)) {
|
||||
if (!replaceEvent(GameEvent.getEvent(GameEvent.EventType.DESTROY_PERMANENT_BY_LEGENDARY_RULE, legend.getId(), legend.getControllerId()))) {
|
||||
Player controller = this.getPlayer(legend.getControllerId());
|
||||
if (controller != null) {
|
||||
Target targetLegendaryToKeep = new TargetPermanent(filterLegendName);
|
||||
targetLegendaryToKeep.setTargetName(legend.getName() + " to keep (Legendary Rule)?");
|
||||
controller.chooseTarget(Outcome.Benefit, targetLegendaryToKeep, null, this);
|
||||
for (Permanent dupLegend : getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) {
|
||||
if (!targetLegendaryToKeep.getTargets().contains(dupLegend.getId())) {
|
||||
movePermanentToGraveyardWithInfo(dupLegend);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
filterLegendName.add(LegendRuleAppliesPredicate.instance);
|
||||
if (!getBattlefield().contains(filterLegendName, legend.getControllerId(), null, this, 2)) {
|
||||
continue;
|
||||
}
|
||||
Player controller = this.getPlayer(legend.getControllerId());
|
||||
if (controller == null) {
|
||||
continue;
|
||||
}
|
||||
Target targetLegendaryToKeep = new TargetPermanent(filterLegendName);
|
||||
targetLegendaryToKeep.setNotTarget(true);
|
||||
targetLegendaryToKeep.setTargetName(legend.getName() + " to keep (Legendary Rule)?");
|
||||
controller.choose(Outcome.Benefit, targetLegendaryToKeep, null, this);
|
||||
for (Permanent dupLegend : getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) {
|
||||
if (!targetLegendaryToKeep.getTargets().contains(dupLegend.getId())) {
|
||||
movePermanentToGraveyardWithInfo(dupLegend);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//704.5k - World Enchantments
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
private int stepNum = 0;
|
||||
private UUID turnId = null;
|
||||
private boolean extraTurn = false;
|
||||
private boolean legendaryRuleActive = true;
|
||||
private boolean gameOver;
|
||||
private boolean paused;
|
||||
private ContinuousEffects effects;
|
||||
|
|
@ -159,7 +158,6 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
this.turnNum = state.turnNum;
|
||||
this.stepNum = state.stepNum;
|
||||
this.extraTurn = state.extraTurn;
|
||||
this.legendaryRuleActive = state.legendaryRuleActive;
|
||||
this.effects = state.effects.copy();
|
||||
for (TriggeredAbility trigger : state.triggered) {
|
||||
this.triggered.add(trigger.copy());
|
||||
|
|
@ -227,7 +225,6 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
turnNum = 1;
|
||||
stepNum = 0;
|
||||
extraTurn = false;
|
||||
legendaryRuleActive = true;
|
||||
gameOver = false;
|
||||
specialActions.clear();
|
||||
cardState.clear();
|
||||
|
|
@ -264,7 +261,6 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
this.turnNum = state.turnNum;
|
||||
this.stepNum = state.stepNum;
|
||||
this.extraTurn = state.extraTurn;
|
||||
this.legendaryRuleActive = state.legendaryRuleActive;
|
||||
this.effects = state.effects;
|
||||
this.triggered = state.triggered;
|
||||
this.triggers = state.triggers;
|
||||
|
|
@ -1224,7 +1220,6 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
// All gained abilities have to be removed to prevent adding it multiple times
|
||||
triggers.removeAllGainedAbilities();
|
||||
getContinuousEffects().removeAllTemporaryEffects();
|
||||
this.setLegendaryRuleActive(true);
|
||||
for (CardState state : cardState.values()) {
|
||||
state.clearAbilities();
|
||||
}
|
||||
|
|
@ -1244,14 +1239,6 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
return this.paused;
|
||||
}
|
||||
|
||||
public boolean isLegendaryRuleActive() {
|
||||
return legendaryRuleActive;
|
||||
}
|
||||
|
||||
public void setLegendaryRuleActive(boolean legendaryRuleActive) {
|
||||
this.legendaryRuleActive = legendaryRuleActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only used for diagnostic purposes of tests
|
||||
*
|
||||
|
|
@ -1447,21 +1434,22 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
boolean isDaytime() {
|
||||
return isDaytime;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CardUtil.getTurnInfo(this);
|
||||
}
|
||||
|
||||
public boolean setReverseTurnOrder(boolean reverse){
|
||||
if(this.reverseTurnOrder&&reverse){
|
||||
public boolean setReverseTurnOrder(boolean reverse) {
|
||||
if (this.reverseTurnOrder && reverse) {
|
||||
this.reverseTurnOrder = false;
|
||||
} else {
|
||||
this.reverseTurnOrder = reverse;
|
||||
}
|
||||
return this.reverseTurnOrder;
|
||||
}
|
||||
public boolean getReverseTurnOrder(){
|
||||
|
||||
public boolean getReverseTurnOrder() {
|
||||
return this.reverseTurnOrder;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -222,6 +222,10 @@ public interface Permanent extends Card, Controllable {
|
|||
|
||||
boolean canLoyaltyBeUsed(Game game);
|
||||
|
||||
void setLegendRuleApplies(boolean legendRuleApplies);
|
||||
|
||||
boolean legendRuleApplies();
|
||||
|
||||
void resetControl();
|
||||
|
||||
boolean changeControllerId(UUID controllerId, Game game, Ability source);
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
protected int transformCount = 0;
|
||||
protected Map<String, String> info;
|
||||
protected int createOrder;
|
||||
protected boolean legendRuleApplies = true;
|
||||
|
||||
private static final List<UUID> emptyList = Collections.unmodifiableList(new ArrayList<UUID>());
|
||||
|
||||
|
|
@ -171,6 +172,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
this.bandedCards.addAll(permanent.bandedCards);
|
||||
this.timesLoyaltyUsed = permanent.timesLoyaltyUsed;
|
||||
this.loyaltyActivationsAvailable = permanent.loyaltyActivationsAvailable;
|
||||
this.legendRuleApplies = permanent.legendRuleApplies;
|
||||
this.transformCount = permanent.transformCount;
|
||||
|
||||
this.morphed = permanent.morphed;
|
||||
|
|
@ -214,6 +216,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
this.copy = false;
|
||||
this.goadingPlayers.clear();
|
||||
this.loyaltyActivationsAvailable = 1;
|
||||
this.legendRuleApplies = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -491,6 +494,16 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLegendRuleApplies(boolean legendRuleApplies) {
|
||||
this.legendRuleApplies = legendRuleApplies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean legendRuleApplies() {
|
||||
return this.legendRuleApplies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTapped() {
|
||||
return tapped;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue