mirror of
https://github.com/correl/mage.git
synced 2025-04-08 17:00:07 -09:00
Simplified Mirri and Crawlspace by making their identical effects a common effect that is shared between them
This commit is contained in:
parent
7b64fc6ed4
commit
0a96201b6a
3 changed files with 78 additions and 100 deletions
Mage.Sets/src/mage/cards
Mage/src/main/java/mage/abilities/effects/common/continuous
|
@ -5,6 +5,7 @@ import java.util.UUID;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.common.continuous.ChangeMaxNumberThatCanAttackSourceEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
|
@ -21,7 +22,7 @@ public final class Crawlspace extends CardImpl {
|
|||
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{3}");
|
||||
|
||||
// No more than two creatures can attack you each combat.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ChangeMaxAttackedBySourceEffect(2)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ChangeMaxNumberThatCanAttackSourceEffect(2)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,50 +35,3 @@ public final class Crawlspace extends CardImpl {
|
|||
return new Crawlspace(this);
|
||||
}
|
||||
}
|
||||
|
||||
class ChangeMaxAttackedBySourceEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final int maxAttackedBy;
|
||||
|
||||
public ChangeMaxAttackedBySourceEffect(int maxAttackedBy) {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Benefit);
|
||||
this.maxAttackedBy = maxAttackedBy;
|
||||
staticText = "No more than two creatures can attack you each combat";
|
||||
}
|
||||
|
||||
public ChangeMaxAttackedBySourceEffect(final ChangeMaxAttackedBySourceEffect effect) {
|
||||
super(effect);
|
||||
this.maxAttackedBy = effect.maxAttackedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeMaxAttackedBySourceEffect copy() {
|
||||
return new ChangeMaxAttackedBySourceEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
|
||||
switch (layer) {
|
||||
case RulesEffects:
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
// Change the rule
|
||||
if (controller.getMaxAttackedBy()> maxAttackedBy) {
|
||||
controller.setMaxAttackedBy(maxAttackedBy);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLayer(Layer layer) {
|
||||
return layer == Layer.RulesEffects;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import mage.abilities.decorator.ConditionalContinuousEffect;
|
|||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.RestrictionEffect;
|
||||
import mage.abilities.effects.common.AddContinuousEffectToGame;
|
||||
import mage.abilities.effects.common.continuous.ChangeMaxNumberThatCanAttackSourceEffect;
|
||||
import mage.abilities.keyword.FirstStrikeAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
|
@ -41,7 +42,7 @@ public final class MirriWeatherlightDuelist extends CardImpl {
|
|||
|
||||
// As long as Mirri, Weatherlight Duelist is tapped, no more than one creature can attack you each combat.
|
||||
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(
|
||||
new MirriWeatherlightDuelistAttackRestrictionEffect(1), SourceTappedCondition.TAPPED,
|
||||
new ChangeMaxNumberThatCanAttackSourceEffect(1), SourceTappedCondition.TAPPED,
|
||||
"As long as {this} is tapped, no more than one creature can attack you each combat."));
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
@ -82,59 +83,21 @@ class MirriWeatherlightDuelistBlockRestrictionEffect extends RestrictionEffect {
|
|||
if (attacker == null) {
|
||||
return true;
|
||||
}
|
||||
for (UUID creatureId : game.getCombat().getBlockers()) {
|
||||
Permanent existingBlocker = game.getPermanent(creatureId);
|
||||
if (game.getPlayer(existingBlocker.getControllerId()).hasOpponent(attacker.getControllerId(), game) && existingBlocker.isControlledBy(newBlocker.getControllerId())) {
|
||||
Player controller = game.getPlayer(attacker.getControllerId());
|
||||
if (controller == null) {
|
||||
return true; // Supposed to return false since without the controller this effect should not restrict blockers
|
||||
}
|
||||
|
||||
for (UUID existingBlockerId : game.getCombat().getBlockers()) {
|
||||
Permanent existingBlocker = game.getPermanent(existingBlockerId);
|
||||
if (existingBlocker == null) {
|
||||
continue;
|
||||
}
|
||||
if (controller.hasOpponent(existingBlocker.getControllerId(), game)
|
||||
&& existingBlocker.isControlledBy(newBlocker.getControllerId())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class MirriWeatherlightDuelistAttackRestrictionEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final int maxAttackedBy;
|
||||
|
||||
public MirriWeatherlightDuelistAttackRestrictionEffect(int maxAttackedBy) {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Benefit);
|
||||
this.maxAttackedBy = maxAttackedBy;
|
||||
staticText = "No more than one creature can attack you each combat";
|
||||
}
|
||||
|
||||
public MirriWeatherlightDuelistAttackRestrictionEffect(final MirriWeatherlightDuelistAttackRestrictionEffect effect) {
|
||||
super(effect);
|
||||
this.maxAttackedBy = effect.maxAttackedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MirriWeatherlightDuelistAttackRestrictionEffect copy() {
|
||||
return new MirriWeatherlightDuelistAttackRestrictionEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
|
||||
switch (layer) {
|
||||
case RulesEffects:
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
// Change the rule
|
||||
if (controller.getMaxAttackedBy() > maxAttackedBy) {
|
||||
controller.setMaxAttackedBy(maxAttackedBy);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLayer(Layer layer) {
|
||||
return layer == Layer.RulesEffects;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue