Simplified Mirri and Crawlspace by making their identical effects a common effect that is shared between them

This commit is contained in:
Alex Vasile 2022-08-22 21:39:28 -04:00
parent 7b64fc6ed4
commit 0a96201b6a
3 changed files with 78 additions and 100 deletions

View file

@ -0,0 +1,61 @@
package mage.abilities.effects.common.continuous;
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.game.Game;
import mage.players.Player;
/**
* @author LevelX2
*/
public class ChangeMaxNumberThatCanAttackSourceEffect extends ContinuousEffectImpl {
private final int maxAttackedBy;
public ChangeMaxNumberThatCanAttackSourceEffect(int maxAttackedBy) {
super(Duration.WhileOnBattlefield, Outcome.Benefit);
this.maxAttackedBy = maxAttackedBy;
staticText = "No more than " + (maxAttackedBy == 1 ? "one" : "two") + " creatures can attack you each combat";
}
public ChangeMaxNumberThatCanAttackSourceEffect(final ChangeMaxNumberThatCanAttackSourceEffect effect) {
super(effect);
this.maxAttackedBy = effect.maxAttackedBy;
}
@Override
public ChangeMaxNumberThatCanAttackSourceEffect copy() {
return new ChangeMaxNumberThatCanAttackSourceEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
if (layer != Layer.RulesEffects) {
return false;
}
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// Change the rule
if (controller.getMaxAttackedBy()> maxAttackedBy) {
controller.setMaxAttackedBy(maxAttackedBy);
}
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.RulesEffects;
}
}