mirror of
https://github.com/correl/mage.git
synced 2025-04-07 13:01:06 -09:00
-don't static import static filters
-use existing choose color and gain protection from color attached effects -update naming and add null check for AttachedToCreatureSourceTriggeredAbility
This commit is contained in:
parent
c567fc2ee1
commit
874ff7179f
5 changed files with 25 additions and 86 deletions
Mage.Sets/src/mage/cards
Mage.Tests/src/test/java/org/mage/test/cards/single/c20
Mage/src/main/java/mage/abilities
common
effects/common/continuous
|
@ -1,15 +1,19 @@
|
||||||
package mage.cards.s;
|
package mage.cards.s;
|
||||||
|
|
||||||
import mage.abilities.common.AttachedToCreatureTriggeredAbility;
|
import mage.abilities.common.AttachedToCreatureSourceTriggeredAbility;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.costs.mana.GenericManaCost;
|
import mage.abilities.costs.mana.GenericManaCost;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
|
import mage.abilities.effects.common.ChooseColorEffect;
|
||||||
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
|
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
|
||||||
import mage.abilities.effects.common.continuous.GainProtectionFromColorAttachedEffect;
|
import mage.abilities.effects.keyword.ProtectionChosenColorAttachedEffect;
|
||||||
import mage.abilities.keyword.EquipAbility;
|
import mage.abilities.keyword.EquipAbility;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.CardType;
|
||||||
|
import mage.constants.Outcome;
|
||||||
|
import mage.constants.SubType;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -25,13 +29,15 @@ public final class SanctuaryBlade extends CardImpl {
|
||||||
this.subtype.add(SubType.EQUIPMENT);
|
this.subtype.add(SubType.EQUIPMENT);
|
||||||
|
|
||||||
// As Sanctuary Blade becomes attached to a creature, choose a color.
|
// As Sanctuary Blade becomes attached to a creature, choose a color.
|
||||||
GainProtectionFromColorAttachedEffect protectionEffect = new GainProtectionFromColorAttachedEffect(Duration.WhileOnBattlefield);
|
this.addAbility(new AttachedToCreatureSourceTriggeredAbility(new ChooseColorEffect(Outcome.Benefit), false));
|
||||||
this.addAbility(new AttachedToCreatureTriggeredAbility(protectionEffect, false));
|
|
||||||
|
|
||||||
// Equipped creature gets +2/+0 and has protection from the last chosen color.
|
// Equipped creature gets +2/+0
|
||||||
Effect boostEffect = new BoostEquippedEffect(2, 0);
|
Effect boostEffect = new BoostEquippedEffect(2, 0);
|
||||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, boostEffect));
|
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, boostEffect));
|
||||||
|
|
||||||
|
// and has protection from the last chosen color
|
||||||
|
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ProtectionChosenColorAttachedEffect(false)));
|
||||||
|
|
||||||
// Equip {3}
|
// Equip {3}
|
||||||
this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(3)));
|
this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(3)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,12 @@ import mage.cards.CardSetInfo;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.SubType;
|
import mage.constants.SubType;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
|
import mage.filter.StaticFilters;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static mage.filter.StaticFilters.FILTER_CARD_LAND;
|
|
||||||
import static mage.filter.StaticFilters.FILTER_LAND;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author htrajan
|
* @author htrajan
|
||||||
|
@ -56,7 +54,7 @@ public final class VergeRangers extends CardImpl {
|
||||||
class VergeRangersEffect extends PlayTheTopCardEffect {
|
class VergeRangersEffect extends PlayTheTopCardEffect {
|
||||||
|
|
||||||
public VergeRangersEffect() {
|
public VergeRangersEffect() {
|
||||||
super(FILTER_CARD_LAND);
|
super(StaticFilters.FILTER_CARD_LAND);
|
||||||
staticText = "As long as an opponent controls more lands than you, you may play lands from the top of your library.";
|
staticText = "As long as an opponent controls more lands than you, you may play lands from the top of your library.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +70,9 @@ class VergeRangersEffect extends PlayTheTopCardEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
|
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
|
||||||
if (super.applies(objectId, affectedAbility, source, game, playerId)) {
|
if (super.applies(objectId, affectedAbility, source, game, playerId)) {
|
||||||
int myLandCount = game.getBattlefield().countAll(FILTER_LAND, playerId, game);
|
int myLandCount = game.getBattlefield().countAll(StaticFilters.FILTER_LAND, playerId, game);
|
||||||
int maxOpponentLandCount = game.getOpponents(playerId).stream()
|
int maxOpponentLandCount = game.getOpponents(playerId).stream()
|
||||||
.map(opponentId -> game.getBattlefield().countAll(FILTER_LAND, opponentId, game))
|
.map(opponentId -> game.getBattlefield().countAll(StaticFilters.FILTER_LAND, opponentId, game))
|
||||||
.max(Comparator.naturalOrder())
|
.max(Comparator.naturalOrder())
|
||||||
.orElse(0);
|
.orElse(0);
|
||||||
return maxOpponentLandCount > myLandCount;
|
return maxOpponentLandCount > myLandCount;
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class SanctuaryBladeTest extends CardTestPlayerBase {
|
||||||
assertAllCommandsUsed();
|
assertAllCommandsUsed();
|
||||||
|
|
||||||
assertPowerToughness(playerA, "Savai Sabertooth", 5, 1);
|
assertPowerToughness(playerA, "Savai Sabertooth", 5, 1);
|
||||||
assertAbility(playerA, "Savai Sabertooth", new ProtectionAbility(new FilterCard("Black")), true);
|
assertAbility(playerA, "Savai Sabertooth", new ProtectionAbility(new FilterCard("black")), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,19 +13,21 @@ import static mage.constants.CardType.CREATURE;
|
||||||
*
|
*
|
||||||
* @author htrajan
|
* @author htrajan
|
||||||
*/
|
*/
|
||||||
public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl {
|
public class AttachedToCreatureSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
public AttachedToCreatureTriggeredAbility(Effect effect, boolean optional) {
|
public AttachedToCreatureSourceTriggeredAbility(Effect effect, boolean optional) {
|
||||||
super(Zone.BATTLEFIELD, effect, optional);
|
super(Zone.BATTLEFIELD, effect, optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AttachedToCreatureTriggeredAbility(final AttachedToCreatureTriggeredAbility ability) {
|
public AttachedToCreatureSourceTriggeredAbility(final AttachedToCreatureSourceTriggeredAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkEventType(GameEvent event, Game game) {
|
public boolean checkEventType(GameEvent event, Game game) {
|
||||||
return event.getType() == GameEvent.EventType.ATTACHED && event.getSourceId().equals(this.getSourceId());
|
return event.getType() == GameEvent.EventType.ATTACHED
|
||||||
|
&& event.getSourceId() != null
|
||||||
|
&& event.getSourceId().equals(this.getSourceId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +42,7 @@ public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttachedToCreatureTriggeredAbility copy() {
|
public AttachedToCreatureSourceTriggeredAbility copy() {
|
||||||
return new AttachedToCreatureTriggeredAbility(this);
|
return new AttachedToCreatureSourceTriggeredAbility(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,67 +0,0 @@
|
||||||
|
|
||||||
package mage.abilities.effects.common.continuous;
|
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.abilities.keyword.ProtectionAbility;
|
|
||||||
import mage.choices.ChoiceColor;
|
|
||||||
import mage.constants.Duration;
|
|
||||||
import mage.filter.FilterCard;
|
|
||||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.permanent.Permanent;
|
|
||||||
import mage.players.Player;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author htrajan
|
|
||||||
*/
|
|
||||||
public class GainProtectionFromColorAttachedEffect extends GainAbilitySourceEffect {
|
|
||||||
|
|
||||||
FilterCard protectionFilter;
|
|
||||||
|
|
||||||
public GainProtectionFromColorAttachedEffect(Duration duration) {
|
|
||||||
super(new ProtectionAbility(new FilterCard()), duration);
|
|
||||||
protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GainProtectionFromColorAttachedEffect(final GainProtectionFromColorAttachedEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
this.protectionFilter = effect.protectionFilter.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GainProtectionFromColorAttachedEffect copy() {
|
|
||||||
return new GainProtectionFromColorAttachedEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Ability source, Game game) {
|
|
||||||
super.init(source, game);
|
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
|
||||||
if (controller != null) {
|
|
||||||
ChoiceColor colorChoice = new ChoiceColor(true);
|
|
||||||
colorChoice.setMessage("Choose color for protection ability");
|
|
||||||
if (controller.choose(outcome, colorChoice, game)) {
|
|
||||||
game.informPlayers("Choosen color: " + colorChoice.getColor());
|
|
||||||
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
|
|
||||||
protectionFilter.setMessage(colorChoice.getChoice());
|
|
||||||
((ProtectionAbility) ability).setFilter(protectionFilter);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
discard();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
|
||||||
if (permanent != null && permanent.getAttachedTo() != null) {
|
|
||||||
Permanent attachedPermanent = game.getPermanent(permanent.getAttachedTo());
|
|
||||||
attachedPermanent.addAbility(ability, source.getSourceId(), game);
|
|
||||||
} else {
|
|
||||||
// the source permanent is no longer on the battlefield, or it is not attached -- effect can be discarded
|
|
||||||
discard();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue